# YAML Test Matrix

--- &test-QLJ7
  Title: Tag shorthand used in documents but only defined in the first
  Tags: [ directive, error, tag ]

YAML

%TAG !prefix! tag:example.com,2011:
--- !prefix!A
a: b
--- !prefix!B
c: d
--- !prefix!C
e: f

Expected Events

+STR
+DOC ---
+MAP <tag:example.com,2011:A>
=VAL :a
=VAL :b
-MAP
-DOC
+DOC ---

Expected JSON



cpp-yamlcpp-event

 invalid_incorrect
+STR
+DOC
+MAP <tag:example.com,2011:A>
=VAL :a
=VAL :b
-MAP
-DOC
+DOC
+MAP <tag:example.com,2011:B>
=VAL :c
=VAL :d
-MAP
-DOC
+DOC
+MAP <tag:example.com,2011:C>
=VAL :e
=VAL :f
-MAP
-DOC
-STR

java-snakeyaml-event

 invalid_incorrect
+STR
+DOC ---
+MAP <tag:example.com,2011:A>
=VAL :a
=VAL :b
-MAP
-DOC
+DOC ---
+MAP <tag:example.com,2011:B>
=VAL :c
=VAL :d
-MAP
-DOC
+DOC ---
+MAP <tag:example.com,2011:C>
=VAL :e
=VAL :f
-MAP
-DOC
-STR

perl-syck-json

 invalid_incorrect
{
   "%TAG !prefix! tag:example.com,2011" : null
}
{
   "a" : "b"
}
{
   "c" : "d"
}
{
   "e" : "f"
}

perl-syck-perl

 invalid_incorrect
{
  '%TAG !prefix! tag:example.com,2011' => undef
}
{
  'a' => 'b'
}
{
  'c' => 'd'
}
{
  'e' => 'f'
}

c-libfyaml-event

 invalid_correct
stdin:4:5: error: undefined tag prefix
--- !prefix!B
    ^~~~~~~~~
[NOT]: fy_fetch_tag() failed
[NOT]: fy_fetch_tokens() failed
[NOT]: failed to peek token
+STR
+DOC ---
+MAP <tag:example.com,2011:A>
=VAL :a
=VAL :b
-MAP
-DOC
+DOC ---

c-libfyaml-json

 invalid_correct
stdin:4:5: error: undefined tag prefix
--- !prefix!B
    ^~~~~~~~~
[NOT]: fy_fetch_tag() failed
[NOT]: fy_fetch_tokens() failed
[NOT]: failed to peek token
{
  "a": "b"
}

c-libyaml-event

 invalid_correct
Parse error: found undefined tag handle
+STR
+DOC ---
+MAP <tag:example.com,2011:A>
=VAL :a
=VAL :b
-MAP
-DOC
+DOC ---

dotnet-yamldotnet-event

 invalid_correct
Unhandled exception. YamlDotNet.Core.SemanticErrorException: (Line: 4, Col: 5, Idx: 59) - (Line: 4, Col: 14, Idx: 68): While parsing a node, found undefined tag handle.
   at YamlDotNet.Core.Parser.ParseNode(Boolean isBlock, Boolean isIndentlessSequence)
   at YamlDotNet.Core.Parser.ParseDocumentContent()
   at YamlDotNet.Core.Parser.StateMachine()
   at YamlDotNet.Core.Parser.MoveNext()
   at YamlDotNet.RepresentationModel.LibYamlEventStream.WriteTo(TextWriter textWriter)
   at Program.Main(String[] commandLineArguments)
Aborted (core dumped)
+STR
+DOC ---
+MAP <tag:example.com,2011:A>
=VAL :a
=VAL :b
-MAP
-DOC
+DOC ---

dotnet-yamldotnet-json

 invalid_correct
Unhandled exception. YamlDotNet.Core.YamlException: (Line: 2, Col: 5, Idx: 40) - (Line: 3, Col: 1, Idx: 50): Encountered an unresolved tag 'tag:example.com,2011:A'
   at YamlDotNet.Serialization.NodeTypeResolvers.PreventUnknownTagsNodeTypeResolver.YamlDotNet.Serialization.INodeTypeResolver.Resolve(NodeEvent nodeEvent, Type& currentType)
   at YamlDotNet.Serialization.ValueDeserializers.NodeValueDeserializer.GetTypeFromEvent(NodeEvent nodeEvent, Type currentType)
   at YamlDotNet.Serialization.ValueDeserializers.NodeValueDeserializer.DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
   at YamlDotNet.Serialization.ValueDeserializers.AliasValueDeserializer.DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
   at YamlDotNet.Serialization.Deserializer.Deserialize(IParser parser, Type type)
   at YamlDotNet.Serialization.Deserializer.Deserialize(TextReader input, Type type)
   at YamlDotNet.Serialization.Deserializer.Deserialize(TextReader input)
   at Program.Main(String[] commandLineArguments)
Aborted (core dumped)

hs-hsyaml-event

 invalid_correct
Parsing error near byte offset Pos {posByteOffset = 59, posCharOffset = 59, posLine = 4, posColumn = 4} (Parse failure near BeginHandle token)
+STR
+DOC ---
+MAP <tag:example.com,2011:A>
=VAL :a
=VAL :b
-MAP
-DOC
+DOC ---

hs-hsyaml-json

 invalid_correct
hsyaml-parser: user error (Parse failure near BeginHandle token)

java-snakeyaml-json

 invalid_correct
Exception in thread "main" Can't construct a java object for tag:example.com,2011:A; exception=Invalid tag: tag:example.com,2011:A
 in 'reader', line 2, column 5:
    --- !prefix!A
        ^

	at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:336)
	at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:230)
	at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:220)
	at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:174)
	at org.yaml.snakeyaml.constructor.BaseConstructor.getData(BaseConstructor.java:139)
	at org.yaml.snakeyaml.Yaml$1.next(Yaml.java:514)
	at org.yaml.editor.Snake2Json.yamlToJson(Snake2Json.java:18)
	at org.yaml.editor.Snake2Json.main(Snake2Json.java:25)
Caused by: org.yaml.snakeyaml.error.YAMLException: Invalid tag: tag:example.com,2011:A
	at org.yaml.snakeyaml.nodes.Tag.getClassName(Tag.java:125)
	at org.yaml.snakeyaml.constructor.Constructor.getClassForNode(Constructor.java:664)
	at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.getConstructor(Constructor.java:323)
	at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:332)
	... 7 more

js-jsyaml-json

 invalid_correct
/node/node_modules/js-yaml/lib/loader.js:187
  throw generateError(state, message);
  ^
YAMLException: unknown tag !<tag:example.com,2011:A> (4:1)

 1 | %TAG !prefix! tag:example.com,2011:
 2 | --- !prefix!A
 3 | a: b
 4 | --- !prefix!B
-----^
 5 | c: d
 6 | --- !prefix!C
    at generateError (/node/node_modules/js-yaml/lib/loader.js:183:10)
    at throwError (/node/node_modules/js-yaml/lib/loader.js:187:9)
    at composeNode (/node/node_modules/js-yaml/lib/loader.js:1521:7)
    at readDocument (/node/node_modules/js-yaml/lib/loader.js:1625:3)
    at loadDocuments (/node/node_modules/js-yaml/lib/loader.js:1688:5)
    at Object.loadAll (/node/node_modules/js-yaml/lib/loader.js:1701:19)
    at Object.<anonymous> (/yaml/bin/js-jsyaml-json:7:13)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)

js-yaml-event

 invalid_correct
Could not resolve tag: !prefix!B at line 4, column 5:

--- !prefix!B
    ^^^^^^^^^
+STR
+DOC ---
+MAP <tag:example.com,2011:A>
=VAL :a
=VAL :b
-MAP
-DOC
+DOC ---

js-yaml-json

 invalid_correct
/yaml/bin/js-yaml-json:8
  if (doc.errors.length !== 0) throw doc.errors[0]
                               ^

YAMLParseError: Could not resolve tag: !prefix!B at line 4, column 5:

--- !prefix!B
    ^^^^^^^^^

    at Composer.onError (/node/node_modules/yaml/dist/compose/composer.js:71:34)
    at ctx.directives.tagName.msg (/node/node_modules/yaml/dist/compose/compose-collection.js:27:68)
    at Directives.tagName (/node/node_modules/yaml/dist/doc/directives.js:126:9)
    at Object.composeCollection (/node/node_modules/yaml/dist/compose/compose-collection.js:27:36)
    at Object.composeNode (/node/node_modules/yaml/dist/compose/compose-node.js:30:38)
    at Object.composeDoc (/node/node_modules/yaml/dist/compose/compose-doc.js:31:23)
    at Composer.next (/node/node_modules/yaml/dist/compose/composer.js:152:40)
    at next (<anonymous>)
    at Composer.compose (/node/node_modules/yaml/dist/compose/composer.js:134:25)
    at compose.next (<anonymous>)

lua-lyaml-json

 invalid_correct
luajit: 4:1: found undefined tag handle
stack traceback:
	[C]: in function 'error'
	/usr/local/share/lua/5.1/lyaml/init.lua:306: in function 'error'
	/usr/local/share/lua/5.1/lyaml/init.lua:325: in function 'parse'
	/usr/local/share/lua/5.1/lyaml/init.lua:443: in function 'load_node'
	/usr/local/share/lua/5.1/lyaml/init.lua:497: in function 'load'
	/yaml/bin/lua-lyaml-json:6: in main chunk
	[C]: at 0x55a563d9ff97

nim-nimyaml-event

 invalid_correct
/tmp/NimYAML-0.16.0/yaml/stream.nim(134) nimyaml_event
/tmp/NimYAML-0.16.0/yaml/stream.nim(106) next
Error: unhandled exception: unknown handle: "!prefix!" [YamlStreamError]
+STR
+DOC ---
+MAP <tag:example.com,2011:A>
=VAL :a
=VAL :b
-MAP
-DOC
+DOC ---

perl-pp-event

 invalid_correct
Found undefined tag handle '!prefix!' at /perl5/lib/perl5/YAML/PP/Parser.pm line 994, <STDIN> line 1.
 at /yaml/bin/perl-pp-event line 25.
+STR
+DOC ---
+MAP <tag:example.com,2011:A>
=VAL :a
=VAL :b
-MAP
-DOC
+DOC ---

perl-pp-json

 invalid_correct
Found undefined tag handle '!prefix!' at /perl5/lib/perl5/YAML/PP/Parser.pm line 994, <> line 1.
 at /perl5/lib/perl5/YAML/PP/Loader.pm line 94.

perl-pp-perl

 invalid_correct
Found undefined tag handle '!prefix!' at /perl5/lib/perl5/YAML/PP/Parser.pm line 994, <> line 1.
 at /perl5/lib/perl5/YAML/PP/Loader.pm line 94.

perl-pplibyaml-event

 invalid_correct
YAML::PP::LibYAML Error: The problem:

    found undefined tag handle

was found at , line: 4, column: 5
while parsing a node at line: 4, column: 5

perl-pplibyaml-json

 invalid_correct
YAML::PP::LibYAML Error: The problem:

    found undefined tag handle

was found at , line: 4, column: 5
while parsing a node at line: 4, column: 5

perl-pplibyaml-perl

 invalid_correct
YAML::PP::LibYAML Error: The problem:

    found undefined tag handle

was found at , line: 4, column: 5
while parsing a node at line: 4, column: 5

perl-refparser-event

 invalid_correct
No %TAG entry for '' at /perl5/lib/perl5/YAML/Parser.pm line 5069, <> line 1.

perl-tiny-json

 invalid_correct
YAML::Tiny does not support a feature in line '!prefix!A' at /yaml/bin/perl-tiny-json line 12.

perl-tiny-perl

 invalid_correct
YAML::Tiny does not support a feature in line '!prefix!A' at /yaml/bin/perl-tiny-perl line 15.

perl-xs-json

 invalid_correct
YAML::XS::Load Error: The problem:

    bad tag found for hash: 'tag:example.com,2011:A'

was found at document: 1

perl-xs-perl

 invalid_correct
YAML::XS::Load Error: The problem:

    bad tag found for hash: 'tag:example.com,2011:A'

was found at document: 1

perl-yaml-json

 invalid_correct
Use of uninitialized value in sprintf at /perl5/lib/perl5/YAML/Error.pm line 18, <> line 1.
YAML Error: Can't parse inline implicit value ''
   Code: YAML_PARSE_ERR_BAD_INLINE_IMPLICIT
   Line: 1
   Document: 1
 at /perl5/lib/perl5/YAML/Loader.pm line 607.

perl-yaml-perl

 invalid_correct
Use of uninitialized value in sprintf at /perl5/lib/perl5/YAML/Error.pm line 18, <> line 1.
YAML Error: Can't parse inline implicit value ''
   Code: YAML_PARSE_ERR_BAD_INLINE_IMPLICIT
   Line: 1
   Document: 1
 at /perl5/lib/perl5/YAML/Loader.pm line 607.

py-pyyaml-event

 invalid_correct
Traceback (most recent call last):
  File "/yaml/bin/py-pyyaml-event", line 7, in <module>
    for event in yaml.parse(sys.stdin.read()):
  File "/python/lib/python3.7/site-packages/yaml/__init__.py", line 75, in parse
    while loader.check_event():
  File "/python/lib/python3.7/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
  File "/python/lib/python3.7/site-packages/yaml/parser.py", line 215, in parse_document_content
    return self.parse_block_node()
  File "/python/lib/python3.7/site-packages/yaml/parser.py", line 265, in parse_block_node
    return self.parse_node(block=True)
  File "/python/lib/python3.7/site-packages/yaml/parser.py", line 307, in parse_node
    tag_mark)
yaml.parser.ParserError: while parsing a node
found undefined tag handle '!prefix!'
  in "<unicode string>", line 4, column 5:
    --- !prefix!B
        ^
+STR
+DOC ---
+MAP <tag:example.com,2011:A>
=VAL :a
=VAL :b
-MAP
-DOC
+DOC ---

py-pyyaml-json

 invalid_correct
Traceback (most recent call last):
  File "/yaml/bin/py-pyyaml-json", line 19, in <module>
    for doc in yaml.load_all(sys.stdin.read(), Loader=yaml.FullLoader):
  File "/python/lib/python3.7/site-packages/yaml/__init__.py", line 130, in load_all
    yield loader.get_data()
  File "/python/lib/python3.7/site-packages/yaml/constructor.py", line 45, in get_data
    return self.construct_document(self.get_node())
  File "/python/lib/python3.7/site-packages/yaml/composer.py", line 27, in get_node
    return self.compose_document()
  File "/python/lib/python3.7/site-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
  File "/python/lib/python3.7/site-packages/yaml/composer.py", line 64, in compose_node
    if self.check_event(AliasEvent):
  File "/python/lib/python3.7/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
  File "/python/lib/python3.7/site-packages/yaml/parser.py", line 215, in parse_document_content
    return self.parse_block_node()
  File "/python/lib/python3.7/site-packages/yaml/parser.py", line 265, in parse_block_node
    return self.parse_node(block=True)
  File "/python/lib/python3.7/site-packages/yaml/parser.py", line 307, in parse_node
    tag_mark)
yaml.parser.ParserError: while parsing a node
found undefined tag handle '!prefix!'
  in "<unicode string>", line 4, column 5:
    --- !prefix!B
        ^
{
  "a": "b"
}

py-pyyaml-py

 invalid_correct
Traceback (most recent call last):
  File "/yaml/bin/py-pyyaml-py", line 36, in <module>
    for doc in yaml.load_all(sys.stdin.read(), Loader=yaml.FullLoader):
  File "/python/lib/python3.7/site-packages/yaml/__init__.py", line 130, in load_all
    yield loader.get_data()
  File "/python/lib/python3.7/site-packages/yaml/constructor.py", line 45, in get_data
    return self.construct_document(self.get_node())
  File "/python/lib/python3.7/site-packages/yaml/composer.py", line 27, in get_node
    return self.compose_document()
  File "/python/lib/python3.7/site-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
  File "/python/lib/python3.7/site-packages/yaml/composer.py", line 64, in compose_node
    if self.check_event(AliasEvent):
  File "/python/lib/python3.7/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
  File "/python/lib/python3.7/site-packages/yaml/parser.py", line 215, in parse_document_content
    return self.parse_block_node()
  File "/python/lib/python3.7/site-packages/yaml/parser.py", line 265, in parse_block_node
    return self.parse_node(block=True)
  File "/python/lib/python3.7/site-packages/yaml/parser.py", line 307, in parse_node
    tag_mark)
yaml.parser.ParserError: while parsing a node
found undefined tag handle '!prefix!'
  in "<unicode string>", line 4, column 5:
    --- !prefix!B
        ^
GenericMapping(tag='tag:example.com,2011:A', content={'a': 'b'})

py-ruamel-event

 invalid_correct
Traceback (most recent call last):
  File "/yaml/bin/py-ruamel-event", line 7, in <module>
    for event in ruamel.yaml.parse(sys.stdin.read()):
  File "/python/lib/python3.7/site-packages/ruamel/yaml/main.py", line 907, in parse
    while loader._parser.check_event():
  File "/python/lib/python3.7/site-packages/ruamel/yaml/parser.py", line 140, in check_event
    self.current_event = self.state()
  File "/python/lib/python3.7/site-packages/ruamel/yaml/parser.py", line 267, in parse_document_content
    return self.parse_block_node()
  File "/python/lib/python3.7/site-packages/ruamel/yaml/parser.py", line 329, in parse_block_node
    return self.parse_node(block=True)
  File "/python/lib/python3.7/site-packages/ruamel/yaml/parser.py", line 382, in parse_node
    tag_mark,
ruamel.yaml.parser.ParserError: while parsing a node
found undefined tag handle '!prefix!'
  in "<unicode string>", line 4, column 5:
    --- !prefix!B
        ^ (line: 4)
+STR
+DOC ---
+MAP <tag:example.com,2011:A>
=VAL :a
=VAL :b
-MAP
-DOC
+DOC ---

py-ruamel-json

 invalid_correct
Traceback (most recent call last):
  File "/yaml/bin/py-ruamel-json", line 19, in <module>
    for doc in ruamel.yaml.load_all(sys.stdin.read(), Loader=ruamel.yaml.Loader):
  File "/python/lib/python3.7/site-packages/ruamel/yaml/main.py", line 976, in load_all
    yield loader._constructor.get_data()
  File "/python/lib/python3.7/site-packages/ruamel/yaml/constructor.py", line 106, in get_data
    return self.construct_document(self.composer.get_node())
  File "/python/lib/python3.7/site-packages/ruamel/yaml/composer.py", line 68, in get_node
    return self.compose_document()
  File "/python/lib/python3.7/site-packages/ruamel/yaml/composer.py", line 101, in compose_document
    node = self.compose_node(None, None)
  File "/python/lib/python3.7/site-packages/ruamel/yaml/composer.py", line 111, in compose_node
    if self.parser.check_event(AliasEvent):
  File "/python/lib/python3.7/site-packages/ruamel/yaml/parser.py", line 140, in check_event
    self.current_event = self.state()
  File "/python/lib/python3.7/site-packages/ruamel/yaml/parser.py", line 267, in parse_document_content
    return self.parse_block_node()
  File "/python/lib/python3.7/site-packages/ruamel/yaml/parser.py", line 329, in parse_block_node
    return self.parse_node(block=True)
  File "/python/lib/python3.7/site-packages/ruamel/yaml/parser.py", line 382, in parse_node
    tag_mark,
ruamel.yaml.parser.ParserError: while parsing a node
found undefined tag handle '!prefix!'
  in "<unicode string>", line 4, column 5:
    --- !prefix!B
        ^ (line: 4)
{
  "a": "b"
}

py-ruamel-py

 invalid_correct
Traceback (most recent call last):
  File "/yaml/bin/py-ruamel-py", line 36, in <module>
    for doc in ruamel.yaml.load_all(sys.stdin.read(), Loader=ruamel.yaml.Loader):
  File "/python/lib/python3.7/site-packages/ruamel/yaml/main.py", line 976, in load_all
    yield loader._constructor.get_data()
  File "/python/lib/python3.7/site-packages/ruamel/yaml/constructor.py", line 106, in get_data
    return self.construct_document(self.composer.get_node())
  File "/python/lib/python3.7/site-packages/ruamel/yaml/composer.py", line 68, in get_node
    return self.compose_document()
  File "/python/lib/python3.7/site-packages/ruamel/yaml/composer.py", line 101, in compose_document
    node = self.compose_node(None, None)
  File "/python/lib/python3.7/site-packages/ruamel/yaml/composer.py", line 111, in compose_node
    if self.parser.check_event(AliasEvent):
  File "/python/lib/python3.7/site-packages/ruamel/yaml/parser.py", line 140, in check_event
    self.current_event = self.state()
  File "/python/lib/python3.7/site-packages/ruamel/yaml/parser.py", line 267, in parse_document_content
    return self.parse_block_node()
  File "/python/lib/python3.7/site-packages/ruamel/yaml/parser.py", line 329, in parse_block_node
    return self.parse_node(block=True)
  File "/python/lib/python3.7/site-packages/ruamel/yaml/parser.py", line 382, in parse_node
    tag_mark,
ruamel.yaml.parser.ParserError: while parsing a node
found undefined tag handle '!prefix!'
  in "<unicode string>", line 4, column 5:
    --- !prefix!B
        ^ (line: 4)
GenericMapping(tag='tag:example.com,2011:A', content={'a': 'b'})

ruby-psych-json

 invalid_correct
/usr/lib/ruby/2.5.0/psych.rb:405:in `parse': (<unknown>): found undefined tag handle while parsing a node at line 4 column 5 (Psych::SyntaxError)
	from /usr/lib/ruby/2.5.0/psych.rb:405:in `parse_stream'
	from /usr/lib/ruby/2.5.0/psych.rb:488:in `load_stream'
	from /yaml/bin/ruby-psych-json:6:in `<main>'