on master help sign in
Recognizes all null formats (#21)
1eea9e3Michael Snoyman
Data/Yaml.hs+1−1
@@ -182,8 +182,8 @@ textToValue SingleQuoted _ t = String t
182textToValue DoubleQuoted _ t = String t
182textToValue DoubleQuoted _ t = String t
183textToValue _ StrTag t = String t
183textToValue _ StrTag t = String t
184textToValue Folded _ t = String t
184textToValue Folded _ t = String t
185−textToValue _ _ "null" = Null
186textToValue _ _ t
185textToValue _ _ t
186+ | t `elem` ["null", "Null", "NULL", "~", ""] = Null
187 | any (t `isLike`) ["y", "yes", "on", "true"] = Bool True
187 | any (t `isLike`) ["y", "yes", "on", "true"] = Bool True
188 | any (t `isLike`) ["n", "no", "off", "false"] = Bool False
188 | any (t `isLike`) ["n", "no", "off", "false"] = Bool False
189 | Right (x, "") <- signed decimal t = Number $ I x
189 | Right (x, "") <- signed decimal t = Number $ I x
test/main.hs+12
@@ -62,6 +62,12 @@ main = hspec $ do
62 it "parses when titlecase" caseTitlecaseBool
62 it "parses when titlecase" caseTitlecaseBool
63 describe "empty input" $ do
63 describe "empty input" $ do
64 it "doesn't crash" caseEmptyInput
64 it "doesn't crash" caseEmptyInput
65+ describe "nulls" $ do
66+ checkNull "null"
67+ checkNull "Null"
68+ checkNull "NULL"
69+ checkNull "~"
70+ checkNull ""
65
71
66counter :: Monad m => (Y.Event -> Bool) -> C.Sink Y.Event m Int
72counter :: Monad m => (Y.Event -> Bool) -> C.Sink Y.Event m Int
67counter pred' =
73counter pred' =
@@ -326,3 +332,9 @@ caseTitlecaseBool = D.decode "foo: No\nbar: Yes\nbaz: True" @?= obj
326
332
327caseEmptyInput :: Assertion
333caseEmptyInput :: Assertion
328caseEmptyInput = D.decode B8.empty @?= (Nothing :: Maybe D.Value)
334caseEmptyInput = 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)