n3 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  var N3Store = require('../N3').Store;
2
- var chai = require('chai'),
3
- expect = chai.expect;
2
+ var chai = require('chai');
3
+ var expect = chai.expect;
4
4
  chai.should();
5
5
  chai.use(require('chai-things'));
6
6
 
@@ -30,57 +30,126 @@ describe('N3Store', function () {
30
30
  store.find().should.be.empty;
31
31
  });
32
32
 
33
- it('should be able to create unnamed blank nodes', function () {
33
+ it('should be able to generate unnamed blank nodes', function () {
34
34
  store.createBlankNode().should.eql('_:b0');
35
35
  store.createBlankNode().should.eql('_:b1');
36
36
 
37
- store.addTriple('_:b0', '_:b1', '_:b2');
37
+ store.addTriple('_:b0', '_:b1', '_:b2').should.be.true;
38
38
  store.createBlankNode().should.eql('_:b3');
39
39
  });
40
40
 
41
- it('should be able to create named blank nodes', function () {
41
+ it('should be able to generate named blank nodes', function () {
42
42
  store.createBlankNode('blank').should.eql('_:blank');
43
43
  store.createBlankNode('blank').should.eql('_:blank1');
44
44
  store.createBlankNode('blank').should.eql('_:blank2');
45
45
  });
46
+
47
+ it('should be able to store triples with generated blank nodes', function () {
48
+ store.addTriple(store.createBlankNode('x'), 'b', 'c').should.be.true;
49
+ shouldIncludeAll(store.find(null, 'b'), ['_:x1', 'b', 'd']);
50
+ });
51
+ });
52
+
53
+ describe('An N3Store without a configured default graph', function () {
54
+ var store = new N3Store();
55
+
56
+ it('should have a dummy default graph', function () {
57
+ store.defaultGraph.should.eql('http://example.org/#defaultGraph');
58
+ });
59
+ });
60
+
61
+ describe('An N3Store with a configured default graph', function () {
62
+ var dg = 'http://example.org/#defaultGraph';
63
+ var store = new N3Store({ defaultGraph: dg });
64
+
65
+ it('should return that configured default graph', function () {
66
+ store.defaultGraph.should.eql(dg);
67
+ });
46
68
  });
47
69
 
48
70
  describe('An N3Store with initialized with 3 elements', function () {
49
71
  var store = new N3Store([
50
- { subject: 's1', predicate: 'p1', object: 'o1'},
51
- { subject: 's1', predicate: 'p1', object: 'o2'},
52
- { subject: 's1', predicate: 'p1', object: 'o3'},
72
+ { subject: 's1', predicate: 'p1', object: 'o1' },
73
+ { subject: 's1', predicate: 'p1', object: 'o2' },
74
+ { subject: 's1', predicate: 'p1', object: 'o3' },
53
75
  ]);
54
76
 
55
77
  it('should have size 3', function () {
56
78
  store.size.should.eql(3);
57
79
  });
80
+
81
+ describe('adding a triple that already exists', function () {
82
+ it('should return false', function () {
83
+ store.addTriple('s1', 'p1', 'o1').should.be.false;
84
+ });
85
+
86
+ it('should not increase the size', function () {
87
+ store.size.should.eql(3);
88
+ });
89
+ });
90
+
91
+ describe('adding a triple that did not exist yet', function () {
92
+ it('should return true', function () {
93
+ store.addTriple('s1', 'p1', 'o4').should.be.true;
94
+ });
95
+
96
+ it('should increase the size', function () {
97
+ store.size.should.eql(4);
98
+ });
99
+ });
100
+
101
+ describe('removing an existing triple', function () {
102
+ it('should return true', function () {
103
+ store.removeTriple('s1', 'p1', 'o4').should.be.true;
104
+ });
105
+
106
+ it('should decrease the size', function () {
107
+ store.size.should.eql(3);
108
+ });
109
+ });
110
+
111
+ describe('removing a non-existing triple', function () {
112
+ it('should return false', function () {
113
+ store.removeTriple('s1', 'p1', 'o5').should.be.false;
114
+ });
115
+
116
+ it('should not decrease the size', function () {
117
+ store.size.should.eql(3);
118
+ });
119
+ });
58
120
  });
59
121
 
60
122
  describe('An N3Store with 5 elements', function () {
61
- var store = new N3Store();
62
- store.addTriple('s1', 'p1', 'o1');
63
- store.addTriple({ subject: 's1', predicate: 'p1', object: 'o2'});
123
+ var store = new N3Store({ defaultGraph: 'http://example.org/#defaultGraph' });
124
+ store.addTriple('s1', 'p1', 'o1').should.be.true;
125
+ store.addTriple({ subject: 's1', predicate: 'p1', object: 'o2' }).should.be.true;
64
126
  store.addTriples([
65
- { subject: 's1', predicate: 'p2', object: 'o2'},
66
- { subject: 's2', predicate: 'p1', object: 'o1'},
127
+ { subject: 's1', predicate: 'p2', object: 'o2' },
128
+ { subject: 's2', predicate: 'p1', object: 'o1' },
67
129
  ]);
68
- store.addTriple('s1', 'p2', 'o3', 'c4');
130
+ store.addTriple('s1', 'p2', 'o3', 'c4').should.be.true;
69
131
 
70
132
  it('should have size 5', function () {
71
133
  store.size.should.eql(5);
72
134
  });
73
135
 
74
136
  describe('when searched without parameters', function () {
75
- it('should return all items in the default graph',
137
+ it('should return all items',
76
138
  shouldIncludeAll(store.find(),
77
- ['s1', 'p1', 'o1'], ['s1', 'p1', 'o2'], ['s1', 'p2', 'o2'], ['s2', 'p1', 'o1']));
139
+ ['s1', 'p1', 'o1', store.defaultGraph],
140
+ ['s1', 'p1', 'o2', store.defaultGraph],
141
+ ['s1', 'p2', 'o2', store.defaultGraph],
142
+ ['s2', 'p1', 'o1', store.defaultGraph],
143
+ ['s1', 'p2', 'o3', 'c4']));
78
144
  });
79
145
 
80
146
  describe('when searched with an existing subject parameter', function () {
81
- it('should return all items with this subject in the default graph',
147
+ it('should return all items with this subject in all graphs',
82
148
  shouldIncludeAll(store.find('s1', null, null),
83
- ['s1', 'p1', 'o1'], ['s1', 'p1', 'o2'], ['s1', 'p2', 'o2']));
149
+ ['s1', 'p1', 'o1', store.defaultGraph],
150
+ ['s1', 'p1', 'o2', store.defaultGraph],
151
+ ['s1', 'p2', 'o2', store.defaultGraph],
152
+ ['s1', 'p2', 'o3', 'c4']));
84
153
  });
85
154
 
86
155
  describe('when searched with a non-existing subject parameter', function () {
@@ -94,7 +163,9 @@ describe('N3Store', function () {
94
163
  describe('when searched with an existing predicate parameter', function () {
95
164
  it('should return all items with this predicate in the default graph',
96
165
  shouldIncludeAll(store.find(null, 'p1', null),
97
- ['s1', 'p1', 'o1'], ['s1', 'p1', 'o2'], ['s2', 'p1', 'o1']));
166
+ ['s1', 'p1', 'o1', store.defaultGraph],
167
+ ['s1', 'p1', 'o2', store.defaultGraph],
168
+ ['s2', 'p1', 'o1', store.defaultGraph]));
98
169
  });
99
170
 
100
171
  describe('when searched with a non-existing predicate parameter', function () {
@@ -103,7 +174,9 @@ describe('N3Store', function () {
103
174
 
104
175
  describe('when searched with an existing object parameter', function () {
105
176
  it('should return all items with this object in the default graph',
106
- shouldIncludeAll(store.find(null, null, 'o1'), ['s1', 'p1', 'o1'], ['s2', 'p1', 'o1']));
177
+ shouldIncludeAll(store.find(null, null, 'o1'),
178
+ ['s1', 'p1', 'o1', store.defaultGraph],
179
+ ['s2', 'p1', 'o1', store.defaultGraph]));
107
180
  });
108
181
 
109
182
  describe('when searched with a non-existing object parameter', function () {
@@ -112,7 +185,9 @@ describe('N3Store', function () {
112
185
 
113
186
  describe('when searched with existing subject and predicate parameters', function () {
114
187
  it('should return all items with this subject and predicate in the default graph',
115
- shouldIncludeAll(store.find('s1', 'p1', null), ['s1', 'p1', 'o1'], ['s1', 'p1', 'o2']));
188
+ shouldIncludeAll(store.find('s1', 'p1', null),
189
+ ['s1', 'p1', 'o1', store.defaultGraph],
190
+ ['s1', 'p1', 'o2', store.defaultGraph]));
116
191
  });
117
192
 
118
193
  describe('when searched with non-existing subject and predicate parameters', function () {
@@ -121,7 +196,9 @@ describe('N3Store', function () {
121
196
 
122
197
  describe('when searched with existing subject and object parameters', function () {
123
198
  it('should return all items with this subject and object in the default graph',
124
- shouldIncludeAll(store.find('s1', null, 'o2'), ['s1', 'p1', 'o2'], ['s1', 'p2', 'o2']));
199
+ shouldIncludeAll(store.find('s1', null, 'o2'),
200
+ ['s1', 'p1', 'o2', store.defaultGraph],
201
+ ['s1', 'p2', 'o2', store.defaultGraph]));
125
202
  });
126
203
 
127
204
  describe('when searched with non-existing subject and object parameters', function () {
@@ -130,16 +207,18 @@ describe('N3Store', function () {
130
207
 
131
208
  describe('when searched with existing predicate and object parameters', function () {
132
209
  it('should return all items with this predicate and object in the default graph',
133
- shouldIncludeAll(store.find(null, 'p1', 'o1'), ['s1', 'p1', 'o1'], ['s2', 'p1', 'o1']));
210
+ shouldIncludeAll(store.find(null, 'p1', 'o1'),
211
+ ['s1', 'p1', 'o1', store.defaultGraph],
212
+ ['s2', 'p1', 'o1', store.defaultGraph]));
134
213
  });
135
214
 
136
- describe('when searched with non-existing predicate and object parameters', function () {
137
- itShouldBeEmpty(store.find(null, 'p2', 'o3'));
215
+ describe('when searched with non-existing predicate and object parameters in the default graph', function () {
216
+ itShouldBeEmpty(store.find(null, 'p2', 'o3', store.defaultGraph));
138
217
  });
139
218
 
140
219
  describe('when searched with existing subject, predicate, and object parameters', function () {
141
220
  it('should return all items with this subject, predicate, and object in the default graph',
142
- shouldIncludeAll(store.find('s1', 'p1', 'o1'), ['s1', 'p1', 'o1']));
221
+ shouldIncludeAll(store.find('s1', 'p1', 'o1'), ['s1', 'p1', 'o1', store.defaultGraph]));
143
222
  });
144
223
 
145
224
  describe('when searched with a non-existing triple', function () {
@@ -148,8 +227,11 @@ describe('N3Store', function () {
148
227
 
149
228
  describe('when searched with the default graph parameter', function () {
150
229
  it('should return all items in the default graph',
151
- shouldIncludeAll(store.find(),
152
- ['s1', 'p1', 'o1'], ['s1', 'p1', 'o2'], ['s1', 'p2', 'o2'], ['s2', 'p1', 'o1']));
230
+ shouldIncludeAll(store.find(null, null, null, store.defaultGraph),
231
+ ['s1', 'p1', 'o1', store.defaultGraph],
232
+ ['s1', 'p1', 'o2', store.defaultGraph],
233
+ ['s1', 'p2', 'o2', store.defaultGraph],
234
+ ['s2', 'p1', 'o1', store.defaultGraph]));
153
235
  });
154
236
 
155
237
  describe('when searched with an existing non-default graph parameter', function () {
@@ -276,62 +358,65 @@ describe('N3Store', function () {
276
358
  });
277
359
 
278
360
  describe('when trying to remove a triple with a non-existing subject', function () {
279
- before(function () { store.removeTriple('s0', 'p1', 'o1'); });
361
+ before(function () { store.removeTriple('s0', 'p1', 'o1').should.be.false; });
280
362
  it('should still have size 5', function () { store.size.should.eql(5); });
281
363
  });
282
364
 
283
365
  describe('when trying to remove a triple with a non-existing predicate', function () {
284
- before(function () { store.removeTriple('s1', 'p0', 'o1'); });
366
+ before(function () { store.removeTriple('s1', 'p0', 'o1').should.be.false; });
285
367
  it('should still have size 5', function () { store.size.should.eql(5); });
286
368
  });
287
369
 
288
370
  describe('when trying to remove a triple with a non-existing object', function () {
289
- before(function () { store.removeTriple('s1', 'p1', 'o0'); });
371
+ before(function () { store.removeTriple('s1', 'p1', 'o0').should.be.false; });
290
372
  it('should still have size 5', function () { store.size.should.eql(5); });
291
373
  });
292
374
 
293
375
  describe('when trying to remove a triple for which no subjects exist', function () {
294
- before(function () { store.removeTriple('o1', 'p1', 'o1'); });
376
+ before(function () { store.removeTriple('o1', 'p1', 'o1').should.be.false; });
295
377
  it('should still have size 5', function () { store.size.should.eql(5); });
296
378
  });
297
379
 
298
380
  describe('when trying to remove a triple for which no predicates exist', function () {
299
- before(function () { store.removeTriple('s1', 's1', 'o1'); });
381
+ before(function () { store.removeTriple('s1', 's1', 'o1').should.be.false; });
300
382
  it('should still have size 5', function () { store.size.should.eql(5); });
301
383
  });
302
384
 
303
385
  describe('when trying to remove a triple for which no objects exist', function () {
304
- before(function () { store.removeTriple('s1', 'p1', 's1'); });
386
+ before(function () { store.removeTriple('s1', 'p1', 's1').should.be.false; });
305
387
  it('should still have size 5', function () { store.size.should.eql(5); });
306
388
  });
307
389
 
308
390
  describe('when trying to remove a triple that does not exist', function () {
309
- before(function () { store.removeTriple('s1', 'p2', 'o1'); });
391
+ before(function () { store.removeTriple('s1', 'p2', 'o1').should.be.false; });
310
392
  it('should still have size 5', function () { store.size.should.eql(5); });
311
393
  });
312
394
 
313
395
  describe('when trying to remove an incomplete triple', function () {
314
- before(function () { store.removeTriple('s1', null, null); });
396
+ before(function () { store.removeTriple('s1', null, null).should.be.false; });
315
397
  it('should still have size 5', function () { store.size.should.eql(5); });
316
398
  });
317
399
 
318
400
  describe('when trying to remove a triple with a non-existing graph', function () {
319
- before(function () { store.removeTriple('s1', 'p1', 'o1', 'c0'); });
401
+ before(function () { store.removeTriple('s1', 'p1', 'o1', 'c0').should.be.false; });
320
402
  it('should still have size 5', function () { store.size.should.eql(5); });
321
403
  });
322
404
 
323
405
  describe('when removing an existing triple', function () {
324
- before(function () { store.removeTriple('s1', 'p1', 'o1'); });
406
+ before(function () { store.removeTriple('s1', 'p1', 'o1').should.be.true; });
325
407
 
326
408
  it('should have size 4', function () { store.size.should.eql(4); });
327
409
 
328
410
  it('should not contain that triple anymore',
329
411
  shouldIncludeAll(function () { return store.find(); },
330
- ['s1', 'p1', 'o2'], ['s1', 'p2', 'o2'], ['s2', 'p1', 'o1']));
412
+ ['s1', 'p1', 'o2', store.defaultGraph],
413
+ ['s1', 'p2', 'o2', store.defaultGraph],
414
+ ['s2', 'p1', 'o1', store.defaultGraph],
415
+ ['s1', 'p2', 'o3', 'c4', store.defaultGraph]));
331
416
  });
332
417
 
333
418
  describe('when removing an existing triple from a non-default graph', function () {
334
- before(function () { store.removeTriple('s1', 'p2', 'o3', 'c4'); });
419
+ before(function () { store.removeTriple('s1', 'p2', 'o3', 'c4').should.be.true; });
335
420
 
336
421
  it('should have size 3', function () { store.size.should.eql(3); });
337
422
 
@@ -341,8 +426,8 @@ describe('N3Store', function () {
341
426
  describe('when removing multiple triples', function () {
342
427
  before(function () {
343
428
  store.removeTriples([
344
- { subject: 's1', predicate: 'p2', object: 'o2'},
345
- { subject: 's2', predicate: 'p1', object: 'o1'},
429
+ { subject: 's1', predicate: 'p2', object: 'o2' },
430
+ { subject: 's2', predicate: 'p1', object: 'o1' },
346
431
  ]);
347
432
  });
348
433
 
@@ -350,13 +435,13 @@ describe('N3Store', function () {
350
435
 
351
436
  it('should not contain those triples anymore',
352
437
  shouldIncludeAll(function () { return store.find(); },
353
- ['s1', 'p1', 'o2']));
438
+ ['s1', 'p1', 'o2', store.defaultGraph]));
354
439
  });
355
440
 
356
441
  describe('when adding and removing a triple', function () {
357
442
  before(function () {
358
- store.addTriple('a', 'b', 'c');
359
- store.removeTriple('a', 'b', 'c');
443
+ store.addTriple('a', 'b', 'c').should.be.true;
444
+ store.removeTriple('a', 'b', 'c').should.be.true;
360
445
  });
361
446
 
362
447
  it('should have an unchanged size', function () { store.size.should.eql(1); });
@@ -371,33 +456,43 @@ describe('N3Store', function () {
371
456
  { subject: 'http://foo.org/#s3', predicate: 'http://bar.org/p3', object: '"a"^^http://foo.org/#t1' },
372
457
  { subject: 'http://foo.org/#s1', predicate: 'http://bar.org/p1', object: 'http://foo.org/#o1', graph: 'http://graphs.org/#g1' },
373
458
  ],
374
- { prefixes: { 'a': 'http://foo.org/#', 'b': 'http://bar.org/', 'g': 'http://graphs.org/#' } });
459
+ { prefixes: { a: 'http://foo.org/#', b: 'http://bar.org/', g: 'http://graphs.org/#' } });
375
460
 
376
461
  describe('should allow to query subjects with prefixes', function () {
377
462
  it('should return all triples with that subject',
378
- shouldIncludeAll(store.find('a:s1', null, null),
379
- ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1'],
380
- ['http://foo.org/#s1', 'http://bar.org/p2', 'http://foo.org/#o1']));
463
+ shouldIncludeAll(store.find('a:s1', null, null),
464
+ ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1', store.defaultGraph],
465
+ ['http://foo.org/#s1', 'http://bar.org/p2', 'http://foo.org/#o1', store.defaultGraph],
466
+ ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1', 'http://graphs.org/#g1']));
467
+ });
468
+
469
+ describe('should allow to query subjects with prefixes', function () {
470
+ it('should return all triples with that subject in the default graph',
471
+ shouldIncludeAll(store.find('a:s1', null, null, store.defaultGraph),
472
+ ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1', store.defaultGraph],
473
+ ['http://foo.org/#s1', 'http://bar.org/p2', 'http://foo.org/#o1', store.defaultGraph]));
381
474
  });
382
475
 
383
476
  describe('should allow to query predicates with prefixes', function () {
384
477
  it('should return all triples with that predicate',
385
478
  shouldIncludeAll(store.find(null, 'b:p1', null),
386
- ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1'],
387
- ['http://foo.org/#s2', 'http://bar.org/p1', 'http://foo.org/#o2']));
479
+ ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1', store.defaultGraph],
480
+ ['http://foo.org/#s2', 'http://bar.org/p1', 'http://foo.org/#o2', store.defaultGraph],
481
+ ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1', 'http://graphs.org/#g1']));
388
482
  });
389
483
 
390
484
  describe('should allow to query objects with prefixes', function () {
391
485
  it('should return all triples with that object',
392
486
  shouldIncludeAll(store.find(null, null, 'a:o1'),
393
- ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1'],
394
- ['http://foo.org/#s1', 'http://bar.org/p2', 'http://foo.org/#o1']));
487
+ ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1', store.defaultGraph],
488
+ ['http://foo.org/#s1', 'http://bar.org/p2', 'http://foo.org/#o1', store.defaultGraph],
489
+ ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1', 'http://graphs.org/#g1']));
395
490
  });
396
491
 
397
492
  describe('should allow to query graphs with prefixes', function () {
398
493
  it('should return all triples with that graph',
399
494
  shouldIncludeAll(store.find(null, null, null, 'http://graphs.org/#g1'),
400
- ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1', 'http://graphs.org/#g1']));
495
+ ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1', 'http://graphs.org/#g1', store.defaultGraph]));
401
496
  });
402
497
  });
403
498
 
@@ -410,27 +505,51 @@ describe('N3Store', function () {
410
505
  ]);
411
506
 
412
507
  store.addPrefix('a', 'http://foo.org/#');
413
- store.addPrefixes({ 'b': 'http://bar.org/', 'g': 'http://graphs.org/#' });
508
+ store.addPrefixes({ b: 'http://bar.org/', g: 'http://graphs.org/#' });
509
+
510
+ describe('should allow to query subjects with prefixes', function () {
511
+ it('should return all triples with that subject in the default graph',
512
+ shouldIncludeAll(store.find('a:s1', null, null, store.defaultGraph),
513
+ ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1', store.defaultGraph],
514
+ ['http://foo.org/#s1', 'http://bar.org/p2', 'http://foo.org/#o1', store.defaultGraph]));
515
+ });
414
516
 
415
517
  describe('should allow to query subjects with prefixes', function () {
416
518
  it('should return all triples with that subject',
417
- shouldIncludeAll(store.find('a:s1', null, null),
418
- ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1'],
419
- ['http://foo.org/#s1', 'http://bar.org/p2', 'http://foo.org/#o1']));
519
+ shouldIncludeAll(store.find('a:s1', null, null),
520
+ ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1', store.defaultGraph],
521
+ ['http://foo.org/#s1', 'http://bar.org/p2', 'http://foo.org/#o1', store.defaultGraph],
522
+ ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1', 'http://graphs.org/#g1']));
523
+ });
524
+
525
+ describe('should allow to query predicates with prefixes', function () {
526
+ it('should return all triples with that predicate in the default graph',
527
+ shouldIncludeAll(store.find(null, 'b:p1', null, store.defaultGraph),
528
+ ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1', store.defaultGraph],
529
+ ['http://foo.org/#s2', 'http://bar.org/p1', 'http://foo.org/#o2', store.defaultGraph]));
420
530
  });
421
531
 
422
532
  describe('should allow to query predicates with prefixes', function () {
423
533
  it('should return all triples with that predicate',
424
- shouldIncludeAll(store.find(null, 'b:p1', null),
425
- ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1'],
426
- ['http://foo.org/#s2', 'http://bar.org/p1', 'http://foo.org/#o2']));
534
+ shouldIncludeAll(store.find(null, 'b:p1', null),
535
+ ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1', store.defaultGraph],
536
+ ['http://foo.org/#s2', 'http://bar.org/p1', 'http://foo.org/#o2', store.defaultGraph],
537
+ ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1', 'http://graphs.org/#g1']));
538
+ });
539
+
540
+ describe('should allow to query objects with prefixes', function () {
541
+ it('should return all triples with that object in the default graph',
542
+ shouldIncludeAll(store.find(null, null, 'a:o1', store.defaultGraph),
543
+ ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1', store.defaultGraph],
544
+ ['http://foo.org/#s1', 'http://bar.org/p2', 'http://foo.org/#o1', store.defaultGraph]));
427
545
  });
428
546
 
429
547
  describe('should allow to query objects with prefixes', function () {
430
548
  it('should return all triples with that object',
431
549
  shouldIncludeAll(store.find(null, null, 'a:o1'),
432
- ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1'],
433
- ['http://foo.org/#s1', 'http://bar.org/p2', 'http://foo.org/#o1']));
550
+ ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1', store.defaultGraph],
551
+ ['http://foo.org/#s1', 'http://bar.org/p2', 'http://foo.org/#o1', store.defaultGraph],
552
+ ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1', 'http://graphs.org/#g1']));
434
553
  });
435
554
 
436
555
  describe('should allow to query graphs with prefixes', function () {
@@ -446,24 +565,24 @@ describe('N3Store', function () {
446
565
  { subject: 'http://foo.org/#s1', predicate: 'http://bar.org/p2', object: 'http://foo.org/#o1' },
447
566
  { subject: 'http://foo.org/#s2', predicate: 'http://bar.org/p1', object: 'http://foo.org/#o2' },
448
567
  ],
449
- { prefixes: { 'http': 'http://www.w3.org/2006/http#' } });
568
+ { prefixes: { http: 'http://www.w3.org/2006/http#' } });
450
569
 
451
570
  describe('should allow to query subjects without prefixes', function () {
452
571
  it('should return all triples with that subject',
453
572
  shouldIncludeAll(store.find('http://foo.org/#s1', null, null),
454
- ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1'],
455
- ['http://foo.org/#s1', 'http://bar.org/p2', 'http://foo.org/#o1']));
573
+ ['http://foo.org/#s1', 'http://bar.org/p1', 'http://foo.org/#o1', store.defaultGraph],
574
+ ['http://foo.org/#s1', 'http://bar.org/p2', 'http://foo.org/#o1', store.defaultGraph]));
456
575
  });
457
576
  });
458
577
 
459
578
  describe('An N3Store created without triples but with prefixes', function () {
460
- var store = new N3Store({ prefixes: { 'http': 'http://www.w3.org/2006/http#' } });
461
- store.addTriple('a', 'http://www.w3.org/2006/http#b', 'c');
579
+ var store = new N3Store({ prefixes: { http: 'http://www.w3.org/2006/http#' } });
580
+ store.addTriple('a', 'http://www.w3.org/2006/http#b', 'c').should.be.true;
462
581
 
463
582
  describe('should allow to query predicates with prefixes', function () {
464
583
  it('should return all triples with that predicate',
465
584
  shouldIncludeAll(store.find(null, 'http:b', null),
466
- ['a', 'http://www.w3.org/2006/http#b', 'c']));
585
+ ['a', 'http://www.w3.org/2006/http#b', 'c', store.defaultGraph]));
467
586
  });
468
587
  });
469
588
 
@@ -473,13 +592,13 @@ describe('N3Store', function () {
473
592
  // Test inspired by http://www.devthought.com/2012/01/18/an-object-is-not-a-hash/.
474
593
  // The value `__proto__` is not supported however – fixing it introduces too much overhead.
475
594
  it('should be able to contain entities with JavaScript object property names', function () {
476
- store.addTriple('toString', 'valueOf', 'toLocaleString', 'hasOwnProperty');
595
+ store.addTriple('toString', 'valueOf', 'toLocaleString', 'hasOwnProperty').should.be.true;
477
596
  shouldIncludeAll(store.find(null, null, null, 'hasOwnProperty'),
478
597
  ['toString', 'valueOf', 'toLocaleString', 'hasOwnProperty'])();
479
598
  });
480
599
 
481
600
  it('should be able to contain entities named "null"', function () {
482
- store.addTriple('null', 'null', 'null', 'null');
601
+ store.addTriple('null', 'null', 'null', 'null').should.be.true;
483
602
  shouldIncludeAll(store.find(null, null, null, 'null'), ['null', 'null', 'null', 'null'])();
484
603
  });
485
604
  });
@@ -87,7 +87,7 @@ function shouldEmitPrefixes(chunks, expectedPrefixes) {
87
87
 
88
88
  function ArrayReader(items) {
89
89
  var reader = new Readable();
90
- reader._read = function () { this.push(items.shift()); };
90
+ reader._read = function () { this.push(items.shift() || null); };
91
91
  return reader;
92
92
  }
93
93
 
@@ -3,7 +3,6 @@ var chai = require('chai'),
3
3
  Readable = require('stream').Readable,
4
4
  Writable = require('stream').Writable;
5
5
  chai.should();
6
- chai.use(require('chai-things'));
7
6
 
8
7
  describe('N3StreamWriter', function () {
9
8
  describe('The N3StreamWriter module', function () {
@@ -99,7 +98,7 @@ function shouldNotSerialize(tripleArrays, expectedMessage) {
99
98
  function ArrayReader(items) {
100
99
  var reader = new Readable({ objectMode: true });
101
100
  items = items.map(function (i) { return { subject: i[0], predicate: i[1], object: i[2] }; });
102
- reader._read = function () { this.push(items.shift()); };
101
+ reader._read = function () { this.push(items.shift() || null); };
103
102
  return reader;
104
103
  }
105
104
 
@@ -1,6 +1,6 @@
1
1
  var N3Util = require('../N3').Util;
2
- var chai = require('chai'),
3
- expect = chai.expect;
2
+ var chai = require('chai');
3
+ var expect = chai.expect;
4
4
  chai.should();
5
5
 
6
6
  describe('N3Util', function () {
@@ -261,11 +261,11 @@ describe('N3Util', function () {
261
261
 
262
262
  describe('expandPrefixedName', function () {
263
263
  it('expands a prefixed name', function () {
264
- N3Util.expandPrefixedName('ex:Test', { 'ex': 'http://ex.org/#' }).should.equal('http://ex.org/#Test');
264
+ N3Util.expandPrefixedName('ex:Test', { ex: 'http://ex.org/#' }).should.equal('http://ex.org/#Test');
265
265
  });
266
266
 
267
267
  it('expands a type with a prefixed name', function () {
268
- N3Util.expandPrefixedName('"a"^^ex:type', { 'ex': 'http://ex.org/#' }).should.equal('"a"^^http://ex.org/#type');
268
+ N3Util.expandPrefixedName('"a"^^ex:type', { ex: 'http://ex.org/#' }).should.equal('"a"^^http://ex.org/#type');
269
269
  });
270
270
 
271
271
  it('expands a prefixed name with the empty prefix', function () {
@@ -273,7 +273,7 @@ describe('N3Util', function () {
273
273
  });
274
274
 
275
275
  it('does not expand a prefixed name if the prefix is unknown', function () {
276
- N3Util.expandPrefixedName('a:Test', { 'b': 'http://ex.org/#' }).should.equal('a:Test');
276
+ N3Util.expandPrefixedName('a:Test', { b: 'http://ex.org/#' }).should.equal('a:Test');
277
277
  });
278
278
 
279
279
  it('returns the input if it is not a prefixed name', function () {
@@ -340,4 +340,70 @@ describe('N3Util', function () {
340
340
  N3Util.createLiteral(true).should.equal('"true"^^http://www.w3.org/2001/XMLSchema#boolean');
341
341
  });
342
342
  });
343
+
344
+ describe('prefix', function () {
345
+ var baz = N3Util.prefix('http://ex.org/baz#');
346
+ it('should return a function', function () {
347
+ expect(baz).to.be.an.instanceof(Function);
348
+ });
349
+
350
+ describe('the function', function () {
351
+ it('should expand the prefix', function () {
352
+ expect(baz('bar')).to.equal('http://ex.org/baz#bar');
353
+ });
354
+ });
355
+ });
356
+
357
+ describe('prefixes', function () {
358
+ describe('called without arguments', function () {
359
+ var prefixes = N3Util.prefixes();
360
+ it('should return a function', function () {
361
+ expect(prefixes).to.be.an.instanceof(Function);
362
+ });
363
+
364
+ describe('the function', function () {
365
+ it('should not expand non-registered prefixes', function () {
366
+ expect(prefixes('baz')('bar')).to.equal('bar');
367
+ });
368
+
369
+ it('should allow registering prefixes', function () {
370
+ var p = prefixes('baz', 'http://ex.org/baz#');
371
+ expect(p).to.exist;
372
+ expect(p).to.equal(prefixes('baz'));
373
+ });
374
+
375
+ it('should expand the newly registered prefix', function () {
376
+ expect(prefixes('baz')('bar')).to.equal('http://ex.org/baz#bar');
377
+ });
378
+ });
379
+ });
380
+
381
+ describe('called with a hash of prefixes', function () {
382
+ var prefixes = N3Util.prefixes({ foo: 'http://ex.org/foo#', bar: 'http://ex.org/bar#' });
383
+ it('should return a function', function () {
384
+ expect(prefixes).to.be.an.instanceof(Function);
385
+ });
386
+
387
+ describe('the function', function () {
388
+ it('should expand registered prefixes', function () {
389
+ expect(prefixes('foo')('bar')).to.equal('http://ex.org/foo#bar');
390
+ expect(prefixes('bar')('bar')).to.equal('http://ex.org/bar#bar');
391
+ });
392
+
393
+ it('should not expand non-registered prefixes', function () {
394
+ expect(prefixes('baz')('bar')).to.equal('bar');
395
+ });
396
+
397
+ it('should allow registering prefixes', function () {
398
+ var p = prefixes('baz', 'http://ex.org/baz#');
399
+ expect(p).to.exist;
400
+ expect(p).to.equal(prefixes('baz'));
401
+ });
402
+
403
+ it('should expand the newly registered prefix', function () {
404
+ expect(prefixes('baz')('bar')).to.equal('http://ex.org/baz#bar');
405
+ });
406
+ });
407
+ });
408
+ });
343
409
  });