on master help sign in
Strip aliases #27
commit1343cf41f2ed2736f9312b3f501527ff072e2f12 authorMichael Snoyman <michael@snoyman.com> dateMon 29 Jul 2013, 12:59 (13 years ago) parent8b565b3
3 files changed+22−4
Data/Yaml.hs+3−3 test/main.hs+18 yaml.cabal+1−1
Data/Yaml.hs+3−3
@@ -260,11 +260,11 @@ parseM a front = do
260260 let al = M.insert s o front
261261 al' = if s == pack "<<"
262262 then case o of
263− Object l -> M.union al l
264− Array l -> M.union al $ foldl merge' M.empty $ V.toList l
263+ Object l -> M.union front l
264+ Array l -> M.union front $ foldl merge' M.empty $ V.toList l
265265 _ -> al
266266 else al
267− parseM a $ M.insert s o al'
267+ parseM a al'
268268 where merge' al (Object om) = M.union al om
269269 merge' al _ = al
270270
test/main.hs+18
@@ -62,6 +62,8 @@ main = hspec $ do
6262 it "parses when titlecase" caseTitlecaseBool
6363 describe "empty input" $ do
6464 it "doesn't crash" caseEmptyInput
65+ describe "alias stripping" $ do
66+ it "works" caseStripAlias
6567 describe "nulls" $ do
6668 checkNull "null"
6769 checkNull "Null"
@@ -365,3 +367,19 @@ checkNull x =
365367 it ("null recognized: " ++ show x) assertion
366368 where
367369 assertion = Just (object [("foo", D.Null)]) @=? D.decode (B8.pack $ "foo: " ++ T.unpack x)
370+
371+caseStripAlias :: Assertion
372+caseStripAlias =
373+ D.decode src @?= Just (object
374+ [ "Default" .= object
375+ [ "foo" .= (1 :: Int)
376+ , "bar" .= (2 :: Int)
377+ ]
378+ , "Obj" .= object
379+ [ "foo" .= (1 :: Int)
380+ , "bar" .= (2 :: Int)
381+ , "key" .= (3 :: Int)
382+ ]
383+ ])
384+ where
385+ src = "Default: &def\n foo: 1\n bar: 2\nObj:\n <<: *def\n key: 3\n"
yaml.cabal+1−1
@@ -1,5 +1,5 @@
11name: yaml
2−version: 0.8.4
2+version: 0.8.4.1
33license: BSD3
44license-file: LICENSE
55author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov