Fork of https://github.com/oxigraph/oxigraph.git for the purpose of NextGraph project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
oxigraph/js/test/store.js

66 lines
2.3 KiB

const { MemoryStore } = require('../pkg/oxigraph.js');
const assert = require('assert');
const dataFactory = require('@rdfjs/data-model');
const ex = dataFactory.namedNode('http://example.com');
describe('MemoryStore', function() {
describe('#add()', function() {
it('an added quad should be in the store', function() {
const store = new MemoryStore();
store.add(dataFactory.triple(ex, ex, ex));
assert(store.has(dataFactory.triple(ex, ex, ex)));
});
});
describe('#delete()', function() {
it('an removed quad should not be in the store anymore', function() {
const store = new MemoryStore([dataFactory.triple(ex, ex, ex)]);
assert(store.has(dataFactory.triple(ex, ex, ex)));
store.delete(dataFactory.triple(ex, ex, ex))
assert(!store.has(dataFactory.triple(ex, ex, ex)));
});
});
describe('#has()', function() {
it('an added quad should be in the store', function() {
const store = new MemoryStore([dataFactory.triple(ex, ex, ex)]);
assert(store.has(dataFactory.triple(ex, ex, ex)));
});
});
describe('#match_quads()', function() {
it('blank pattern should return all quads', function() {
const store = new MemoryStore([dataFactory.triple(ex, ex, ex)]);
const results = store.match();
assert.equal(1, results.length);
assert(dataFactory.triple(ex, ex, ex).equals(results[0]));
});
});
describe('#query()', function() {
it('ASK true', function() {
const store = new MemoryStore([dataFactory.triple(ex, ex, ex)]);
assert.equal(true, store.query("ASK { ?s ?s ?s }"));
});
it('ASK false', function() {
const store = new MemoryStore();
assert.equal(false, store.query("ASK { FILTER(false)}"));
});
it('CONSTRUCT', function() {
const store = new MemoryStore([dataFactory.triple(ex, ex, ex)]);
const results = store.query("CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }");
assert.equal(1, results.length);
assert(dataFactory.triple(ex, ex, ex).equals(results[0]));
});
it('SELECT', function() {
const store = new MemoryStore([dataFactory.triple(ex, ex, ex)]);
const results = store.query("SELECT ?s WHERE { ?s ?p ?o }");
assert.equal(1, results.length);
assert(ex.equals(results[0].get("s")));
});
});
});