Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add tests for deeply nested triples #303

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion test/N3Store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1646,13 +1646,39 @@ describe('Store', () => {
]);
});

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

it('should include added elements in match if iteration has not yet started', () => {
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(3);
[...store.match(null, null, null, null)].should.have.length(3);
});

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
100 changes: 54 additions & 46 deletions test/Term-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,55 @@ 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')
)

const DEEP_TRIPLE_STRING = '<<<<<<<<_:n3-000 ?var-b "abc"@en-us http://ex.org/d>> ?var-b <<_:n3-000 ?var-b "abc"@en-us http://ex.org/d>> http://ex.org/d>> ?var-b <<_:n3-000 ?var-b "abc"@en-us http://ex.org/d>> http://ex.org/d>> http://ex.org/b <<<<_:n3-000 ?var-b "abc"@en-us http://ex.org/d>> ?var-b <<_:n3-000 ?var-b "abc"@en-us http://ex.org/d>> http://ex.org/d>> http://ex.org/d>>'

describe('Term', () => {
describe('The Term module', () => {
it('should be a function', () => {
Expand Down Expand Up @@ -159,6 +208,10 @@ describe('Term', () => {
));
});

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

describe('with a custom factory', () => {
const factory = {
defaultGraph: function () { return ['d']; },
Expand Down Expand Up @@ -429,52 +482,7 @@ describe('Term', () => {
});

it('should correctly handle deeply nested quads', () => {
termToId(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')
)).should.equal('<<<<<<<<_:n3-000 ?var-b "abc"@en-us http://ex.org/d>> ?var-b <<_:n3-000 ?var-b "abc"@en-us http://ex.org/d>> http://ex.org/d>> ?var-b <<_:n3-000 ?var-b "abc"@en-us http://ex.org/d>> http://ex.org/d>> http://ex.org/b <<<<_:n3-000 ?var-b "abc"@en-us http://ex.org/d>> ?var-b <<_:n3-000 ?var-b "abc"@en-us http://ex.org/d>> http://ex.org/d>> http://ex.org/d>>');
termToId(DEEP_TRIPLE).should.equal(DEEP_TRIPLE_STRING);
});

it('should throw on an unknown type', () => {
Expand Down