Skip to content

Commit

Permalink
Add JSON literal tests.
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
davidlehn committed Mar 1, 2023
1 parent 4f1c16f commit ad04884
Show file tree
Hide file tree
Showing 58 changed files with 588 additions and 2 deletions.
54 changes: 54 additions & 0 deletions tests/compact-manifest.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,15 @@
"input": "compact/ep15-in.jsonld",
"context": "compact/ep15-context.jsonld",
"expectErrorCode": "invalid container mapping"
}, {
"@id": "#tej01",
"@type": ["jld:NegativeEvaluationTest", "jld:CompactTest"],
"name": "Multiple JSON values for a JSON literal properties",
"purpose": "Tests compacting multiple JSON values for a JSON literal property.",
"input": "compact/ej01-in.jsonld",
"context": "compact/ej01-context.jsonld",
"expectErrorCode": "multiple JSON literals",
"option": {"specVersion": "json-ld-1.1"}
}, {
"@id": "#tin01",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
Expand Down Expand Up @@ -1542,6 +1551,51 @@
"context": "compact/js11-context.jsonld",
"expect": "compact/js11-out.jsonld",
"option": {"specVersion": "json-ld-1.1"}
}, {
"@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).",
"input": "compact/js12-in.jsonld",
"context": "compact/js12-context.jsonld",
"expect": "compact/js12-out.jsonld",
"option": {"specVersion": "json-ld-1.1"}
}, {
"@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).",
"input": "compact/js13-in.jsonld",
"context": "compact/js13-context.jsonld",
"expect": "compact/js13-out.jsonld",
"option": {"specVersion": "json-ld-1.1"}
}, {
"@id": "#tjs14",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
"name": "Compact JSON literal and non-JSON with @json property",
"purpose": "Tests compacting property with @type @json with JSON literal and non-JSON.",
"input": "compact/js14-in.jsonld",
"context": "compact/js14-context.jsonld",
"expect": "compact/js14-out.jsonld",
"option": {"specVersion": "json-ld-1.1"}
}, {
"@id": "#tjs15",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
"name": "Compact JSON literal and non-JSON without @json property",
"purpose": "Tests compacting property without @type @json with JSON literal and non-JSON.",
"input": "compact/js15-in.jsonld",
"context": "compact/js15-context.jsonld",
"expect": "compact/js15-out.jsonld",
"option": {"specVersion": "json-ld-1.1"}
}, {
"@id": "#tjs16",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
"name": "Compact JSON literal and non-JSON with and without @json property",
"purpose": "Tests compacting property with and without @type @json with JSON literal and non-JSON.",
"input": "compact/js16-in.jsonld",
"context": "compact/js16-context.jsonld",
"expect": "compact/js16-out.jsonld",
"option": {"specVersion": "json-ld-1.1"}
}, {
"@id": "#tla01",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
Expand Down
6 changes: 6 additions & 0 deletions tests/compact/ej01-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"@context": {
"@version": 1.1,
"e": {"@id": "http://example.org/vocab#value", "@type": "@json"}
}
}
9 changes: 9 additions & 0 deletions tests/compact/ej01-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[{
"http://example.org/vocab#value": [{
"@value": ["JSON1"],
"@type": "@json"
}, {
"@value": ["JSON2"],
"@type": "@json"
}]
}]
4 changes: 2 additions & 2 deletions tests/compact/js07-out.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"@version": 1.1,
"e": {"@id": "http://example.org/vocab#array", "@type": "@json", "@container": "@set"}
},
"e": [{"foo": "bar"}]
}
"e": [[{"foo": "bar"}]]
}
6 changes: 6 additions & 0 deletions tests/compact/js12-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"@context": {
"@version": 1.1,
"e": {"@id": "http://example.org/vocab#value", "@type": "@json"}
}
}
6 changes: 6 additions & 0 deletions tests/compact/js12-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[{
"http://example.org/vocab#value": [{
"@value": ["string"],
"@type": "@json"
}]
}]
7 changes: 7 additions & 0 deletions tests/compact/js12-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"@context": {
"@version": 1.1,
"e": {"@id": "http://example.org/vocab#value", "@type": "@json"}
},
"e": ["string"]
}
6 changes: 6 additions & 0 deletions tests/compact/js13-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"@context": {
"@version": 1.1,
"e": {"@id": "http://example.org/vocab#value", "@type": "@json"}
}
}
6 changes: 6 additions & 0 deletions tests/compact/js13-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[{
"http://example.org/vocab#value": [{
"@value": [],
"@type": "@json"
}]
}]
7 changes: 7 additions & 0 deletions tests/compact/js13-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"@context": {
"@version": 1.1,
"e": {"@id": "http://example.org/vocab#value", "@type": "@json"}
},
"e": []
}
6 changes: 6 additions & 0 deletions tests/compact/js14-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"@context": {
"@version": 1.1,
"e": {"@id": "http://example.org/vocab#value", "@type": "@json"}
}
}
8 changes: 8 additions & 0 deletions tests/compact/js14-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[{
"http://example.org/vocab#value": [{
"@value": [],
"@type": "@json"
},
"non-JSON"
]
}]
8 changes: 8 additions & 0 deletions tests/compact/js14-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"@context": {
"@version": 1.1,
"e": {"@id": "http://example.org/vocab#value", "@type": "@json"}
},
"e": [],
"http://example.org/vocab#value": "non-JSON"
}
6 changes: 6 additions & 0 deletions tests/compact/js15-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"@context": {
"@version": 1.1,
"e": {"@id": "http://example.org/vocab#value"}
}
}
8 changes: 8 additions & 0 deletions tests/compact/js15-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[{
"http://example.org/vocab#value": [{
"@value": [],
"@type": "@json"
},
"non-JSON"
]
}]
13 changes: 13 additions & 0 deletions tests/compact/js15-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"@context": {
"@version": 1.1,
"e": {"@id": "http://example.org/vocab#value"}
},
"e": [
{
"@type": "@json",
"@value": []
},
"non-JSON"
]
}
7 changes: 7 additions & 0 deletions tests/compact/js16-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"@context": {
"@version": 1.1,
"e-json": {"@id": "http://example.org/vocab#value", "@type": "@json"},
"e-non-json": {"@id": "http://example.org/vocab#value"}
}
}
8 changes: 8 additions & 0 deletions tests/compact/js16-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[{
"http://example.org/vocab#value": [{
"@value": [],
"@type": "@json"
},
"non-JSON"
]
}]
9 changes: 9 additions & 0 deletions tests/compact/js16-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"@context": {
"@version": 1.1,
"e-json": {"@id": "http://example.org/vocab#value", "@type": "@json"},
"e-non-json": {"@id": "http://example.org/vocab#value"}
},
"e-json": [],
"e-non-json": "non-JSON"
}
70 changes: 70 additions & 0 deletions tests/expand-manifest.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,20 @@
"purpose": "The value of @type in an expanded term definition object MUST be a string or null.",
"input": "expand/er55-in.jsonld",
"expectErrorCode": "invalid type mapping"
}, {
"@id": "#ter56",
"@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/er56-in.jsonld",
"expectErrorCode": "invalid set or list object"
}, {
"@id": "#ter57",
"@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/er57-in.jsonld",
"expectErrorCode": "invalid set or list object"
}, {
"@id": "#tes01",
"@type": ["jld:NegativeEvaluationTest", "jld:ExpandTest"],
Expand Down Expand Up @@ -2083,6 +2097,62 @@
"input": "expand/js23-in.jsonld",
"expect": "expand/js23-out.jsonld",
"option": {"specVersion": "json-ld-1.1"}
}, {
"@id": "#tjs24",
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
"name": "Expand JSON literal (one JSON literal).",
"purpose": "Tests expanding property with @type @json (one JSON literal).",
"input": "expand/js24-in.jsonld",
"expect": "expand/js24-out.jsonld",
"option": {"specVersion": "json-ld-1.1"}
}, {
"@id": "#tjs25",
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
"name": "Expand JSON literal (two JSON literals).",
"purpose": "Tests expanding property with @type @json (two JSON literals).",
"input": "expand/js25-in.jsonld",
"expect": "expand/js25-out.jsonld",
"option": {"specVersion": "json-ld-1.1"}
}, {
"@id": "#tjs26",
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
"name": "Expand JSON literal (JSON literal and non-JSON).",
"purpose": "Tests expanding property with @type @json (JSON literal and non-JSON).",
"input": "expand/js26-in.jsonld",
"expect": "expand/js26-out.jsonld",
"option": {"specVersion": "json-ld-1.1"}
}, {
"@id": "#tjs27",
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
"name": "Expand JSON literal (duplicate JSON literals).",
"purpose": "Tests expanding property with @type @json (dupcliate JSON literals).",
"input": "expand/js27-in.jsonld",
"expect": "expand/js27-out.jsonld",
"option": {"specVersion": "json-ld-1.1"}
}, {
"@id": "#tjs28",
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
"name": "Expand array-like value with @json and no @set/@list in @context.",
"purpose": "Tests expanding array-like value with @json and no @set/@list in @context.",
"input": "expand/js28-in.jsonld",
"expect": "expand/js28-out.jsonld",
"option": {"specVersion": "json-ld-1.1"}
}, {
"@id": "#tjs29",
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
"name": "Expand array-like value with @json and @set in @context.",
"purpose": "Tests expanding array-like value with @json and @set in @context.",
"input": "expand/js29-in.jsonld",
"expect": "expand/js29-out.jsonld",
"option": {"specVersion": "json-ld-1.1"}
}, {
"@id": "#tjs30",
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
"name": "Expand array-like value with @json and @list in @context.",
"purpose": "Tests expanding array-like value with @json and @list in @context.",
"input": "expand/js30-in.jsonld",
"expect": "expand/js30-out.jsonld",
"option": {"specVersion": "json-ld-1.1"}
}, {
"@id": "#tl001",
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
Expand Down
10 changes: 10 additions & 0 deletions tests/expand/er56-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"@context": {
"prop": {
"@id": "ex:prop",
"@type": "@json",
"@container": "@set"
}
},
"prop": "value"
}
10 changes: 10 additions & 0 deletions tests/expand/er57-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"@context": {
"prop": {
"@id": "ex:prop",
"@type": "@json",
"@container": "@list"
}
},
"prop": "value"
}
3 changes: 3 additions & 0 deletions tests/expand/js24-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"http://example.org/vocab#null": {"@value": ["JSON"], "@type": "@json"}
}
8 changes: 8 additions & 0 deletions tests/expand/js24-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[{
"http://example.org/vocab#null": [{
"@type": "@json",
"@value": [
"JSON"
]
}]
}]
6 changes: 6 additions & 0 deletions tests/expand/js25-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"http://example.org/vocab#value": [
{"@value": ["JSON1"], "@type": "@json"},
{"@value": ["JSON2"], "@type": "@json"}
]
}
13 changes: 13 additions & 0 deletions tests/expand/js25-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[{
"http://example.org/vocab#value": [{
"@type": "@json",
"@value": [
"JSON1"
]
}, {
"@type": "@json",
"@value": [
"JSON2"
]
}]
}]
6 changes: 6 additions & 0 deletions tests/expand/js26-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"http://example.org/vocab#value": [
{"@value": ["JSON"], "@type": "@json"},
{"@value": "non-JSON"}
]
}
10 changes: 10 additions & 0 deletions tests/expand/js26-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[{
"http://example.org/vocab#value": [{
"@type": "@json",
"@value": [
"JSON"
]
}, {
"@value": "non-JSON"
}]
}]
6 changes: 6 additions & 0 deletions tests/expand/js27-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"http://example.org/vocab#value": [
{"@value": ["dup"], "@type": "@json"},
{"@value": ["dup"], "@type": "@json"}
]
}
13 changes: 13 additions & 0 deletions tests/expand/js27-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[{
"http://example.org/vocab#value": [{
"@type": "@json",
"@value": [
"dup"
]
}, {
"@type": "@json",
"@value": [
"dup"
]
}]
}]
Loading

0 comments on commit ad04884

Please sign in to comment.