Skip to content

Commit ad04884

Browse files
committed
Add JSON literal tests.
- 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.
1 parent 4f1c16f commit ad04884

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+588
-2
lines changed

tests/compact-manifest.jsonld

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,15 @@
13981398
"input": "compact/ep15-in.jsonld",
13991399
"context": "compact/ep15-context.jsonld",
14001400
"expectErrorCode": "invalid container mapping"
1401+
}, {
1402+
"@id": "#tej01",
1403+
"@type": ["jld:NegativeEvaluationTest", "jld:CompactTest"],
1404+
"name": "Multiple JSON values for a JSON literal properties",
1405+
"purpose": "Tests compacting multiple JSON values for a JSON literal property.",
1406+
"input": "compact/ej01-in.jsonld",
1407+
"context": "compact/ej01-context.jsonld",
1408+
"expectErrorCode": "multiple JSON literals",
1409+
"option": {"specVersion": "json-ld-1.1"}
14011410
}, {
14021411
"@id": "#tin01",
14031412
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
@@ -1542,6 +1551,51 @@
15421551
"context": "compact/js11-context.jsonld",
15431552
"expect": "compact/js11-out.jsonld",
15441553
"option": {"specVersion": "json-ld-1.1"}
1554+
}, {
1555+
"@id": "#tjs12",
1556+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
1557+
"name": "Compact JSON literal (empty array)",
1558+
"purpose": "Tests compacting property with @type @json to a JSON literal (empty array).",
1559+
"input": "compact/js12-in.jsonld",
1560+
"context": "compact/js12-context.jsonld",
1561+
"expect": "compact/js12-out.jsonld",
1562+
"option": {"specVersion": "json-ld-1.1"}
1563+
}, {
1564+
"@id": "#tjs13",
1565+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
1566+
"name": "Compact JSON literal (array with string)",
1567+
"purpose": "Tests compacting property with @type @json to a JSON literal (array with string).",
1568+
"input": "compact/js13-in.jsonld",
1569+
"context": "compact/js13-context.jsonld",
1570+
"expect": "compact/js13-out.jsonld",
1571+
"option": {"specVersion": "json-ld-1.1"}
1572+
}, {
1573+
"@id": "#tjs14",
1574+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
1575+
"name": "Compact JSON literal and non-JSON with @json property",
1576+
"purpose": "Tests compacting property with @type @json with JSON literal and non-JSON.",
1577+
"input": "compact/js14-in.jsonld",
1578+
"context": "compact/js14-context.jsonld",
1579+
"expect": "compact/js14-out.jsonld",
1580+
"option": {"specVersion": "json-ld-1.1"}
1581+
}, {
1582+
"@id": "#tjs15",
1583+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
1584+
"name": "Compact JSON literal and non-JSON without @json property",
1585+
"purpose": "Tests compacting property without @type @json with JSON literal and non-JSON.",
1586+
"input": "compact/js15-in.jsonld",
1587+
"context": "compact/js15-context.jsonld",
1588+
"expect": "compact/js15-out.jsonld",
1589+
"option": {"specVersion": "json-ld-1.1"}
1590+
}, {
1591+
"@id": "#tjs16",
1592+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
1593+
"name": "Compact JSON literal and non-JSON with and without @json property",
1594+
"purpose": "Tests compacting property with and without @type @json with JSON literal and non-JSON.",
1595+
"input": "compact/js16-in.jsonld",
1596+
"context": "compact/js16-context.jsonld",
1597+
"expect": "compact/js16-out.jsonld",
1598+
"option": {"specVersion": "json-ld-1.1"}
15451599
}, {
15461600
"@id": "#tla01",
15471601
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],

tests/compact/ej01-context.jsonld

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"e": {"@id": "http://example.org/vocab#value", "@type": "@json"}
5+
}
6+
}

tests/compact/ej01-in.jsonld

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[{
2+
"http://example.org/vocab#value": [{
3+
"@value": ["JSON1"],
4+
"@type": "@json"
5+
}, {
6+
"@value": ["JSON2"],
7+
"@type": "@json"
8+
}]
9+
}]

tests/compact/js07-out.jsonld

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"@version": 1.1,
44
"e": {"@id": "http://example.org/vocab#array", "@type": "@json", "@container": "@set"}
55
},
6-
"e": [{"foo": "bar"}]
7-
}
6+
"e": [[{"foo": "bar"}]]
7+
}

tests/compact/js12-context.jsonld

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"e": {"@id": "http://example.org/vocab#value", "@type": "@json"}
5+
}
6+
}

tests/compact/js12-in.jsonld

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[{
2+
"http://example.org/vocab#value": [{
3+
"@value": ["string"],
4+
"@type": "@json"
5+
}]
6+
}]

tests/compact/js12-out.jsonld

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"e": {"@id": "http://example.org/vocab#value", "@type": "@json"}
5+
},
6+
"e": ["string"]
7+
}

tests/compact/js13-context.jsonld

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"e": {"@id": "http://example.org/vocab#value", "@type": "@json"}
5+
}
6+
}

tests/compact/js13-in.jsonld

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[{
2+
"http://example.org/vocab#value": [{
3+
"@value": [],
4+
"@type": "@json"
5+
}]
6+
}]

tests/compact/js13-out.jsonld

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"e": {"@id": "http://example.org/vocab#value", "@type": "@json"}
5+
},
6+
"e": []
7+
}

tests/compact/js14-context.jsonld

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"e": {"@id": "http://example.org/vocab#value", "@type": "@json"}
5+
}
6+
}

tests/compact/js14-in.jsonld

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[{
2+
"http://example.org/vocab#value": [{
3+
"@value": [],
4+
"@type": "@json"
5+
},
6+
"non-JSON"
7+
]
8+
}]

tests/compact/js14-out.jsonld

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"e": {"@id": "http://example.org/vocab#value", "@type": "@json"}
5+
},
6+
"e": [],
7+
"http://example.org/vocab#value": "non-JSON"
8+
}

tests/compact/js15-context.jsonld

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"e": {"@id": "http://example.org/vocab#value"}
5+
}
6+
}

tests/compact/js15-in.jsonld

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[{
2+
"http://example.org/vocab#value": [{
3+
"@value": [],
4+
"@type": "@json"
5+
},
6+
"non-JSON"
7+
]
8+
}]

tests/compact/js15-out.jsonld

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"e": {"@id": "http://example.org/vocab#value"}
5+
},
6+
"e": [
7+
{
8+
"@type": "@json",
9+
"@value": []
10+
},
11+
"non-JSON"
12+
]
13+
}

tests/compact/js16-context.jsonld

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"e-json": {"@id": "http://example.org/vocab#value", "@type": "@json"},
5+
"e-non-json": {"@id": "http://example.org/vocab#value"}
6+
}
7+
}

tests/compact/js16-in.jsonld

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[{
2+
"http://example.org/vocab#value": [{
3+
"@value": [],
4+
"@type": "@json"
5+
},
6+
"non-JSON"
7+
]
8+
}]

tests/compact/js16-out.jsonld

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"e-json": {"@id": "http://example.org/vocab#value", "@type": "@json"},
5+
"e-non-json": {"@id": "http://example.org/vocab#value"}
6+
},
7+
"e-json": [],
8+
"e-non-json": "non-JSON"
9+
}

tests/expand-manifest.jsonld

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,6 +1811,20 @@
18111811
"purpose": "The value of @type in an expanded term definition object MUST be a string or null.",
18121812
"input": "expand/er55-in.jsonld",
18131813
"expectErrorCode": "invalid type mapping"
1814+
}, {
1815+
"@id": "#ter56",
1816+
"@type": ["jld:NegativeEvaluationTest", "jld:ExpandTest"],
1817+
"name": "Array not found for @json @set.",
1818+
"purpose": "The value for a @json @set term MUST be an array.",
1819+
"input": "expand/er56-in.jsonld",
1820+
"expectErrorCode": "invalid set or list object"
1821+
}, {
1822+
"@id": "#ter57",
1823+
"@type": ["jld:NegativeEvaluationTest", "jld:ExpandTest"],
1824+
"name": "Array not found for @json @list.",
1825+
"purpose": "The value for a @json @list term MUST be an array.",
1826+
"input": "expand/er57-in.jsonld",
1827+
"expectErrorCode": "invalid set or list object"
18141828
}, {
18151829
"@id": "#tes01",
18161830
"@type": ["jld:NegativeEvaluationTest", "jld:ExpandTest"],
@@ -2083,6 +2097,62 @@
20832097
"input": "expand/js23-in.jsonld",
20842098
"expect": "expand/js23-out.jsonld",
20852099
"option": {"specVersion": "json-ld-1.1"}
2100+
}, {
2101+
"@id": "#tjs24",
2102+
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
2103+
"name": "Expand JSON literal (one JSON literal).",
2104+
"purpose": "Tests expanding property with @type @json (one JSON literal).",
2105+
"input": "expand/js24-in.jsonld",
2106+
"expect": "expand/js24-out.jsonld",
2107+
"option": {"specVersion": "json-ld-1.1"}
2108+
}, {
2109+
"@id": "#tjs25",
2110+
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
2111+
"name": "Expand JSON literal (two JSON literals).",
2112+
"purpose": "Tests expanding property with @type @json (two JSON literals).",
2113+
"input": "expand/js25-in.jsonld",
2114+
"expect": "expand/js25-out.jsonld",
2115+
"option": {"specVersion": "json-ld-1.1"}
2116+
}, {
2117+
"@id": "#tjs26",
2118+
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
2119+
"name": "Expand JSON literal (JSON literal and non-JSON).",
2120+
"purpose": "Tests expanding property with @type @json (JSON literal and non-JSON).",
2121+
"input": "expand/js26-in.jsonld",
2122+
"expect": "expand/js26-out.jsonld",
2123+
"option": {"specVersion": "json-ld-1.1"}
2124+
}, {
2125+
"@id": "#tjs27",
2126+
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
2127+
"name": "Expand JSON literal (duplicate JSON literals).",
2128+
"purpose": "Tests expanding property with @type @json (dupcliate JSON literals).",
2129+
"input": "expand/js27-in.jsonld",
2130+
"expect": "expand/js27-out.jsonld",
2131+
"option": {"specVersion": "json-ld-1.1"}
2132+
}, {
2133+
"@id": "#tjs28",
2134+
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
2135+
"name": "Expand array-like value with @json and no @set/@list in @context.",
2136+
"purpose": "Tests expanding array-like value with @json and no @set/@list in @context.",
2137+
"input": "expand/js28-in.jsonld",
2138+
"expect": "expand/js28-out.jsonld",
2139+
"option": {"specVersion": "json-ld-1.1"}
2140+
}, {
2141+
"@id": "#tjs29",
2142+
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
2143+
"name": "Expand array-like value with @json and @set in @context.",
2144+
"purpose": "Tests expanding array-like value with @json and @set in @context.",
2145+
"input": "expand/js29-in.jsonld",
2146+
"expect": "expand/js29-out.jsonld",
2147+
"option": {"specVersion": "json-ld-1.1"}
2148+
}, {
2149+
"@id": "#tjs30",
2150+
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
2151+
"name": "Expand array-like value with @json and @list in @context.",
2152+
"purpose": "Tests expanding array-like value with @json and @list in @context.",
2153+
"input": "expand/js30-in.jsonld",
2154+
"expect": "expand/js30-out.jsonld",
2155+
"option": {"specVersion": "json-ld-1.1"}
20862156
}, {
20872157
"@id": "#tl001",
20882158
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],

tests/expand/er56-in.jsonld

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"@context": {
3+
"prop": {
4+
"@id": "ex:prop",
5+
"@type": "@json",
6+
"@container": "@set"
7+
}
8+
},
9+
"prop": "value"
10+
}

tests/expand/er57-in.jsonld

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"@context": {
3+
"prop": {
4+
"@id": "ex:prop",
5+
"@type": "@json",
6+
"@container": "@list"
7+
}
8+
},
9+
"prop": "value"
10+
}

tests/expand/js24-in.jsonld

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"http://example.org/vocab#null": {"@value": ["JSON"], "@type": "@json"}
3+
}

tests/expand/js24-out.jsonld

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[{
2+
"http://example.org/vocab#null": [{
3+
"@type": "@json",
4+
"@value": [
5+
"JSON"
6+
]
7+
}]
8+
}]

tests/expand/js25-in.jsonld

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"http://example.org/vocab#value": [
3+
{"@value": ["JSON1"], "@type": "@json"},
4+
{"@value": ["JSON2"], "@type": "@json"}
5+
]
6+
}

tests/expand/js25-out.jsonld

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[{
2+
"http://example.org/vocab#value": [{
3+
"@type": "@json",
4+
"@value": [
5+
"JSON1"
6+
]
7+
}, {
8+
"@type": "@json",
9+
"@value": [
10+
"JSON2"
11+
]
12+
}]
13+
}]

tests/expand/js26-in.jsonld

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"http://example.org/vocab#value": [
3+
{"@value": ["JSON"], "@type": "@json"},
4+
{"@value": "non-JSON"}
5+
]
6+
}

tests/expand/js26-out.jsonld

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[{
2+
"http://example.org/vocab#value": [{
3+
"@type": "@json",
4+
"@value": [
5+
"JSON"
6+
]
7+
}, {
8+
"@value": "non-JSON"
9+
}]
10+
}]

tests/expand/js27-in.jsonld

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"http://example.org/vocab#value": [
3+
{"@value": ["dup"], "@type": "@json"},
4+
{"@value": ["dup"], "@type": "@json"}
5+
]
6+
}

tests/expand/js27-out.jsonld

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[{
2+
"http://example.org/vocab#value": [{
3+
"@type": "@json",
4+
"@value": [
5+
"dup"
6+
]
7+
}, {
8+
"@type": "@json",
9+
"@value": [
10+
"dup"
11+
]
12+
}]
13+
}]

0 commit comments

Comments
 (0)