# YAML Test Matrix

--- &test-PW8X
  Title: Anchors on Empty Scalars
  Tags: [ anchor, explicit-key ]

YAML

- &a
- a
-
  &a : a
  b: &b
-
  &c : &a
-
  ? &d
-
  ? &e
  : &a

Expected Events

+STR
+DOC
+SEQ
=VAL &a :
=VAL :a
+MAP
=VAL &a :
=VAL :a
=VAL :b
=VAL &b :
-MAP
+MAP
=VAL &c :
=VAL &a :
-MAP
+MAP
=VAL &d :
=VAL :
-MAP
+MAP
=VAL &e :
=VAL &a :
-MAP
-SEQ
-DOC
-STR

Expected JSON



c-libfyaml-event

 ok

c-libyaml-event

 ok

cpp-yamlcpp-event

 ok

dotnet-yamldotnet-event

 ok

hs-hsyaml-event

 ok

java-snakeyaml-event

 ok

js-yaml-event

 ok

nim-nimyaml-event

 ok

perl-pp-event

 ok

perl-pplibyaml-event

 ok

py-pyyaml-event

 ok

py-ruamel-event

 ok

perl-syck-perl

 error
Syck parser (line 4, column 6): syntax error at /perl5/lib/perl5/x86_64-linux-thread-multi/YAML/Syck.pm line 60, <> line 1.

perl-yaml-perl

 error
Use of uninitialized value $key in string at /perl5/lib/perl5/YAML/Loader.pm line 341, <> line 1.
YAML Error: Invalid element in map
   Code: YAML_LOAD_ERR_BAD_MAP_ELEMENT
   Line: 10
   Document: 1
 at /perl5/lib/perl5/YAML/Loader.pm line 360.

py-pyyaml-py

 error
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 82, in compose_node
    node = self.compose_sequence_node(anchor)
  File "/python/lib/python3.7/site-packages/yaml/composer.py", line 111, in compose_sequence_node
    node.value.append(self.compose_node(node, index))
  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 129, in compose_mapping_node
    item_key = self.compose_node(node, None)
  File "/python/lib/python3.7/site-packages/yaml/composer.py", line 77, in compose_node
    "second occurrence", event.start_mark)
yaml.composer.ComposerError: found duplicate anchor 'a'; first occurrence
  in "<unicode string>", line 1, column 3:
    - &a
      ^
second occurrence
  in "<unicode string>", line 4, column 3:
      &a : a
      ^

c-libfyaml-json

 na
[
  null,
  "a",
  {
    "": "a",
    "b": null
  },
  {
    "": null
  },
  {
    "": null
  },
  {
    "": null
  }
]

dotnet-yamldotnet-json

 na
Unhandled exception. YamlDotNet.Core.YamlException: (Line: 4, Col: 3, Idx: 13) - (Line: 4, Col: 3, Idx: 13): Exception during deserialization
 ---> System.ArgumentNullException: Value cannot be null. (Parameter 'key')
   at System.Collections.Generic.Dictionary`2.System.Collections.IDictionary.set_Item(Object key, Object value)
   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)
   --- End of inner exception stack trace ---
   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.CollectionNodeDeserializer.DeserializeHelper(Type tItem, IParser parser, Func`3 nestedObjectDeserializer, IList result, Boolean canUpdate)
   at YamlDotNet.Serialization.NodeDeserializers.CollectionNodeDeserializer.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-json

 na
[null,"a",{"":"a","b":null},{"":null},{"":null},{"":null}]

java-snakeyaml-json

 na
[
  null,
  "a",
  {
    "null": "a"
  },
  {},
  {},
  {}
]

js-jsyaml-json

 na
/node/node_modules/js-yaml/lib/js-yaml/loader.js:173
  throw generateError(state, message);
  ^
YAMLException: bad indentation of a sequence entry at line 4, column 6:
      &a : a
         ^
    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 readBlockSequence (/node/node_modules/js-yaml/lib/js-yaml/loader.js:962:7)
    at composeNode (/node/node_modules/js-yaml/lib/js-yaml/loader.js:1358:12)
    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)

js-yaml-json

 na
[
  null,
  "a",
  {
    "": "a",
    "b": null
  },
  {
    "": null
  },
  {
    "": null
  },
  {
    "": null
  }
]

lua-lyaml-json

 na
luajit: /yaml/bin/lua-lyaml-json:8: Cannot serialise table: table key must be a number or string
stack traceback:
	[C]: in function 'encode'
	/yaml/bin/lua-lyaml-json:8: in main chunk
	[C]: at 0x55af5f742f97

perl-pp-json

 na
[
   null,
   "a",
   {
      "" : "a",
      "b" : null
   },
   {
      "" : null
   },
   {
      "" : null
   },
   {
      "" : null
   }
]

perl-pp-perl

 na
[
  undef,
  'a',
  {
    '' => 'a',
    'b' => undef
  },
  {
    '' => undef
  },
  {
    '' => undef
  },
  {
    '' => undef
  }
]

perl-pplibyaml-json

 na
[
   null,
   "a",
   {
      "" : "a",
      "b" : null
   },
   {
      "" : null
   },
   {
      "" : null
   },
   {
      "" : null
   }
]

perl-pplibyaml-perl

 na
[
  undef,
  'a',
  {
    '' => 'a',
    'b' => undef
  },
  {
    '' => undef
  },
  {
    '' => undef
  },
  {
    '' => undef
  }
]

perl-syck-json

 na
Syck parser (line 4, column 6): syntax error at /perl5/lib/perl5/x86_64-linux-thread-multi/YAML/Syck.pm line 60, <> line 1.

perl-tiny-json

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

perl-xs-json

 na
[
   null,
   "a",
   {
      "" : "a",
      "b" : null
   },
   {
      "" : null
   },
   {
      "" : null
   },
   {
      "" : null
   }
]
Use of uninitialized value in subroutine entry at /yaml/bin/perl-xs-json line 14, <> line 1.
Use of uninitialized value in subroutine entry at /yaml/bin/perl-xs-json line 14, <> line 1.
Use of uninitialized value in subroutine entry at /yaml/bin/perl-xs-json line 14, <> line 1.
Use of uninitialized value in subroutine entry at /yaml/bin/perl-xs-json line 14, <> line 1.

perl-xs-perl

 na
[
  undef,
  'a',
  {
    '' => 'a',
    'b' => undef
  },
  {
    '' => undef
  },
  {
    '' => undef
  },
  {
    '' => undef
  }
]
Use of uninitialized value in subroutine entry at /yaml/bin/perl-xs-perl line 16, <> line 1.
Use of uninitialized value in subroutine entry at /yaml/bin/perl-xs-perl line 16, <> line 1.
Use of uninitialized value in subroutine entry at /yaml/bin/perl-xs-perl line 16, <> line 1.
Use of uninitialized value in subroutine entry at /yaml/bin/perl-xs-perl line 16, <> line 1.

perl-yaml-json

 na
Use of uninitialized value $key in string at /perl5/lib/perl5/YAML/Loader.pm line 341, <> line 1.
YAML Error: Invalid element in map
   Code: YAML_LOAD_ERR_BAD_MAP_ELEMENT
   Line: 10
   Document: 1
 at /perl5/lib/perl5/YAML/Loader.pm line 360.

py-pyyaml-json

 na
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 82, in compose_node
    node = self.compose_sequence_node(anchor)
  File "/python/lib/python3.7/site-packages/yaml/composer.py", line 111, in compose_sequence_node
    node.value.append(self.compose_node(node, index))
  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 129, in compose_mapping_node
    item_key = self.compose_node(node, None)
  File "/python/lib/python3.7/site-packages/yaml/composer.py", line 77, in compose_node
    "second occurrence", event.start_mark)
yaml.composer.ComposerError: found duplicate anchor 'a'; first occurrence
  in "<unicode string>", line 1, column 3:
    - &a
      ^
second occurrence
  in "<unicode string>", line 4, column 3:
      &a : a
      ^

py-ruamel-json

 na
Error json.dumps: <class 'TypeError'>
/python/lib/python3.7/site-packages/ruamel/yaml/composer.py:131: ReusedAnchorWarning: 
found duplicate anchor 'a'
first occurrence   in "<unicode string>", line 1, column 3:
    - &a
      ^ (line: 1)
second occurrence   in "<unicode string>", line 4, column 3:
      &a : a
      ^ (line: 4)
  warnings.warn(ws, ReusedAnchorWarning)
/python/lib/python3.7/site-packages/ruamel/yaml/composer.py:131: ReusedAnchorWarning: 
found duplicate anchor 'a'
first occurrence   in "<unicode string>", line 4, column 3:
      &a : a
      ^ (line: 4)
second occurrence   in "<unicode string>", line 7, column 8:
      &c : &a
           ^ (line: 7)
  warnings.warn(ws, ReusedAnchorWarning)
/python/lib/python3.7/site-packages/ruamel/yaml/composer.py:131: ReusedAnchorWarning: 
found duplicate anchor 'a'
first occurrence   in "<unicode string>", line 7, column 8:
      &c : &a
           ^ (line: 7)
second occurrence   in "<unicode string>", line 12, column 5:
      : &a
        ^ (line: 12)
  warnings.warn(ws, ReusedAnchorWarning)
Traceback (most recent call last):
  File "/yaml/bin/py-ruamel-json", line 21, in <module>
    print(json.dumps(doc, sort_keys=True, skipkeys=True, indent=2))
  File "/usr/lib/python3.7/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/usr/lib/python3.7/json/encoder.py", line 201, in encode
    chunks = list(chunks)
  File "/usr/lib/python3.7/json/encoder.py", line 429, in _iterencode
    yield from _iterencode_list(o, _current_indent_level)
  File "/usr/lib/python3.7/json/encoder.py", line 325, in _iterencode_list
    yield from chunks
  File "/usr/lib/python3.7/json/encoder.py", line 353, in _iterencode_dict
    items = sorted(dct.items(), key=lambda kv: kv[0])
TypeError: '<' not supported between instances of 'str' and 'NoneType'

py-ruamel-py

 na
[None, 'a', {None: 'a', 'b': None}, {None: None}, {None: None}, {None: None}]
/python/lib/python3.7/site-packages/ruamel/yaml/composer.py:131: ReusedAnchorWarning: 
found duplicate anchor 'a'
first occurrence   in "<unicode string>", line 1, column 3:
    - &a
      ^ (line: 1)
second occurrence   in "<unicode string>", line 4, column 3:
      &a : a
      ^ (line: 4)
  warnings.warn(ws, ReusedAnchorWarning)
/python/lib/python3.7/site-packages/ruamel/yaml/composer.py:131: ReusedAnchorWarning: 
found duplicate anchor 'a'
first occurrence   in "<unicode string>", line 4, column 3:
      &a : a
      ^ (line: 4)
second occurrence   in "<unicode string>", line 7, column 8:
      &c : &a
           ^ (line: 7)
  warnings.warn(ws, ReusedAnchorWarning)
/python/lib/python3.7/site-packages/ruamel/yaml/composer.py:131: ReusedAnchorWarning: 
found duplicate anchor 'a'
first occurrence   in "<unicode string>", line 7, column 8:
      &c : &a
           ^ (line: 7)
second occurrence   in "<unicode string>", line 12, column 5:
      : &a
        ^ (line: 12)
  warnings.warn(ws, ReusedAnchorWarning)

ruby-psych-json

 na
[null,"a",{"":"a","b":null},{"":null},{"":null},{"":null}]

perl-tiny-perl

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