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.
@@ -197,7 +197,7 @@ describe('N3Writer', function () {
197
197
  it('calls the done callback when ending the outputstream errors', function (done) {
198
198
  var writer = new N3Writer({
199
199
  write: function () {},
200
- end: function () { throw 'error'; },
200
+ end: function () { throw new Error('error'); },
201
201
  });
202
202
  writer.end(done);
203
203
  });
@@ -269,6 +269,211 @@ describe('N3Writer', function () {
269
269
  });
270
270
  });
271
271
 
272
+ it('should serialize triples with an empty blank node as object', function (done) {
273
+ var writer = N3Writer();
274
+ writer.addTriple('a1', 'b', writer.blank());
275
+ writer.addTriple('a2', 'b', writer.blank([]));
276
+ writer.end(function (error, output) {
277
+ output.should.equal('<a1> <b> [].\n' +
278
+ '<a2> <b> [].\n');
279
+ done(error);
280
+ });
281
+ });
282
+
283
+ it('should serialize triples with a one-triple blank node as object', function (done) {
284
+ var writer = N3Writer();
285
+ writer.addTriple('a1', 'b', writer.blank('d', 'e'));
286
+ writer.addTriple('a2', 'b', writer.blank({ predicate: 'd', object: 'e' }));
287
+ writer.addTriple('a3', 'b', writer.blank([{ predicate: 'd', object: 'e' }]));
288
+ writer.end(function (error, output) {
289
+ output.should.equal('<a1> <b> [ <d> <e> ].\n' +
290
+ '<a2> <b> [ <d> <e> ].\n' +
291
+ '<a3> <b> [ <d> <e> ].\n');
292
+ done(error);
293
+ });
294
+ });
295
+
296
+ it('should serialize triples with a two-triple blank node as object', function (done) {
297
+ var writer = N3Writer();
298
+ writer.addTriple('a', 'b', writer.blank([
299
+ { predicate: 'd', object: 'e' },
300
+ { predicate: 'f', object: '"g"' },
301
+ ]));
302
+ writer.end(function (error, output) {
303
+ output.should.equal('<a> <b> [\n' +
304
+ ' <d> <e>;\n' +
305
+ ' <f> "g"\n' +
306
+ '].\n');
307
+ done(error);
308
+ });
309
+ });
310
+
311
+ it('should serialize triples with a three-triple blank node as object', function (done) {
312
+ var writer = N3Writer();
313
+ writer.addTriple('a', 'b', writer.blank([
314
+ { predicate: 'd', object: 'e' },
315
+ { predicate: 'f', object: '"g"' },
316
+ { predicate: 'h', object: 'i' },
317
+ ]));
318
+ writer.end(function (error, output) {
319
+ output.should.equal('<a> <b> [\n' +
320
+ ' <d> <e>;\n' +
321
+ ' <f> "g";\n' +
322
+ ' <h> <i>\n' +
323
+ '].\n');
324
+ done(error);
325
+ });
326
+ });
327
+
328
+ it('should serialize triples with predicate-sharing blank node triples as object', function (done) {
329
+ var writer = N3Writer();
330
+ writer.addTriple('a', 'b', writer.blank([
331
+ { predicate: 'd', object: 'e' },
332
+ { predicate: 'd', object: 'f' },
333
+ { predicate: 'g', object: 'h' },
334
+ { predicate: 'g', object: 'i' },
335
+ ]));
336
+ writer.end(function (error, output) {
337
+ output.should.equal('<a> <b> [\n' +
338
+ ' <d> <e>, <f>;\n' +
339
+ ' <g> <h>, <i>\n' +
340
+ '].\n');
341
+ done(error);
342
+ });
343
+ });
344
+
345
+ it('should serialize triples with nested blank nodes as object', function (done) {
346
+ var writer = N3Writer();
347
+ writer.addTriple('a1', 'b', writer.blank([
348
+ { predicate: 'd', object: writer.blank() },
349
+ ]));
350
+ writer.addTriple('a2', 'b', writer.blank([
351
+ { predicate: 'd', object: writer.blank('e', 'f') },
352
+ { predicate: 'g', object: writer.blank('h', '"i"') },
353
+ ]));
354
+ writer.addTriple('a3', 'b', writer.blank([
355
+ { predicate: 'd', object: writer.blank([
356
+ { predicate: 'g', object: writer.blank('h', 'i') },
357
+ { predicate: 'j', object: writer.blank('k', '"l"') },
358
+ ]) },
359
+ ]));
360
+ writer.end(function (error, output) {
361
+ output.should.equal('<a1> <b> [\n' +
362
+ ' <d> []\n' +
363
+ '].\n' +
364
+ '<a2> <b> [\n' +
365
+ ' <d> [ <e> <f> ];\n' +
366
+ ' <g> [ <h> "i" ]\n' +
367
+ '].\n' +
368
+ '<a3> <b> [\n' +
369
+ ' <d> [\n' +
370
+ ' <g> [ <h> <i> ];\n' +
371
+ ' <j> [ <k> "l" ]\n' +
372
+ ']\n' +
373
+ '].\n');
374
+ done(error);
375
+ });
376
+ });
377
+
378
+ it('should serialize triples with an empty blank node as subject', function (done) {
379
+ var writer = N3Writer();
380
+ writer.addTriple(writer.blank(), 'b', 'c');
381
+ writer.addTriple(writer.blank([]), 'b', 'c');
382
+ writer.end(function (error, output) {
383
+ output.should.equal('[] <b> <c>.\n' +
384
+ '[] <b> <c>.\n');
385
+ done(error);
386
+ });
387
+ });
388
+
389
+ it('should serialize triples with a one-triple blank node as subject', function (done) {
390
+ var writer = N3Writer();
391
+ writer.addTriple(writer.blank('a', 'b'), 'c', 'd');
392
+ writer.addTriple(writer.blank({ predicate: 'a', object: 'b' }), 'c', 'd');
393
+ writer.addTriple(writer.blank([{ predicate: 'a', object: 'b' }]), 'c', 'd');
394
+ writer.end(function (error, output) {
395
+ output.should.equal('[ <a> <b> ] <c> <d>.\n' +
396
+ '[ <a> <b> ] <c> <d>.\n' +
397
+ '[ <a> <b> ] <c> <d>.\n');
398
+ done(error);
399
+ });
400
+ });
401
+
402
+ it('should serialize triples with an empty blank node as graph', function (done) {
403
+ var writer = N3Writer();
404
+ writer.addTriple('a', 'b', 'c', writer.blank());
405
+ writer.addTriple('a', 'b', 'c', writer.blank([]));
406
+ writer.end(function (error, output) {
407
+ output.should.equal('[] {\n<a> <b> <c>\n}\n' +
408
+ '[] {\n<a> <b> <c>\n}\n');
409
+ done(error);
410
+ });
411
+ });
412
+
413
+ it('should serialize triples with an empty list as object', function (done) {
414
+ var writer = N3Writer();
415
+ writer.addTriple('a1', 'b', writer.list());
416
+ writer.addTriple('a2', 'b', writer.list([]));
417
+ writer.end(function (error, output) {
418
+ output.should.equal('<a1> <b> ().\n' +
419
+ '<a2> <b> ().\n');
420
+ done(error);
421
+ });
422
+ });
423
+
424
+ it('should serialize triples with a one-element list as object', function (done) {
425
+ var writer = N3Writer();
426
+ writer.addTriple('a1', 'b', writer.list(['c']));
427
+ writer.addTriple('a2', 'b', writer.list(['"c"']));
428
+ writer.end(function (error, output) {
429
+ output.should.equal('<a1> <b> (<c>).\n' +
430
+ '<a2> <b> ("c").\n');
431
+ done(error);
432
+ });
433
+ });
434
+
435
+ it('should serialize triples with a three-element list as object', function (done) {
436
+ var writer = N3Writer();
437
+ writer.addTriple('a1', 'b', writer.list(['c', 'd', 'e']));
438
+ writer.addTriple('a2', 'b', writer.list(['"c"', '"d"', '"e"']));
439
+ writer.end(function (error, output) {
440
+ output.should.equal('<a1> <b> (<c> <d> <e>).\n' +
441
+ '<a2> <b> ("c" "d" "e").\n');
442
+ done(error);
443
+ });
444
+ });
445
+
446
+ it('should serialize triples with an empty list as subject', function (done) {
447
+ var writer = N3Writer();
448
+ writer.addTriple(writer.list(), 'b1', 'c');
449
+ writer.addTriple(writer.list([]), 'b2', 'c');
450
+ writer.end(function (error, output) {
451
+ output.should.equal('() <b1> <c>;\n' +
452
+ ' <b2> <c>.\n');
453
+ done(error);
454
+ });
455
+ });
456
+
457
+ it('should serialize triples with a one-element list as subject', function (done) {
458
+ var writer = N3Writer();
459
+ writer.addTriple(writer.list(['a']), 'b1', 'c');
460
+ writer.addTriple(writer.list(['a']), 'b2', 'c');
461
+ writer.end(function (error, output) {
462
+ output.should.equal('(<a>) <b1> <c>;\n' +
463
+ ' <b2> <c>.\n');
464
+ done(error);
465
+ });
466
+ });
467
+
468
+ it('should serialize triples with a three-element list as subject', function (done) {
469
+ var writer = N3Writer();
470
+ writer.addTriple(writer.list(['a', '"b"', '"c"']), 'd', 'e');
471
+ writer.end(function (error, output) {
472
+ output.should.equal('(<a> "b" "c") <d> <e>.\n');
473
+ done(error);
474
+ });
475
+ });
476
+
272
477
  it('should accept triples in bulk', function (done) {
273
478
  var writer = N3Writer();
274
479
  writer.addTriples([{ subject: 'a', predicate: 'b', object: 'c' },
@@ -327,6 +532,33 @@ describe('N3Writer', function () {
327
532
  done();
328
533
  });
329
534
  });
535
+
536
+ it('should end when the end option is not set', function (done) {
537
+ var outputStream = new QuickStream(), writer = N3Writer(outputStream, {});
538
+ outputStream.should.have.property('ended', false);
539
+ writer.end(function () {
540
+ outputStream.should.have.property('ended', true);
541
+ done();
542
+ });
543
+ });
544
+
545
+ it('should end when the end option is set to true', function (done) {
546
+ var outputStream = new QuickStream(), writer = N3Writer(outputStream, { end: true });
547
+ outputStream.should.have.property('ended', false);
548
+ writer.end(function () {
549
+ outputStream.should.have.property('ended', true);
550
+ done();
551
+ });
552
+ });
553
+
554
+ it('should not end when the end option is set to false', function (done) {
555
+ var outputStream = new QuickStream(), writer = N3Writer(outputStream, { end: false });
556
+ outputStream.should.have.property('ended', false);
557
+ writer.end(function () {
558
+ outputStream.should.have.property('ended', false);
559
+ done();
560
+ });
561
+ });
330
562
  });
331
563
  });
332
564
 
@@ -344,13 +576,14 @@ function shouldSerialize(prefixes, tripleArrays, expectedResult) {
344
576
  writer.end(function (error) {
345
577
  try {
346
578
  outputStream.result.should.equal(expectedResult);
579
+ outputStream.should.have.property('ended', true);
347
580
  done(error);
348
581
  }
349
582
  catch (e) {
350
583
  done(e);
351
584
  }
352
585
  });
353
- })();
586
+ }());
354
587
  };
355
588
  }
356
589
 
@@ -370,8 +603,16 @@ function shouldNotSerialize(tripleArrays, expectedMessage) {
370
603
  }
371
604
 
372
605
  function QuickStream() {
373
- var stream = {}, buffer = '';
374
- stream.write = function (chunk, encoding, callback) { buffer += chunk; callback && callback(); };
375
- stream.end = function (callback) { stream.result = buffer; buffer = null; callback(); };
606
+ var stream = { ended: false }, buffer = '';
607
+ stream.write = function (chunk, encoding, callback) {
608
+ buffer += chunk;
609
+ callback && callback();
610
+ };
611
+ stream.end = function (callback) {
612
+ stream.ended = true;
613
+ stream.result = buffer;
614
+ buffer = null;
615
+ callback();
616
+ };
376
617
  return stream;
377
618
  }
package/.jshintrc DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "node": true, // Allow use of node.js globals.
3
- "loopfunc": true, // Allow functions to be defined within loops.
4
- "proto": true, // Allow use of `__proto__`.
5
- "expr": true, // Allow expressions where statements are allowed.
6
- "boss": true, // Allow assignments where expressions are allowed.
7
- "trailing": true, // Do not leave trailing whitespace.
8
- "strict": false, // Do not enforce strict mode.
9
- "undef": true, // Don't use undefined variables.
10
- "unused": true, // Warn about unused variables.
11
- "-W086": true, // Allow fall-through in switch statement.
12
- "white": true, // Enable strict whitespace checking.
13
- "indent": 2, // The code uses an indentation width of 2 spaces.
14
- "globals": { // Allow mocha globals in tests.
15
- "describe": true,
16
- "it": true,
17
- "before": true,
18
- "beforeEach": true
19
- }
20
- }