JS: Migrates tests to @rdfjs/data-model v2

pull/190/head
Tpt 3 years ago
parent ed13b7bcf3
commit bfbaa402a3
  1. 4
      js/package.json
  2. 8
      js/test/model.mjs
  3. 72
      js/test/store.mjs

@ -4,11 +4,11 @@
"private": true, "private": true,
"devDependencies": { "devDependencies": {
"mocha": "^9.0.0", "mocha": "^9.0.0",
"@rdfjs/data-model": "^1.3.0", "@rdfjs/data-model": "^2.0.0",
"standard": "^16.0.0" "standard": "^16.0.0"
}, },
"scripts": { "scripts": {
"test": "standard test/*.js && wasm-pack build --dev --target nodejs && mocha", "test": "standard test/* && 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,8 +1,10 @@
/* global describe, it */ /* global describe, it */
const oxigraph = require('../pkg/oxigraph.js') import oxigraph from '../pkg/oxigraph.js'
const assert = require('assert') import assert from 'assert'
require('../node_modules/@rdfjs/data-model/test/index.js')(oxigraph) import runTests from '../node_modules/@rdfjs/data-model/test/index.js'
runTests({ factory: oxigraph })
describe('DataModel', function () { describe('DataModel', function () {
describe('#toString()', function () { describe('#toString()', function () {

@ -1,60 +1,60 @@
/* global describe, it */ /* global describe, it */
const { Store } = require('../pkg/oxigraph.js') import { Store } from '../pkg/oxigraph.js'
const assert = require('assert') import assert from 'assert'
const dataFactory = require('@rdfjs/data-model') import dataModel from '@rdfjs/data-model'
const ex = dataFactory.namedNode('http://example.com') const ex = dataModel.namedNode('http://example.com')
const triple = dataFactory.triple( const triple = dataModel.quad(
dataFactory.blankNode('s'), dataModel.blankNode('s'),
dataFactory.namedNode('http://example.com/p'), dataModel.namedNode('http://example.com/p'),
dataFactory.literal('o') dataModel.literal('o')
) )
describe('Store', function () { describe('Store', 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 Store() const store = new Store()
store.add(dataFactory.triple(ex, ex, triple)) store.add(dataModel.quad(ex, ex, triple))
assert(store.has(dataFactory.triple(ex, ex, triple))) assert(store.has(dataModel.quad(ex, ex, triple)))
}) })
}) })
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 Store([dataFactory.triple(triple, ex, ex)]) const store = new Store([dataModel.quad(triple, ex, ex)])
assert(store.has(dataFactory.triple(triple, ex, ex))) assert(store.has(dataModel.quad(triple, ex, ex)))
store.delete(dataFactory.triple(triple, ex, ex)) store.delete(dataModel.quad(triple, ex, ex))
assert(!store.has(dataFactory.triple(triple, ex, ex))) assert(!store.has(dataModel.quad(triple, 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 Store([dataFactory.triple(ex, ex, ex)]) const store = new Store([dataModel.quad(ex, ex, ex)])
assert(store.has(dataFactory.triple(ex, ex, ex))) assert(store.has(dataModel.quad(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 Store([dataFactory.triple(ex, ex, ex)]) const store = new Store([dataModel.quad(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 Store([dataFactory.triple(ex, ex, ex)]) const store = new Store([dataModel.quad(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(dataModel.quad(ex, ex, ex).equals(results[0]))
}) })
}) })
describe('#query()', function () { describe('#query()', function () {
it('ASK true', function () { it('ASK true', function () {
const store = new Store([dataFactory.triple(ex, ex, ex)]) const store = new Store([dataModel.quad(ex, ex, ex)])
assert.strictEqual(true, store.query('ASK { ?s ?s ?s }')) assert.strictEqual(true, store.query('ASK { ?s ?s ?s }'))
}) })
@ -64,27 +64,27 @@ describe('Store', function () {
}) })
it('CONSTRUCT', function () { it('CONSTRUCT', function () {
const store = new Store([dataFactory.triple(ex, ex, ex)]) const store = new Store([dataModel.quad(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(dataModel.quad(ex, ex, ex).equals(results[0]))
}) })
it('SELECT', function () { it('SELECT', function () {
const store = new Store([dataFactory.triple(ex, ex, ex)]) const store = new Store([dataModel.quad(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')))
}) })
it('SELECT with NOW()', function () { it('SELECT with NOW()', function () {
const store = new Store([dataFactory.triple(ex, ex, ex)]) const store = new Store([dataModel.quad(ex, ex, ex)])
const results = store.query('SELECT (YEAR(NOW()) AS ?y) WHERE {}') const results = store.query('SELECT (YEAR(NOW()) AS ?y) WHERE {}')
assert.strictEqual(1, results.length) assert.strictEqual(1, results.length)
}) })
it('SELECT with RAND()', function () { it('SELECT with RAND()', function () {
const store = new Store([dataFactory.triple(ex, ex, ex)]) const store = new Store([dataModel.quad(ex, ex, ex)])
const results = store.query('SELECT (RAND() AS ?y) WHERE {}') const results = store.query('SELECT (RAND() AS ?y) WHERE {}')
assert.strictEqual(1, results.length) assert.strictEqual(1, results.length)
}) })
@ -98,13 +98,13 @@ describe('Store', function () {
}) })
it('DELETE DATA', function () { it('DELETE DATA', function () {
const store = new Store([dataFactory.triple(ex, ex, ex)]) const store = new Store([dataModel.quad(ex, ex, ex)])
store.update('DELETE DATA { <http://example.com> <http://example.com> <http://example.com> }') store.update('DELETE DATA { <http://example.com> <http://example.com> <http://example.com> }')
assert.strictEqual(0, store.size) assert.strictEqual(0, store.size)
}) })
it('DELETE WHERE', function () { it('DELETE WHERE', function () {
const store = new Store([dataFactory.triple(ex, ex, ex)]) const store = new Store([dataModel.quad(ex, ex, ex)])
store.update('DELETE WHERE { ?v ?v ?v }') store.update('DELETE WHERE { ?v ?v ?v }')
assert.strictEqual(0, store.size) assert.strictEqual(0, store.size)
}) })
@ -114,47 +114,47 @@ describe('Store', function () {
it('load NTriples in the default graph', function () { it('load NTriples in the default graph', function () {
const store = new Store() const store = new Store()
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(dataModel.quad(ex, ex, ex)))
}) })
it('load NTriples in an other graph', function () { it('load NTriples in an other graph', function () {
const store = new Store() const store = new Store()
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(dataModel.quad(ex, ex, ex, ex)))
}) })
it('load Turtle with a base IRI', function () { it('load Turtle with a base IRI', function () {
const store = new Store() const store = new Store()
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(dataModel.quad(ex, ex, ex)))
}) })
it('load NQuads', function () { it('load NQuads', function () {
const store = new Store() const store = new Store()
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(dataModel.quad(ex, ex, ex, ex)))
}) })
it('load TriG with a base IRI', function () { it('load TriG with a base IRI', function () {
const store = new Store() const store = new Store()
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(dataModel.quad(ex, ex, ex, ex)))
}) })
}) })
describe('#dump()', function () { describe('#dump()', function () {
it('dump dataset content', function () { it('dump dataset content', function () {
const store = new Store([dataFactory.quad(ex, ex, ex, ex)]) const store = new Store([dataModel.quad(ex, ex, ex, ex)])
assert.strictEqual('<http://example.com> <http://example.com> <http://example.com> <http://example.com> .\n', store.dump('application/n-quads')) assert.strictEqual('<http://example.com> <http://example.com> <http://example.com> <http://example.com> .\n', store.dump('application/n-quads'))
}) })
it('dump named graph content', function () { it('dump named graph content', function () {
const store = new Store([dataFactory.quad(ex, ex, ex, ex)]) const store = new Store([dataModel.quad(ex, ex, ex, ex)])
assert.strictEqual('<http://example.com> <http://example.com> <http://example.com> .\n', store.dump('application/n-triples', ex)) assert.strictEqual('<http://example.com> <http://example.com> <http://example.com> .\n', store.dump('application/n-triples', ex))
}) })
it('dump default graph content', function () { it('dump default graph content', function () {
const store = new Store([dataFactory.quad(ex, ex, ex, ex)]) const store = new Store([dataModel.quad(ex, ex, ex, ex)])
assert.strictEqual('', store.dump('application/n-triples')) assert.strictEqual('', store.dump('application/n-triples'))
}) })
}) })
Loading…
Cancel
Save