Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
chore: add tests from rdfjs#303
Browse files Browse the repository at this point in the history
  • Loading branch information
jeswr committed Nov 26, 2022
1 parent d258f22 commit 56cc184
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/N3Store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,32 @@ describe('Store', () => {
[...store.match(null, null, null, null)].should.have.length(3);
});

it('should include added elements in match if iteration has not yet started (deeply nested)', () => {
const m = store.match(null, null, null, null);
store.add(new Quad(
new NamedNode('s1'),
new NamedNode('p1'),
new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o3'))
)
);
store.add(new Quad(
new NamedNode('s1'),
new NamedNode('p1'),
new Quad(
new NamedNode('s1'),
new NamedNode('p1'),
new Quad(
new NamedNode('s1'),
new NamedNode('p1'),
new NamedNode('o3')
)
)
)
);
[...m].should.have.length(4);
[...store.match(null, null, null, null)].should.have.length(4);
});

it('should still include results of original match after iterating while adding new data', () => {
const m = store.match(null, null, null, null)[Symbol.iterator]();
m.next().value.should.deep.equal(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1')));
Expand Down
53 changes: 53 additions & 0 deletions test/Term-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,54 @@ import {
unescapeQuotes,
} from '../src/N3DataFactory';


const DEEP_TRIPLE = new Quad(
new Quad(
new Quad(
new Quad(
new BlankNode('n3-000'),
new Variable('var-b'),
new Literal('"abc"@en-us'),
new NamedNode('http://ex.org/d')
),
new Variable('var-b'),
new Quad(
new BlankNode('n3-000'),
new Variable('var-b'),
new Literal('"abc"@en-us'),
new NamedNode('http://ex.org/d')
),
new NamedNode('http://ex.org/d')
),
new Variable('var-b'),
new Quad(
new BlankNode('n3-000'),
new Variable('var-b'),
new Literal('"abc"@en-us'),
new NamedNode('http://ex.org/d')
),
new NamedNode('http://ex.org/d')
),
new NamedNode('http://ex.org/b'),
new Quad(
new Quad(
new BlankNode('n3-000'),
new Variable('var-b'),
new Literal('"abc"@en-us'),
new NamedNode('http://ex.org/d')
),
new Variable('var-b'),
new Quad(
new BlankNode('n3-000'),
new Variable('var-b'),
new Literal('"abc"@en-us'),
new NamedNode('http://ex.org/d')
),
new NamedNode('http://ex.org/d')
),
new NamedNode('http://ex.org/d')
);

describe('Term', () => {
describe('The Term module', () => {
it('should be a function', () => {
Expand Down Expand Up @@ -161,6 +209,11 @@ describe('Term', () => {
termFromId(termToId(q)).should.deep.equal(q);
});

it('should correctly handle deeply nested quads', () => {
DEEP_TRIPLE.equals(termFromId(termToId(DEEP_TRIPLE))).should.equal(true);
termFromId(termToId(DEEP_TRIPLE)).equals(DEEP_TRIPLE).should.equal(true);
});

describe('with a custom factory', () => {
const factory = {
defaultGraph: function () { return ['d']; },
Expand Down

0 comments on commit 56cc184

Please sign in to comment.