-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
125 lines (96 loc) · 2.7 KB
/
test.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
"use strict";
const test = require('tape')
test('Triple builder', t => {
t.plan(4);
const $ = require('./')({})
const triple = $('http://example.com/s')('http://example.com/p')('http://example.com/o');
t.deepEqual(triple, {
subject: 'http://example.com/s',
predicate: 'http://example.com/p',
object: 'http://example.com/o'
})
t.deepEqual(triple, $('http://example.com/s', 'http://example.com/p', 'http://example.com/o'))
const partialTriple = $('http://example.com/s')('http://example.com/p')
t.ok(typeof partialTriple === 'function');
t.equal(JSON.stringify($('http://example.com/s')), '"http://example.com/s"');
})
test('Quad builder', t => {
t.plan(1);
const $ = require('./')({ graph: 'http://example.com/g' })
const quad = $('http://example.com/s')('http://example.com/p')('http://example.com/o');
t.deepEqual(quad, {
graph: 'http://example.com/g',
subject: 'http://example.com/s',
predicate: 'http://example.com/p',
object: 'http://example.com/o'
}, 'should allow generating quads')
})
test('Multiple triple builder', t => {
t.plan(2);
const $ = require('./')({})
const triples = $('http://example.com/s')({
'http://example.com/p1': [
'http://example.com/o1a',
'http://example.com/o1b',
],
'http://example.com/p2': 'http://example.com/o2'
})
t.deepEqual(triples, [
{
subject: 'http://example.com/s',
predicate: 'http://example.com/p1',
object: 'http://example.com/o1a',
},
{
subject: 'http://example.com/s',
predicate: 'http://example.com/p1',
object: 'http://example.com/o1b',
},
{
subject: 'http://example.com/s',
predicate: 'http://example.com/p2',
object: 'http://example.com/o2',
}
])
const triples2 = $({
'http://example.com/s': {
'http://example.com/p1': [
'http://example.com/o1a',
'http://example.com/o1b',
],
'http://example.com/p2': 'http://example.com/o2'
}
})
t.deepEqual(triples, triples2);
})
test('Namespace expansion', t => {
t.plan(1);
const $ = require('./')({
prefixes: {
ex: 'http://example.com/'
}
})
const triple = $('ex:s')('ex:p')('ex:o')
t.deepEqual(triple, {
subject: 'http://example.com/s',
predicate: 'http://example.com/p',
object: 'http://example.com/o'
})
})
test('Factory functions as properties', t => {
t.plan(1);
const $ = require('./')({
prefixes: {
ex: 'http://example.com/'
}
})
const s = $('ex:s')
, p = $('ex:p')
, o = $('ex:o')
const triple = s(p)(o)
t.deepEqual(triple, {
subject: 'http://example.com/s',
predicate: 'http://example.com/p',
object: 'http://example.com/o'
})
})