yaml / yaml-test-suite

Comprehensive, language independent Test Suite for YAML
MIT License
181 stars 62 forks source link

Tests with repeated keys should be marked as errors #25

Open eemeli opened 6 years ago

eemeli commented 6 years ago

Specifically, 2JQS has repeated empty keys and E76Z has an alias referring to another key in the same map. These are both errors, as the spec requires mapping keys to be unique.

eemeli commented 6 years ago

Also test PW8X has repeated empty/null keys.

eemeli commented 6 years ago

X38W also has an alias referring to another key in the same map.

perlpunk commented 6 years ago

Thanks. We were discussing duplicate keys several times, and came to the conclusion that it's not really definable what equality or duplicate actually means, at least not at the parser level. http://yaml.org/spec/1.2/spec.html#id2764652

The parser can't (always) know if keys are considered equal or not.

For example:

# duplicate! right?
"blue": 1
blue: 2

# duplicate?
"true": 1
true: 2

# duplicate?
"3.14": 1
3.14: 2

# duplicate?
0x17: 1
23: 2

# duplicate?
? a: 1
  b: 2
: 1
? b: 2
  a: 1
: 2

Therefor, the constructor/schema has to define equality. We could define for our test cases, that we apply the YAML Core Schema, and so can identify all cases with duplicate keys.

We still haven't decided how to mark loader/constructor errors; maybe with tags like error-loader. We additionally have to consider YAML version differences. Ideas welcome ;-)

eemeli commented 6 years ago

Explicitly specifying the core schema for the tests sounds like a Good Idea; with that answering the equality of each of the above examples becomes straightforward:

eemeli commented 6 years ago

As an update, this is still an issue with the tests 2JQS and PW8X due to their repeated empty/null keys.

avonwyss commented 5 years ago

Test E76Z is also still broken. This test uses an alias to an anchored key, so the key must be unambiguously the same by definition. However, since that test does test specific functionality and should therefore not just be marked as erroneous, therefore I'd suggest to change it like this:

--- in-yaml
&a a: &b b
*b : *a

--- in-json
{
  "a": "b",
  "b": "a"
}
perlpunk commented 4 years ago

I marked the test with a duplicate-key tag, and it shows up as "not implemented" in https://matrix.yaml.io/ Hope that's ok now =)