# 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-rapidyaml-event

 ok

cpp-yamlcpp-event

 ok

dotnet-yamldotnet-event

 ok

hs-hsyaml-event

 ok

java-snakeengine-event

 ok

java-snakeyaml-event

 ok

js-yaml-event

 ok

nim-nimyaml-event

 ok

perl-pp-event

 ok

perl-refparser-event

 ok

py-pyyaml-event

 ok

py-ruamel-event

 ok

rust-yamlrust-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 93, 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
      ^

raku-yamlish-raku

 error
Couldn't parse YAML
  in sub load-yamls at /raku/sources/44795C7AB0F35700F4CA9C3E2CC5C924EE4C608F (YAMLish) line 959
  in block <unit> at /yaml/bin/raku-yamlish-raku line 6

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)

go-yaml-json

 na
panic: interface conversion: interface {} is nil, not string

goroutine 1 [running]:
main.convert({0x4f7d40, 0xc00010e630})
	/buildutils/go-yaml-json.go:17 +0x1c7
main.convert({0x4f2260, 0xc00011c0c0})
	/buildutils/go-yaml-json.go:22 +0x1ec
main.main()
	/buildutils/go-yaml-json.go:45 +0x2a5

hs-hsyaml-json

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

hs-reference-yeast

 na
Line  Col Char Byte Token|Content
   1    0    0    0 +DOC |
   1    0    0    0 +NODE|
   1    0    0    0 +SEQ |
   1    0    0    0 =SYNX|-
   1    1    1    1 =WSPC|.
   1    2    2    2 +NODE|
   1    2    2    2 +PROP|
   1    2    2    2 +ANCH|
   1    2    2    2 =SYNX|&
   1    3    3    3 =META|a
   1    4    4    4 -ANCH|
   1    4    4    4 -PROP|
   1    4    4    4 +VAL |
   1    4    4    4 -VAL |
   1    4    4    4 -NODE|
   1    4    4    4 =EOL |\x0a
   2    0    5    5 =SYNX|-
   2    1    6    6 =WSPC|.
   2    2    7    7 +NODE|
   2    2    7    7 +VAL |
   2    2    7    7 =TEXT|a
   2    3    8    8 -VAL |
   2    3    8    8 -NODE|
   2    3    8    8 =EOL |\x0a
   3    0    9    9 =SYNX|-
   3    1   10   10 +NODE|
   3    1   10   10 =EOL |\x0a
   4    0   11   11 +MAP |
   4    0   11   11 =DENT|..
   4    2   13   13 +PAIR|
   4    2   13   13 +NODE|
   4    2   13   13 +PROP|
   4    2   13   13 +ANCH|
   4    2   13   13 =SYNX|&
   4    3   14   14 =META|a
   4    4   15   15 -ANCH|
   4    4   15   15 -PROP|
   4    4   15   15 +VAL |
   4    4   15   15 -VAL |
   4    4   15   15 -NODE|
   4    4   15   15 =WSPC|.
   4    5   16   16 =SYNX|:
   4    6   17   17 =WSPC|.
   4    7   18   18 +NODE|
   4    7   18   18 +VAL |
   4    7   18   18 =TEXT|a
   4    8   19   19 -VAL |
   4    8   19   19 -NODE|
   4    8   19   19 =EOL |\x0a
   5    0   20   20 -PAIR|
   5    0   20   20 =DENT|..
   5    2   22   22 +PAIR|
   5    2   22   22 +NODE|
   5    2   22   22 +VAL |
   5    2   22   22 =TEXT|b
   5    3   23   23 -VAL |
   5    3   23   23 -NODE|
   5    3   23   23 =SYNX|:
   5    4   24   24 =WSPC|.
   5    5   25   25 +NODE|
   5    5   25   25 +PROP|
   5    5   25   25 +ANCH|
   5    5   25   25 =SYNX|&
   5    6   26   26 =META|b
   5    7   27   27 -ANCH|
   5    7   27   27 -PROP|
   5    7   27   27 +VAL |
   5    7   27   27 -VAL |
   5    7   27   27 -NODE|
   5    7   27   27 =EOL |\x0a
   6    0   28   28 -PAIR|
   6    0   28   28 -MAP |
   6    0   28   28 -NODE|
   6    0   28   28 =SYNX|-
   6    1   29   29 +NODE|
   6    1   29   29 =EOL |\x0a
   7    0   30   30 +MAP |
   7    0   30   30 =DENT|..
   7    2   32   32 +PAIR|
   7    2   32   32 +NODE|
   7    2   32   32 +PROP|
   7    2   32   32 +ANCH|
   7    2   32   32 =SYNX|&
   7    3   33   33 =META|c
   7    4   34   34 -ANCH|
   7    4   34   34 -PROP|
   7    4   34   34 +VAL |
   7    4   34   34 -VAL |
   7    4   34   34 -NODE|
   7    4   34   34 =WSPC|.
   7    5   35   35 =SYNX|:
   7    6   36   36 =WSPC|.
   7    7   37   37 +NODE|
   7    7   37   37 +PROP|
   7    7   37   37 +ANCH|
   7    7   37   37 =SYNX|&
   7    8   38   38 =META|a
   7    9   39   39 -ANCH|
   7    9   39   39 -PROP|
   7    9   39   39 +VAL |
   7    9   39   39 -VAL |
   7    9   39   39 -NODE|
   7    9   39   39 =EOL |\x0a
   8    0   40   40 -PAIR|
   8    0   40   40 -MAP |
   8    0   40   40 -NODE|
   8    0   40   40 =SYNX|-
   8    1   41   41 +NODE|
   8    1   41   41 =EOL |\x0a
   9    0   42   42 +MAP |
   9    0   42   42 =DENT|..
   9    2   44   44 +PAIR|
   9    2   44   44 =SYNX|?
   9    3   45   45 =WSPC|.
   9    4   46   46 +NODE|
   9    4   46   46 +PROP|
   9    4   46   46 +ANCH|
   9    4   46   46 =SYNX|&
   9    5   47   47 =META|d
   9    6   48   48 -ANCH|
   9    6   48   48 -PROP|
   9    6   48   48 +VAL |
   9    6   48   48 -VAL |
   9    6   48   48 -NODE|
   9    6   48   48 =EOL |\x0a
  10    0   49   49 +NODE|
  10    0   49   49 +VAL |
  10    0   49   49 -VAL |
  10    0   49   49 -NODE|
  10    0   49   49 -PAIR|
  10    0   49   49 -MAP |
  10    0   49   49 -NODE|
  10    0   49   49 =SYNX|-
  10    1   50   50 +NODE|
  10    1   50   50 =EOL |\x0a
  11    0   51   51 +MAP |
  11    0   51   51 =DENT|..
  11    2   53   53 +PAIR|
  11    2   53   53 =SYNX|?
  11    3   54   54 =WSPC|.
  11    4   55   55 +NODE|
  11    4   55   55 +PROP|
  11    4   55   55 +ANCH|
  11    4   55   55 =SYNX|&
  11    5   56   56 =META|e
  11    6   57   57 -ANCH|
  11    6   57   57 -PROP|
  11    6   57   57 +VAL |
  11    6   57   57 -VAL |
  11    6   57   57 -NODE|
  11    6   57   57 =EOL |\x0a
  12    0   58   58 =DENT|..
  12    2   60   60 =SYNX|:
  12    3   61   61 =WSPC|.
  12    4   62   62 +NODE|
  12    4   62   62 +PROP|
  12    4   62   62 +ANCH|
  12    4   62   62 =SYNX|&
  12    5   63   63 =META|a
  12    6   64   64 -ANCH|
  12    6   64   64 -PROP|
  12    6   64   64 +VAL |
  12    6   64   64 -VAL |
  12    6   64   64 -NODE|
  12    6   64   64 =EOL |\x0a
  13    0   65   65 -PAIR|
  13    0   65   65 -MAP |
  13    0   65   65 -NODE|
  13    0   65   65 -SEQ |
  13    0   65   65 -NODE|
  13    0   65   65 -DOC |

java-snakeengine-json

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

java-snakeyaml-json

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

js-jsyaml-json

 na
/node/node_modules/js-yaml/lib/loader.js:187
  throw generateError(state, message);
  ^
YAMLException: bad indentation of a sequence entry (4:6)

 1 | - &a
 2 | - a
 3 | -
 4 |   &a : a
----------^
 5 |   b: &b
 6 | -
    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 readBlockSequence (/node/node_modules/js-yaml/lib/loader.js:1015:7)
    at composeNode (/node/node_modules/js-yaml/lib/loader.js:1440: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)
    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 0x555cf85f6f97

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 93, 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:136: 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:136: 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:136: 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:136: 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:136: 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:136: 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)

raku-yamlish-json

 na
Couldn't parse YAML
  in sub load-yamls at /raku/sources/44795C7AB0F35700F4CA9C3E2CC5C924EE4C608F (YAMLish) line 959
  in block <unit> at /yaml/bin/raku-yamlish-json line 6

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.