This repository has been archived by the owner on Jun 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-fromjsonld.js
261 lines (232 loc) · 8.86 KB
/
test-fromjsonld.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
'use strict'
import test from 'tape'
import Immutable from 'immutable'
import { JSONLDNode
, JSONLDValue
, fromJSONLD
, fromExpandedJSONLD
} from '../ImmutableJSONLD'
import person from '../../test/data/person-expanded.json'
import event from '../../test/data/event-expanded.json'
import place from '../../test/data/place-expanded.json'
import product from '../../test/data/product-expanded.json'
import recipe from '../../test/data/recipe-expanded.json'
import library from '../../test/data/library-expanded.json'
import activity from '../../test/data/activity-expanded.json'
import stupid from '../../test/data/stupid.json'
import stupid_expanded from '../../test/data/stupid-expanded.json'
import reverse from '../../test/data/reverse.json'
import reverse_expanded from '../../test/data/reverse-expanded.json'
import list from '../../test/data/list.json'
import list_expanded from '../../test/data/list-expanded.json'
import set from '../../test/data/set.json'
import set_expanded from '../../test/data/set-expanded.json'
test('test fromExpandedJSONLD()', t => {
const nodes = fromExpandedJSONLD()
t.plan(3)
t.ok(nodes instanceof Immutable.List, 'is Immutable.List')
t.ok(nodes.isEmpty(), 'is empty')
t.equal(nodes.size, 0, 'size is 0')
})
test('test fromExpandedJSONLD(null)', t => {
const nodes = fromExpandedJSONLD(null)
t.plan(3)
t.ok(nodes instanceof Immutable.List, 'is Immutable.List')
t.ok(nodes.isEmpty(), 'is empty')
t.equal(nodes.size, 0, 'size is 0')
})
test('test fromExpandedJSONLD([])', t => {
const nodes = fromExpandedJSONLD([])
t.plan(3)
t.ok(nodes instanceof Immutable.List, 'is Immutable.List')
t.ok(nodes.isEmpty(), 'is empty')
t.equal(nodes.size, 0, 'size is 0')
})
test('test fromExpandedJSONLD(Immutable.List)', t => {
const nodes = fromExpandedJSONLD(Immutable.List())
t.plan(3)
t.ok(nodes instanceof Immutable.List, 'is Immutable.List')
t.ok(nodes.isEmpty(), 'is empty')
t.equal(nodes.size, 0, 'size is 0')
})
test('test fromExpandedJSONLD({})', t => {
const nodes = fromExpandedJSONLD({})
t.plan(4)
t.ok(nodes instanceof Immutable.List, 'is Immutable.List')
t.equal(nodes.size, 1, 'size is 1')
t.ok(nodes.first() instanceof JSONLDNode, 'contains a JSONLDNode')
t.ok(nodes.first().isEmpty(), 'contains an empty JSONLDNode')
})
test('test fromExpandedJSONLD(Immutable.Map)', t => {
const nodes = fromExpandedJSONLD(Immutable.Map())
t.plan(4)
t.ok(nodes instanceof Immutable.List, 'is Immutable.List')
t.equal(nodes.size, 1, 'size is 1')
t.ok(nodes.first() instanceof JSONLDNode, 'contains a JSONLDNode')
t.ok(nodes.first().isEmpty(), 'contains an empty JSONLDNode')
})
test('test fromExpandedJSONLD(person)', t => {
const nodes = fromExpandedJSONLD(person)
t.plan(5)
t.ok(nodes instanceof Immutable.List, 'is Immutable.List')
t.equal(nodes.size, 1, 'size is 1')
t.deepEqual(nodes.toJS(), person, 'round-trips OK')
let node = nodes.first()
t.ok(node instanceof JSONLDNode, 'contains a JSONLDNode')
t.equal(node.size, 5, 'with 5 entries')
})
test('test fromExpandedJSONLD(event)', t => {
const nodes = fromExpandedJSONLD(event)
t.plan(5)
t.ok(nodes instanceof Immutable.List, 'is Immutable.List')
t.equal(nodes.size, 1, 'size is 1')
t.deepEqual(nodes.toJS(), event, 'round-trips OK')
let node = nodes.first()
t.ok(node instanceof JSONLDNode, 'contains a JSONLDNode')
t.equal(node.size, 3, 'with 3 entries')
})
test('test fromExpandedJSONLD(place)', t => {
const nodes = fromExpandedJSONLD(place)
t.plan(5)
t.ok(nodes instanceof Immutable.List, 'is Immutable.List')
t.equal(nodes.size, 1, 'size is 1')
t.deepEqual(nodes.toJS(), place, 'round-trips OK')
let node = nodes.first()
t.ok(node instanceof JSONLDNode, 'contains a JSONLDNode')
t.equal(node.size, 4, 'with 4 entries')
})
test('test fromExpandedJSONLD(product)', t => {
const nodes = fromExpandedJSONLD(product)
t.plan(5)
t.ok(nodes instanceof Immutable.List, 'is Immutable.List')
t.equal(nodes.size, 1, 'size is 1')
t.deepEqual(nodes.toJS(), product, 'round-trips OK')
let node = nodes.first()
t.ok(node instanceof JSONLDNode, 'contains a JSONLDNode')
t.equal(node.size, 8, 'with 8 entries')
})
test('test fromExpandedJSONLD(recipe)', t => {
const nodes = fromExpandedJSONLD(recipe)
t.plan(5)
t.ok(nodes instanceof Immutable.List, 'is Immutable.List')
t.equal(nodes.size, 1, 'size is 1')
t.deepEqual(nodes.toJS(), recipe, 'round-trips OK')
let node = nodes.first()
t.ok(node instanceof JSONLDNode, 'contains a JSONLDNode')
t.equal(node.size, 4, 'with 4 entries')
})
test('test fromExpandedJSONLD(library)', t => {
const nodes = fromExpandedJSONLD(library)
t.plan(4)
t.ok(nodes instanceof Immutable.List, 'is Immutable.List')
t.equal(nodes.size, 3, 'size is 3')
t.deepEqual(nodes.toJS(), library, 'round-trips OK')
let node = nodes.first()
t.ok(node instanceof JSONLDNode, 'contains a JSONLDNode')
})
test('test fromExpandedJSONLD(activity)', t => {
const nodes = fromExpandedJSONLD(activity)
t.plan(5)
t.ok(nodes instanceof Immutable.List, 'is Immutable.List')
t.equal(nodes.size, 1, 'size is 1')
t.deepEqual(nodes.toJS(), activity, 'round-trips OK')
let node = nodes.first()
t.ok(node instanceof JSONLDNode, 'contains a JSONLDNode')
t.equal(node.size, 4, 'with 4 entries')
})
test('test fromExpandedJSONLD(stupid)', t => {
const nodes = fromExpandedJSONLD(stupid_expanded)
t.plan(5)
t.ok(nodes instanceof Immutable.List, 'is Immutable.List')
t.equal(nodes.size, 1, 'size is 1')
t.deepEqual(nodes.toJS(), stupid_expanded, 'round-trips OK')
let node = nodes.first()
t.ok(node instanceof JSONLDNode, 'contains a JSONLDNode')
t.equal(node.size, 2, 'with 2 entries')
})
test('test fromJSONLD(stupid)', t => {
fromJSONLD(stupid)
.then(
nodes => {
t.ok(nodes instanceof Immutable.List, 'is Immutable.List')
t.equal(nodes.size, 1, 'size is 1')
t.deepEqual(nodes.toJS(), stupid_expanded, 'round-trips OK')
let node = nodes.first()
t.ok(node instanceof JSONLDNode, 'contains a JSONLDNode')
t.equal(node.size, 2, 'with 2 entries')
t.end()
})
.catch(err => t.end(err))
})
test('test fromJSONLD(url)', t => {
fromJSONLD('https://gist.githubusercontent.com/rybesh/'
+ '3cbacf6cbc539b7c22f7/raw/2c15ecbd3e878dd40523fa1ad8c70f004a1bb193/'
+ 'stupid.json')
.then(
nodes => {
t.ok(nodes instanceof Immutable.List, 'is Immutable.List')
t.equal(nodes.size, 1, 'size is 1')
t.deepEqual(nodes.toJS(), stupid_expanded, 'round-trips OK')
let node = nodes.first()
t.ok(node instanceof JSONLDNode, 'contains a JSONLDNode')
t.equal(node.size, 2, 'with 2 entries')
t.end()
})
.catch(err => t.end(err))
})
test('test @reverse handling', t => {
fromJSONLD(reverse)
.then(
nodes => {
t.ok(nodes instanceof Immutable.List, 'is Immutable.List')
t.equal(nodes.size, 1, 'size is 1')
t.deepEqual(nodes.toJS(), reverse_expanded, 'round-trips OK')
let node = nodes.first()
t.ok(node instanceof JSONLDNode, 'contains a JSONLDNode')
t.equal(node.size, 3, 'with 3 entries')
let atreverse = node.get('@reverse')
t.ok(atreverse instanceof JSONLDNode, '@reverse is a JSONLDNode')
t.equal(atreverse.size, 1, 'with 1 entry')
t.end()
})
.catch(err => t.end(err))
})
test('test @list handling', t => {
fromJSONLD(list)
.then(
nodes => {
t.ok(nodes instanceof Immutable.List, 'is Immutable.List')
t.equal(nodes.size, 1, 'size is 1')
t.deepEqual(nodes.toJS(), list_expanded, 'round-trips OK')
let node = nodes.first()
t.ok(node instanceof JSONLDNode, 'contains a JSONLDNode')
t.equal(node.size, 2, 'with 2 entries')
let values = node.get('http://xmlns.com/foaf/0.1/nick')
t.ok(values instanceof Immutable.List, 'is Immutable.List')
let map = values.first()
t.ok(map instanceof Immutable.Map, 'is Immutable.Map')
t.false(JSONLDNode.isJSONLDNode(map), 'is not a JSONLDNode')
let list = map.get('@list')
t.ok(list instanceof Immutable.List, 'is Immutable.List')
t.end()
})
.catch(err => t.end(err))
})
test('test @set handling', t => {
fromJSONLD(set)
.then(
nodes => {
t.ok(nodes instanceof Immutable.List, 'is Immutable.List')
t.equal(nodes.size, 1, 'size is 1')
t.deepEqual(nodes.toJS(), set_expanded, 'round-trips OK')
let node = nodes.first()
t.ok(node instanceof JSONLDNode, 'contains a JSONLDNode')
t.equal(node.size, 2, 'with 2 entries')
let values = node.get('http://xmlns.com/foaf/0.1/nick')
t.ok(values instanceof Immutable.List, 'is Immutable.List')
let value = values.first()
t.ok(value instanceof JSONLDValue, 'is JSONLDValue')
t.end()
})
.catch(err => t.end(err))
})