@@ -73,9 +73,18 @@ shouldEmitWithTagsOn es expected = do
74 [Y.EventStreamStart, Y.EventDocumentStart] ++
74 [Y.EventStreamStart, Y.EventDocumentStart] ++
75 es ++ [Y.EventDocumentEnd, Y.EventStreamEnd]
75 es ++ [Y.EventDocumentEnd, Y.EventStreamEnd]
76− opts =
76+ opts = Y.setCollectionTagRendering Y.renderAll $ Y.defaultFormatOptions
77− Y.setMappingTagsExplicit True $
77+
78− Y.setSequenceTagsExplicit True $ Y.defaultFormatOptions
78+shouldEmitWithUriTagsOn :: [Y.Event] -> BS.ByteString -> IO ()
79+shouldEmitWithUriTagsOn es expected = do
80+ actual <- runConduitRes (CL.sourceList events .| Y.encodeWith opts)
81+ actual `shouldBe` expected
84+ [Y.EventStreamStart, Y.EventDocumentStart] ++
85+ es ++ [Y.EventDocumentEnd, Y.EventStreamEnd]
86+ opts = Y.setCollectionTagRendering Y.renderUriTags $ Y.defaultFormatOptions
80main :: IO ()
89main :: IO ()
81main = hspec spec
90main = hspec spec
@@ -227,85 +236,57 @@ spec = do
227 go "12.3015e+02" (1230.15 :: Scientific)
236 go "12.3015e+02" (1230.15 :: Scientific)
228 go "1230.15" (1230.15 :: Scientific)
237 go "1230.15" (1230.15 :: Scientific)
230− describe "Text.Libyaml with mapping and sequence tags off" $ do
239+ describe "Text.Libyaml with collection tags off" $ do
231 it "elides custom sequence tags" $
240 it "elides custom sequence tags" $
232− [ Y.EventSequenceStart (Y.UriTag "!foo") Y.FlowSequence Nothing
233− , Y.EventSequenceEnd
234− ] `shouldEmit` "[]\n"
241+ taggedSequence `shouldEmit` "[]\n"
235 it "elides custom mapping tags" $
242 it "elides custom mapping tags" $
236− [ Y.EventMappingStart (Y.UriTag "!foo") Y.FlowMapping Nothing
238− ] `shouldEmit` "{}\n"
243+ taggedMapping `shouldEmit` "{}\n"
239 it "elides default sequence tags" $
244 it "elides default sequence tags" $
240− [ Y.EventSequenceStart Y.SeqTag Y.FlowSequence Nothing
241− , Y.EventSequenceEnd
242− ] `shouldEmit` "[]\n"
245+ defaultTaggedSequence `shouldEmit` "[]\n"
243 it "elides default mapping tags" $
246 it "elides default mapping tags" $
244− [ Y.EventMappingStart Y.MapTag Y.FlowMapping Nothing
246− ] `shouldEmit` "{}\n"
247+ defaultTaggedMapping `shouldEmit` "{}\n"
247 it "handles NoTag on sequences" $
248 it "handles NoTag on sequences" $
248− [ Y.EventSequenceStart Y.NoTag Y.FlowSequence Nothing
249− , Y.EventSequenceEnd
250− ] `shouldEmit` "[]\n"
249+ untaggedSequence `shouldEmit` "[]\n"
251 it "handles NoTag on mappings" $
250 it "handles NoTag on mappings" $
252− [ Y.EventMappingStart Y.NoTag Y.FlowMapping Nothing
254− ] `shouldEmit` "{}\n"
251+ untaggedMapping `shouldEmit` "{}\n"
255 it "handles mixed tag usages but elides all mapping and sequence tags" $
252 it "handles mixed tag usages but elides all mapping and sequence tags" $
256− [ Y.EventSequenceStart Y.NoTag Y.BlockSequence Nothing
257− , Y.EventMappingStart (Y.UriTag "!foo") Y.FlowMapping Nothing
259− , Y.EventSequenceEnd
260− ] `shouldEmit` "- {}\n"
253+ mixedTagSampleA `shouldEmit` "- {}\n"
261 it "in combination of tags, anchors and styles, outputs only the scalar tags" $
254 it "in combination of tags, anchors and styles, outputs only the scalar tags" $
262− [ Y.EventMappingStart Y.NoTag Y.BlockMapping (Just "a")
263− , Y.EventScalar "foo" (Y.UriTag "bar") Y.Plain (Just "b")
264− , Y.EventSequenceStart (Y.UriTag "!baz") Y.FlowSequence (Just "c")
265− , Y.EventScalar "" Y.NullTag Y.Plain (Just "d")
266− , Y.EventSequenceEnd
268− ] `shouldEmit` "&a\n&b !<bar> foo: &c [&d !!null '']\n"
255+ mixedTagSampleB `shouldEmit` "&a\n&b !<bar> foo: &c [&d !!null '']\n"
269− describe "Text.Libyaml with mapping and sequence tags on" $ do
256+ describe "Text.Libyaml with collection tags on" $ do
270 it "will output custom sequence tags" $
257 it "will output custom sequence tags" $
271− [ Y.EventSequenceStart (Y.UriTag "!foo") Y.FlowSequence Nothing
272− , Y.EventSequenceEnd
273− ] `shouldEmitWithTagsOn` "!foo []\n"
258+ taggedSequence `shouldEmitWithTagsOn` "!foo []\n"
274 it "will output custom mapping tags" $
259 it "will output custom mapping tags" $
275− [ Y.EventMappingStart (Y.UriTag "!foo") Y.FlowMapping Nothing
277− ] `shouldEmitWithTagsOn` "!foo {}\n"
260+ taggedMapping `shouldEmitWithTagsOn` "!foo {}\n"
278 it "will output default sequence tags" $
261 it "will output default sequence tags" $
279− [ Y.EventSequenceStart Y.SeqTag Y.FlowSequence Nothing
280− , Y.EventSequenceEnd
281− ] `shouldEmitWithTagsOn` "!!seq []\n"
262+ defaultTaggedSequence `shouldEmitWithTagsOn` "!!seq []\n"
282 it "will output default mapping tags" $
263 it "will output default mapping tags" $
283− [ Y.EventMappingStart Y.MapTag Y.FlowMapping Nothing
285− ] `shouldEmitWithTagsOn` "!!map {}\n"
264+ defaultTaggedMapping `shouldEmitWithTagsOn` "!!map {}\n"
286 it "handles NoTag on sequences" $
265 it "handles NoTag on sequences" $
287− [ Y.EventSequenceStart Y.NoTag Y.FlowSequence Nothing
288− , Y.EventSequenceEnd
289− ] `shouldEmitWithTagsOn` "[]\n"
266+ untaggedSequence `shouldEmitWithTagsOn` "[]\n"
290 it "handles NoTag on mappings" $
267 it "handles NoTag on mappings" $
291− [ Y.EventMappingStart Y.NoTag Y.FlowMapping Nothing
293− ] `shouldEmitWithTagsOn` "{}\n"
268+ untaggedMapping `shouldEmitWithTagsOn` "{}\n"
294 it "handles mixed tag usages outputting all mapping and sequence tags" $
269 it "handles mixed tag usages outputting all mapping and sequence tags" $
295− [ Y.EventSequenceStart Y.NoTag Y.BlockSequence Nothing
296− , Y.EventMappingStart (Y.UriTag "!foo") Y.FlowMapping Nothing
298− , Y.EventSequenceEnd
299− ] `shouldEmitWithTagsOn` "- !foo {}\n"
270+ mixedTagSampleA `shouldEmitWithTagsOn` "- !foo {}\n"
300 it "in combination of tags, anchors and styles, outputs all the tags" $
271 it "in combination of tags, anchors and styles, outputs all the tags" $
301− [ Y.EventMappingStart Y.NoTag Y.BlockMapping (Just "a")
302− , Y.EventScalar "foo" (Y.UriTag "bar") Y.Plain (Just "b")
303− , Y.EventSequenceStart (Y.UriTag "!baz") Y.FlowSequence (Just "c")
304− , Y.EventScalar "" Y.NullTag Y.Plain (Just "d")
305− , Y.EventSequenceEnd
307− ] `shouldEmitWithTagsOn` "&a\n&b !<bar> foo: &c !baz [&d !!null '']\n"
272+ mixedTagSampleB `shouldEmitWithTagsOn` "&a\n&b !<bar> foo: &c !baz [&d !!null '']\n"
308−
273+ describe "Text.Libyaml with collection uri tags on" $ do
274+ it "will output custom sequence tags" $
275+ taggedSequence `shouldEmitWithUriTagsOn` "!foo []\n"
276+ it "will output custom mapping tags" $
277+ taggedMapping `shouldEmitWithUriTagsOn` "!foo {}\n"
278+ it "will output default sequence tags" $
279+ defaultTaggedSequence `shouldEmitWithUriTagsOn` "[]\n"
280+ it "will output default mapping tags" $
281+ defaultTaggedMapping `shouldEmitWithUriTagsOn` "{}\n"
282+ it "handles NoTag on sequences" $
283+ untaggedSequence `shouldEmitWithUriTagsOn` "[]\n"
284+ it "handles NoTag on mappings" $
285+ untaggedMapping `shouldEmitWithUriTagsOn` "{}\n"
286+ it "handles mixed tag usages outputting all mapping and sequence tags" $
287+ mixedTagSampleA `shouldEmitWithUriTagsOn` "- !foo {}\n"
288+ it "in combination of tags, anchors and styles, outputs all the tags" $
289+ mixedTagSampleB `shouldEmitWithUriTagsOn` "&a\n&b !<bar> foo: &c !baz [&d !!null '']\n"
310specialStrings :: [T.Text]
291specialStrings :: [T.Text]
311specialStrings =
292specialStrings =
@@ -724,3 +705,50 @@ caseTruncatesFiles = withSystemTempFile "truncate.yaml" $ \fp h -> do
724 D.encodeFile fp val
705 D.encodeFile fp val
725 res <- D.decodeFileEither fp
706 res <- D.decodeFileEither fp
726 either (Left . show) Right res `shouldBe` Right val
707 either (Left . show) Right res `shouldBe` Right val
710+taggedSequence :: [Y.Event]
712+ [ Y.EventSequenceStart (Y.UriTag "!foo") Y.FlowSequence Nothing
713+ , Y.EventSequenceEnd
716+taggedMapping :: [Y.Event]
718+ [ Y.EventMappingStart (Y.UriTag "!foo") Y.FlowMapping Nothing
722+defaultTaggedSequence :: [Y.Event]
723+defaultTaggedSequence =
724+ [Y.EventSequenceStart Y.SeqTag Y.FlowSequence Nothing, Y.EventSequenceEnd]
726+defaultTaggedMapping :: [Y.Event]
727+defaultTaggedMapping =
728+ [Y.EventMappingStart Y.MapTag Y.FlowMapping Nothing, Y.EventMappingEnd]
730+untaggedSequence :: [Y.Event]
732+ [Y.EventSequenceStart Y.NoTag Y.FlowSequence Nothing, Y.EventSequenceEnd]
734+untaggedMapping :: [Y.Event]
736+ [Y.EventMappingStart Y.NoTag Y.FlowMapping Nothing, Y.EventMappingEnd]
738+mixedTagSampleA :: [Y.Event]
740+ [ Y.EventSequenceStart Y.NoTag Y.BlockSequence Nothing
741+ , Y.EventMappingStart (Y.UriTag "!foo") Y.FlowMapping Nothing
743+ , Y.EventSequenceEnd
746+mixedTagSampleB :: [Y.Event]
748+ [ Y.EventMappingStart Y.NoTag Y.BlockMapping (Just "a")
749+ , Y.EventScalar "foo" (Y.UriTag "bar") Y.Plain (Just "b")
750+ , Y.EventSequenceStart (Y.UriTag "!baz") Y.FlowSequence (Just "c")
751+ , Y.EventScalar "" Y.NullTag Y.Plain (Just "d")
752+ , Y.EventSequenceEnd