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

feat: make return quads return a boolean indicating if all removed quads were in store #501

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion src/N3Store.js
Original file line number Diff line number Diff line change
@@ -446,9 +446,12 @@ export default class N3Store {
}

// ### `removeQuads` removes multiple quads from the store
// returns `true` if all quads were removed, `false` if some were not found
removeQuads(quads) {
let removed = quads.length >= 0;
for (let i = 0; i < quads.length; i++)
this.removeQuad(quads[i]);
removed = this.removeQuad(quads[i]) && removed;
return removed;
}

// ### `remove` removes a stream of quads from the store
7 changes: 5 additions & 2 deletions test/N3Store-test.js
Original file line number Diff line number Diff line change
@@ -121,7 +121,7 @@ describe('Store', () => {

expect(store.addQuad('_:b0', '_:b1', '_:b2')).toBe(true);
expect(store.createBlankNode().value).toEqual('b3');
store.removeQuads(store.getQuads());
expect(store.removeQuads(store.getQuads())).toBe(true);
});

it('should be able to generate named blank nodes', () => {
@@ -135,7 +135,10 @@ describe('Store', () => {
store.addQuad(store.createBlankNode('x'), new NamedNode('b'), new NamedNode('c')),
).toBe(true);
shouldIncludeAll(store.getQuads(null, new NamedNode('b')), ['_:x', 'b', 'c'])();
store.removeQuads(store.getQuads());
const quads = [...store.getQuads()];
expect(store.removeQuads([quad(namedNode('p'), namedNode('q'), namedNode('r'))])).toBe(false);
expect(store.removeQuads(quads)).toBe(true);
expect(store.removeQuads(quads)).toBe(false);
});
});