on master help sign in
Strip aliases #27
1343cf4Michael Snoyman
Data/Yaml.hs+3−3
@@ -260,11 +260,11 @@ parseM a front = do
260 let al = M.insert s o front
260 let al = M.insert s o front
261 al' = if s == pack "<<"
261 al' = if s == pack "<<"
262 then case o of
262 then case o of
263− Object l -> M.union al l
263+ Object l -> M.union front l
264− Array l -> M.union al $ foldl merge' M.empty $ V.toList l
264+ Array l -> M.union front $ foldl merge' M.empty $ V.toList l
265 _ -> al
265 _ -> al
266 else al
266 else al
267− parseM a $ M.insert s o al'
267+ parseM a al'
268 where merge' al (Object om) = M.union al om
268 where merge' al (Object om) = M.union al om
269 merge' al _ = al
269 merge' al _ = al
270
270
test/main.hs+18
@@ -62,6 +62,8 @@ 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 "alias stripping" $ do
66+ it "works" caseStripAlias
65 describe "nulls" $ do
67 describe "nulls" $ do
66 checkNull "null"
68 checkNull "null"
67 checkNull "Null"
69 checkNull "Null"
@@ -365,3 +367,19 @@ checkNull x =
365 it ("null recognized: " ++ show x) assertion
367 it ("null recognized: " ++ show x) assertion
366 where
368 where
367 assertion = Just (object [("foo", D.Null)]) @=? D.decode (B8.pack $ "foo: " ++ T.unpack x)
369 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 @@
1name: yaml
1name: yaml
2−version: 0.8.4
2+version: 0.8.4.1
3license: BSD3
3license: BSD3
4license-file: LICENSE
4license-file: LICENSE
5author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov
5author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov