interpolate 0.1.0 → 0.1.1
raw patch · 8 files changed
+255/−20 lines, 8 filesdep ~haskell-src-metaPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: haskell-src-meta
API changes (from Hackage documentation)
Files
- LICENSE +1/−1
- interpolate.cabal +35/−18
- src/Data/String/Interpolate.hs +1/−1
- test/Data/String/Interpolate/Internal/UtilSpec.hs +84/−0
- test/Data/String/Interpolate/IsStringSpec.hs +19/−0
- test/Data/String/Interpolate/ParseSpec.hs +26/−0
- test/Data/String/Interpolate/UtilSpec.hs +55/−0
- test/Data/String/InterpolateSpec.hs +34/−0
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2013 Simon Hengel <sol@typeful.net>+Copyright (c) 2013-2015 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
interpolate.cabal view
@@ -1,12 +1,18 @@+-- This file has been generated from package.yaml by hpack version 0.17.0.+--+-- see: https://github.com/sol/hpack+ name: interpolate-version: 0.1.0+version: 0.1.1+homepage: https://github.com/sol/interpolate#readme+bug-reports: https://github.com/sol/interpolate/issues license: MIT license-file: LICENSE-copyright: (c) 2013 Simon Hengel+copyright: (c) 2013-2015 Simon Hengel author: Simon Hengel <sol@typeful.net> maintainer: Simon Hengel <sol@typeful.net> build-type: Simple-cabal-version: >= 1.8+cabal-version: >= 1.10 category: Data, Text stability: experimental synopsis: String interpolation done right@@ -17,8 +23,6 @@ location: https://github.com/sol/interpolate library- ghc-options:- -Wall hs-source-dirs: src exposed-modules:@@ -26,30 +30,43 @@ Data.String.Interpolate.IsString Data.String.Interpolate.Util other-modules:+ Data.String.Interpolate.Compat Data.String.Interpolate.Internal.Util Data.String.Interpolate.Parse- Data.String.Interpolate.Compat+ Paths_interpolate build-depends:- base == 4.*+ base == 4.* , template-haskell- , haskell-src-meta+ , haskell-src-meta >= 0.8+ ghc-options: -Wall+ default-language: Haskell2010 test-suite spec- type:- exitcode-stdio-1.0- ghc-options:- -Wall+ type: exitcode-stdio-1.0 hs-source-dirs:- src, test- main-is:- Spec.hs+ src+ test+ main-is: Spec.hs+ other-modules:+ Data.String.Interpolate+ Data.String.Interpolate.Compat+ Data.String.Interpolate.Internal.Util+ Data.String.Interpolate.IsString+ Data.String.Interpolate.Parse+ Data.String.Interpolate.Util+ Data.String.Interpolate.Internal.UtilSpec+ Data.String.Interpolate.IsStringSpec+ Data.String.Interpolate.ParseSpec+ Data.String.Interpolate.UtilSpec+ Data.String.InterpolateSpec build-depends:- base == 4.*+ base == 4.* , template-haskell- , haskell-src-meta-+ , haskell-src-meta >= 0.8 , text , bytestring , hspec >= 1.5 , QuickCheck , quickcheck-instances+ ghc-options: -Wall+ default-language: Haskell2010
src/Data/String/Interpolate.hs view
@@ -11,7 +11,7 @@ ) where import Language.Haskell.TH.Quote (QuasiQuoter(..))-import Language.Haskell.Meta.Parse.Careful (parseExp)+import Language.Haskell.Meta.Parse (parseExp) import Data.String.Interpolate.Internal.Util import Data.String.Interpolate.Parse
+ test/Data/String/Interpolate/Internal/UtilSpec.hs view
@@ -0,0 +1,84 @@+{-# LANGUAGE CPP #-}+module Data.String.Interpolate.Internal.UtilSpec where++import Test.Hspec+import Test.QuickCheck+import Test.QuickCheck.Instances ()++import qualified Data.Text as T+import qualified Data.Text.Lazy as LT+import qualified Data.ByteString.Char8 as B+import qualified Data.ByteString.Lazy.Char8 as LB++import Data.String.Interpolate.Internal.Util++main :: IO ()+main = hspec spec++spec :: Spec+spec = do+ describe "toString" $ do+ it "behaves like `show`" $ do+ property $ \n -> toString (n :: Int) `shouldBe` show n++ context "when used with String" $ do+ it "behaves like `id`" $ do+ property $ \s -> toString s `shouldBe` s++ context "when used with Text" $ do+ it "behaves like `unpack`" $ do+ property $ \s -> toString s `shouldBe` T.unpack s++ context "when used with lazy Text" $ do+ it "behaves like `unpack`" $ do+ property $ \s -> toString s `shouldBe` LT.unpack s++ context "when used with ByteString" $ do+ it "behaves like `unpack`" $ do+ property $ \s -> toString s `shouldBe` B.unpack s++ context "when used with lazy ByteString" $ do+ it "behaves like `unpack`" $ do+ property $ \s -> do+#if __GLASGOW_HASKELL__ < 706+ pendingWith "Does not work with GHC < 7.6"+#endif+ toString s `shouldBe` LB.unpack s++ describe "unescape" $ do+ it "unescapes single-character escape codes" $ do+ unescape "\\n" `shouldBe` "\n"++ it "unescapes ASCII control code abbreviations" $ do+ unescape "\\BEL" `shouldBe` "\BEL"++ it "unescapes decimal character literals" $ do+ unescape "\\955" `shouldBe` "\955"++ it "unescapes hexadecimal character literals" $ do+ unescape "\\xbeef" `shouldBe` "\xbeef"++ it "unescapes octal character literals" $ do+ unescape "\\o1234" `shouldBe` "\o1234"++ context "with control escape sequences" $ do+ it "unescapes null character" $ do+ unescape "\\^@" `shouldBe` "\^@"++ it "unescapes control codes" $ do+ unescape "\\^A" `shouldBe` "\^A"++ it "unescapes escape" $ do+ unescape "\\^[" `shouldBe` "\^["++ it "unescapes file separator" $ do+ unescape "\\^\\ x" `shouldBe` "\^\ x"++ it "unescapes group separator" $ do+ unescape "\\^]" `shouldBe` "\^]"++ it "unescapes record separator" $ do+ unescape "\\^^" `shouldBe` "\^^"++ it "unescapes unit separator" $ do+ unescape "\\^_" `shouldBe` "\^_"
+ test/Data/String/Interpolate/IsStringSpec.hs view
@@ -0,0 +1,19 @@+{-# LANGUAGE QuasiQuotes #-}+module Data.String.Interpolate.IsStringSpec (main, spec) where++import Test.Hspec++import qualified Data.Text as T+import Data.String.Interpolate.IsString++main :: IO ()+main = hspec spec++spec :: Spec+spec = do+ describe "[i|...|]" $ do+ it "can be used to construct String literals" $ do+ [i|foo #{23 :: Int} bar|] `shouldBe` "foo 23 bar"++ it "can be used to construct Text literals" $ do+ [i|foo #{23 :: Int} bar|] `shouldBe` T.pack "foo 23 bar"
+ test/Data/String/Interpolate/ParseSpec.hs view
@@ -0,0 +1,26 @@+{-# LANGUAGE StandaloneDeriving #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}+module Data.String.Interpolate.ParseSpec (main, spec) where++import Test.Hspec++import Data.String.Interpolate.Parse++deriving instance Eq Node+deriving instance Show Node++main :: IO ()+main = hspec spec++spec :: Spec+spec = do+ describe "parseNodes" $ do+ it "parses string literals" $ do+ parseNodes "foo" `shouldBe` [Literal "foo"]++ it "parses embedded expressions" $ do+ parseNodes "foo #{bar} baz" `shouldBe` [Literal "foo ", Expression "bar", Literal " baz"]++ context "when given an unterminated expression" $ do+ it "parses it as a string literal" $ do+ parseNodes "foo #{bar" `shouldBe` [Literal "foo #{bar"]
+ test/Data/String/Interpolate/UtilSpec.hs view
@@ -0,0 +1,55 @@+module Data.String.Interpolate.UtilSpec (main, spec) where++import Test.Hspec+import Test.QuickCheck+import Control.Applicative++import Data.String.Interpolate.Util++main :: IO ()+main = hspec spec++emptyLine :: Gen String+emptyLine = (++ "\n") <$> listOf (elements " \t")++spec :: Spec+spec = do+ describe "unindent" $ do+ it "removes indentation" $ do+ let xs = " foo\n bar\n baz \n"+ unindent xs `shouldBe` " foo\nbar\n baz \n"++ it "removes the first line of the string if it is empty" $ do+ forAll emptyLine $ \xs -> do+ let ys = " foo\nbar\n baz\n"+ unindent (xs ++ ys) `shouldBe` ys++ it "does not affect additional empty lines at the beginning" $ do+ unindent " \n \nfoo" `shouldBe` " \nfoo"++ it "empties the last line if it only consists of spaces" $ do+ let xs = "foo\n "+ unindent xs `shouldBe` "foo\n"++ it "does not affect other whitespace lines at the end" $ do+ unindent "foo\n \n " `shouldBe` "foo\n \n"++ it "disregards empty lines when calculating indentation" $ do+ let xs = " foo\n\n \n bar\n"+ unindent xs `shouldBe` "foo\n\n\nbar\n"++ it "correctly handles strings that do not end with a newline" $ do+ let xs = "foo"+ unindent xs `shouldBe` xs++ it "does not affect lines consisting of whitespace (apart from unindenting)" $ do+ unindent " foo\n \n bar" `shouldBe` "foo\n \nbar"++ it "is total" $ do+ property $ \xs -> length (unindent xs) `shouldSatisfy` (>= 0)++ context "when all lines are empty" $ do+ it "does not unindent at all" $ do+ forAll emptyLine $ \x -> (forAll $ listOf emptyLine) $ \xs -> do+ let ys = concat xs+ unindent (x ++ ys) `shouldBe` ys
+ test/Data/String/InterpolateSpec.hs view
@@ -0,0 +1,34 @@+{-# LANGUAGE QuasiQuotes #-}+module Data.String.InterpolateSpec (main, spec) where++import Test.Hspec+import Test.QuickCheck++import Data.String.Interpolate++main :: IO ()+main = hspec spec++spec :: Spec+spec = do+ describe "[i|...|]" $ do+ it "interpolates an expression of type Int" $ do+ property $ \x y -> [i|foo #{x + y :: Int} bar|] `shouldBe` "foo " ++ show (x + y) ++ " bar"++ it "interpolates an expression of type String" $ do+ property $ \xs ys -> [i|foo #{xs ++ ys} bar|] `shouldBe` "foo " ++ xs ++ ys ++ " bar"++ it "accepts character escapes" $ do+ [i|foo \955 bar|] `shouldBe` "foo \955 bar"++ it "accepts character escapes in interpolated expressions" $ do+ [i|foo #{"\955" :: String} bar|] `shouldBe` "foo \955 bar"++ it "dose not strip backslashes (issue #1)" $ do+ [i|foo\\bar|] `shouldBe` "foo\\bar"++ it "allows to prevent interpolation by escaping the hash with a backslash" $ do+ [i|foo \#{23 :: Int} bar|] `shouldBe` "foo #{23 :: Int} bar"++ it "does not prevent interpolation on literal backslash" $ do+ [i|foo \\#{23 :: Int} bar|] `shouldBe` "foo \\23 bar"