Skip to content

Commit c13a86b

Browse files
jeswropl-
andauthored
feat: add N3Util.isQuad (#535)
* Add N3Util.isQuad * feat: add IRI content to quad --------- Co-authored-by: opl- <opl-@users.noreply.github.com>
1 parent 8f32865 commit c13a86b

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/N3Util.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export function isVariable(term) {
2222
return !!term && term.termType === 'Variable';
2323
}
2424

25+
// Tests whether the given term represents a quad
26+
export function isQuad(term) {
27+
return !!term && term.termType === 'Quad';
28+
}
29+
2530
// Tests whether the given term represents the default graph
2631
export function isDefaultGraph(term) {
2732
return !!term && term.termType === 'DefaultGraph';

test/N3Util-test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,45 @@ describe('Util', () => {
131131
});
132132
});
133133

134+
describe('isQuad', () => {
135+
it('matches a quad', () => {
136+
expect(Util.isQuad(quad(null, null, null, null))).toBe(true);
137+
});
138+
139+
it('matches a quad with iri content', () => {
140+
expect(Util.isQuad(quad(
141+
namedNode('http://example.org/'),
142+
namedNode('http://example.org/'),
143+
namedNode('http://example.org/'),
144+
namedNode('http://example.org/'),
145+
))).toBe(true);
146+
});
147+
148+
it('does not match an IRI', () => {
149+
expect(Util.isQuad(namedNode('http://example.org/'))).toBe(false);
150+
});
151+
152+
it('does not match a literal', () => {
153+
expect(Util.isQuad(literal('http://example.org/'))).toBe(false);
154+
});
155+
156+
it('does not match a blank node', () => {
157+
expect(Util.isQuad(blankNode('x'))).toBe(false);
158+
});
159+
160+
it('does not match a variable', () => {
161+
expect(Util.isQuad(variable('x'))).toBe(false);
162+
});
163+
164+
it('does not match null', () => {
165+
expect(Util.isQuad(null)).toBe(false);
166+
});
167+
168+
it('does not match undefined', () => {
169+
expect(Util.isQuad(undefined)).toBe(false);
170+
});
171+
});
172+
134173
describe('isDefaultGraph', () => {
135174
it('does not match a blank node', () => {
136175
expect(Util.isDefaultGraph(blankNode('x'))).toBe(false);

0 commit comments

Comments
 (0)