Path: blob/main/contrib/lyaml/spec/ext_yaml_emitter_spec.yaml
178467 views
# LYAML binding for Lua 5.1, 5.2, 5.3 & 5.41# Copyright (C) 2013-2022 Gary V. Vaughan23specify emitting:4- it diagnoses an invalid event:5emitter = yaml.emitter ()6expect (emitter.emit "not an event").to_raise "expected table"7- it can generate an empty stream:8pending (github_issue "2")9expect (emit {10{type = "DOCUMENT_START", implicit = true},11{type = "SCALAR", value = ""},12{type = "DOCUMENT_END", implicit = true},13}).14to_equal ""1516- describe STREAM_START:17- it diagnoses unrecognised encodings:18expect (emitevents (yaml.emitter (), {19{type = "STREAM_START", encoding = "notexists"},20"STREAM_END"})).21to_raise "invalid stream encoding 'notexists'"22- it accepts an encoding parameter:23expect (emitevents (yaml.emitter (), {24{type = "STREAM_START", encoding = "UTF16BE"},25"STREAM_END"})).26to_equal (BOM)2728- describe STREAM_END:29- it returns the yaml document from the preceding events:30expect (emit {"DOCUMENT_START", {type = "SCALAR", value = "woo!"},31"DOCUMENT_END"}).32to_equal "--- woo!\n...\n"3334- describe DOCUMENT_START:35- it accepts a version directive parameter:36expect (emit {{type = "DOCUMENT_START",37version_directive = { major = 1, minor = 1 }},38{type = "SCALAR", value = ""},39"DOCUMENT_END"}).40to_match "^%%YAML 1.1\n---"41- it accepts a list of tag directives:42expect (emit {{type = "DOCUMENT_START",43tag_directives = {{handle = "!",44prefix = "tag:ben-kiki.org,2000:app/"}}},45{type = "SCALAR", value = ""},46"DOCUMENT_END"}).47to_contain "%TAG ! tag:ben-kiki.org,2000:app/\n---"48expect (emit {49{type = "DOCUMENT_START",50tag_directives = {{handle = "!",51prefix = "tag:ben-kiki.org,2000:app/"},52{handle = "!!",53prefix = "tag:yaml.org,2002:"}}},54{type = "SCALAR", value = ""},55"DOCUMENT_END"}).56to_contain ("%TAG ! tag:ben-kiki.org,2000:app/\n" ..57"%TAG !! tag:yaml.org,2002:\n---")58- it accepts an implicit parameter:59expect (emit {{type = "DOCUMENT_START", implicit = true},60{type = "SCALAR", value = ""}, "DOCUMENT_END"}).61not_to_contain "--- \n"62pending (github_issue "2")63expect (emit {{type = "DOCUMENT_START", implicit = false},64{type = "SCALAR", value = ""}, "DOCUMENT_END"}).65not_to_contain "---"6667- describe DOCUMENT_END:68- it accepts an implicit parameter:69expect (emit {"DOCUMENT_START", {type = "SCALAR", value = ""},70{type = "DOCUMENT_END", implicit = false}}).71to_contain "\n..."72pending (github_issue "2")73expect (emit {"DOCUMENT_START", {type = "SCALAR", value = ""},74{type = "DOCUMENT_END", implicit = true}}).75not_to_contain "\n..."7677- describe MAPPING_START:78- it accepts an anchor parameter:79expect (emit {"DOCUMENT_START",80{type = "MAPPING_START", anchor = "foo"},81"MAPPING_END", "DOCUMENT_END"}).82to_contain "&foo"83- it diagnoses unrecognised styles:84expect (emit {"DOCUMENT_START",85{type = "MAPPING_START", style = "notexists"},86"MAPPING_END", "DOCUMENT_END"}).87to_raise "invalid mapping style 'notexists'"88- it understands block style: '89expect (emit {"DOCUMENT_START",90{type = "MAPPING_START", style = "BLOCK"},91{type = "SCALAR", value = "foo"}, {type = "SCALAR", value = "bar"},92"MAPPING_END", "DOCUMENT_END"}).93to_contain "foo: bar\n"'94- it understands flow style: '95expect (emit {"DOCUMENT_START",96{type = "MAPPING_START", style = "FLOW"},97{type = "SCALAR", value = "foo"}, {type = "SCALAR", value = "bar"},98{type = "SCALAR", value = "baz"}, {type = "SCALAR", value = "qux"},99"MAPPING_END", "DOCUMENT_END"}).100to_contain "{foo: bar, baz: qux}\n"'101- it accepts an explicit tag parameter: '102expect (emit {"DOCUMENT_START",103{type = "MAPPING_START", style = "FLOW",104tag = "tag:yaml.org,2002:map", implicit = false},105{type = "SCALAR", value = "foo"}, {type = "SCALAR", value = "bar"},106"MAPPING_END", "DOCUMENT_END"}).107to_contain "!!map {foo: bar}"'108- it accepts an implicit tag parameter: '109expect (emit {"DOCUMENT_START",110{type = "MAPPING_START", tag = "tag:yaml.org,2002:map", implicit = true},111{type = "SCALAR", value = "foo"}, {type = "SCALAR", value = "bar"},112"MAPPING_END", "DOCUMENT_END"}).113not_to_contain "map"'114115- describe MAPPING_END:116- it requires no parameters: '117expect (emit {"DOCUMENT_START", "MAPPING_START",118{type = "SCALAR", value = "foo"}, {type = "SCALAR", value = "bar"},119"MAPPING_END", "DOCUMENT_END"}).120to_contain "foo: bar\n"'121122- describe SEQUENCE_START:123- it accepts an anchor parameter:124expect (emit {"DOCUMENT_START",125{type = "SEQUENCE_START", anchor = "foo"},126"SEQUENCE_END", "DOCUMENT_END"}).127to_contain "&foo"128- it diagnoses unrecognised styles:129expect (emit {"DOCUMENT_START",130{type = "SEQUENCE_START", style = "notexists"},131"SEQUENCE_END", "DOCUMENT_END"}).132to_raise "invalid sequence style 'notexists'"133- it understands block style:134expect (emit {"DOCUMENT_START",135{type = "SEQUENCE_START", style = "BLOCK"},136{type = "SCALAR", value = "foo"}, {type = "SCALAR", value = "bar"},137"SEQUENCE_END", "DOCUMENT_END"}).138to_contain "- foo\n- bar\n"139- it understands flow style:140expect (emit {"DOCUMENT_START",141{type = "SEQUENCE_START", style = "FLOW"},142{type = "SCALAR", value = "foo"}, {type = "SCALAR", value = "bar"},143"SEQUENCE_END", "DOCUMENT_END"}).144to_contain "[foo, bar]"145- it accepts an explicit tag parameter:146expect (emit {"DOCUMENT_START",147{type = "SEQUENCE_START", style = "FLOW",148tag = "tag:yaml.org,2002:sequence", implicit = false},149{type = "SCALAR", value = "foo"}, {type = "SCALAR", value = "bar"},150"SEQUENCE_END", "DOCUMENT_END"}).151to_contain "!!sequence [foo, bar]\n"152- it accepts an implicit tag parameter:153expect (emit {"DOCUMENT_START",154{type = "SEQUENCE_START", style = "FLOW",155tag = "tag:yaml.org,2002:sequence", implicit = true},156{type = "SCALAR", value = "foo"}, {type = "SCALAR", value = "bar"},157"SEQUENCE_END", "DOCUMENT_END"}).158not_to_contain "sequence"159160- describe SEQUENCE_END:161- it requires no parameters: '162expect (emit {"DOCUMENT_START", "SEQUENCE_START",163{type = "SCALAR", value = "moo"},164"SEQUENCE_END", "DOCUMENT_END"}).165to_contain "- moo\n"'166167- describe SCALAR:168- it diagnoses a missing value parameter:169- it accepts a value parameter:170expect (emit {"DOCUMENT_START", {type = "SCALAR", value = "boo"},171"DOCUMENT_END"}).172to_contain "boo"173- it diagnoses unrecognised styles:174expect (emit {"DOCUMENT_START",175{type = "SCALAR", style = "notexists", value = "foo"},176"DOCUMENT_END"}).177to_raise "invalid scalar style 'notexists'"178- it understands plain style:179expect (emit {"DOCUMENT_START",180{type = "SCALAR", style = "PLAIN", value = "boo"},181"DOCUMENT_END"}).182to_contain "boo\n"183- it understands single quoted style:184expect (emit {"DOCUMENT_START",185{type = "SCALAR", style = "SINGLE_QUOTED", value = "bar"},186"DOCUMENT_END"}).187to_contain "'bar'\n"188expect (emit {"DOCUMENT_START",189{type = "SCALAR", style = "SINGLE_QUOTED", value = "bar'"},190"DOCUMENT_END"}).191to_contain "'bar'''\n"192- it understands double quoted style:193expect (emit {"DOCUMENT_START",194{type = "SCALAR", style = "DOUBLE_QUOTED", value = "baz"},195"DOCUMENT_END"}).196to_contain '"baz"\n'197expect (emit {"DOCUMENT_START",198{type = "SCALAR", style = "DOUBLE_QUOTED", value = '"baz"'},199"DOCUMENT_END"}).200to_contain ([["\"baz\""]] .. "\n")201- it understands literal style:202expect (emit {"DOCUMENT_START",203{type = "SCALAR", style = "LITERAL", value = "quux"},204"DOCUMENT_END"}).205to_contain "|-\n quux\n"206- it understands folded style:207expect (emit {"DOCUMENT_START",208{type = "SCALAR", style = "FOLDED", value = "thud"},209"DOCUMENT_END"}).210to_contain ">-\n thud\n"211- it understands plain_implicit:212expect (emit {"DOCUMENT_START",213{type = "SCALAR", style = "PLAIN", value = "hello", plain_implicit=false},214"DOCUMENT_END"}).215to_contain "'hello'\n"216- it understands quoted_implicit:217expect (emit {"DOCUMENT_START",218{type = "SCALAR", style = "PLAIN", value = "- world", quoted_implicit=false},219"DOCUMENT_END"}).220to_contain "! '- world'\n"221- it understands tag:222expect (emit {"DOCUMENT_START",223{type = "SCALAR", style = "PLAIN", value = "bug_squash", tag="tagger", plain_implicit=false, quoted_implicit=false},224"DOCUMENT_END"}).225to_contain "!<tagger> bug_squash\n"226227- describe ALIAS:228- it diagnoses missing anchor parameter:229- it diagnoses non-alphanumeric anchor characters:230expect (emit {"DOCUMENT_START", {type = "ALIAS", anchor = "woo!"},231"DOCUMENT_END"}).232to_raise "must contain alphanumerical characters only"233- it accepts an anchor parameter:234expect (emit {"DOCUMENT_START", "SEQUENCE_START",235{type = "SCALAR", anchor = "woo", value = "hoo"},236{type = "ALIAS", anchor = "woo"},237"SEQUENCE_END", "DOCUMENT_END"}).238to_contain.all_of {"&woo", "*woo"}239240241