Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSON literal tests. #559

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Add JSON literal tests. #559

wants to merge 5 commits into from

Conversation

davidlehn
Copy link
Contributor

  • Various tests of when @type of @json is used, the JSON may be an array, and the interaction with a @container of @set and @list.
  • Change compaction output for @json and @set with a JSON array.
  • Add test for many other possibilities and processing algorithms.
  • Propose new multiple JSON literals error code when trying to add multiple JSON literals as values for a property not declared a @set.

NOTE: This is a work-in-progress that needs feedback. HTML rebuild has not yet been done.

Please put major discussion in the issue that links here as this PR may need to be replaced.

davidlehn and others added 2 commits July 29, 2024 15:51
- Various tests of when `@type` of `@json` is used, the JSON may be an
  array, and the interaction with a `@container` of `@set` and `@list`.
- Change compaction output for `@json` and `@set` with a JSON array.
- Add test for many other possibilities and processing algorithms.
- Propose new `multiple JSON literals` error code when trying to add
  multiple JSON literals as values for a property.
@gkellogg
Copy link
Member

Some of these assume changes to the algorithms that will need their own PRs:

  • Tests expand/er57 and er58 along with toRdf/er57 and er58 need a check to be sure that the value is an array, or generate the invalid set or list object error. The presumed semantics are that each array value becomes its own JSON value.
  • Test compact/ej01 is expected to raise multiple JSON literals because the term didn't use @set. This is arguably a breaking change as any data that did this before would now fail (of course two JSON values on input would now be one JSON value on output). This will certainly require checks in the compaction algorithm.
  • Test compact/js07 (and others) also change the behavior to preserve the array value.

@gkellogg
Copy link
Member

Addresses #560.

Copy link
Member

@TallTed TallTed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

editorial, human-facing typo

tests/compact-manifest.html Show resolved Hide resolved
Copy link
Contributor

@pchampin pchampin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with tests er57 and er58 (in expand and toRdf) -- see my comments inline.

The rests of the tests make sense, but I agree with @gkellogg that some of them are breaking changes.

"@id": "#tjs12",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
"name": "Compact JSON literal (empty array)",
"purpose": "Tests compacting property with @type @json to a JSON literal (empty array).",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"purpose": "Tests compacting property with @type @json to a JSON literal (empty array).",
"purpose": "Tests compacting property with @type @json to a JSON literal (array with string).",

"@id": "#tjs13",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
"name": "Compact JSON literal (array with string)",
"purpose": "Tests compacting property with @type @json to a JSON literal (array with string).",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"purpose": "Tests compacting property with @type @json to a JSON literal (array with string).",
"purpose": "Tests compacting property with @type @json to a JSON literal (empty array).",

Comment on lines +1836 to +1842
}, {
"@id": "#ter58",
"@type": ["jld:NegativeEvaluationTest", "jld:ExpandTest"],
"name": "Array not found for @json @set.",
"purpose": "The value for a @json @set term MUST be an array.",
"input": "expand/er57-in.jsonld",
"expectErrorCode": "invalid set or list object"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}, {
"@id": "#ter58",
"@type": ["jld:NegativeEvaluationTest", "jld:ExpandTest"],
"name": "Array not found for @json @set.",
"purpose": "The value for a @json @set term MUST be an array.",
"input": "expand/er57-in.jsonld",
"expectErrorCode": "invalid set or list object"

Duplicate id with the next one, and duplicate content with the previous one.

Comment on lines +1830 to +1835
"@id": "#ter57",
"@type": ["jld:NegativeEvaluationTest", "jld:ExpandTest"],
"name": "Array not found for @json @set.",
"purpose": "The value for a @json @set term MUST be an array.",
"input": "expand/er57-in.jsonld",
"expectErrorCode": "invalid set or list object"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I this test is accepted, it should have counterparts with other values for @type (ex:datatype, @id), and without any @type. I see no reason why "@type": "@json" should behave differently.

But more generally, I don't think that this test should be accepted nor that this behavior should be required. There are many other situations where parts of the context are ignored if the encountered value is not of the expected kind. For example, @type coertion is ignored if the value of the property is not a JSON scalar.

Comment on lines +1843 to +1849
}, {
"@id": "#ter58",
"@type": ["jld:NegativeEvaluationTest", "jld:ExpandTest"],
"name": "Array not found for @json @list.",
"purpose": "The value for a @json @list term MUST be an array.",
"input": "expand/er58-in.jsonld",
"expectErrorCode": "invalid set or list object"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above (for ter57): I don't think that this test should be accepted.

I concur that having a simple value converted to an RDF list is a bit counter-intuitive, but it follows the principle that, in JSON-LD, "prop": val and "prop": [val] are equivalent.

Comment on lines +385 to +386
"name": "JSON literals (strings)",
"purpose": "Tests creating property with multiple rdf:type rdf:JSON to a JSON literal (null).",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the 'name' is not accurate, and I don't understand the sentence under 'purpose' (using "rdf:type" to talk about the datatype is very confusing).

Suggested change
"name": "JSON literals (strings)",
"purpose": "Tests creating property with multiple rdf:type rdf:JSON to a JSON literal (null).",
"name": "Multiple JSON literals",
"purpose": "Tests creating property with multiple literal values of datatype rdf:JSON",

Comment on lines +393 to +394
"name": "Mixed JSON literals and non-JSON",
"purpose": "Tests creating property with mixed rdf:type rdf:JSON and non-JSON.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"name": "Mixed JSON literals and non-JSON",
"purpose": "Tests creating property with mixed rdf:type rdf:JSON and non-JSON.",
"name": "Mixed JSON literal and non-JSON",
"purpose": "Tests creating property with mixed values: literal of datatype rdf:type and non-JSON.",

Actually, the test is mixing a literal of datatype rdf:JSON and an IRI, so the text is still a bit misleading (I would expect "non-JSON" to mean "a literal with another datatype than rdf:JSON).

Comment on lines +2254 to +2267
}, {
"@id": "#ter57",
"@type": ["jld:NegativeEvaluationTest", "jld:ToRDFTest" ],
"name": "Array not found for @json @list.",
"purpose": "The value for a @json @list term MUST be an array.",
"input": "toRdf/er57-in.jsonld",
"expectErrorCode": "invalid set or list object"
}, {
"@id": "#ter58",
"@type": ["jld:NegativeEvaluationTest", "jld:ToRDFTest" ],
"name": "Array not found for @json @set.",
"purpose": "The value for a @json @set term MUST be an array.",
"input": "toRdf/er58-in.jsonld",
"expectErrorCode": "invalid set or list object"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}, {
"@id": "#ter57",
"@type": ["jld:NegativeEvaluationTest", "jld:ToRDFTest" ],
"name": "Array not found for @json @list.",
"purpose": "The value for a @json @list term MUST be an array.",
"input": "toRdf/er57-in.jsonld",
"expectErrorCode": "invalid set or list object"
}, {
"@id": "#ter58",
"@type": ["jld:NegativeEvaluationTest", "jld:ToRDFTest" ],
"name": "Array not found for @json @set.",
"purpose": "The value for a @json @set term MUST be an array.",
"input": "toRdf/er58-in.jsonld",
"expectErrorCode": "invalid set or list object"

For the reasons explained above (in expand-manifest.jsonld), I believe that these tests should not be accepted.

}, {
"@id": "#tej01",
"@type": ["jld:NegativeEvaluationTest", "jld:CompactTest"],
"name": "Multiple JSON values for a JSON literal properties",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Goes with change elsewhere

Suggested change
"name": "Multiple JSON values for a JSON literal properties",
"name": "Multiple JSON values for a JSON literal property",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

4 participants