marvin-interpolate 1.1.1 → 1.1.2
raw patch · 3 files changed
+18/−13 lines, 3 filesdep ~haskell-src-metadep ~marvin-interpolatePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: haskell-src-meta, marvin-interpolate
API changes (from Hackage documentation)
Files
- marvin-interpolate.cabal +2/−2
- src/Marvin/Interpolate.hs +5/−0
- test/Spec.hs +11/−11
marvin-interpolate.cabal view
@@ -1,5 +1,5 @@ name: marvin-interpolate-version: 1.1.1+version: 1.1.2 synopsis: Compile time string interpolation a la Scala and CoffeeScript description: The documentation can be found on readthedocs <https://marvin.readthedocs.io/en/latest/interpolation.html> homepage: http://marvin.readthedocs.io/en/latest/interpolation.html@@ -39,7 +39,7 @@ hs-source-dirs: test main-is: Spec.hs build-depends: base >= 4.7 && < 5- , marvin-interpolate >= 1.0+ , marvin-interpolate , hspec >= 2 , text >= 1.0 ghc-options: -threaded -rtsopts -with-rtsopts=-N
src/Marvin/Interpolate.hs view
@@ -10,6 +10,7 @@ Please refer to the documentation at https://marvin.readthedocs.io/en/latest/interpolation.html for examples and explanations on how to use this library. -} {-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE CPP #-} module Marvin.Interpolate ( is , iq@@ -23,7 +24,11 @@ import Data.Either import Data.List (intercalate) import Data.Monoid+#if __GLASGOW_HASKELL__ < 704 import Language.Haskell.Meta.Parse.Careful+#else+import Language.Haskell.Meta.Parse+#endif import Language.Haskell.TH import Language.Haskell.TH.Quote import Text.Parsec
test/Spec.hs view
@@ -29,47 +29,47 @@ main = hspec $ do describe "parsing to itself" $ do it "#" $- [iq|#|] `shouldBe` "#"+ [iq|#|] `shouldBe` ("#" :: String) it "#anything" $- [iq|#anything|] `shouldBe` "#anything"+ [iq|#anything|] `shouldBe` ("#anything" :: String) describe "general parsing" $ do it "allows primes in at the end of binding names" $- let x' = "str" in [iq|Hello #{x'}|] `shouldBe` "Hello str"+ let x' = "str" in [iq|Hello #{x'}|] `shouldBe` ("Hello str" :: String) it "allows primes in the middle of binding names" $ let isn't = 5 :: Int in $(isS "Hello #{isn't}") `shouldBe` "Hello 5" describe "parsing escape sequences" $ it "parses ## as #" $- [iq|##|] `shouldBe` "#"+ [iq|##|] `shouldBe` ("#" :: String) describe "interpolation substitution" $ do it "leaves an empty string" $- [iq||] `shouldBe` ""+ [iq||] `shouldBe` ("" :: String) it "returns a string unchanged if no variable is in it" $- [iq|this is not changed|] `shouldBe` "this is not changed"+ [iq|this is not changed|] `shouldBe` ("this is not changed" :: String) it "interpolates just an external variable" $- let y = "str" in+ let y = "str" :: String in [iq|#{y}|] `shouldBe` y it "interpolates an external variable" $- let y = "str2" in [iq| hello you #{y} end|] `shouldBe` " hello you " ++ y ++ " end"+ let y = "str2" :: String in [iq| hello you #{y} end|] `shouldBe` " hello you " ++ y ++ " end" it "interpolates the variable x (used to be special)" $- let x = "str" in [iq| hello x: #{x}|] `shouldBe` " hello x: " ++ x+ let x = "str" :: String in [iq| hello x: #{x}|] `shouldBe` " hello x: " ++ x it "interpolates infix with $" $ [iq|str #{show $ 4 + (5 :: Int)} str|] `shouldBe` "str 9 str" it "interpolates multiple bindings" $ let x = "multiple" y = "can"- z = "local scope"+ z = "local scope" :: String in [iq|We #{y} interpolate #{x} bindings from #{z}|] `shouldBe` "We can interpolate multiple bindings from local scope" it "interpolates complex expressions" $ let x = ["haskell", "expression"]- y = " can be"+ y = " can be" :: String in [iq|Any #{intercalate " " x ++ y} interpolated|] `shouldBe` "Any haskell expression can be interpolated"