Uses JavaScript "standard" code style

pull/43/head
Tpt 4 years ago
parent 5eb9d28696
commit c9d61ce3d5
  1. 5
      js/package.json
  2. 5
      js/test/model.js
  3. 136
      js/test/store.js

@ -4,10 +4,11 @@
"private": true, "private": true,
"devDependencies": { "devDependencies": {
"mocha": "^8.0.1", "mocha": "^8.0.1",
"@rdfjs/data-model": "^1.1.2" "@rdfjs/data-model": "^1.1.2",
"standard": "^14.3.4"
}, },
"scripts": { "scripts": {
"test": "wasm-pack build --dev --target nodejs && mocha", "test": "standard test/*.js && wasm-pack build --dev --target nodejs && mocha",
"build": "wasm-pack build --release --target nodejs && sed -i 's/oxigraph_js/oxigraph/g' pkg/package.json", "build": "wasm-pack build --release --target nodejs && sed -i 's/oxigraph_js/oxigraph/g' pkg/package.json",
"release": "wasm-pack pack && wasm-pack publish" "release": "wasm-pack pack && wasm-pack publish"
} }

@ -1,3 +1,2 @@
const { MemoryStore } = require('../pkg/oxigraph.js'); const { MemoryStore } = require('../pkg/oxigraph.js')
const assert = require('assert'); require('../node_modules/@rdfjs/data-model/test/index.js')((new MemoryStore()).dataFactory)
require('../node_modules/@rdfjs/data-model/test/index.js')((new MemoryStore()).dataFactory);

@ -1,105 +1,107 @@
const { MemoryStore } = require('../pkg/oxigraph.js'); /* global describe, it */
const assert = require('assert');
const dataFactory = require('@rdfjs/data-model');
const ex = dataFactory.namedNode('http://example.com'); 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('MemoryStore', function () {
describe('#add()', function () { describe('#add()', function () {
it('an added quad should be in the store', function () { it('an added quad should be in the store', function () {
const store = new MemoryStore(); const store = new MemoryStore()
store.add(dataFactory.triple(ex, ex, ex)); store.add(dataFactory.triple(ex, ex, ex))
assert(store.has(dataFactory.triple(ex, ex, ex))); assert(store.has(dataFactory.triple(ex, ex, ex)))
}); })
}); })
describe('#delete()', function () { describe('#delete()', function () {
it('an removed quad should not be in the store anymore', function () { it('an removed quad should not be in the store anymore', function () {
const store = new MemoryStore([dataFactory.triple(ex, ex, ex)]); const store = new MemoryStore([dataFactory.triple(ex, ex, ex)])
assert(store.has(dataFactory.triple(ex, ex, ex))); assert(store.has(dataFactory.triple(ex, ex, ex)))
store.delete(dataFactory.triple(ex, ex, ex)) store.delete(dataFactory.triple(ex, ex, ex))
assert(!store.has(dataFactory.triple(ex, ex, ex))); assert(!store.has(dataFactory.triple(ex, ex, ex)))
}); })
}); })
describe('#has()', function () { describe('#has()', function () {
it('an added quad should be in the store', function () { it('an added quad should be in the store', function () {
const store = new MemoryStore([dataFactory.triple(ex, ex, ex)]); const store = new MemoryStore([dataFactory.triple(ex, ex, ex)])
assert(store.has(dataFactory.triple(ex, ex, ex))); assert(store.has(dataFactory.triple(ex, ex, ex)))
}); })
}); })
describe('#size()', function () { describe('#size()', function () {
it('A store with one quad should have 1 for size', function () { it('A store with one quad should have 1 for size', function () {
const store = new MemoryStore([dataFactory.triple(ex, ex, ex)]); const store = new MemoryStore([dataFactory.triple(ex, ex, ex)])
assert.strictEqual(1, store.size); assert.strictEqual(1, store.size)
}); })
}); })
describe('#match_quads()', function () { describe('#match_quads()', function () {
it('blank pattern should return all quads', function () { it('blank pattern should return all quads', function () {
const store = new MemoryStore([dataFactory.triple(ex, ex, ex)]); const store = new MemoryStore([dataFactory.triple(ex, ex, ex)])
const results = store.match(); const results = store.match()
assert.strictEqual(1, results.length); assert.strictEqual(1, results.length)
assert(dataFactory.triple(ex, ex, ex).equals(results[0])); assert(dataFactory.triple(ex, ex, ex).equals(results[0]))
}); })
}); })
describe('#query()', function () { describe('#query()', function () {
it('ASK true', function () { it('ASK true', function () {
const store = new MemoryStore([dataFactory.triple(ex, ex, ex)]); const store = new MemoryStore([dataFactory.triple(ex, ex, ex)])
assert.strictEqual(true, store.query("ASK { ?s ?s ?s }")); assert.strictEqual(true, store.query('ASK { ?s ?s ?s }'))
}); })
it('ASK false', function () { it('ASK false', function () {
const store = new MemoryStore(); const store = new MemoryStore()
assert.strictEqual(false, store.query("ASK { FILTER(false)}")); assert.strictEqual(false, store.query('ASK { FILTER(false)}'))
}); })
it('CONSTRUCT', function () { it('CONSTRUCT', function () {
const store = new MemoryStore([dataFactory.triple(ex, ex, ex)]); const store = new MemoryStore([dataFactory.triple(ex, ex, ex)])
const results = store.query("CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }"); const results = store.query('CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }')
assert.strictEqual(1, results.length); assert.strictEqual(1, results.length)
assert(dataFactory.triple(ex, ex, ex).equals(results[0])); assert(dataFactory.triple(ex, ex, ex).equals(results[0]))
}); })
it('SELECT', function () { it('SELECT', function () {
const store = new MemoryStore([dataFactory.triple(ex, ex, ex)]); const store = new MemoryStore([dataFactory.triple(ex, ex, ex)])
const results = store.query("SELECT ?s WHERE { ?s ?p ?o }"); const results = store.query('SELECT ?s WHERE { ?s ?p ?o }')
assert.strictEqual(1, results.length); assert.strictEqual(1, results.length)
assert(ex.equals(results[0].get("s"))); assert(ex.equals(results[0].get('s')))
}); })
}); })
describe('#load()', function () { describe('#load()', function () {
it('load NTriples in the default graph', function () { it('load NTriples in the default graph', function () {
const store = new MemoryStore(); const store = new MemoryStore()
store.load("<http://example.com> <http://example.com> <http://example.com> .", "application/n-triples"); store.load('<http://example.com> <http://example.com> <http://example.com> .', 'application/n-triples')
assert(store.has(dataFactory.triple(ex, ex, ex))); assert(store.has(dataFactory.triple(ex, ex, ex)))
}); })
it('load NTriples in an other graph', function () { it('load NTriples in an other graph', function () {
const store = new MemoryStore(); const store = new MemoryStore()
store.load("<http://example.com> <http://example.com> <http://example.com> .", "application/n-triples", null, ex); store.load('<http://example.com> <http://example.com> <http://example.com> .', 'application/n-triples', null, ex)
assert(store.has(dataFactory.quad(ex, ex, ex, ex))); assert(store.has(dataFactory.quad(ex, ex, ex, ex)))
}); })
it('load Turtle with a base IRI', function () { it('load Turtle with a base IRI', function () {
const store = new MemoryStore(); const store = new MemoryStore()
store.load("<http://example.com> <http://example.com> <> .", "text/turtle", "http://example.com"); store.load('<http://example.com> <http://example.com> <> .', 'text/turtle', 'http://example.com')
assert(store.has(dataFactory.triple(ex, ex, ex))); assert(store.has(dataFactory.triple(ex, ex, ex)))
}); })
it('load NQuads', function () { it('load NQuads', function () {
const store = new MemoryStore(); const store = new MemoryStore()
store.load("<http://example.com> <http://example.com> <http://example.com> <http://example.com> .", "application/n-quads"); store.load('<http://example.com> <http://example.com> <http://example.com> <http://example.com> .', 'application/n-quads')
assert(store.has(dataFactory.quad(ex, ex, ex, ex))); assert(store.has(dataFactory.quad(ex, ex, ex, ex)))
}); })
it('load TriG with a base IRI', function () { it('load TriG with a base IRI', function () {
const store = new MemoryStore(); const store = new MemoryStore()
store.load("GRAPH <> { <http://example.com> <http://example.com> <> }", "application/trig", "http://example.com"); store.load('GRAPH <> { <http://example.com> <http://example.com> <> }', 'application/trig', 'http://example.com')
assert(store.has(dataFactory.quad(ex, ex, ex, ex))); assert(store.has(dataFactory.quad(ex, ex, ex, ex)))
}); })
}); })
}); })

Loading…
Cancel
Save