@@ -81,16 +81,17 @@ describe('Term', () => {
8181 } ) ;
8282
8383 it ( 'should create a Quad with the default graph if the id doesnt specify the graph' , ( ) => {
84- termFromId ( '<<http://ex.org/a http://ex.org/b "abc"@en-us>>' ) . should . deep . equal ( new Quad (
84+ const q = new Quad (
8585 new NamedNode ( 'http://ex.org/a' ) ,
8686 new NamedNode ( 'http://ex.org/b' ) ,
8787 new Literal ( '"abc"@en-us' ) ,
8888 new DefaultGraph ( )
89- ) ) ;
89+ ) ;
90+ expect ( q . equals ( termFromId ( termToId ( q ) ) ) ) . equals ( true ) ;
9091 } ) ;
9192
9293 it ( 'should create a Quad with the correct graph if the id specifies a graph' , ( ) => {
93- const id = '<< http://ex.org/a http://ex.org/b " abc"@en-us http://ex.org/d>> ' ;
94+ const id = '[" http://ex.org/a", " http://ex.org/b", "\\" abc\\ "@en-us", " http://ex.org/d"] ' ;
9495 termFromId ( id ) . should . deep . equal ( new Quad (
9596 new NamedNode ( 'http://ex.org/a' ) ,
9697 new NamedNode ( 'http://ex.org/b' ) ,
@@ -100,7 +101,7 @@ describe('Term', () => {
100101 } ) ;
101102
102103 it ( 'should create a Quad correctly' , ( ) => {
103- const id = '<< http://ex.org/a http://ex.org/b http://ex.org/c>> ' ;
104+ const id = '[" http://ex.org/a", " http://ex.org/b", " http://ex.org/c"] ' ;
104105 termFromId ( id ) . should . deep . equal ( new Quad (
105106 new NamedNode ( 'http://ex.org/a' ) ,
106107 new NamedNode ( 'http://ex.org/b' ) ,
@@ -110,7 +111,7 @@ describe('Term', () => {
110111 } ) ;
111112
112113 it ( 'should create a Quad correctly' , ( ) => {
113- const id = '<< _:n3-123 ?var-a ?var-b _:n3-000>> ' ;
114+ const id = '[" _:n3-123", " ?var-a", " ?var-b", " _:n3-000"] ' ;
114115 termFromId ( id ) . should . deep . equal ( new Quad (
115116 new BlankNode ( 'n3-123' ) ,
116117 new Variable ( 'var-a' ) ,
@@ -120,7 +121,7 @@ describe('Term', () => {
120121 } ) ;
121122
122123 it ( 'should create a Quad correctly' , ( ) => {
123- const id = '<< ?var-a ?var-b " abc"@en-us ?var-d>> ' ;
124+ const id = '[" ?var-a", " ?var-b", "\\" abc\\ "@en-us", " ?var-d"] ' ;
124125 termFromId ( id ) . should . deep . equal ( new Quad (
125126 new Variable ( 'var-a' ) ,
126127 new Variable ( 'var-b' ) ,
@@ -130,7 +131,7 @@ describe('Term', () => {
130131 } ) ;
131132
132133 it ( 'should create a Quad correctly' , ( ) => {
133- const id = '<< _:n3-000 ?var-b _:n3-123 http://ex.org/d>> ' ;
134+ const id = '[" _:n3-000", " ?var-b", " _:n3-123", " http://ex.org/d"] ' ;
134135 termFromId ( id ) . should . deep . equal ( new Quad (
135136 new BlankNode ( 'n3-000' ) ,
136137 new Variable ( 'var-b' ) ,
@@ -140,7 +141,7 @@ describe('Term', () => {
140141 } ) ;
141142
142143 it ( 'should create a Quad correctly from literal containing escaped quotes' , ( ) => {
143- const id = '<< _:n3-000 ?var-b " Hello ""W"" orl""d! "@en-us http://ex.org/d>> ' ;
144+ const id = '[" _:n3-000", " ?var-b", "\\" Hello \\"W\\" orl\\"d!\\ "@en-us", " http://ex.org/d"] ' ;
144145 termFromId ( id ) . should . deep . equal ( new Quad (
145146 new BlankNode ( 'n3-000' ) ,
146147 new Variable ( 'var-b' ) ,
@@ -150,13 +151,14 @@ describe('Term', () => {
150151 } ) ;
151152
152153 it ( 'should create a Quad correctly from literal containing escaped quotes' , ( ) => {
153- const id = '<<"Hello ""W""orl""d!"@en-us http://ex.org/b http://ex.org/c>>' ;
154- termFromId ( id ) . should . deep . equal ( new Quad (
154+ const q = new Quad (
155155 new Literal ( '"Hello "W"orl"d!"@en-us' ) ,
156156 new NamedNode ( 'http://ex.org/b' ) ,
157157 new NamedNode ( 'http://ex.org/c' ) ,
158158 new DefaultGraph ( )
159- ) ) ;
159+ ) ;
160+
161+ termFromId ( termToId ( q ) ) . should . deep . equal ( q ) ;
160162 } ) ;
161163
162164 describe ( 'with a custom factory' , ( ) => {
@@ -283,7 +285,7 @@ describe('Term', () => {
283285 new NamedNode ( 'http://ex.org/b' ) ,
284286 new Literal ( '"abc"@en-us' ) ,
285287 new DefaultGraph ( )
286- ) ) . should . equal ( '<< http://ex.org/a http://ex.org/b " abc"@en-us>> ' ) ;
288+ ) ) . should . equal ( '[" http://ex.org/a"," http://ex.org/b","\\" abc\\ "@en-us"] ' ) ;
287289 } ) ;
288290
289291 it ( 'should create an id from a Quad' , ( ) => {
@@ -292,7 +294,7 @@ describe('Term', () => {
292294 new NamedNode ( 'http://ex.org/b' ) ,
293295 new Literal ( '"abc"@en-us' ) ,
294296 new NamedNode ( 'http://ex.org/d' )
295- ) ) . should . equal ( '<< http://ex.org/a http://ex.org/b " abc"@en-us http://ex.org/d>> ' ) ;
297+ ) ) . should . equal ( '[" http://ex.org/a"," http://ex.org/b","\\" abc\\ "@en-us"," http://ex.org/d"] ' ) ;
296298 } ) ;
297299
298300 it ( 'should create an id from a manually created Quad' , ( ) => {
@@ -303,7 +305,7 @@ describe('Term', () => {
303305 graph : new NamedNode ( 'http://ex.org/d' ) ,
304306 termType : 'Quad' ,
305307 value : '' ,
306- } ) . should . equal ( '<< http://ex.org/a http://ex.org/b " abc"@en-us http://ex.org/d>> ' ) ;
308+ } ) . should . equal ( '[" http://ex.org/a"," http://ex.org/b","\\" abc\\ "@en-us"," http://ex.org/d"] ' ) ;
307309 } ) ;
308310
309311 it ( 'should create an id with escaped literals from a Quad' , ( ) => {
@@ -312,7 +314,7 @@ describe('Term', () => {
312314 new Variable ( 'var-b' ) ,
313315 new Literal ( '"Hello "W"orl"d!"@en-us' ) ,
314316 new NamedNode ( 'http://ex.org/d' )
315- ) ) . should . equal ( '<< _:n3-000 ?var-b " Hello ""W"" orl""d! "@en-us http://ex.org/d>> ' ) ;
317+ ) ) . should . equal ( '[" _:n3-000"," ?var-b","\\" Hello \\"W\\" orl\\"d!\\ "@en-us"," http://ex.org/d"] ' ) ;
316318 } ) ;
317319
318320 it ( 'should create an id without graph from a Quad with default graph and Quad as subject' , ( ) => {
@@ -326,7 +328,7 @@ describe('Term', () => {
326328 new NamedNode ( 'http://ex.org/b' ) ,
327329 new Literal ( '"abc"@en-us' ) ,
328330 new DefaultGraph ( )
329- ) ) . should . equal ( '<<<< _:n3-000 ?var-b " abc"@en-us http://ex.org/d>> http://ex.org/b " abc"@en-us>> ' ) ;
331+ ) ) . should . equal ( '[[" _:n3-000"," ?var-b","\\" abc\\ "@en-us"," http://ex.org/d"]," http://ex.org/b","\\" abc\\ "@en-us"] ' ) ;
330332 } ) ;
331333
332334 it ( 'should create an id without graph from a Quad with default graph and Quad as object' , ( ) => {
@@ -340,7 +342,7 @@ describe('Term', () => {
340342 new NamedNode ( 'http://ex.org/d' )
341343 ) ,
342344 new DefaultGraph ( )
343- ) ) . should . equal ( '<<" abc"@en-us http://ex.org/b << _:n3-000 ?var-b " abc"@en-us http://ex.org/d>>>> ' ) ;
345+ ) ) . should . equal ( '["\\" abc\\ "@en-us"," http://ex.org/b",[" _:n3-000"," ?var-b","\\" abc\\ "@en-us"," http://ex.org/d"]] ' ) ;
344346 } ) ;
345347
346348 it ( 'should create an id without graph from a Quad with default graph and Quad as subject and object' , ( ) => {
@@ -359,7 +361,7 @@ describe('Term', () => {
359361 new NamedNode ( 'http://ex.org/d' )
360362 ) ,
361363 new DefaultGraph ( )
362- ) ) . should . equal ( '<<<< _:n3-000 ?var-b " abc"@en-us http://ex.org/d>> http://ex.org/b << _:n3-000 ?var-b " abc"@en-us http://ex.org/d>>>> ' ) ;
364+ ) ) . should . equal ( '[[" _:n3-000"," ?var-b","\\" abc\\ "@en-us"," http://ex.org/d"]," http://ex.org/b",[" _:n3-000"," ?var-b","\\" abc\\ "@en-us"," http://ex.org/d"]] ' ) ;
363365 } ) ;
364366
365367 it ( 'should create an id without graph from a Quad with Quad as subject' , ( ) => {
@@ -373,7 +375,7 @@ describe('Term', () => {
373375 new NamedNode ( 'http://ex.org/b' ) ,
374376 new Literal ( '"abc"@en-us' ) ,
375377 new NamedNode ( 'http://ex.org/d' )
376- ) ) . should . equal ( '<<<< _:n3-000 ?var-b " abc"@en-us http://ex.org/d>> http://ex.org/b " abc"@en-us http://ex.org/d>> ' ) ;
378+ ) ) . should . equal ( '[[" _:n3-000"," ?var-b","\\" abc\\ "@en-us"," http://ex.org/d"]," http://ex.org/b","\\" abc\\ "@en-us"," http://ex.org/d"] ' ) ;
377379 } ) ;
378380
379381 it ( 'should create an id without graph from a Quad with Quad as object' , ( ) => {
@@ -387,7 +389,7 @@ describe('Term', () => {
387389 new NamedNode ( 'http://ex.org/d' )
388390 ) ,
389391 new NamedNode ( 'http://ex.org/d' )
390- ) ) . should . equal ( '<<" abc"@en-us http://ex.org/b << _:n3-000 ?var-b " abc"@en-us http://ex.org/d>> http://ex.org/d>> ' ) ;
392+ ) ) . should . equal ( '["\\" abc\\ "@en-us"," http://ex.org/b",[" _:n3-000"," ?var-b","\\" abc\\ "@en-us"," http://ex.org/d"]," http://ex.org/d"] ' ) ;
391393 } ) ;
392394
393395 it ( 'should create an id from a Quad with Quad as subject and object' , ( ) => {
@@ -406,7 +408,7 @@ describe('Term', () => {
406408 new NamedNode ( 'http://ex.org/d' )
407409 ) ,
408410 new NamedNode ( 'http://ex.org/d' )
409- ) ) . should . equal ( '<<<< _:n3-000 ?var-b " abc"@en-us http://ex.org/d>> http://ex.org/b << _:n3-000 ?var-b " abc"@en-us http://ex.org/d>> http://ex.org/d>> ' ) ;
411+ ) ) . should . equal ( '[[" _:n3-000"," ?var-b","\\" abc\\ "@en-us"," http://ex.org/d"]," http://ex.org/b",[" _:n3-000"," ?var-b","\\" abc\\ "@en-us"," http://ex.org/d"]," http://ex.org/d"] ' ) ;
410412 } ) ;
411413
412414 it ( 'should escape literals in nested Quads' , ( ) => {
@@ -425,11 +427,46 @@ describe('Term', () => {
425427 new NamedNode ( 'http://ex.org/d' )
426428 ) ,
427429 new DefaultGraph ( )
428- ) ) . should . equal ( '<<<<_:n3-000 ?var-b "Hello ""W""orl""d!"@en-us http://ex.org/d>> http://ex.org/b <<_:n3-000 ?var-b "Hello ""W""orl""d!"@en-us http://ex.org/d>>>>' ) ;
430+ ) ) . should . equal ( '[["_:n3-000","?var-b","\\"Hello \\"W\\"orl\\"d!\\"@en-us","http://ex.org/d"],"http://ex.org/b",["_:n3-000","?var-b","\\"Hello \\"W\\"orl\\"d!\\"@en-us","http://ex.org/d"]]' ) ;
431+ } ) ;
432+
433+
434+ it ( 'should termToId <-> termFromId should roundtrip on deeply nested quad' , ( ) => {
435+ const q = new Quad (
436+ new Quad (
437+ new NamedNode ( 'http://example.org/s1' ) ,
438+ new NamedNode ( 'http://example.org/p1' ) ,
439+ new NamedNode ( 'http://example.org/o1' )
440+ ) ,
441+ new NamedNode ( 'http://example.org/p1' ) ,
442+ new Quad (
443+ new Quad (
444+ new Literal ( '"s1"' ) ,
445+ new NamedNode ( 'http://example.org/p1' ) ,
446+ new BlankNode ( 'o1' )
447+ ) ,
448+ new NamedNode ( 'p2' ) ,
449+ new Quad (
450+ new Quad (
451+ new Literal ( '"s1"' ) ,
452+ new NamedNode ( 'http://example.org/p1' ) ,
453+ new BlankNode ( 'o1' )
454+ ) ,
455+ new NamedNode ( 'http://example.org/p1' ) ,
456+ new NamedNode ( 'http://example.org/o1' )
457+ )
458+ )
459+ ) ;
460+
461+ expect ( q ) . deep . equals ( termFromId ( termToId ( q ) ) ) ;
462+ expect ( termFromId ( termToId ( q ) ) ) . deep . equals ( q ) ;
463+ expect ( q . equals ( termFromId ( termToId ( q ) ) ) ) . equal ( true ) ;
464+ expect ( termFromId ( termToId ( q ) ) . equals ( q ) ) . equal ( true ) ;
465+ expect ( termFromId ( termToId ( q ) ) . equals ( termFromId ( termToId ( q ) ) ) ) . equal ( true ) ;
429466 } ) ;
430467
431468 it ( 'should correctly handle deeply nested quads' , ( ) => {
432- termToId ( new Quad (
469+ const q = new Quad (
433470 new Quad (
434471 new Quad (
435472 new Quad (
@@ -474,7 +511,9 @@ describe('Term', () => {
474511 new NamedNode ( 'http://ex.org/d' )
475512 ) ,
476513 new NamedNode ( 'http://ex.org/d' )
477- ) ) . should . equal ( '<<<<<<<<_:n3-000 ?var-b "abc"@en-us http://ex.org/d>> ?var-b <<_:n3-000 ?var-b "abc"@en-us http://ex.org/d>> http://ex.org/d>> ?var-b <<_:n3-000 ?var-b "abc"@en-us http://ex.org/d>> http://ex.org/d>> http://ex.org/b <<<<_:n3-000 ?var-b "abc"@en-us http://ex.org/d>> ?var-b <<_:n3-000 ?var-b "abc"@en-us http://ex.org/d>> http://ex.org/d>> http://ex.org/d>>' ) ;
514+ ) ;
515+
516+ expect ( q . equals ( termFromId ( termToId ( q ) ) ) ) . equal ( true ) ;
478517 } ) ;
479518
480519 it ( 'should throw on an unknown type' , ( ) => {
0 commit comments