Skip to content

Commit 4fdcb37

Browse files
committed
Add isDefaultGraph and inDefaultGraph.
1 parent 1c5f1ff commit 4fdcb37

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

lib/N3Util.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ var N3Util = {
2626
return entity && entity.substr(0, 2) === '_:';
2727
},
2828

29+
// Tests whether the given entity represents the default graph
30+
isDefaultGraph: function (entity) {
31+
return !entity;
32+
},
33+
34+
// Tests whether the given triple is in the default graph
35+
inDefaultGraph: function (triple) {
36+
return !triple.graph;
37+
},
38+
2939
// Gets the string value of a literal in the N3 library
3040
getLiteralValue: function (literal) {
3141
var match = /^"([^]*)"/.exec(literal);

test/N3Util-test.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,58 @@ describe('N3Util', function () {
112112
});
113113
});
114114

115+
describe('isDefaultGraph', function () {
116+
it('does not match a blank node', function () {
117+
N3Util.isDefaultGraph('_:x').should.be.false;
118+
});
119+
120+
it('does not match an IRI', function () {
121+
N3Util.isDefaultGraph('http://example.org/').should.be.false;
122+
});
123+
124+
it('does not match a literal', function () {
125+
N3Util.isDefaultGraph('"http://example.org/"').should.be.false;
126+
});
127+
128+
it('matches null', function () {
129+
expect(N3Util.isDefaultGraph(null)).to.be.true;
130+
});
131+
132+
it('matches undefined', function () {
133+
expect(N3Util.isDefaultGraph(undefined)).to.be.true;
134+
});
135+
136+
it('matches the empty string', function () {
137+
expect(N3Util.isDefaultGraph('')).to.be.true;
138+
});
139+
});
140+
141+
describe('inDefaultGraph', function () {
142+
it('does not match a blank node', function () {
143+
N3Util.inDefaultGraph({ graph: '_:x' }).should.be.false;
144+
});
145+
146+
it('does not match an IRI', function () {
147+
N3Util.inDefaultGraph({ graph: 'http://example.org/' }).should.be.false;
148+
});
149+
150+
it('does not match a literal', function () {
151+
N3Util.inDefaultGraph({ graph: '"http://example.org/"' }).should.be.false;
152+
});
153+
154+
it('matches null', function () {
155+
N3Util.inDefaultGraph({ graph: null }).should.be.true;
156+
});
157+
158+
it('matches undefined', function () {
159+
N3Util.inDefaultGraph({ graph: undefined }).should.be.true;
160+
});
161+
162+
it('matches the empty string', function () {
163+
N3Util.inDefaultGraph({ graph: '' }).should.be.true;
164+
});
165+
});
166+
115167
describe('getLiteralValue', function () {
116168
it('gets the value of a literal', function () {
117169
N3Util.getLiteralValue('"Mickey"').should.equal('Mickey');

0 commit comments

Comments
 (0)