Skip to content

Commit 73932ee

Browse files
committed
Add callback interface tests.
1 parent 07c69c5 commit 73932ee

File tree

3 files changed

+177
-0
lines changed

3 files changed

+177
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Added
44
- Initial support for benchmarking.
5+
- Basic callback interface tests.
56

67
## 1.1.0 - 2018-09-05
78

tests/callbacks.js

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/**
2+
* Test the callback interface.
3+
*/
4+
const jsonld = require('..');
5+
const assert = require('assert');
6+
7+
describe('callback API', () => {
8+
// common data
9+
const doc = {};
10+
const ctx = {};
11+
const frame = {};
12+
const options = {};
13+
14+
it('should compact', done => {
15+
jsonld.compact(doc, ctx, (err, result) => {
16+
assert.ifError(err);
17+
assert.deepEqual(result, []);
18+
done();
19+
});
20+
});
21+
it('should compact with options', done => {
22+
jsonld.compact(doc, ctx, options, (err, result) => {
23+
assert.ifError(err);
24+
assert.deepEqual(result, []);
25+
done();
26+
});
27+
});
28+
29+
it('should expand', done => {
30+
jsonld.expand(doc, (err, result) => {
31+
assert.ifError(err);
32+
assert.deepEqual(result, []);
33+
done();
34+
});
35+
});
36+
it('should expand with options', done => {
37+
jsonld.expand(doc, options, (err, result) => {
38+
assert.ifError(err);
39+
assert.deepEqual(result, []);
40+
done();
41+
});
42+
});
43+
44+
it('should flatten', done => {
45+
jsonld.flatten(doc, ctx, (err, result) => {
46+
assert.ifError(err);
47+
assert.deepEqual(result, {'@graph': []});
48+
done();
49+
});
50+
});
51+
it('should flatten with options', done => {
52+
jsonld.flatten(doc, ctx, options, (err, result) => {
53+
assert.ifError(err);
54+
assert.deepEqual(result, {'@graph': []});
55+
done();
56+
});
57+
});
58+
59+
it('should frame', done => {
60+
jsonld.frame(doc, frame, (err, result) => {
61+
assert.ifError(err);
62+
assert.deepEqual(result, {'@graph': []});
63+
done();
64+
});
65+
});
66+
it('should frame with options', done => {
67+
jsonld.frame(doc, frame, options, (err, result) => {
68+
assert.ifError(err);
69+
assert.deepEqual(result, {'@graph': []});
70+
done();
71+
});
72+
});
73+
74+
it('should link', done => {
75+
jsonld.link(doc, (err, result) => {
76+
assert.ifError(err);
77+
assert.deepEqual(result, {'@graph': []});
78+
done();
79+
});
80+
});
81+
it('should link with context', done => {
82+
jsonld.link(doc, ctx, (err, result) => {
83+
assert.ifError(err);
84+
assert.deepEqual(result, {'@graph': []});
85+
done();
86+
});
87+
});
88+
it('should link with context and options', done => {
89+
jsonld.link(doc, ctx, options, (err, result) => {
90+
assert.ifError(err);
91+
assert.deepEqual(result, {'@graph': []});
92+
done();
93+
});
94+
});
95+
96+
it('should normalize', done => {
97+
jsonld.normalize(doc, (err, result) => {
98+
assert.ifError(err);
99+
assert.deepEqual(result, '');
100+
done();
101+
});
102+
});
103+
it('should normalize with options', done => {
104+
jsonld.normalize(doc, options, (err, result) => {
105+
assert.ifError(err);
106+
assert.deepEqual(result, '');
107+
done();
108+
});
109+
});
110+
111+
it('should convert from RDF', done => {
112+
jsonld.fromRDF('', (err, result) => {
113+
assert.ifError(err);
114+
assert.deepEqual(result, {});
115+
done();
116+
});
117+
});
118+
it('should convert from RDF with options', done => {
119+
jsonld.fromRDF('', options, (err, result) => {
120+
assert.ifError(err);
121+
assert.deepEqual(result, {});
122+
done();
123+
});
124+
});
125+
126+
it('should convert to RDF', done => {
127+
jsonld.toRDF(doc, (err, result) => {
128+
assert.ifError(err);
129+
assert.deepEqual(result, []);
130+
done();
131+
});
132+
});
133+
it('should convert to RDF with options', done => {
134+
jsonld.toRDF(doc, options, (err, result) => {
135+
assert.ifError(err);
136+
assert.deepEqual(result, []);
137+
done();
138+
});
139+
});
140+
141+
it('should create node map', done => {
142+
jsonld.createNodeMap(doc, (err, result) => {
143+
assert.ifError(err);
144+
assert.deepEqual(result, []);
145+
done();
146+
});
147+
});
148+
it('should create node map with options', done => {
149+
jsonld.createNodeMap(doc, options, (err, result) => {
150+
assert.ifError(err);
151+
assert.deepEqual(result, []);
152+
done();
153+
});
154+
});
155+
156+
it('should merge', done => {
157+
jsonld.merge([doc, doc], ctx, (err, result) => {
158+
assert.ifError(err);
159+
assert.deepEqual(result, {'@graph': []});
160+
done();
161+
});
162+
});
163+
it('should merge with options', done => {
164+
jsonld.merge([doc, doc], ctx, options, (err, result) => {
165+
assert.ifError(err);
166+
assert.deepEqual(result, {'@graph': []});
167+
done();
168+
});
169+
});
170+
171+
// TODO
172+
//it('should load document');
173+
//it('should get document');
174+
//it('should process context');
175+
});

tests/test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ if(process.env.JSONLD_TESTS) {
5252
}
5353

5454
// other tests
55+
entries.push(path.resolve(_top, 'tests/callbacks.js'));
5556
entries.push(path.resolve(_top, 'tests/misc.js'));
5657
entries.push(path.resolve(_top, 'tests/graph-container.js'));
5758
entries.push(path.resolve(_top, 'tests/new-embed-api'));

0 commit comments

Comments
 (0)