on master help sign in
Recognizes all null formats (#21)
commit1eea9e34954b3ff2e52885ead5d8ceeedf7a4d08 authorMichael Snoyman <michael@snoyman.com> dateSat 22 Dec 2012, 21:07 (14 years ago) parentefe39e3
2 files changed+13−1
Data/Yaml.hs+1−1 test/main.hs+12
Data/Yaml.hs+1−1
@@ -182,8 +182,8 @@ textToValue SingleQuoted _ t = String t
182182textToValue DoubleQuoted _ t = String t
183183textToValue _ StrTag t = String t
184184textToValue Folded _ t = String t
185−textToValue _ _ "null" = Null
186185textToValue _ _ t
186+ | t `elem` ["null", "Null", "NULL", "~", ""] = Null
187187 | any (t `isLike`) ["y", "yes", "on", "true"] = Bool True
188188 | any (t `isLike`) ["n", "no", "off", "false"] = Bool False
189189 | Right (x, "") <- signed decimal t = Number $ I x
test/main.hs+12
@@ -62,6 +62,12 @@ main = hspec $ do
6262 it "parses when titlecase" caseTitlecaseBool
6363 describe "empty input" $ do
6464 it "doesn't crash" caseEmptyInput
65+ describe "nulls" $ do
66+ checkNull "null"
67+ checkNull "Null"
68+ checkNull "NULL"
69+ checkNull "~"
70+ checkNull ""
6571
6672counter :: Monad m => (Y.Event -> Bool) -> C.Sink Y.Event m Int
6773counter pred' =
@@ -326,3 +332,9 @@ caseTitlecaseBool = D.decode "foo: No\nbar: Yes\nbaz: True" @?= obj
326332
327333caseEmptyInput :: Assertion
328334caseEmptyInput = D.decode B8.empty @?= (Nothing :: Maybe D.Value)
335+
336+checkNull :: T.Text -> Spec
337+checkNull x =
338+ it ("null recognized: " ++ show x) assertion
339+ where
340+ assertion = Just (object [("foo", D.Null)]) @=? D.decode (B8.pack $ "foo: " ++ T.unpack x)