Description
Following up on #247 and in light of @jdesrosiers' #652, I think we can do better for output tests.
The current test structure presents a JSON Schema that constrains several locations to specific values.
Example:
However, maybe a simpler approach (both to implement and write) would be just to have a series of JSON Pointers and the values that are expected to be in the output at those locations. For example, the above test file could be re-written as:
[
{
"description": "readOnly generates its value as an annotation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://json-schema.org/tests/content/draft2020-12/readOnly/0",
"readOnly": true
},
"tests": [
{
"description": "readOnly is true",
"data": 1,
"output": {
"basic": {
"/annotations/0/keywordLocation": "/readOnly",
"/annotations/0/absoluteKeywordLocation": "https://json-schema.org/tests/content/draft2020-12/readOnly/0#/readOnly",
"/annotations/0/instanceLocation": "",
"/annotations/0/annotation": true
}
}
}
]
}
]
As long as all of those locations in the output contain those values, it is considered valid.
There is one caveat that the current version of the test also enforces that the the errors
property is disallowed when annotations
is present, which is something that the spec requires, but the proposal can't cover that case. I'm open to options here if that's important to us.
Edit: I've since realized that the pointers need indices because annotations
is an array. I'm not sure if we can specify that the first one needs to be a particular value. Items in the array could be in any order. Maybe the tests could be engineered so that it's the only expected item?