Skip to content

Commit aaa1574

Browse files
committed
Add tests to check for keyword redefinition allowing @protected.
For w3c/json-ld-syntax#246.
1 parent 565f239 commit aaa1574

13 files changed

+305
-2
lines changed

index.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,8 +1365,10 @@ <h3>Algorithm</h3>
13651365
<li class="changed">If <a>processing mode</a>
13661366
is <code>json-ld-1.1</code>
13671367
and <var>term</var> is <code>@type</code>, <var>value</var>
1368-
MUST be a <a>map</a> with the entry <code>@container</code>
1369-
and value <code>@set</code>. Any other value means that a
1368+
MUST be a <a>map</a> with only the entry <code>@container</code>
1369+
and value <code>@set</code>
1370+
and optional entry `@protected`.
1371+
Any other value means that a
13701372
<a data-link-for="JsonLdErrorCode">keyword redefinition</a> error has
13711373
been detected and processing is aborted.</li>
13721374
<li><span class="changed">Otherwise</span>, since <a>keywords</a> cannot be overridden,

tests/expand-manifest.html

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8128,6 +8128,90 @@ <h2>
81288128
</dd>
81298129
</dl>
81308130
</dd>
8131+
<dt id='tpr30'>
8132+
Test tpr30 Keywords may be protected.
8133+
</dt>
8134+
<dd>
8135+
<dl class='entry'>
8136+
<dt>id</dt>
8137+
<dd>#tpr30</dd>
8138+
<dt>Type</dt>
8139+
<dd>jld:PositiveEvaluationTest, jld:ExpandTest</dd>
8140+
<dt>Purpose</dt>
8141+
<dd>Keywords may not be redefined other than to protect them.</dd>
8142+
<dt>input</dt>
8143+
<dd>
8144+
<a href='expand/pr30-in.jsonld'>expand/pr30-in.jsonld</a>
8145+
</dd>
8146+
<dt>expect</dt>
8147+
<dd>
8148+
<a href='expand/pr30-out.jsonld'>expand/pr30-out.jsonld</a>
8149+
</dd>
8150+
<dt>Options</dt>
8151+
<dd>
8152+
<dl class='options'>
8153+
<dt>specVersion</dt>
8154+
<dd>json-ld-1.1</dd>
8155+
</dl>
8156+
</dd>
8157+
</dl>
8158+
</dd>
8159+
<dt id='tpr31'>
8160+
Test tpr31 Protected keyword aliases cannot be overridden.
8161+
</dt>
8162+
<dd>
8163+
<dl class='entry'>
8164+
<dt>id</dt>
8165+
<dd>#tpr31</dd>
8166+
<dt>Type</dt>
8167+
<dd>jld:NegativeEvaluationTest, jld:ExpandTest</dd>
8168+
<dt>Purpose</dt>
8169+
<dd>Keywords may not be redefined other than to protect them.</dd>
8170+
<dt>input</dt>
8171+
<dd>
8172+
<a href='expand/pr31-in.jsonld'>expand/pr31-in.jsonld</a>
8173+
</dd>
8174+
<dt>expect</dt>
8175+
<dd>
8176+
protected term redefinition
8177+
</dd>
8178+
<dt>Options</dt>
8179+
<dd>
8180+
<dl class='options'>
8181+
<dt>specVersion</dt>
8182+
<dd>json-ld-1.1</dd>
8183+
</dl>
8184+
</dd>
8185+
</dl>
8186+
</dd>
8187+
<dt id='tpr32'>
8188+
Test tpr32 Protected @type cannot be overridden.
8189+
</dt>
8190+
<dd>
8191+
<dl class='entry'>
8192+
<dt>id</dt>
8193+
<dd>#tpr32</dd>
8194+
<dt>Type</dt>
8195+
<dd>jld:NegativeEvaluationTest, jld:ExpandTest</dd>
8196+
<dt>Purpose</dt>
8197+
<dd>Keywords may not be redefined other than to protect them.</dd>
8198+
<dt>input</dt>
8199+
<dd>
8200+
<a href='expand/pr32-in.jsonld'>expand/pr32-in.jsonld</a>
8201+
</dd>
8202+
<dt>expect</dt>
8203+
<dd>
8204+
protected term redefinition
8205+
</dd>
8206+
<dt>Options</dt>
8207+
<dd>
8208+
<dl class='options'>
8209+
<dt>specVersion</dt>
8210+
<dd>json-ld-1.1</dd>
8211+
</dl>
8212+
</dd>
8213+
</dl>
8214+
</dd>
81318215
<dt id='tpr33'>
81328216
Test tpr33 Fails if trying to declare a keyword alias as prefix.
81338217
</dt>

tests/expand-manifest.jsonld

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,6 +2368,30 @@
23682368
"option": {"specVersion": "json-ld-1.1"},
23692369
"input": "expand/pr29-in.jsonld",
23702370
"expect": "expand/pr29-out.jsonld"
2371+
}, {
2372+
"@id": "#tpr30",
2373+
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
2374+
"name": "Keywords may be protected.",
2375+
"purpose": "Keywords may not be redefined other than to protect them.",
2376+
"option": {"specVersion": "json-ld-1.1"},
2377+
"input": "expand/pr30-in.jsonld",
2378+
"expect": "expand/pr30-out.jsonld"
2379+
}, {
2380+
"@id": "#tpr31",
2381+
"@type": ["jld:NegativeEvaluationTest", "jld:ExpandTest"],
2382+
"name": "Protected keyword aliases cannot be overridden.",
2383+
"purpose": "Keywords may not be redefined other than to protect them.",
2384+
"option": {"specVersion": "json-ld-1.1"},
2385+
"input": "expand/pr31-in.jsonld",
2386+
"expect": "protected term redefinition"
2387+
}, {
2388+
"@id": "#tpr32",
2389+
"@type": ["jld:NegativeEvaluationTest", "jld:ExpandTest"],
2390+
"name": "Protected @type cannot be overridden.",
2391+
"purpose": "Keywords may not be redefined other than to protect them.",
2392+
"option": {"specVersion": "json-ld-1.1"},
2393+
"input": "expand/pr32-in.jsonld",
2394+
"expect": "protected term redefinition"
23712395
}, {
23722396
"@id": "#tpr33",
23732397
"@type": ["jld:NegativeEvaluationTest", "jld:ExpandTest"],

tests/expand/pr30-in.jsonld

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"id": {"@id": "@id", "@protected": true},
5+
"type": {"@id" : "@type", "@container": "@set", "@protected" : true},
6+
"@type": {"@container": "@set", "@protected": true}
7+
},
8+
"id": "http://example.com/1",
9+
"type": "http://example.org/ns/Foo",
10+
"@type": "http://example.org/ns/Bar"
11+
}

tests/expand/pr30-out.jsonld

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[
2+
{
3+
"@id": "http://example.com/1",
4+
"@type": [
5+
"http://example.org/ns/Foo",
6+
"http://example.org/ns/Bar"
7+
]
8+
}
9+
]

tests/expand/pr31-in.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+
"id": {"@id": "@id", "@protected": true},
5+
"type": {"@id" : "@type", "@container": "@set", "@protected" : true},
6+
"@type": {"@container": "@set", "@protected": true}
7+
}, {
8+
"@version": 1.1,
9+
"id": "http://example.com/id"
10+
}],
11+
"id": "http://example.com/1",
12+
"type": ["http://example.org/ns/Foo"]
13+
}

tests/expand/pr32-in.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+
"id": {"@id": "@id", "@protected": true},
5+
"type": {"@id" : "@type", "@container": "@set", "@protected" : true},
6+
"@type": {"@container": "@set", "@protected": true}
7+
}, {
8+
"@version": 1.1,
9+
"@type": {"@protected": true}
10+
}],
11+
"id": "http://example.com/1",
12+
"type": ["http://example.org/ns/Foo"]
13+
}

tests/toRdf-manifest.html

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7066,6 +7066,90 @@ <h2>
70667066
</dd>
70677067
</dl>
70687068
</dd>
7069+
<dt id='tpr30'>
7070+
Test tpr30 Keywords may be protected.
7071+
</dt>
7072+
<dd>
7073+
<dl class='entry'>
7074+
<dt>id</dt>
7075+
<dd>#tpr30</dd>
7076+
<dt>Type</dt>
7077+
<dd>jld:PositiveEvaluationTest, jld:ToRDFTest</dd>
7078+
<dt>Purpose</dt>
7079+
<dd>Keywords may not be redefined other than to protect them.</dd>
7080+
<dt>input</dt>
7081+
<dd>
7082+
<a href='toRdf/pr30-in.jsonld'>toRdf/pr30-in.jsonld</a>
7083+
</dd>
7084+
<dt>expect</dt>
7085+
<dd>
7086+
<a href='toRdf/pr30-out.nq'>toRdf/pr30-out.nq</a>
7087+
</dd>
7088+
<dt>Options</dt>
7089+
<dd>
7090+
<dl class='options'>
7091+
<dt>specVersion</dt>
7092+
<dd>json-ld-1.1</dd>
7093+
</dl>
7094+
</dd>
7095+
</dl>
7096+
</dd>
7097+
<dt id='tpr31'>
7098+
Test tpr31 Protected keyword aliases cannot be overridden.
7099+
</dt>
7100+
<dd>
7101+
<dl class='entry'>
7102+
<dt>id</dt>
7103+
<dd>#tpr31</dd>
7104+
<dt>Type</dt>
7105+
<dd>jld:NegativeEvaluationTest, jld:ToRDFTest</dd>
7106+
<dt>Purpose</dt>
7107+
<dd>Keywords may not be redefined other than to protect them.</dd>
7108+
<dt>input</dt>
7109+
<dd>
7110+
<a href='toRdf/pr31-in.jsonld'>toRdf/pr31-in.jsonld</a>
7111+
</dd>
7112+
<dt>expect</dt>
7113+
<dd>
7114+
term redefinition
7115+
</dd>
7116+
<dt>Options</dt>
7117+
<dd>
7118+
<dl class='options'>
7119+
<dt>specVersion</dt>
7120+
<dd>json-ld-1.1</dd>
7121+
</dl>
7122+
</dd>
7123+
</dl>
7124+
</dd>
7125+
<dt id='tpr32'>
7126+
Test tpr32 Protected @type cannot be overridden.
7127+
</dt>
7128+
<dd>
7129+
<dl class='entry'>
7130+
<dt>id</dt>
7131+
<dd>#tpr32</dd>
7132+
<dt>Type</dt>
7133+
<dd>jld:NegativeEvaluationTest, jld:ToRDFTest</dd>
7134+
<dt>Purpose</dt>
7135+
<dd>Keywords may not be redefined other than to protect them.</dd>
7136+
<dt>input</dt>
7137+
<dd>
7138+
<a href='toRdf/pr32-in.jsonld'>toRdf/pr32-in.jsonld</a>
7139+
</dd>
7140+
<dt>expect</dt>
7141+
<dd>
7142+
protected term redefinition
7143+
</dd>
7144+
<dt>Options</dt>
7145+
<dd>
7146+
<dl class='options'>
7147+
<dt>specVersion</dt>
7148+
<dd>json-ld-1.1</dd>
7149+
</dl>
7150+
</dd>
7151+
</dl>
7152+
</dd>
70697153
<dt id='tpr33'>
70707154
Test tpr33 Fails if trying to declare a keyword alias as prefix.
70717155
</dt>

tests/toRdf-manifest.jsonld

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,6 +2110,30 @@
21102110
"option": {"specVersion": "json-ld-1.1"},
21112111
"input": "toRdf/pr29-in.jsonld",
21122112
"expect": "toRdf/pr29-out.nq"
2113+
}, {
2114+
"@id": "#tpr30",
2115+
"@type": ["jld:PositiveEvaluationTest", "jld:ToRDFTest"],
2116+
"name": "Keywords may be protected.",
2117+
"purpose": "Keywords may not be redefined other than to protect them.",
2118+
"option": {"specVersion": "json-ld-1.1"},
2119+
"input": "toRdf/pr30-in.jsonld",
2120+
"expect": "toRdf/pr30-out.nq"
2121+
}, {
2122+
"@id": "#tpr31",
2123+
"@type": ["jld:NegativeEvaluationTest", "jld:ToRDFTest"],
2124+
"name": "Protected keyword aliases cannot be overridden.",
2125+
"purpose": "Keywords may not be redefined other than to protect them.",
2126+
"option": {"specVersion": "json-ld-1.1"},
2127+
"input": "toRdf/pr31-in.jsonld",
2128+
"expect": "term redefinition"
2129+
}, {
2130+
"@id": "#tpr32",
2131+
"@type": ["jld:NegativeEvaluationTest", "jld:ToRDFTest"],
2132+
"name": "Protected @type cannot be overridden.",
2133+
"purpose": "Keywords may not be redefined other than to protect them.",
2134+
"option": {"specVersion": "json-ld-1.1"},
2135+
"input": "toRdf/pr32-in.jsonld",
2136+
"expect": "protected term redefinition"
21132137
}, {
21142138
"@id": "#tpr33",
21152139
"@type": ["jld:NegativeEvaluationTest", "jld:ToRDFTest"],

tests/toRdf/pr30-in.jsonld

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"id": {"@id": "@id", "@protected": true},
5+
"type": {"@id" : "@type", "@container": "@set", "@protected" : true},
6+
"@type": {"@container": "@set", "@protected": true}
7+
},
8+
"id": "http://example.com/1",
9+
"type": "http://example.org/ns/Foo",
10+
"@type": "http://example.org/ns/Bar"
11+
}

tests/toRdf/pr30-out.nq

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<http://example.com/1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/ns/Bar> .
2+
<http://example.com/1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/ns/Foo> .

tests/toRdf/pr31-in.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+
"id": {"@id": "@id", "@protected": true},
5+
"type": {"@id" : "@type", "@container": "@set", "@protected" : true},
6+
"@type": {"@container": "@set", "@protected": true}
7+
}, {
8+
"@version": 1.1,
9+
"id": "http://example.com/id"
10+
}],
11+
"id": "http://example.com/1",
12+
"type": ["http://example.org/ns/Foo"]
13+
}

tests/toRdf/pr32-in.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+
"id": {"@id": "@id", "@protected": true},
5+
"type": {"@id" : "@type", "@container": "@set", "@protected" : true},
6+
"@type": {"@container": "@set", "@protected": true}
7+
}, {
8+
"@version": 1.1,
9+
"@type": {"@protected": true}
10+
}],
11+
"id": "http://example.com/1",
12+
"type": ["http://example.org/ns/Foo"]
13+
}

0 commit comments

Comments
 (0)