# YAML Test Matrix

--- &test-3GZX
  Title: Spec Example 7.1. Alias Nodes
  Tags: [ alias, spec ]

YAML

First occurrence: &anchor Foo
Second occurrence: *anchor
Override anchor: &anchor Bar
Reuse anchor: *anchor

Expected Events

+STR
+DOC
+MAP
=VAL :First occurrence
=VAL &anchor :Foo
=VAL :Second occurrence
=ALI *anchor
=VAL :Override anchor
=VAL &anchor :Bar
=VAL :Reuse anchor
=ALI *anchor
-MAP
-DOC
-STR

Expected JSON

{
"First occurrence": "Foo",
"Second occurrence": "Foo",
"Override anchor": "Bar",
"Reuse anchor": "Bar"
}

cpp-event

 ok

hs-yaml-event

 ok

java-event

 ok

libyaml-event

 ok

nimyaml-event

 ok

perl5-pegex-event

 ok

perl5-pp-event

 ok

pyyaml-event

 ok

ruamel-event

 ok

hs-yaml-json

 json_ok

java-json

 json_ok

js-yaml-json

 json_ok

luajit-json

 json_ok

perl5-pm-json

 json_ok

perl5-pp-json

 json_ok

perl5-syck-json

 json_ok

perl5-xs-json

 json_ok

ruamel-json

 json_ok

ruby-json

 json_ok

perl5-tiny-json

 error
YAML::Tiny does not support a feature in line '&anchor Foo' at /bin/perl5-tiny-json line 12.

perl5-tiny-pl

 error
YAML::Tiny does not support a feature in line '&anchor Foo' at /bin/perl5-tiny-pl line 15.

pyyaml-json

 error
Traceback (most recent call last):
  File "/bin/pyyaml-json", line 19, in <module>
    for doc in yaml.load_all(sys.stdin.read()):
  File "/lib/python2.7/site-packages/yaml/__init__.py", line 90, in load_all
    yield loader.get_data()
  File "/lib/python2.7/site-packages/yaml/constructor.py", line 33, in get_data
    return self.construct_document(self.get_node())
  File "/lib/python2.7/site-packages/yaml/composer.py", line 27, in get_node
    return self.compose_document()
  File "/lib/python2.7/site-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
  File "/lib/python2.7/site-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/lib/python2.7/site-packages/yaml/composer.py", line 133, in compose_mapping_node
    item_value = self.compose_node(node, item_key)
  File "/lib/python2.7/site-packages/yaml/composer.py", line 77, in compose_node
    "second occurrence", event.start_mark)
yaml.composer.ComposerError: found duplicate anchor 'anchor'; first occurrence
  in "<string>", line 1, column 19:
    First occurrence: &anchor Foo
                      ^
second occurrence
  in "<string>", line 3, column 18:
    Override anchor: &anchor Bar
                     ^

pyyaml-py

 error
Traceback (most recent call last):
  File "/bin/pyyaml-py", line 36, in <module>
    for doc in yaml.load_all(sys.stdin.read()):
  File "/lib/python2.7/site-packages/yaml/__init__.py", line 90, in load_all
    yield loader.get_data()
  File "/lib/python2.7/site-packages/yaml/constructor.py", line 33, in get_data
    return self.construct_document(self.get_node())
  File "/lib/python2.7/site-packages/yaml/composer.py", line 27, in get_node
    return self.compose_document()
  File "/lib/python2.7/site-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
  File "/lib/python2.7/site-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/lib/python2.7/site-packages/yaml/composer.py", line 133, in compose_mapping_node
    item_value = self.compose_node(node, item_key)
  File "/lib/python2.7/site-packages/yaml/composer.py", line 77, in compose_node
    "second occurrence", event.start_mark)
yaml.composer.ComposerError: found duplicate anchor 'anchor'; first occurrence
  in "<string>", line 1, column 19:
    First occurrence: &anchor Foo
                      ^
second occurrence
  in "<string>", line 3, column 18:
    Override anchor: &anchor Bar
                     ^

perl5-pm-pl

 na
{
  'First occurrence' => 'Foo',
  'Override anchor' => 'Bar',
  'Reuse anchor' => 'Bar',
  'Second occurrence' => 'Foo'
}

perl5-pp-pl

 na
{
  'First occurrence' => 'Foo',
  'Override anchor' => 'Bar',
  'Reuse anchor' => 'Bar',
  'Second occurrence' => 'Foo'
}

perl5-syck-pl

 na
{
  'First occurrence' => 'Foo',
  'Override anchor' => 'Bar',
  'Reuse anchor' => 'Bar',
  'Second occurrence' => 'Foo'
}

perl5-xs-pl

 na
{
  'First occurrence' => 'Foo',
  'Override anchor' => 'Bar',
  'Reuse anchor' => ${\$VAR1->{'Override anchor'}},
  'Second occurrence' => ${\$VAR1->{'First occurrence'}}
}

ruamel-py

 na
{'First occurrence': 'Foo',
 'Override anchor': 'Bar',
 'Reuse anchor': 'Bar',
 'Second occurrence': 'Foo'}
/usr/local/lib/python2.7/dist-packages/ruamel/yaml/composer.py:125: ReusedAnchorWarning: 
found duplicate anchor u'anchor'
first occurrence   in "<byte string>", line 1, column 19:
    First occurrence: &anchor Foo
                      ^ (line: 1)
second occurrence   in "<byte string>", line 3, column 18:
    Override anchor: &anchor Bar
                     ^ (line: 3)
  warnings.warn(ws, ReusedAnchorWarning)