@@ -17,7 +17,7 @@ import Control.Exception (try, SomeException)
1717import Test.Hspec
1818
1919import qualified Data.Yaml as D
20−import Data.Yaml (object, array)
20+import Data.Yaml (object, array, (.=))
2121import Data.Maybe
2222import qualified Data.HashMap.Strict as M
2323import qualified Data.Text as T
@@ -68,6 +68,31 @@ main = hspec $ do
6868 checkNull "NULL"
6969 checkNull "~"
7070 checkNull ""
71+ describe "pretty output" $ do
72+ it "simple nulls" $ D.encode (object ["foo" .= D.Null]) `shouldBe` "foo: null\n"
73+ it "simple numbers" $ D.encode (object ["foo" .= (4 :: Int)]) `shouldBe` "foo: 4\n"
74+ it "True" $ D.encode (object ["foo" .= True]) `shouldBe` "foo: true\n"
75+ it "False" $ D.encode (object ["foo" .= False]) `shouldBe` "foo: false\n"
76+ it "simple string" $ D.encode (object ["foo" .= ("bar" :: T.Text)]) `shouldBe` "foo: bar\n"
77+ describe "special keys" $ do
78+ let tester key = it (T.unpack key) $
79+ let value = object [key .= True]
80+ in D.decode (D.encode value) `shouldBe` Just value
81+ mapM_ tester specialStrings
82+ describe "special values" $ do
83+ let tester value = it (T.unpack value) $
84+ let value' = object ["foo" .= value]
85+ in D.decode (D.encode value') `shouldBe` Just value'
86+ mapM_ tester specialStrings
87+
88+specialStrings :: [T.Text]
89+specialStrings =
90+ [ "fo\"o"
91+ , "fo\'o"
92+ , "fo\\'o"
93+ , "fo: o"
94+ , "foo\nbar\nbaz\n"
95+ ]
7196
7297counter :: Monad m => (Y.Event -> Bool) -> C.Sink Y.Event m Int
7398counter pred' =