yaml-test-suite icon indicating copy to clipboard operation
yaml-test-suite copied to clipboard

Tests with repeated keys should be marked as errors

Open eemeli opened this issue 7 years ago • 7 comments

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 avatar Feb 01 '18 00:02 eemeli

Also test PW8X has repeated empty/null keys.

eemeli avatar Feb 01 '18 22:02 eemeli

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

eemeli avatar Feb 18 '18 20:02 eemeli

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 ;-)

perlpunk avatar Mar 17 '18 23:03 perlpunk

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:

  • blue: equal, !!str "blue"
  • true: not equal, !!str "true" vs. !!bool true
  • 3.14: not equal, !!str "3.14" vs. !!float 3.14
  • 23: equal, !!int 23
  • { a: 1, b: 2 }: equal, !!map { !!str "a" : !!int 1 , !!str "b" : !!int 2 } (key order does not matter)

eemeli avatar Mar 18 '18 10:03 eemeli

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

eemeli avatar Jul 01 '18 20:07 eemeli

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"
}

avonwyss avatar Jan 13 '19 17:01 avonwyss

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 =)

perlpunk avatar May 23 '20 19:05 perlpunk