Add frame test case, update to latest jsonld.js.
authorDave Longley <dlongley@digitalbazaar.com>
Mon, 21 May 2012 15:52:15 -0400
changeset 664 28d69a9da4a9
parent 663 667033d27436
child 665 3595fa871cbc
Add frame test case, update to latest jsonld.js.
playground/jsonld.js
test-suite/tests/frame-0020-frame.jsonld
test-suite/tests/frame-0020-in.jsonld
test-suite/tests/frame-0020-out.jsonld
test-suite/tests/frame-manifest.jsonld
--- a/playground/jsonld.js	Mon May 21 15:21:12 2012 -0400
+++ b/playground/jsonld.js	Mon May 21 15:52:15 2012 -0400
@@ -2349,10 +2349,7 @@
         // handle embedded subject or subject reference
         if(_isSubject(o) || _isSubjectReference(o)) {
           // rename blank node @id
-          var id = ('@id' in o) ? o['@id'] : '_:';
-          if(id.indexOf('_:') === 0) {
-            id = namer.getName(id);
-          }
+          var id = _isBlankNode(o) ? namer.getName(o['@id']) : o['@id'];
 
           // add reference and recurse
           jsonld.addValue(subject, prop, {'@id': id}, true);
@@ -3972,7 +3969,13 @@
       s.object = {nominalValue: match[5], interfaceName: 'BlankNode'};
     }
     else {
-      s.object = {nominalValue: match[6], interfaceName: 'LiteralNode'};
+      var unescaped = match[6]
+        .replace(/\\"/g, '"')
+        .replace(/\\t/g, '\t')
+        .replace(/\\n/g, '\n')
+        .replace(/\\r/g, '\r')
+        .replace(/\\\\/g, '\\');
+      s.object = {nominalValue: unescaped, interfaceName: 'LiteralNode'};
       if(!_isUndefined(match[7])) {
         s.object.datatype = {nominalValue: match[7], interfaceName: 'IRI'};
       }
@@ -4047,7 +4050,13 @@
     }
   }
   else {
-    quad += '"' + o.nominalValue + '"';
+    var escaped = o.nominalValue
+      .replace(/\\/g, '\\\\')
+      .replace(/\t/g, '\\t')
+      .replace(/\n/g, '\\n')
+      .replace(/\r/g, '\\r')
+      .replace(/\"/g, '\\"');
+    quad += '"' + escaped + '"';
     if('datatype' in o) {
       quad += '^^<' + o.datatype.nominalValue + '>';
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-suite/tests/frame-0020-frame.jsonld	Mon May 21 15:52:15 2012 -0400
@@ -0,0 +1,1 @@
+{}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-suite/tests/frame-0020-in.jsonld	Mon May 21 15:52:15 2012 -0400
@@ -0,0 +1,34 @@
+{
+  "@context": {
+    "name": "http://rdf.data-vocabulary.org/#name",
+    "ingredient": "http://rdf.data-vocabulary.org/#ingredients",
+    "yield": "http://rdf.data-vocabulary.org/#yield",
+    "instructions": "http://rdf.data-vocabulary.org/#instructions",
+    "step": {
+      "@id": "http://rdf.data-vocabulary.org/#step",
+      "@type": "xsd:integer"
+    },
+    "description": "http://rdf.data-vocabulary.org/#description",
+    "xsd": "http://www.w3.org/2001/XMLSchema#"
+  },
+  "name": "Mojito",
+  "ingredient": ["12 fresh mint leaves", "1/2 lime, juiced with pulp", "1 tablespoons white sugar", "1 cup ice cubes", "2 fluid ounces white rum", "1/2 cup club soda"],
+  "yield": "1 cocktail",
+  "instructions": [
+  {
+    "step": 1,
+    "description": "Crush lime juice, mint and sugar together in glass."
+  }, {
+    "step": 2,
+    "description": "Fill glass to top with ice cubes."
+  }, {
+    "step": 3,
+    "description": "Pour white rum over ice."
+  }, {
+    "step": 4,
+    "description": "Fill the rest of glass with club soda, stir."
+  }, {
+    "step": 5,
+    "description": "Garnish with a lime wedge."
+  }]
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-suite/tests/frame-0020-out.jsonld	Mon May 21 15:52:15 2012 -0400
@@ -0,0 +1,80 @@
+{
+  "@graph": [
+  {
+    "@id": "_:t0",
+    "http://rdf.data-vocabulary.org/#ingredients": ["12 fresh mint leaves", "1/2 lime, juiced with pulp", "1 tablespoons white sugar", "1 cup ice cubes", "2 fluid ounces white rum", "1/2 cup club soda"],
+    "http://rdf.data-vocabulary.org/#instructions": [{
+      "@id": "_:t1",
+      "http://rdf.data-vocabulary.org/#step": {
+        "@value": 1,
+        "@type": "http://www.w3.org/2001/XMLSchema#integer"
+      },
+      "http://rdf.data-vocabulary.org/#description": "Crush lime juice, mint and sugar together in glass."
+    }, {
+      "@id": "_:t2",
+      "http://rdf.data-vocabulary.org/#step": {
+        "@value": 2,
+        "@type": "http://www.w3.org/2001/XMLSchema#integer"
+      },
+      "http://rdf.data-vocabulary.org/#description": "Fill glass to top with ice cubes."
+    }, {
+      "@id": "_:t3",
+      "http://rdf.data-vocabulary.org/#step": {
+        "@value": 3,
+        "@type": "http://www.w3.org/2001/XMLSchema#integer"
+      },
+      "http://rdf.data-vocabulary.org/#description": "Pour white rum over ice."
+    }, {
+      "@id": "_:t4",
+      "http://rdf.data-vocabulary.org/#step": {
+        "@value": 4,
+        "@type": "http://www.w3.org/2001/XMLSchema#integer"
+      },
+      "http://rdf.data-vocabulary.org/#description": "Fill the rest of glass with club soda, stir."
+    }, {
+      "@id": "_:t5",
+      "http://rdf.data-vocabulary.org/#step": {
+        "@value": 5,
+        "@type": "http://www.w3.org/2001/XMLSchema#integer"
+      },
+      "http://rdf.data-vocabulary.org/#description": "Garnish with a lime wedge."
+    }],
+    "http://rdf.data-vocabulary.org/#name": "Mojito",
+    "http://rdf.data-vocabulary.org/#yield": "1 cocktail"
+  }, {
+    "@id": "_:t1",
+    "http://rdf.data-vocabulary.org/#step": {
+      "@value": 1,
+      "@type": "http://www.w3.org/2001/XMLSchema#integer"
+    },
+    "http://rdf.data-vocabulary.org/#description": "Crush lime juice, mint and sugar together in glass."
+  }, {
+    "@id": "_:t2",
+    "http://rdf.data-vocabulary.org/#step": {
+      "@value": 2,
+      "@type": "http://www.w3.org/2001/XMLSchema#integer"
+    },
+    "http://rdf.data-vocabulary.org/#description": "Fill glass to top with ice cubes."
+  }, {
+    "@id": "_:t3",
+    "http://rdf.data-vocabulary.org/#step": {
+      "@value": 3,
+      "@type": "http://www.w3.org/2001/XMLSchema#integer"
+    },
+    "http://rdf.data-vocabulary.org/#description": "Pour white rum over ice."
+  }, {
+    "@id": "_:t4",
+    "http://rdf.data-vocabulary.org/#step": {
+      "@value": 4,
+      "@type": "http://www.w3.org/2001/XMLSchema#integer"
+    },
+    "http://rdf.data-vocabulary.org/#description": "Fill the rest of glass with club soda, stir."
+  }, {
+    "@id": "_:t5",
+    "http://rdf.data-vocabulary.org/#step": {
+      "@value": 5,
+      "@type": "http://www.w3.org/2001/XMLSchema#integer"
+    },
+    "http://rdf.data-vocabulary.org/#description": "Garnish with a lime wedge."
+  }]
+}
--- a/test-suite/tests/frame-manifest.jsonld	Mon May 21 15:21:12 2012 -0400
+++ b/test-suite/tests/frame-manifest.jsonld	Mon May 21 15:52:15 2012 -0400
@@ -118,5 +118,11 @@
       "input": "frame-0019-in.jsonld",
       "frame": "frame-0019-frame.jsonld",
       "expect": "frame-0019-out.jsonld"
+   }, {
+      "@type": ["test:TestCase", "jld:FrameTest"],
+      "name": "Blank nodes in an array",
+      "input": "frame-0020-in.jsonld",
+      "frame": "frame-0020-frame.jsonld",
+      "expect": "frame-0020-out.jsonld"
    }]
 }