# YAML Test Matrix

--- &test-4JVG
  Title: Scalar value with two anchors
  Tags: [ anchor, error, mapping ]

YAML

top1: &node1
  &k1 key1: val1
top2: &node2
  &v2 val2

Expected Events

+STR
+DOC
+MAP
=VAL :top1
+MAP &node1
=VAL &k1 :key1
=VAL :val1
-MAP
=VAL :top2

Expected JSON



perl-syck-json

 invalid_incorrect
{
   "top1" : {
      "key1" : "val1"
   },
   "top2" : "val2"
}

perl-syck-perl

 invalid_incorrect
{
  'top1' => {
              'key1' => 'val1'
            },
  'top2' => 'val2'
}

c-libfyaml-event

 invalid_correct
stdin:4:4: error: two anchors for a single value while in mapping
  &v2 val2
   ^~
+STR
+DOC
+MAP
=VAL :top1
+MAP &node1
=VAL &k1 :key1
=VAL :val1
-MAP
=VAL :top2
=VAL &node2 :

c-libfyaml-json

 invalid_correct
stdin:4:4: error: two anchors for a single value while in mapping
  &v2 val2
   ^~

c-libyaml-event

 invalid_correct
Parse error: did not find expected key
+STR
+DOC
+MAP
=VAL :top1
+MAP &node1
=VAL &k1 :key1
=VAL :val1
-MAP
=VAL :top2
=VAL &node2 :

cpp-yamlcpp-event

 invalid_correct
Exception:
yaml-cpp: error at line 4, column 3: cannot assign multiple anchors to the same node
+STR
+DOC
+MAP
=VAL :top1
+MAP &1
=VAL &2 :key1
=VAL :val1
-MAP
=VAL :top2

dotnet-yamldotnet-event

 invalid_correct
Unhandled exception. YamlDotNet.Core.SemanticErrorException: (Line: 4, Col: 3, Idx: 45) - (Line: 4, Col: 6, Idx: 48): While parsing a node, found more than one anchor.
   at YamlDotNet.Core.Parser.ParseNode(Boolean isBlock, Boolean isIndentlessSequence)
   at YamlDotNet.Core.Parser.ParseBlockMappingValue()
   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
=VAL :top1
+MAP &node1
=VAL &k1 :key1
=VAL :val1
-MAP
=VAL :top2

dotnet-yamldotnet-json

 invalid_correct
Unhandled exception. YamlDotNet.Core.SemanticErrorException: (Line: 4, Col: 3, Idx: 45) - (Line: 4, Col: 6, Idx: 48): While parsing a node, found more than one anchor.
   at YamlDotNet.Core.Parser.ParseNode(Boolean isBlock, Boolean isIndentlessSequence)
   at YamlDotNet.Core.Parser.ParseBlockMappingValue()
   at YamlDotNet.Core.Parser.StateMachine()
   at YamlDotNet.Core.Parser.MoveNext()
   at YamlDotNet.Core.ParserExtensions.TryConsume[T](IParser parser, T& event)
   at YamlDotNet.Serialization.NodeDeserializers.ScalarNodeDeserializer.YamlDotNet.Serialization.INodeDeserializer.Deserialize(IParser parser, Type expectedType, Func`3 nestedObjectDeserializer, Object& value)
   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.ValueDeserializers.NodeValueDeserializer.<>c__DisplayClass3_0.<DeserializeValue>b__0(IParser r, Type t)
   at YamlDotNet.Serialization.NodeDeserializers.DictionaryNodeDeserializer.DeserializeHelper(Type tKey, Type tValue, IParser parser, Func`3 nestedObjectDeserializer, IDictionary result)
   at YamlDotNet.Serialization.NodeDeserializers.DictionaryNodeDeserializer.YamlDotNet.Serialization.INodeDeserializer.Deserialize(IParser parser, Type expectedType, Func`3 nestedObjectDeserializer, Object& value)
   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 = 43, posCharOffset = 43, posLine = 4, posColumn = 0} (Unexpected ' ')
+STR
+DOC
+MAP
=VAL :top1
+MAP &node1
=VAL &k1 :key1
=VAL :val1
-MAP
=VAL :top2
=VAL &node2 :
-MAP
-DOC

hs-hsyaml-json

 invalid_correct
hsyaml-parser: user error (Unexpected ' ')

java-snakeyaml-event

 invalid_correct
Exception in thread "main" while parsing a block mapping
 in 'reader', line 1, column 1:
    top1: &node1
    ^
expected <block end>, but found '<anchor>'
 in 'reader', line 4, column 3:
      &v2 val2
      ^

	at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingKey.produce(ParserImpl.java:649)
	at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:165)
	at org.yaml.snakeyaml.Yaml$3.hasNext(Yaml.java:677)
	at org.yaml.editor.Snake2Events.yamlToEvents(Snake2Events.java:111)
	at org.yaml.editor.Snake2Events.main(Snake2Events.java:119)

java-snakeyaml-json

 invalid_correct
Exception in thread "main" while parsing a block mapping
 in 'reader', line 1, column 1:
    top1: &node1
    ^
expected <block end>, but found '<anchor>'
 in 'reader', line 4, column 3:
      &v2 val2
      ^

	at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingKey.produce(ParserImpl.java:649)
	at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:165)
	at org.yaml.snakeyaml.comments.CommentEventsCollector$1.peek(CommentEventsCollector.java:59)
	at org.yaml.snakeyaml.comments.CommentEventsCollector$1.peek(CommentEventsCollector.java:45)
	at org.yaml.snakeyaml.comments.CommentEventsCollector.collectEvents(CommentEventsCollector.java:140)
	at org.yaml.snakeyaml.comments.CommentEventsCollector.collectEvents(CommentEventsCollector.java:119)
	at org.yaml.snakeyaml.composer.Composer.composeScalarNode(Composer.java:214)
	at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:184)
	at org.yaml.snakeyaml.composer.Composer.composeValueNode(Composer.java:314)
	at org.yaml.snakeyaml.composer.Composer.composeMappingChildren(Composer.java:305)
	at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:286)
	at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:188)
	at org.yaml.snakeyaml.composer.Composer.getNode(Composer.java:115)
	at org.yaml.snakeyaml.constructor.BaseConstructor.getData(BaseConstructor.java:135)
	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)

js-jsyaml-json

 invalid_correct
/node/node_modules/js-yaml/lib/loader.js:187
  throw generateError(state, message);
  ^
YAMLException: duplication of an anchor property (2:3)

 1 | top1: &node1
 2 |   &k1 key1: val1
-------^
 3 | top2: &node2
 4 |   &v2 val2
    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 readAnchorProperty (/node/node_modules/js-yaml/lib/loader.js:1317:5)
    at composeNode (/node/node_modules/js-yaml/lib/loader.js:1407:38)
    at readBlockMapping (/node/node_modules/js-yaml/lib/loader.js:1164:11)
    at composeNode (/node/node_modules/js-yaml/lib/loader.js:1441:12)
    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)

js-yaml-event

 invalid_correct
A node can have at most one anchor at line 4, column 3:

top2: &node2
  &v2 val2
  ^^^
+STR
+DOC
+MAP
=VAL :top1
+MAP &node1
=VAL &k1 :key1
=VAL :val1
-MAP
=VAL :top2

js-yaml-json

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

YAMLParseError: A node can have at most one anchor at line 4, column 3:

top2: &node2
  &v2 val2
  ^^^

    at Composer.onError (/node/node_modules/yaml/dist/compose/composer.js:71:34)
    at Object.resolveProps (/node/node_modules/yaml/dist/compose/resolve-props.js:63:21)
    at Object.resolveBlockMap (/node/node_modules/yaml/dist/compose/resolve-block-map.js:55:41)
    at Object.composeCollection (/node/node_modules/yaml/dist/compose/compose-collection.js:13: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: 3:7: did not find expected key
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:340: 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 0x56536a60ff97

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: Only one anchor allowed per node [YamlStreamError]
+STR
+DOC
+MAP
=VAL :top1
+MAP &node1
=VAL &k1 :key1
=VAL :val1
-MAP
=VAL :top2

perl-pp-event

 invalid_correct
Line      : 4
Column    : 1
Message   : A node can only have one anchor
Where     : /perl5/lib/perl5/YAML/PP/Parser.pm line 704
YAML      : ""
  at /yaml/bin/perl-pp-event line 25.
+STR
+DOC
+MAP
=VAL :top1
+MAP &node1
=VAL &k1 :key1
=VAL :val1
-MAP
=VAL :top2

perl-pp-json

 invalid_correct
Line      : 4
Column    : 1
Message   : A node can only have one anchor
Where     : /perl5/lib/perl5/YAML/PP/Parser.pm line 704
YAML      : ""
  at /perl5/lib/perl5/YAML/PP/Loader.pm line 94.

perl-pp-perl

 invalid_correct
Line      : 4
Column    : 1
Message   : A node can only have one anchor
Where     : /perl5/lib/perl5/YAML/PP/Parser.pm line 704
YAML      : ""
  at /perl5/lib/perl5/YAML/PP/Loader.pm line 94.

perl-pplibyaml-event

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

    did not find expected key

was found at , line: 4, column: 3
while parsing a block mapping at line: 1, column: 1

perl-pplibyaml-json

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

    did not find expected key

was found at , line: 4, column: 3
while parsing a block mapping at line: 1, column: 1

perl-pplibyaml-perl

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

    did not find expected key

was found at , line: 4, column: 3
while parsing a block mapping at line: 1, column: 1

perl-refparser-event

 invalid_correct
Parser finished before end of input at /perl5/lib/perl5/YAML/Parser.pm line 4047, <> line 1.

perl-tiny-json

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

perl-tiny-perl

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

perl-xs-json

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

    did not find expected key

was found at document: 1, line: 4, column: 3
while parsing a block mapping at line: 1, column: 1

perl-xs-perl

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

    did not find expected key

was found at document: 1, line: 4, column: 3
while parsing a block mapping at line: 1, column: 1

perl-yaml-json

 invalid_correct
YAML Error: Expected separator '---'
   Code: YAML_PARSE_ERR_NO_SEPARATOR
   Line: 4
   Document: 2
 at /perl5/lib/perl5/YAML/Loader.pm line 88.

perl-yaml-perl

 invalid_correct
YAML Error: Expected separator '---'
   Code: YAML_PARSE_ERR_NO_SEPARATOR
   Line: 4
   Document: 2
 at /perl5/lib/perl5/YAML/Loader.pm line 88.

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 439, in parse_block_mapping_key
    "expected <block end>, but found %r" % token.id, token.start_mark)
yaml.parser.ParserError: while parsing a block mapping
  in "<unicode string>", line 1, column 1:
    top1: &node1
    ^
expected <block end>, but found '<anchor>'
  in "<unicode string>", line 4, column 3:
      &v2 val2
      ^
+STR
+DOC
+MAP
=VAL :top1
+MAP &node1
=VAL &k1 :key1
=VAL :val1
-MAP
=VAL :top2
=VAL &node2 :

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 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/python/lib/python3.7/site-packages/yaml/composer.py", line 127, in compose_mapping_node
    while not self.check_event(MappingEndEvent):
  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 439, in parse_block_mapping_key
    "expected <block end>, but found %r" % token.id, token.start_mark)
yaml.parser.ParserError: while parsing a block mapping
  in "<unicode string>", line 1, column 1:
    top1: &node1
    ^
expected <block end>, but found '<anchor>'
  in "<unicode string>", line 4, column 3:
      &v2 val2
      ^

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 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/python/lib/python3.7/site-packages/yaml/composer.py", line 127, in compose_mapping_node
    while not self.check_event(MappingEndEvent):
  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 439, in parse_block_mapping_key
    "expected <block end>, but found %r" % token.id, token.start_mark)
yaml.parser.ParserError: while parsing a block mapping
  in "<unicode string>", line 1, column 1:
    top1: &node1
    ^
expected <block end>, but found '<anchor>'
  in "<unicode string>", line 4, column 3:
      &v2 val2
      ^

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 589, in parse_block_mapping_key
    token.start_mark,
ruamel.yaml.parser.ParserError: while parsing a block mapping
  in "<unicode string>", line 1, column 1:
    top1: &node1
    ^ (line: 1)
expected <block end>, but found '<anchor>'
  in "<unicode string>", line 4, column 3:
      &v2 val2
      ^ (line: 4)
+STR
+DOC
+MAP
=VAL :top1
+MAP &node1
=VAL &k1 :key1
=VAL :val1
-MAP
=VAL :top2
=VAL &node2 :

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 138, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/python/lib/python3.7/site-packages/ruamel/yaml/composer.py", line 211, in compose_mapping_node
    while not self.parser.check_event(MappingEndEvent):
  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 589, in parse_block_mapping_key
    token.start_mark,
ruamel.yaml.parser.ParserError: while parsing a block mapping
  in "<unicode string>", line 1, column 1:
    top1: &node1
    ^ (line: 1)
expected <block end>, but found '<anchor>'
  in "<unicode string>", line 4, column 3:
      &v2 val2
      ^ (line: 4)

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 138, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/python/lib/python3.7/site-packages/ruamel/yaml/composer.py", line 211, in compose_mapping_node
    while not self.parser.check_event(MappingEndEvent):
  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 589, in parse_block_mapping_key
    token.start_mark,
ruamel.yaml.parser.ParserError: while parsing a block mapping
  in "<unicode string>", line 1, column 1:
    top1: &node1
    ^ (line: 1)
expected <block end>, but found '<anchor>'
  in "<unicode string>", line 4, column 3:
      &v2 val2
      ^ (line: 4)

ruby-psych-json

 invalid_correct
/usr/lib/ruby/2.5.0/psych.rb:405:in `parse': (<unknown>): did not find expected key while parsing a block mapping at line 1 column 1 (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>'