on de41665 help sign in
typeable/yaml/test/Data/Yaml/IncludeSpec.hs
44 lines 1.2 kB history raw
1{-# LANGUAGE QuasiQuotes #-}
2module Data.Yaml.IncludeSpec (main, spec) where
4import Test.Hspec
5import Data.Either.Compat
6import Data.Aeson
7import Data.Aeson.QQ
8import Data.Yaml (ParseException)
10import Data.Yaml.Include
12main :: IO ()
13main = hspec spec
15spec :: Spec
16spec = do
17 describe "decodeFile" $ do
18 it "supports includes" $ do
19 decodeFile "test/resources/foo.yaml" `shouldReturn` Just [aesonQQ|
20 {
21 foo: 23,
22 bar: {one: 1, two: 2},
23 baz: 42
24 }
25 |]
27 it "supports recursive includes" $ do
28 decodeFile "test/resources/baz.yaml" `shouldReturn` Just [aesonQQ|
29 {
30 foo: {
31 foo: 23,
32 bar: {one: 1, two: 2},
33 baz: 42
34 }
35 }
36 |]
38 it "aborts on cyclic includes" $ do
39 (decodeFile "test/resources/loop/foo.yaml" :: IO (Maybe Value)) `shouldThrow` anyException
41 describe "decodeFileEither" $ do
42 context "when file does not exist" $ do
43 it "returns Left" $ do
44 (decodeFileEither "./does_not_exist.yaml" :: IO (Either ParseException Value)) >>= (`shouldSatisfy` isLeft)