-
Notifications
You must be signed in to change notification settings - Fork 0
/
assert.js
61 lines (47 loc) · 1.58 KB
/
assert.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { strictEqual } from 'assert'
import { join, resolve } from 'path'
import rdf from 'rdf-ext'
const datasetFileEqual = datasetFileEqualFactory()
const quadStreamFileEqual = quadStreamFileEqualFactory()
function datasetEqual (actual, expected) {
actual = rdf.dataset(actual).toCanonical()
expected = rdf.dataset(expected).toCanonical()
strictEqual(actual, expected)
}
function datasetFileEqualFactory ({ base = 'test/assets', ext = '.ttl' } = {}) {
return async (dataset, name) => {
const filename = join(resolve(base), `${name}${ext}`)
datasetEqual(dataset, await rdf.io.dataset.fromURL(filename))
}
}
function quadEqual (actual, expected) {
actual = rdf.fromTerm(actual).toCanonical()
expected = rdf.fromTerm(expected).toCanonical()
strictEqual(actual, expected)
}
async function quadStreamEqual (actual, expected) {
actual = (await rdf.dataset().import(actual)).toCanonical()
expected = rdf.dataset(expected).toCanonical()
strictEqual(actual, expected)
}
function quadStreamFileEqualFactory ({ base = 'test/assets', ext = '.ttl' } = {}) {
return async (quadStream, name) => {
const filename = join(resolve(base), `${name}${ext}`)
await quadStreamEqual(quadStream, await rdf.io.dataset.fromURL(filename))
}
}
function termEqual (actual, expected) {
actual = rdf.fromTerm(actual).toCanonical()
expected = rdf.fromTerm(expected).toCanonical()
strictEqual(actual, expected)
}
export {
datasetEqual,
datasetFileEqual,
datasetFileEqualFactory,
quadEqual,
quadStreamEqual,
quadStreamFileEqual,
quadStreamFileEqualFactory,
termEqual
}