packages feed

stringbuilder (empty) → 0.1.0

raw patch · 5 files changed

+125/−0 lines, 5 filesdep +basedep +hspec-shouldbedep +transformerssetup-changed

Dependencies added: base, hspec-shouldbe, transformers

Files

+ LICENSE view
@@ -0,0 +1,19 @@+Copyright (c) 2011, 2012 Simon Hengel <sol@typeful.net>++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ Setup.lhs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain
+ src/Data/String/Builder.hs view
@@ -0,0 +1,38 @@+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+-- |+-- `build` can be used to construct multi-line string literals in a monadic+-- way.+--+-- > {-# LANGUAGE OverloadedStrings #-}+-- >+-- > import Data.String.Builder+-- >+-- > mystring :: String+-- > mystring = build $ do+-- >   "foo"+-- >   "bar"+-- >   "baz"+--+-- `return` and `>>=` are not useful in this context!+module Data.String.Builder (build, Builder) where++import Prelude hiding (undefined)+import Data.String+import Control.Monad.Trans.Writer++undefined :: a+undefined = error "Data.String.Builder.undefined"++newtype BuilderM a = BuilderM { runBuilderM :: Writer String a }+  deriving Monad++type Builder = BuilderM ()++literal :: String -> Builder+literal = BuilderM . tell++instance IsString (BuilderM a) where+  fromString s = literal s >> literal "\n" >> return undefined++build :: Builder -> String+build = snd . runWriter . runBuilderM
+ stringbuilder.cabal view
@@ -0,0 +1,41 @@+name:             stringbuilder+version:          0.1.0+synopsis:         A monadic builder for multi-line string literals+description:      <https://github.com/sol/stringbuilder#readme>+category:         Testing+license:          MIT+license-file:     LICENSE+copyright:        (c) 2011, 2012 Simon Hengel+author:           Simon Hengel <sol@typeful.net>+maintainer:       Simon Hengel <sol@typeful.net>+build-type:       Simple+cabal-version:    >= 1.8++source-repository head+  type: git+  location: https://github.com/sol/stringbuilder++library+  ghc-options:+      -Wall+  hs-source-dirs:+      src+  build-depends:+      base < 5+    , transformers+  exposed-modules:+      Data.String.Builder++test-suite spec+  type:+      exitcode-stdio-1.0+  main-is:+      Spec.hs+  ghc-options:+      -Wall -Werror+  hs-source-dirs:+      src, test+  build-depends:+      base+    , transformers+    , hspec-shouldbe
+ test/Spec.hs view
@@ -0,0 +1,24 @@+{-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS_GHC -fno-warn-unused-do-bind #-}+module Main (main, spec) where++import           Test.Hspec.ShouldBe++import           Data.String+import           Data.String.Builder++main :: IO ()+main = hspecX spec++spec :: Specs+spec = do+  describe "build" $ do+    it "can be used to construct multi-line string literals in a monadic way" $ do+      build $ do+        "foo"+        "bar"+        "baz"+      `shouldBe` "foo\nbar\nbaz\n"++    prop "works for arbitrary input" $ do+      \l -> (build . sequence_ . map fromString) l == unlines l