# YAML Test Matrix

--- &test-M2N8:01
  Title: Question mark edge cases
  Tags: [ edge, empty-key ]

YAML

? []: x

Expected Events

+STR
+DOC
+MAP
+MAP
+SEQ []
-SEQ
=VAL :x
-MAP
=VAL :
-MAP
-DOC
-STR

Expected JSON



c-libfyaml-event

 ok

c-libyaml-event

 ok

cpp-yamlcpp-event

 ok

dotnet-yamldotnet-event

 ok

hs-hsyaml-event

 ok

js-yaml-event

 ok

nim-nimyaml-event

 ok

perl-refparser-event

 ok

py-pyyaml-event

 ok

py-ruamel-event

 ok

rust-yamlrust-event

 ok

cpp-rapidyaml-event

 diff
Minimal Events:
+STR
+DOC
+MAP
+MAP
+SEQ
-SEQ
=VAL :x
-MAP
=VAL :
-MAP
-DOC
-STR
Transformed Events:
+STR
+DOC
+MAP
=VAL :[]
=VAL :x
-MAP
-DOC
-STR
Got Events:
+STR
+DOC
+MAP
=VAL :[]
=VAL :x
-MAP
-DOC
-STR

perl-pp-event

 error
+STR
+DOC
+MAP
+SEQ []
-SEQ
Line      : 1
Column    : 5
Expected  : EOL
Got       : COLON
Where     : /perl5/lib/perl5/YAML/PP/Parser.pm line 392
YAML      : ": x\n"
  at /yaml/bin/perl-pp-event line 46.

perl-pp-perl

 error
Line      : 1
Column    : 5
Expected  : EOL
Got       : COLON
Where     : /perl5/lib/perl5/YAML/PP/Parser.pm line 392
YAML      : ": x\n"
  at /perl5/lib/perl5/YAML/PP/Loader.pm line 94.

perl-syck-perl

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

perl-yaml-perl

 error
YAML Error: Couldn't parse single line value
   Code: YAML_PARSE_ERR_SINGLE_LINE
   Line: 1
   Document: 1
 at /perl5/lib/perl5/YAML/Loader.pm line 164.

py-ruamel-py

 error
Traceback (most recent call last):
  File "/yaml/bin/py-ruamel-py", line 38, in <module>
    for doc in yaml.load_all(sys.stdin.read()):
  File "/python/lib/python3.12/site-packages/ruamel/yaml/main.py", line 476, in load_all
    yield constructor.get_data()
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/ruamel/yaml/constructor.py", line 110, in get_data
    return self.construct_document(self.composer.get_node())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/ruamel/yaml/constructor.py", line 125, in construct_document
    for _dummy in generator:
  File "/python/lib/python3.12/site-packages/ruamel/yaml/constructor.py", line 633, in construct_yaml_map
    value = self.construct_mapping(node)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/ruamel/yaml/constructor.py", line 429, in construct_mapping
    return BaseConstructor.construct_mapping(self, node, deep=deep)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/ruamel/yaml/constructor.py", line 237, in construct_mapping
    raise ConstructorError(
ruamel.yaml.constructor.ConstructorError: while constructing a mapping
  in "<unicode string>", line 1, column 1:
    ? []: x
    ^ (line: 1)
found unhashable key
  in "<unicode string>", line 1, column 3:
    ? []: x
      ^ (line: 1)

c-libfyaml-json

 na
{
stdin:1:3: error: Non scalar keys are not allowed in JSON emit mode
? []: x
  ^~~~~

dotnet-yamldotnet-json

 na
{? {[]: "x"} : null}

go-yaml-json

 na
yaml: did not find expected key

hs-hsyaml-json

 na
{"{\"[]\":\"x\"}":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 +MAP |
   1    0    0    0 +PAIR|
   1    0    0    0 =SYNX|?
   1    1    1    1 =DENT|.
   1    2    2    2 +NODE|
   1    2    2    2 +MAP |
   1    2    2    2 +PAIR|
   1    2    2    2 +NODE|
   1    2    2    2 +SEQ |
   1    2    2    2 =SYNX|[
   1    3    3    3 =SYNX|]
   1    4    4    4 -SEQ |
   1    4    4    4 -NODE|
   1    4    4    4 =SYNX|:
   1    5    5    5 =WSPC|.
   1    6    6    6 +NODE|
   1    6    6    6 +VAL |
   1    6    6    6 =TEXT|x
   1    7    7    7 -VAL |
   1    7    7    7 -NODE|
   1    7    7    7 =EOL |\x0a
   2    0    8    8 -PAIR|
   2    0    8    8 -MAP |
   2    0    8    8 -NODE|
   2    0    8    8 +NODE|
   2    0    8    8 +VAL |
   2    0    8    8 -VAL |
   2    0    8    8 -NODE|
   2    0    8    8 -PAIR|
   2    0    8    8 -MAP |
   2    0    8    8 -NODE|
   2    0    8    8 -DOC |

js-jsyaml-json

 na
{"[object Object]":null}

js-yaml-json

 na
{
  "{\n  ? []\n  : x\n}": null
}
(node:2945) Warning: Keys with collection values will be stringified due to JS Object restrictions: "[]". Set mapAsMap: true to use object keys.
(Use `node --trace-warnings ...` to show where the warning was created)

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 0x558c912c0ed0

perl-pp-json

 na
Line      : 1
Column    : 5
Expected  : EOL
Got       : COLON
Where     : /perl5/lib/perl5/YAML/PP/Parser.pm line 392
YAML      : ": x\n"
  at /perl5/lib/perl5/YAML/PP/Loader.pm line 94.

perl-pplibyaml-json

 na
{
   "{'[]' => 'x'}" : null
}

perl-pplibyaml-perl

 na
{
  '{\'[]\' => \'x\'}' => undef
}

perl-syck-json

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

perl-tiny-json

 na
{
   "? []" : "x"
}

perl-tiny-perl

 na
{
  '? []' => 'x'
}

perl-xs-json

 na
{
   "HASH(0x7f0b5e2fe8d0)" : null
}

perl-xs-perl

 na
{
  'HASH(0x7f2ce3b6c608)' => undef
}

perl-yaml-json

 na
YAML Error: Couldn't parse single line value
   Code: YAML_PARSE_ERR_SINGLE_LINE
   Line: 1
   Document: 1
 at /perl5/lib/perl5/YAML/Loader.pm line 164.

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.12/site-packages/yaml/__init__.py", line 130, in load_all
    yield loader.get_data()
          ^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/constructor.py", line 45, in get_data
    return self.construct_document(self.get_node())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/constructor.py", line 60, in construct_document
    for dummy in generator:
  File "/python/lib/python3.12/site-packages/yaml/constructor.py", line 413, in construct_yaml_map
    value = self.construct_mapping(node)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/constructor.py", line 218, in construct_mapping
    return super().construct_mapping(node, deep=deep)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/constructor.py", line 141, in construct_mapping
    raise ConstructorError("while constructing a mapping", node.start_mark,
yaml.constructor.ConstructorError: while constructing a mapping
  in "<unicode string>", line 1, column 1:
    ? []: x
    ^
found unhashable key
  in "<unicode string>", line 1, column 3:
    ? []: x
      ^

py-ruamel-json

 na
Traceback (most recent call last):
  File "/yaml/bin/py-ruamel-json", line 21, in <module>
    for doc in yaml.load_all(sys.stdin.read()):
  File "/python/lib/python3.12/site-packages/ruamel/yaml/main.py", line 476, in load_all
    yield constructor.get_data()
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/ruamel/yaml/constructor.py", line 110, in get_data
    return self.construct_document(self.composer.get_node())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/ruamel/yaml/constructor.py", line 125, in construct_document
    for _dummy in generator:
  File "/python/lib/python3.12/site-packages/ruamel/yaml/constructor.py", line 633, in construct_yaml_map
    value = self.construct_mapping(node)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/ruamel/yaml/constructor.py", line 429, in construct_mapping
    return BaseConstructor.construct_mapping(self, node, deep=deep)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/ruamel/yaml/constructor.py", line 237, in construct_mapping
    raise ConstructorError(
ruamel.yaml.constructor.ConstructorError: while constructing a mapping
  in "<unicode string>", line 1, column 1:
    ? []: x
    ^ (line: 1)
found unhashable key
  in "<unicode string>", line 1, column 3:
    ? []: x
      ^ (line: 1)

ruby-psych-json

 na
{"{[]=>\"x\"}":null}

py-pyyaml-py

 ni
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.12/site-packages/yaml/__init__.py", line 130, in load_all
    yield loader.get_data()
          ^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/constructor.py", line 45, in get_data
    return self.construct_document(self.get_node())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/constructor.py", line 60, in construct_document
    for dummy in generator:
  File "/python/lib/python3.12/site-packages/yaml/constructor.py", line 413, in construct_yaml_map
    value = self.construct_mapping(node)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/constructor.py", line 218, in construct_mapping
    return super().construct_mapping(node, deep=deep)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/constructor.py", line 141, in construct_mapping
    raise ConstructorError("while constructing a mapping", node.start_mark,
yaml.constructor.ConstructorError: while constructing a mapping
  in "<unicode string>", line 1, column 1:
    ? []: x
    ^
found unhashable key
  in "<unicode string>", line 1, column 3:
    ? []: x
      ^