Comparing version 0.4.4 to 0.4.5
@@ -336,9 +336,10 @@ // **N3Store** objects store N3 triples by graph in memory. | ||
createBlankNode: function (suggestedName) { | ||
var name; | ||
var name, index; | ||
// Generate a name based on the suggested name | ||
if (suggestedName) { | ||
name = suggestedName = '_:' + suggestedName; | ||
var index = 1; | ||
name = suggestedName = '_:' + suggestedName, index = 1; | ||
while (this._entities[name]) | ||
name = suggestedName + index++; | ||
} | ||
// Generate a generic blank node name | ||
else { | ||
@@ -348,3 +349,4 @@ do { name = '_:b' + this._blankNodeIndex++; } | ||
} | ||
this._entities[name] = this._entityCount++; | ||
// Add the blank node to the entities, avoiding the generation of duplicates | ||
this._entities[name] = ++this._entityCount; | ||
return name; | ||
@@ -351,0 +353,0 @@ }, |
{ | ||
"name": "n3", | ||
"version": "0.4.4", | ||
"version": "0.4.5", | ||
"description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.", | ||
@@ -5,0 +5,0 @@ "author": "Ruben Verborgh <ruben.verborgh@gmail.com>", |
@@ -33,3 +33,3 @@ var N3Store = require('../N3').Store; | ||
it('should be able to create unnamed blank nodes', function () { | ||
it('should be able to generate unnamed blank nodes', function () { | ||
store.createBlankNode().should.eql('_:b0'); | ||
@@ -42,3 +42,3 @@ store.createBlankNode().should.eql('_:b1'); | ||
it('should be able to create named blank nodes', function () { | ||
it('should be able to generate named blank nodes', function () { | ||
store.createBlankNode('blank').should.eql('_:blank'); | ||
@@ -48,2 +48,7 @@ store.createBlankNode('blank').should.eql('_:blank1'); | ||
}); | ||
it('should be able to store triples with generated blank nodes', function () { | ||
store.addTriple(store.createBlankNode('x'), 'b', 'c'); | ||
shouldIncludeAll(store.find(null, 'b'), ['_:x1', 'b', 'd']); | ||
}); | ||
}); | ||
@@ -50,0 +55,0 @@ |
286330
5356