yaml-test-suite
yaml-test-suite copied to clipboard
Tests with repeated keys should be marked as errors
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.
Also test PW8X has repeated empty/null keys.
X38W also has an alias referring to another key in the same map.
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 ;-)
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)
As an update, this is still an issue with the tests 2JQS and PW8X due to their repeated empty/null keys.
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"
}
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 =)