Fix normalize test for removing duplicates, update jsonld.js.
authorDave Longley <dlongley@digitalbazaar.com>
Mon, 16 Jan 2012 15:53:19 -0500
changeset 339 d44108365f01
parent 338 f206ab6e2a0d
child 343 b8201c1e4f5a
Fix normalize test for removing duplicates, update jsonld.js.
playground/jsonld.js
test-suite/tests/normalize-0012-out.jsonld
test-suite/tests/normalize-manifest.jsonld
--- a/playground/jsonld.js	Thu Jan 12 13:31:11 2012 -0500
+++ b/playground/jsonld.js	Mon Jan 16 15:53:19 2012 -0500
@@ -1644,16 +1644,11 @@
    {
       if(parent.constructor === Array)
       {
-         // do not add duplicate IRIs for the same property
-         var duplicate = false;
-         if(flattened.constructor === Object && '@id' in flattened)
+         // do not add duplicates for the same property
+         var duplicate = (parent.filter(function(e)
          {
-            duplicate = (parent.filter(function(e)
-            {
-               return (e.constructor === Object && '@id' in e &&
-                  e['@id'] === flattened['@id']);
-            }).length > 0);
-         }
+            return (_compareObjects(e, flattened) === 0);
+         }).length > 0);
          if(!duplicate)
          {
             parent.push(flattened);
--- a/test-suite/tests/normalize-0012-out.jsonld	Thu Jan 12 13:31:11 2012 -0500
+++ b/test-suite/tests/normalize-0012-out.jsonld	Mon Jan 16 15:53:19 2012 -0500
@@ -1,1 +1,1 @@
-[{"@id":"http://example.org/test#example","http://example.org/vocab#date":[{"@value":"2011-01-25T00:00:00Z","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},{"@value":"2011-01-25T00:00:00Z","@type":"http://www.w3.org/2001/XMLSchema#dateTime"}]}]
\ No newline at end of file
+[{"@id":"http://example.org/test#example","http://example.org/vocab#date":{"@value":"2011-01-25T00:00:00Z","@type":"http://www.w3.org/2001/XMLSchema#dateTime"}}]
--- a/test-suite/tests/normalize-manifest.jsonld	Thu Jan 12 13:31:11 2012 -0500
+++ b/test-suite/tests/normalize-manifest.jsonld	Mon Jan 16 15:53:19 2012 -0500
@@ -61,7 +61,7 @@
       "expect": "normalize-0011-out.jsonld"
    }, {
       "@type": ["test:TestCase", "jld:NormalizeTest"],
-      "name": "type-coerced type, double reference",
+      "name": "type-coerced type, remove duplicate reference",
       "input": "normalize-0012-in.jsonld",
       "expect": "normalize-0012-out.jsonld"
    }, {