Throw an error if keywords are being redefined instead of silently ignoring it
authorMarkus Lanthaler <mark_lanthaler@gmx.net>
Sun, 20 Jan 2013 11:53:53 +0100
changeset 1137 548b07e9079c
parent 1136 9aed4242f72d
child 1138 df5334e8f43b
Throw an error if keywords are being redefined instead of silently ignoring it

I've also created a new manifest `error-expand-manifest.json` to collect expansion tests which result in an error. The expected result represents the error code.

I think we don't need to discuss this issue further and will thus directly close it. Feel free to reopen it.

This closes #210.
spec/latest/json-ld-api/index.html
test-suite/tests/compact-0045-context.jsonld
test-suite/tests/compact-0045-in.jsonld
test-suite/tests/compact-0045-out.jsonld
test-suite/tests/compact-0046-context.jsonld
test-suite/tests/compact-0046-in.jsonld
test-suite/tests/compact-0046-out.jsonld
test-suite/tests/compact-manifest.jsonld
test-suite/tests/error-expand-0001-in.jsonld
test-suite/tests/error-expand-manifest.jsonld
test-suite/tests/expand-0043-in.jsonld
test-suite/tests/expand-0043-out.jsonld
test-suite/tests/expand-0050-in.jsonld
test-suite/tests/expand-0050-out.jsonld
test-suite/tests/expand-manifest.jsonld
--- a/spec/latest/json-ld-api/index.html	Sat Jan 19 17:04:41 2013 -0500
+++ b/spec/latest/json-ld-api/index.html	Sun Jan 20 11:53:53 2013 +0100
@@ -1035,8 +1035,8 @@
               following steps:
               <ol class="algorithm">
                 <li>Remove the <em>key</em>-<em>value</em> pair from <em>context</em>.</li>
-                <li>If <em>key</em> is a JSON-LD <tref>keyword</tref>, continue with the next
-                  <em>key</em>-<em>value</em> pair.</li>
+                <li>If <em>key</em> is a JSON-LD <tref>keyword</tref>, raise a
+                  <code class="error">keyword redefinition</code> error.</li>
                 <li>If <em>value</em> equals <tref>null</tref>, replace the <tref>term definition</tref>
                   for <em>key</em> in the <tref>active context</tref> with an <tref>IRI mapping</tref>
                   set to <tref>null</tref> and continue with the next <em>key</em>-<em>value</em> pair.</li>
@@ -2581,6 +2581,8 @@
         <dt>invalid vocab mapping</dt>
         <dd>An invalid <tref>vocabulary mapping</tref> has been detected, i.e.,
           it is neither an <tref>absolute IRI</tref> nor <tref>null</tref>.</dd>
+        <dt>keyword redefinition</dt>
+        <dd>A <tref>keyword</tref> redefinition has been detected.</dd>
         <dt>invalid term definition</dt>
         <dd>An invalid <tref>term definition</tref> has been detected.</dd>
         <dt>invalid term IRI mapping</dt>
--- a/test-suite/tests/compact-0045-context.jsonld	Sat Jan 19 17:04:41 2013 -0500
+++ b/test-suite/tests/compact-0045-context.jsonld	Sun Jan 20 11:53:53 2013 +0100
@@ -1,5 +1,19 @@
 {
   "@context": {
-    "@type": "@id"
-  }
+    "term": "http://example.com/terms-are-not-considered-in-id",
+    "compact-iris": "http://example.com/compact-iris-",
+    "property": "http://example.com/property",
+    "@vocab": "http://example.org/vocab-is-not-considered-for-id"
+  },
+  "@id": "term",
+  "property": [
+    {
+      "@id": "compact-iris:are-considered",
+      "property": "@id supports the following values: relative, absolute, and compact IRIs"
+    },
+    {
+      "@id": "../parent-node",
+      "property": "relative IRIs get resolved against the document's base IRI"
+    }
+  ]
 }
--- a/test-suite/tests/compact-0045-in.jsonld	Sat Jan 19 17:04:41 2013 -0500
+++ b/test-suite/tests/compact-0045-in.jsonld	Sun Jan 20 11:53:53 2013 +0100
@@ -1,5 +1,19 @@
 [
   {
-    "@type": [ "http://example.org/type" ]
+    "@id": "http://json-ld.org/test-suite/tests/term",
+    "http://example.com/property": [
+      {
+        "@id": "http://example.com/compact-iris-are-considered",
+        "http://example.com/property": [
+          { "@value": "@id supports the following values: relative, absolute, and compact IRIs" }
+        ]
+      },
+      {
+        "@id": "http://json-ld.org/test-suite/parent-node",
+        "http://example.com/property": [
+          { "@value": "relative IRIs get resolved against the document's base IRI" }
+        ]
+      }
+    ]
   }
 ]
--- a/test-suite/tests/compact-0045-out.jsonld	Sat Jan 19 17:04:41 2013 -0500
+++ b/test-suite/tests/compact-0045-out.jsonld	Sun Jan 20 11:53:53 2013 +0100
@@ -1,6 +1,19 @@
 {
   "@context": {
-    "@type": "@id"
+    "term": "http://example.com/terms-are-not-considered-in-id",
+    "compact-iris": "http://example.com/compact-iris-",
+    "property": "http://example.com/property",
+    "@vocab": "http://example.org/vocab-is-not-considered-for-id"
   },
-  "@type": "http://example.org/type"
+  "@id": "term",
+  "property": [
+    {
+      "@id": "compact-iris:are-considered",
+      "property": "@id supports the following values: relative, absolute, and compact IRIs"
+    },
+    {
+      "@id": "../parent-node",
+      "property": "relative IRIs get resolved against the document's base IRI"
+    }
+  ]
 }
--- a/test-suite/tests/compact-0046-context.jsonld	Sat Jan 19 17:04:41 2013 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-{
-  "@context": {
-    "term": "http://example.com/terms-are-not-considered-in-id",
-    "compact-iris": "http://example.com/compact-iris-",
-    "property": "http://example.com/property",
-    "@vocab": "http://example.org/vocab-is-not-considered-for-id"
-  },
-  "@id": "term",
-  "property": [
-    {
-      "@id": "compact-iris:are-considered",
-      "property": "@id supports the following values: relative, absolute, and compact IRIs"
-    },
-    {
-      "@id": "../parent-node",
-      "property": "relative IRIs get resolved against the document's base IRI"
-    }
-  ]
-}
--- a/test-suite/tests/compact-0046-in.jsonld	Sat Jan 19 17:04:41 2013 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-[
-  {
-    "@id": "http://json-ld.org/test-suite/tests/term",
-    "http://example.com/property": [
-      {
-        "@id": "http://example.com/compact-iris-are-considered",
-        "http://example.com/property": [
-          { "@value": "@id supports the following values: relative, absolute, and compact IRIs" }
-        ]
-      },
-      {
-        "@id": "http://json-ld.org/test-suite/parent-node",
-        "http://example.com/property": [
-          { "@value": "relative IRIs get resolved against the document's base IRI" }
-        ]
-      }
-    ]
-  }
-]
--- a/test-suite/tests/compact-0046-out.jsonld	Sat Jan 19 17:04:41 2013 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-{
-  "@context": {
-    "term": "http://example.com/terms-are-not-considered-in-id",
-    "compact-iris": "http://example.com/compact-iris-",
-    "property": "http://example.com/property",
-    "@vocab": "http://example.org/vocab-is-not-considered-for-id"
-  },
-  "@id": "term",
-  "property": [
-    {
-      "@id": "compact-iris:are-considered",
-      "property": "@id supports the following values: relative, absolute, and compact IRIs"
-    },
-    {
-      "@id": "../parent-node",
-      "property": "relative IRIs get resolved against the document's base IRI"
-    }
-  ]
-}
--- a/test-suite/tests/compact-manifest.jsonld	Sat Jan 19 17:04:41 2013 -0500
+++ b/test-suite/tests/compact-manifest.jsonld	Sun Jan 20 11:53:53 2013 +0100
@@ -273,16 +273,10 @@
       "expect": "compact-0044-out.jsonld"
     }, {
       "@type": ["test:TestCase", "jld:CompactTest"],
-      "name": "Keywords cannot be aliased to other keywords",
+      "name": "Values of @id are transformed to relative IRIs, terms are ignored",
       "input": "compact-0045-in.jsonld",
       "context": "compact-0045-context.jsonld",
       "expect": "compact-0045-out.jsonld"
-    }, {
-      "@type": ["test:TestCase", "jld:CompactTest"],
-      "name": "Values of @id are transformed to relative IRIs, terms are ignored",
-      "input": "compact-0046-in.jsonld",
-      "context": "compact-0046-context.jsonld",
-      "expect": "compact-0046-out.jsonld"
     }
   ]
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-suite/tests/error-expand-0001-in.jsonld	Sun Jan 20 11:53:53 2013 +0100
@@ -0,0 +1,6 @@
+{
+  "@context": {
+    "@type": "@id"
+  },
+  "@type": "http://example.org/type"
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-suite/tests/error-expand-manifest.jsonld	Sun Jan 20 11:53:53 2013 +0100
@@ -0,0 +1,16 @@
+{
+  "@context": "http://json-ld.org/test-suite/context.jsonld",
+  "@id": "",
+  "@type": "jld:Manifest",
+  "rdfs:comment": "JSON-LD to Expansion tests use object compare",
+  "name": "error-expand",
+  "baseIri": "http://json-ld.org/test-suite/tests/",
+  "sequence": [
+    {
+      "@type": [ "test:TestCase", "jld:ExpandTest", "jld:ApiErrorTest" ],
+      "name": "Keywords cannot be aliased to other keywords",
+      "input": "error-expand-0001-in.jsonld",
+      "expect": "keyword redefinition"
+    }
+  ]
+}
--- a/test-suite/tests/expand-0043-in.jsonld	Sat Jan 19 17:04:41 2013 -0500
+++ b/test-suite/tests/expand-0043-in.jsonld	Sun Jan 20 11:53:53 2013 +0100
@@ -1,6 +1,20 @@
 {
   "@context": {
-    "@type": "@id"
+    "site": "http://example.com/",
+    "field_tags": {
+      "@id": [ "site:vocab/field_tags", "http://schema.org/about" ]
+    },
+    "field_related": {
+      "@id": [ "site:vocab/field_related", "http://schema.org/about" ]
+    }
   },
-  "@type": "http://example.org/type"
+  "@graph": {
+    "@id": "site:node/1",
+    "field_tags": [
+      { "@id": "site:term/this-is-a-tag" }
+    ],
+    "field_related": [
+      { "@id": "site:node/this-is-related-news" }
+    ]
+  }
 }
--- a/test-suite/tests/expand-0043-out.jsonld	Sat Jan 19 17:04:41 2013 -0500
+++ b/test-suite/tests/expand-0043-out.jsonld	Sun Jan 20 11:53:53 2013 +0100
@@ -1,5 +1,14 @@
-[
-  {
-    "@type": [ "http://example.org/type" ]
-  }
-]
+[{
+   "@id": "http://example.com/node/1",
+   "http://example.com/vocab/field_related": [{
+      "@id": "http://example.com/node/this-is-related-news"
+   }],
+   "http://schema.org/about": [{
+      "@id": "http://example.com/node/this-is-related-news"
+   }, {
+      "@id": "http://example.com/term/this-is-a-tag"
+   }],
+   "http://example.com/vocab/field_tags": [{
+      "@id": "http://example.com/term/this-is-a-tag"
+   }]
+}]
--- a/test-suite/tests/expand-0050-in.jsonld	Sat Jan 19 17:04:41 2013 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-{
-  "@context": {
-    "site": "http://example.com/",
-    "field_tags": {
-      "@id": [ "site:vocab/field_tags", "http://schema.org/about" ]
-    },
-    "field_related": {
-      "@id": [ "site:vocab/field_related", "http://schema.org/about" ]
-    }
-  },
-  "@graph": {
-    "@id": "site:node/1",
-    "field_tags": [
-      { "@id": "site:term/this-is-a-tag" }
-    ],
-    "field_related": [
-      { "@id": "site:node/this-is-related-news" }
-    ]
-  }
-}
--- a/test-suite/tests/expand-0050-out.jsonld	Sat Jan 19 17:04:41 2013 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-[{
-   "@id": "http://example.com/node/1",
-   "http://example.com/vocab/field_related": [{
-      "@id": "http://example.com/node/this-is-related-news"
-   }],
-   "http://schema.org/about": [{
-      "@id": "http://example.com/node/this-is-related-news"
-   }, {
-      "@id": "http://example.com/term/this-is-a-tag"
-   }],
-   "http://example.com/vocab/field_tags": [{
-      "@id": "http://example.com/term/this-is-a-tag"
-   }]
-}]
--- a/test-suite/tests/expand-manifest.jsonld	Sat Jan 19 17:04:41 2013 -0500
+++ b/test-suite/tests/expand-manifest.jsonld	Sun Jan 20 11:53:53 2013 +0100
@@ -218,7 +218,7 @@
       "expect": "expand-0042-out.jsonld"
     }, {
       "@type": ["test:TestCase", "jld:ExpandTest"],
-      "name": "Keywords cannot be aliased to other keywords",
+      "name": "Property generator works with @graph key",
       "input": "expand-0043-in.jsonld",
       "expect": "expand-0043-out.jsonld"
     }, {
@@ -251,11 +251,6 @@
       "name": "Do not add @id to @value objects when expanding property generators",
       "input": "expand-0049-in.jsonld",
       "expect": "expand-0049-out.jsonld"
-    }, {
-      "@type": ["test:TestCase", "jld:ExpandTest"],
-      "name": "Property generator works with @graph key",
-      "input": "expand-0050-in.jsonld",
-      "expect": "expand-0050-out.jsonld"
     }
   ]
 }