# 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

dotnet-yamldotnet-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
    ^~~~~~~~~
+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
    ^~~~~~~~~
{
  "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-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:219)
	at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:173)
	at org.yaml.snakeyaml.constructor.BaseConstructor.getData(BaseConstructor.java:138)
	at org.yaml.snakeyaml.Yaml$1.next(Yaml.java:494)
	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:122)
	at org.yaml.snakeyaml.constructor.Constructor.getClassForNode(Constructor.java:659)
	at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.getConstructor(Constructor.java:322)
	at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:331)
	... 7 more

js-jsyaml-json

 invalid_correct
/node/node_modules/js-yaml/lib/js-yaml/loader.js:173
  throw generateError(state, message);
  ^
YAMLException: unknown tag !<tag:example.com,2011:A> at line 4, column 1:
    --- !prefix!B
    ^
    at generateError (/node/node_modules/js-yaml/lib/js-yaml/loader.js:167:10)
    at throwError (/node/node_modules/js-yaml/lib/js-yaml/loader.js:173:9)
    at composeNode (/node/node_modules/js-yaml/lib/js-yaml/loader.js:1428:7)
    at readDocument (/node/node_modules/js-yaml/lib/js-yaml/loader.js:1519:3)
    at loadDocuments (/node/node_modules/js-yaml/lib/js-yaml/loader.js:1575:5)
    at Object.loadAll (/node/node_modules/js-yaml/lib/js-yaml/loader.js:1583: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
The !prefix! tag handle is non-default and was not declared.
+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]
                               ^

YAMLSemanticError: The !prefix! tag handle is non-default and was not declared.
    at resolveTagHandle (/node/node_modules/yaml/dist/resolveSeq-4a68b39b.js:1302:24)
    at resolveTagName (/node/node_modules/yaml/dist/resolveSeq-4a68b39b.js:1345:16)
    at resolveNodeValue (/node/node_modules/yaml/dist/resolveSeq-4a68b39b.js:1534:19)
    at Object.resolveNode (/node/node_modules/yaml/dist/resolveSeq-4a68b39b.js:1583:15)
    at parseContents (/node/node_modules/yaml/dist/Document-2cf6b08c.js:357:30)
    at Document.parse (/node/node_modules/yaml/dist/Document-2cf6b08c.js:615:5)
    at Object.parseAllDocuments (/node/node_modules/yaml/dist/index.js:34:9)
    at Object.<anonymous> (/yaml/bin/js-yaml-json:7:19)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)

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:291: in function 'error'
	/usr/local/share/lua/5.1/lyaml/init.lua:310: in function 'parse'
	/usr/local/share/lua/5.1/lyaml/init.lua:428: in function 'load_node'
	/usr/local/share/lua/5.1/lyaml/init.lua:482: in function 'load'
	/yaml/bin/lua-lyaml-json:6: in main chunk
	[C]: at 0x5647821f1f97

nim-nimyaml-event

 invalid_correct
/buildutils/nimyaml_event.nim(8) nimyaml_event
/tmp/NimYAML-0.13.1/yaml/stream.nim(223) finished
Error: unhandled exception: Undefined tag shorthand: !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 955, <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 955, <> line 1.
 at /perl5/lib/perl5/YAML/PP/Loader.pm line 92.

perl-pp-perl

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

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-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>'