yaml 0.8.27 → 0.8.28
raw patch · 5 files changed
+79/−16 lines, 5 filesdep ~aesondep ~template-haskell
Dependency ranges changed: aeson, template-haskell
Files
- ChangeLog.md +4/−0
- Data/Yaml/TH.hs +48/−6
- test/Data/Yaml/THSpec.hs +17/−0
- test/Data/YamlSpec.hs +6/−6
- yaml.cabal +4/−4
ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.8.28++* Add `Data.Yaml.TH.yamlQQ`+ ## 0.8.27 * Support conduit 1.3
Data/Yaml/TH.hs view
@@ -1,10 +1,13 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE TemplateHaskell #-} module Data.Yaml.TH ( -- * Decoding- decodeFile+ yamlQQ+#if MIN_VERSION_template_haskell(2,9,0)+ , decodeFile+#endif -- * Re-exports from "Data.Yaml" , Value (..) , Parser@@ -19,11 +22,16 @@ , FromJSON (..) ) where -import Data.Yaml hiding (decodeFile)-import Language.Haskell.TH-import Language.Haskell.TH.Syntax+import Data.Text.Encoding+import qualified Data.Text as T+import Language.Haskell.TH+import Language.Haskell.TH.Syntax+import Language.Haskell.TH.Quote --- | Decode a @yaml@ file at compile time. Only available on GHC version @7.8.1@+import Data.Yaml hiding (decodeFile)++#if MIN_VERSION_template_haskell(2,9,0)+-- | Decode a YAML file at compile time. Only available on GHC version @7.8.1@ -- or higher. -- -- @since 0.8.19.0@@ -42,3 +50,37 @@ runIO (decodeFileEither path) >>= \case Left err -> fail (prettyPrintParseException err) Right x -> fmap TExp (lift (x :: a))+#endif++decodeValue :: String -> Either String Value+decodeValue = decodeEither . encodeUtf8 . T.pack++yamlExp :: String -> Q Exp+yamlExp input = case decodeValue input of+ Left err -> fail err+ Right a -> lift a++-- | A @QuasiQuoter@ for YAML.+--+-- @since 0.8.28.0+--+-- ==== __Examples__+--+-- @+-- {-\# LANGUAGE QuasiQuotes \#-}+-- import Data.Yaml.TH+--+-- value :: Value+-- value = [yamlQQ|+-- name: John Doe+-- age: 23+-- |]+-- @+yamlQQ :: QuasiQuoter+yamlQQ = QuasiQuoter {+ quoteExp = yamlExp+, quotePat = notDefined "quotePat"+, quoteType = notDefined "quoteType"+, quoteDec = notDefined "quoteDec"+} where+ notDefined name _ = fail (name ++ " is not defined for yamlQQ")
+ test/Data/Yaml/THSpec.hs view
@@ -0,0 +1,17 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE QuasiQuotes #-}+module Data.Yaml.THSpec (spec) where++import Test.Hspec+import Data.Aeson++import Data.Yaml.TH++spec :: Spec+spec = do+ describe "yamlQQ" $ do+ it "parses yaml" $ do+ [yamlQQ|+ name: John Doe+ age: 23+ |] `shouldBe` object ["name" .= String "John Doe", "age" .= Number 23]
test/Data/YamlSpec.hs view
@@ -337,12 +337,12 @@ out1 <- D.decodeFile "accenté/bar.yaml" out1 @?= Just mySample - createDirectoryIfMissing True "test/resources/unicode/accenté/"-- readFile "test/resources/accent/foo.yaml" >>=- writeFile "test/resources/unicode/accenté/foo.yaml"- out2 <- D.decodeFile "test/resources/unicode/accenté/foo.yaml"- out2 @?= Just mySample+ c <- readFile "test/resources/accent/foo.yaml"+ inTempDirectory $ do+ createDirectoryIfMissing True "test/resources/unicode/accenté/"+ writeFile "test/resources/unicode/accenté/foo.yaml" c+ out2 <- D.decodeFile "test/resources/unicode/accenté/foo.yaml"+ out2 @?= Just mySample caseEncodeDecodeStrings :: Assertion caseEncodeDecodeStrings = do
yaml.cabal view
@@ -1,5 +1,5 @@ name: yaml-version: 0.8.27+version: 0.8.28 license: BSD3 license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov@@ -60,6 +60,7 @@ , filepath , directory , semigroups+ , template-haskell exposed-modules: Text.Libyaml Data.Yaml Data.Yaml.Aeson@@ -68,9 +69,7 @@ Data.Yaml.Include Data.Yaml.Parser Data.Yaml.Pretty- if impl(ghc >= 7.8.1)- build-depends: template-haskell >= 2.8.0.0- exposed-modules: Data.Yaml.TH+ Data.Yaml.TH other-modules: Data.Yaml.Internal ghc-options: -Wall@@ -126,6 +125,7 @@ main-is: Spec.hs other-modules: Data.YamlSpec Data.Yaml.IncludeSpec+ Data.Yaml.THSpec cpp-options: -DTEST build-depends: hspec >= 1.3 , HUnit