Comparing version 0.8.1 to 0.8.2
@@ -9,7 +9,9 @@ // **N3Lexer** tokenizes N3 documents. | ||
var escapeSequence = /\\u([a-fA-F0-9]{4})|\\U([a-fA-F0-9]{8})|\\[uU]|\\(.)/g; | ||
var escapeReplacements = { '\\': '\\', "'": "'", '"': '"', | ||
'n': '\n', 'r': '\r', 't': '\t', 'f': '\f', 'b': '\b', | ||
'_': '_', '~': '~', '.': '.', '-': '-', '!': '!', '$': '$', '&': '&', | ||
'(': '(', ')': ')', '*': '*', '+': '+', ',': ',', ';': ';', '=': '=', | ||
'/': '/', '?': '?', '#': '#', '@': '@', '%': '%' }; | ||
var escapeReplacements = { | ||
'\\': '\\', "'": "'", '"': '"', | ||
'n': '\n', 'r': '\r', 't': '\t', 'f': '\f', 'b': '\b', | ||
'_': '_', '~': '~', '.': '.', '-': '-', '!': '!', '$': '$', '&': '&', | ||
'(': '(', ')': ')', '*': '*', '+': '+', ',': ',', ';': ';', '=': '=', | ||
'/': '/', '?': '?', '#': '#', '@': '@', '%': '%', | ||
}; | ||
var illegalIriChars = /[\x00-\x20<>\\"\{\}\|\^\`]/; | ||
@@ -49,4 +51,4 @@ | ||
_iri: /^<((?:[^ <>{}\\]|\\[uU])+)>/, // IRI with escape sequences; needs sanity check after unescaping | ||
_unescapedIri: /^<([^\x00-\x20<>\\"\{\}\|\^\`]*)>/, // IRI without escape sequences; no unescaping | ||
_iri: /^<((?:[^ <>{}\\]|\\[uU])+)>[ \t]*/, // IRI with escape sequences; needs sanity check after unescaping | ||
_unescapedIri: /^<([^\x00-\x20<>\\"\{\}\|\^\`]*)>[ \t]*/, // IRI without escape sequences; no unescaping | ||
_unescapedString: /^"[^"\\]+"(?=[^"\\])/, // non-empty string without escape sequences | ||
@@ -57,5 +59,5 @@ _singleQuotedString: /^"[^"\\]*(?:\\.[^"\\]*)*"(?=[^"\\])|^'[^'\\]*(?:\\.[^'\\]*)*'(?=[^'\\])/, | ||
_prefix: /^((?:[A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:\.?[\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)?:(?=[#\s<])/, | ||
_prefixed: /^((?:[A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:\.?[\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)?:((?:(?:[0-:A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~])(?:(?:[\.\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~])*(?:[\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~]))?)?)(?=\.?[,;!\^\s#()\[\]\{\}"'<])/, | ||
_prefixed: /^((?:[A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:\.?[\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)?:((?:(?:[0-:A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~])(?:(?:[\.\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~])*(?:[\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~]))?)?)(?:[ \t]+|(?=\.?[,;!\^\s#()\[\]\{\}"'<]))/, | ||
_variable: /^\?(?:(?:[A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:[\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)(?=[.,;!\^\s#()\[\]\{\}"'<])/, | ||
_blank: /^_:((?:[0-9A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:\.?[\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)(?=\.?[,;:\s#()\[\]\{\}"'<])/, | ||
_blank: /^_:((?:[0-9A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:\.?[\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)(?:[ \t]+|(?=\.?[,;:\s#()\[\]\{\}"'<]))/, | ||
_number: /^[\-+]?(?:\d+\.?\d*([eE](?:[\-\+])?\d+)|\d*\.?\d+)(?=[.,;:\s#()\[\]\{\}"'<])/, | ||
@@ -62,0 +64,0 @@ _boolean: /^(?:true|false)(?=[.,;\s#()\[\]\{\}"'<])/, |
@@ -741,4 +741,4 @@ // **N3Parser** parses N3 documents. | ||
_triple: function (subject, predicate, object, graph) { | ||
this._callback(null, { subject: subject, predicate: predicate, object: object, | ||
graph: graph || '' }); | ||
this._callback(null, | ||
{ subject: subject, predicate: predicate, object: object, graph: graph || '' }); | ||
}, | ||
@@ -845,7 +845,8 @@ | ||
this._prefixes._ = this._blankNodePrefix || '_:b' + blankNodePrefix++ + '_'; | ||
this._prefixCallback = prefixCallback || noop; | ||
this._inversePredicate = false; | ||
this._quantified = Object.create(null); | ||
// Parse synchronously if no callbacks are given. | ||
if (!tripleCallback && !prefixCallback) { | ||
// Parse synchronously if no triple callback is given. | ||
if (!tripleCallback) { | ||
var triples = [], error; | ||
@@ -861,4 +862,3 @@ this._callback = function (e, t) { e ? (error = e) : t && triples.push(t); }; | ||
// Parse asynchronously otherwise, executing the read callback when a token arrives. | ||
this._callback = tripleCallback || noop; | ||
this._prefixCallback = prefixCallback || noop; | ||
this._callback = tripleCallback; | ||
this._lexer.tokenize(input, function (error, token) { | ||
@@ -865,0 +865,0 @@ if (error !== null) |
@@ -13,4 +13,6 @@ // **N3Writer** writes N3 documents. | ||
escapeAll = /["\\\t\n\r\b\f\u0000-\u0019]|[\ud800-\udbff][\udc00-\udfff]/g, | ||
escapeReplacements = { '\\': '\\\\', '"': '\\"', '\t': '\\t', | ||
'\n': '\\n', '\r': '\\r', '\b': '\\b', '\f': '\\f' }; | ||
escapeReplacements = { | ||
'\\': '\\\\', '"': '\\"', '\t': '\\t', | ||
'\n': '\\n', '\r': '\\r', '\b': '\\b', '\f': '\\f', | ||
}; | ||
@@ -17,0 +19,0 @@ // ## Constructor |
{ | ||
"name": "n3", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.", | ||
@@ -24,6 +24,7 @@ "author": "Ruben Verborgh <ruben.verborgh@gmail.com>", | ||
"colors": "^1.1.2", | ||
"coveralls": "^2.11.14", | ||
"docco": "^0.7.0", | ||
"eslint": "^3.4.0", | ||
"istanbul": "^0.4.5", | ||
"eslint": "^3.10.0", | ||
"mocha": "^3.0.2", | ||
"nyc": "^8.3.0", | ||
"pre-commit": "^1.1.3", | ||
@@ -37,3 +38,4 @@ "request": "^2.74.0", | ||
"browser": "node browser/build-browser-versions", | ||
"coverage": "istanbul cover node_modules/.bin/_mocha -- -R spec --timeout 1000", | ||
"cover": "nyc -- mocha -R dot --timeout 1000", | ||
"coveralls": "nyc --reporter=text-lcov -- mocha -R dot --timeout 1000 | coveralls", | ||
"spec": "node spec/turtle-spec && node spec/trig-spec && node spec/ntriples-spec && node spec/nquads-spec", | ||
@@ -40,0 +42,0 @@ "spec-clean": "rm -r spec/turtle spec/trig", |
# Lightning fast, asynchronous, streaming RDF for JavaScript | ||
[](https://travis-ci.org/RubenVerborgh/N3.js) | ||
[](https://coveralls.io/github/RubenVerborgh/N3.js) | ||
[](https://www.npmjs.com/package/n3) | ||
@@ -388,7 +391,3 @@ The N3.js library lets you handle [RDF](http://www.w3.org/TR/rdf-primer/) in JavaScript easily, in [Node.js](http://nodejs.org/) and the browser. | ||
[](https://travis-ci.org/RubenVerborgh/N3.js) | ||
<br> | ||
[](https://ci.testling.com/RubenVerborgh/N3.js) | ||
Contributions are welcome, and bug reports or pull requests are always helpful. | ||
If you plan to implement a larger feature, it's best to contact me first. |
@@ -67,8 +67,10 @@ #!/usr/bin/env node | ||
function (test, callback) { | ||
async.series({ actionStream: self._fetch.bind(self, test.action), | ||
resultStream: self._fetch.bind(self, test.result) }, | ||
function (error, results) { | ||
if (error) return callback(error); | ||
self._performTest(test, results.actionStream, callback); | ||
}); | ||
async.series({ | ||
actionStream: self._fetch.bind(self, test.action), | ||
resultStream: self._fetch.bind(self, test.result), | ||
}, | ||
function (error, results) { | ||
if (error) return callback(error); | ||
self._performTest(test, results.actionStream, callback); | ||
}); | ||
}, | ||
@@ -75,0 +77,0 @@ // 1.2.2 Show the summary of all performed tests |
var N3Lexer = require('../N3').Lexer; | ||
var chai = require('chai'), | ||
EventEmitter = require('events'); | ||
var expect = chai.expect; | ||
chai.should(); | ||
var EventEmitter = require('events'); | ||
describe('N3Lexer', function () { | ||
@@ -8,0 +6,0 @@ describe('The N3Lexer module', function () { |
var N3Store = require('../N3').Store; | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
chai.should(); | ||
chai.use(require('chai-things')); | ||
@@ -7,0 +3,0 @@ describe('N3Store', function () { |
var N3StreamParser = require('../N3').StreamParser; | ||
var chai = require('chai'), | ||
Readable = require('stream').Readable, | ||
var Readable = require('stream').Readable, | ||
Writable = require('stream').Writable; | ||
chai.should(); | ||
@@ -7,0 +6,0 @@ describe('N3StreamParser', function () { |
var N3StreamWriter = require('../N3').StreamWriter; | ||
var chai = require('chai'), | ||
Readable = require('stream').Readable, | ||
var Readable = require('stream').Readable, | ||
Writable = require('stream').Writable; | ||
chai.should(); | ||
@@ -24,11 +23,11 @@ describe('N3StreamWriter', function () { | ||
it('should serialize 0 triples', | ||
shouldSerialize([], '')); | ||
shouldSerialize('')); | ||
it('should serialize 1 triple', | ||
shouldSerialize([['abc', 'def', 'ghi']], | ||
shouldSerialize(['abc', 'def', 'ghi'], | ||
'<abc> <def> <ghi>.\n')); | ||
it('should serialize 2 triples', | ||
shouldSerialize([['abc', 'def', 'ghi'], | ||
['jkl', 'mno', 'pqr']], | ||
shouldSerialize(['abc', 'def', 'ghi'], | ||
['jkl', 'mno', 'pqr'], | ||
'<abc> <def> <ghi>.\n' + | ||
@@ -38,5 +37,5 @@ '<jkl> <mno> <pqr>.\n')); | ||
it('should serialize 3 triples', | ||
shouldSerialize([['abc', 'def', 'ghi'], | ||
['jkl', 'mno', 'pqr'], | ||
['stu', 'vwx', 'yz']], | ||
shouldSerialize(['abc', 'def', 'ghi'], | ||
['jkl', 'mno', 'pqr'], | ||
['stu', 'vwx', 'yz'], | ||
'<abc> <def> <ghi>.\n' + | ||
@@ -47,7 +46,7 @@ '<jkl> <mno> <pqr>.\n' + | ||
it('should not serialize a literal in the subject', | ||
shouldNotSerialize([['"a"', 'b', '"c']], | ||
shouldNotSerialize(['"a"', 'b', '"c'], | ||
'A literal as subject is not allowed: "a"')); | ||
it('should not serialize a literal in the predicate', | ||
shouldNotSerialize([['a', '"b"', '"c']], | ||
shouldNotSerialize(['a', '"b"', '"c'], | ||
'A literal as predicate is not allowed: "b"')); | ||
@@ -57,5 +56,5 @@ | ||
shouldSerialize({ prefixes: { a: 'http://a.org/', b: 'http://a.org/b#', c: 'http://a.org/b' } }, | ||
[['http://a.org/bc', 'http://a.org/b#ef', 'http://a.org/bhi'], | ||
['http://a.org/bc/de', 'http://a.org/b#e#f', 'http://a.org/b#x/t'], | ||
['http://a.org/3a', 'http://a.org/b#3a', 'http://a.org/b#a3']], | ||
['http://a.org/bc', 'http://a.org/b#ef', 'http://a.org/bhi'], | ||
['http://a.org/bc/de', 'http://a.org/b#e#f', 'http://a.org/b#x/t'], | ||
['http://a.org/3a', 'http://a.org/b#3a', 'http://a.org/b#a3'], | ||
'@prefix a: <http://a.org/>.\n' + | ||
@@ -70,5 +69,7 @@ '@prefix b: <http://a.org/b#>.\n\n' + | ||
function shouldSerialize(options, tripleArrays, expectedResult) { | ||
if (!expectedResult) | ||
expectedResult = tripleArrays, tripleArrays = options, options = null; | ||
function shouldSerialize(/* options?, tripleArrays..., expectedResult */) { | ||
var tripleArrays = Array.prototype.slice.call(arguments), | ||
expectedResult = tripleArrays.pop(), | ||
options = tripleArrays[0] instanceof Array ? null : tripleArrays.shift(); | ||
return function (done) { | ||
@@ -88,3 +89,6 @@ var inputStream = new ArrayReader(tripleArrays), | ||
function shouldNotSerialize(tripleArrays, expectedMessage) { | ||
function shouldNotSerialize(/* tripleArrays..., expectedMessage */) { | ||
var tripleArrays = Array.prototype.slice.call(arguments), | ||
expectedMessage = tripleArrays.pop(); | ||
return function (done) { | ||
@@ -91,0 +95,0 @@ var inputStream = new ArrayReader(tripleArrays), |
var N3Util = require('../N3').Util; | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
chai.should(); | ||
@@ -6,0 +3,0 @@ describe('N3Util', function () { |
var N3Writer = require('../N3').Writer; | ||
var chai = require('chai'); | ||
chai.should(); | ||
@@ -22,11 +20,11 @@ describe('N3Writer', function () { | ||
it('should serialize 0 triples', | ||
shouldSerialize([], '')); | ||
shouldSerialize('')); | ||
it('should serialize 1 triple', | ||
shouldSerialize([['abc', 'def', 'ghi']], | ||
shouldSerialize(['abc', 'def', 'ghi'], | ||
'<abc> <def> <ghi>.\n')); | ||
it('should serialize 2 triples', | ||
shouldSerialize([['abc', 'def', 'ghi'], | ||
['jkl', 'mno', 'pqr']], | ||
shouldSerialize(['abc', 'def', 'ghi'], | ||
['jkl', 'mno', 'pqr'], | ||
'<abc> <def> <ghi>.\n' + | ||
@@ -36,5 +34,5 @@ '<jkl> <mno> <pqr>.\n')); | ||
it('should serialize 3 triples', | ||
shouldSerialize([['abc', 'def', 'ghi'], | ||
['jkl', 'mno', 'pqr'], | ||
['stu', 'vwx', 'yz']], | ||
shouldSerialize(['abc', 'def', 'ghi'], | ||
['jkl', 'mno', 'pqr'], | ||
['stu', 'vwx', 'yz'], | ||
'<abc> <def> <ghi>.\n' + | ||
@@ -45,71 +43,71 @@ '<jkl> <mno> <pqr>.\n' + | ||
it('should serialize a literal', | ||
shouldSerialize([['a', 'b', '"cde"']], | ||
shouldSerialize(['a', 'b', '"cde"'], | ||
'<a> <b> "cde".\n')); | ||
it('should serialize a literal with a type', | ||
shouldSerialize([['a', 'b', '"cde"^^fgh']], | ||
shouldSerialize(['a', 'b', '"cde"^^fgh'], | ||
'<a> <b> "cde"^^<fgh>.\n')); | ||
it('should serialize a literal with a language', | ||
shouldSerialize([['a', 'b', '"cde"@en-us']], | ||
shouldSerialize(['a', 'b', '"cde"@en-us'], | ||
'<a> <b> "cde"@en-us.\n')); | ||
it('should serialize a literal containing a single quote', | ||
shouldSerialize([['a', 'b', '"c\'de"']], | ||
shouldSerialize(['a', 'b', '"c\'de"'], | ||
'<a> <b> "c\'de".\n')); | ||
it('should serialize a literal containing a double quote', | ||
shouldSerialize([['a', 'b', '"c"de"']], | ||
shouldSerialize(['a', 'b', '"c"de"'], | ||
'<a> <b> "c\\"de".\n')); | ||
it('should serialize a literal containing a backspace', | ||
shouldSerialize([['a', 'b', '"c\\de"']], | ||
shouldSerialize(['a', 'b', '"c\\de"'], | ||
'<a> <b> "c\\\\de".\n')); | ||
it('should serialize a literal containing a tab character', | ||
shouldSerialize([['a', 'b', '"c\tde"']], | ||
shouldSerialize(['a', 'b', '"c\tde"'], | ||
'<a> <b> "c\\tde".\n')); | ||
it('should serialize a literal containing a newline character', | ||
shouldSerialize([['a', 'b', '"c\nde"']], | ||
shouldSerialize(['a', 'b', '"c\nde"'], | ||
'<a> <b> "c\\nde".\n')); | ||
it('should serialize a literal containing a cariage return character', | ||
shouldSerialize([['a', 'b', '"c\rde"']], | ||
shouldSerialize(['a', 'b', '"c\rde"'], | ||
'<a> <b> "c\\rde".\n')); | ||
it('should serialize a literal containing a backspace character', | ||
shouldSerialize([['a', 'b', '"c\bde"']], | ||
shouldSerialize(['a', 'b', '"c\bde"'], | ||
'<a> <b> "c\\bde".\n')); | ||
it('should serialize a literal containing a form feed character', | ||
shouldSerialize([['a', 'b', '"c\fde"']], | ||
shouldSerialize(['a', 'b', '"c\fde"'], | ||
'<a> <b> "c\\fde".\n')); | ||
it('should serialize a literal containing a line separator', | ||
shouldSerialize([['a', 'b', '"c\u2028de"']], | ||
shouldSerialize(['a', 'b', '"c\u2028de"'], | ||
'<a> <b> "c\u2028de".\n')); | ||
it('should serialize a literal containing a paragraph separator', | ||
shouldSerialize([['a', 'b', '"c\u2029de"']], | ||
shouldSerialize(['a', 'b', '"c\u2029de"'], | ||
'<a> <b> "c\u2029de".\n')); | ||
it('should serialize a literal containing special unicode characters', | ||
shouldSerialize([['a', 'b', '"c\u0000\u0001"']], | ||
shouldSerialize(['a', 'b', '"c\u0000\u0001"'], | ||
'<a> <b> "c\\u0000\\u0001".\n')); | ||
it('should serialize blank nodes', | ||
shouldSerialize([['_:a', 'b', '_:c']], | ||
shouldSerialize(['_:a', 'b', '_:c'], | ||
'_:a <b> _:c.\n')); | ||
it('should not serialize a literal in the subject', | ||
shouldNotSerialize([['"a"', 'b', '"c"']], | ||
shouldNotSerialize(['"a"', 'b', '"c"'], | ||
'A literal as subject is not allowed: "a"')); | ||
it('should not serialize a literal in the predicate', | ||
shouldNotSerialize([['a', '"b"', '"c"']], | ||
shouldNotSerialize(['a', '"b"', '"c"'], | ||
'A literal as predicate is not allowed: "b"')); | ||
it('should not serialize an invalid object literal', | ||
shouldNotSerialize([['a', 'b', '"c']], | ||
shouldNotSerialize(['a', 'b', '"c'], | ||
'Invalid literal: "c')); | ||
@@ -119,3 +117,3 @@ | ||
shouldSerialize({}, | ||
[['a', 'b', 'c']], | ||
['a', 'b', 'c'], | ||
'<a> <b> <c>.\n')); | ||
@@ -125,3 +123,2 @@ | ||
shouldSerialize({ prefixes: { a: 'http://a.org/', b: 'http://a.org/b#', c: 'http://a.org/b' } }, | ||
[], | ||
'@prefix a: <http://a.org/>.\n' + | ||
@@ -132,5 +129,5 @@ '@prefix b: <http://a.org/b#>.\n\n')); | ||
shouldSerialize({ prefixes: { a: 'http://a.org/', b: 'http://a.org/b#', c: 'http://a.org/b' } }, | ||
[['http://a.org/bc', 'http://a.org/b#ef', 'http://a.org/bhi'], | ||
['http://a.org/bc/de', 'http://a.org/b#e#f', 'http://a.org/b#x/t'], | ||
['http://a.org/3a', 'http://a.org/b#3a', 'http://a.org/b#a3']], | ||
['http://a.org/bc', 'http://a.org/b#ef', 'http://a.org/bhi'], | ||
['http://a.org/bc/de', 'http://a.org/b#e#f', 'http://a.org/b#x/t'], | ||
['http://a.org/3a', 'http://a.org/b#3a', 'http://a.org/b#a3'], | ||
'@prefix a: <http://a.org/>.\n' + | ||
@@ -144,3 +141,3 @@ '@prefix b: <http://a.org/b#>.\n\n' + | ||
shouldSerialize({ prefixes: { a: 'http://a.org/', b: 'http://a.org/b#' } }, | ||
[['a:bc', 'b:ef', 'c:bhi']], | ||
['a:bc', 'b:ef', 'c:bhi'], | ||
'@prefix a: <http://a.org/>.\n' + | ||
@@ -151,5 +148,5 @@ '@prefix b: <http://a.org/b#>.\n\n' + | ||
it('should not repeat the same subjects', | ||
shouldSerialize([['abc', 'def', 'ghi'], | ||
['abc', 'mno', 'pqr'], | ||
['stu', 'vwx', 'yz']], | ||
shouldSerialize(['abc', 'def', 'ghi'], | ||
['abc', 'mno', 'pqr'], | ||
['stu', 'vwx', 'yz'], | ||
'<abc> <def> <ghi>;\n' + | ||
@@ -160,7 +157,7 @@ ' <mno> <pqr>.\n' + | ||
it('should not repeat the same predicates', | ||
shouldSerialize([['abc', 'def', 'ghi'], | ||
['abc', 'def', 'pqr'], | ||
['abc', 'bef', 'ghi'], | ||
['abc', 'bef', 'pqr'], | ||
['stu', 'bef', 'yz']], | ||
shouldSerialize(['abc', 'def', 'ghi'], | ||
['abc', 'def', 'pqr'], | ||
['abc', 'bef', 'ghi'], | ||
['abc', 'bef', 'pqr'], | ||
['stu', 'bef', 'yz'], | ||
'<abc> <def> <ghi>, <pqr>;\n' + | ||
@@ -171,7 +168,7 @@ ' <bef> <ghi>, <pqr>.\n' + | ||
it('should write rdf:type as "a"', | ||
shouldSerialize([['abc', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'def']], | ||
shouldSerialize(['abc', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'def'], | ||
'<abc> a <def>.\n')); | ||
it('should serialize a graph with 1 triple', | ||
shouldSerialize([['abc', 'def', 'ghi', 'xyz']], | ||
shouldSerialize(['abc', 'def', 'ghi', 'xyz'], | ||
'<xyz> {\n' + | ||
@@ -182,5 +179,5 @@ '<abc> <def> <ghi>\n' + | ||
it('should serialize a graph with 3 triples', | ||
shouldSerialize([['abc', 'def', 'ghi', 'xyz'], | ||
['jkl', 'mno', 'pqr', 'xyz'], | ||
['stu', 'vwx', 'yz', 'xyz']], | ||
shouldSerialize(['abc', 'def', 'ghi', 'xyz'], | ||
['jkl', 'mno', 'pqr', 'xyz'], | ||
['stu', 'vwx', 'yz', 'xyz'], | ||
'<xyz> {\n' + | ||
@@ -193,5 +190,5 @@ '<abc> <def> <ghi>.\n' + | ||
it('should serialize three graphs', | ||
shouldSerialize([['abc', 'def', 'ghi', 'xyz'], | ||
['jkl', 'mno', 'pqr', ''], | ||
['stu', 'vwx', 'yz', 'abc']], | ||
shouldSerialize(['abc', 'def', 'ghi', 'xyz'], | ||
['jkl', 'mno', 'pqr', ''], | ||
['stu', 'vwx', 'yz', 'abc'], | ||
'<xyz> {\n<abc> <def> <ghi>\n}\n' + | ||
@@ -202,7 +199,7 @@ '<jkl> <mno> <pqr>.\n' + | ||
it('should output 8-bit unicode characters as escape sequences', | ||
shouldSerialize([['\ud835\udc00', '\ud835\udc00', '"\ud835\udc00"^^\ud835\udc00', '\ud835\udc00']], | ||
shouldSerialize(['\ud835\udc00', '\ud835\udc00', '"\ud835\udc00"^^\ud835\udc00', '\ud835\udc00'], | ||
'<\\U0001d400> {\n<\\U0001d400> <\\U0001d400> "\\U0001d400"^^<\\U0001d400>\n}\n')); | ||
it('should not use escape sequences in blank nodes', | ||
shouldSerialize([['_:\ud835\udc00', '_:\ud835\udc00', '_:\ud835\udc00', '_:\ud835\udc00']], | ||
shouldSerialize(['_:\ud835\udc00', '_:\ud835\udc00', '_:\ud835\udc00', '_:\ud835\udc00'], | ||
'_:\ud835\udc00 {\n_:\ud835\udc00 _:\ud835\udc00 _:\ud835\udc00\n}\n')); | ||
@@ -578,5 +575,7 @@ | ||
function shouldSerialize(prefixes, tripleArrays, expectedResult) { | ||
if (!expectedResult) | ||
expectedResult = tripleArrays, tripleArrays = prefixes, prefixes = null; | ||
function shouldSerialize(/* prefixes?, tripleArrays..., expectedResult */) { | ||
var tripleArrays = Array.prototype.slice.call(arguments), | ||
expectedResult = tripleArrays.pop(), | ||
prefixes = tripleArrays[0] instanceof Array ? null : tripleArrays.shift(); | ||
return function (done) { | ||
@@ -604,3 +603,6 @@ var outputStream = new QuickStream(), | ||
function shouldNotSerialize(tripleArrays, expectedMessage) { | ||
function shouldNotSerialize(/* tripleArrays..., expectedResult */) { | ||
var tripleArrays = Array.prototype.slice.call(arguments), | ||
expectedMessage = tripleArrays.pop(); | ||
return function (done) { | ||
@@ -607,0 +609,0 @@ var outputStream = new QuickStream(), |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
37
353800
13
6345
393