-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathjson.js
53 lines (45 loc) · 1.49 KB
/
json.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
/*jshint node: true, mocha: true */
"use strict";
let expect,
qlobber = require('..'),
JSONStream = require('JSONStream'),
streamBuffers = require('stream-buffers'),
common = require('./common'),
rabbitmq = require('./rabbitmq'),
expected_json = JSON.stringify(common.expected_visits);
before(async () => {
({ expect } = await import('chai'));
});
describe('json', function ()
{
it('visit should support serializing to JSON', function (cb)
{
let matcher = new qlobber.QlobberDedup();
for (let [topic, val] of rabbitmq.test_bindings)
{
matcher.add(topic, val);
}
new qlobber.VisitorStream(matcher)
.pipe(JSONStream.stringify('[', ',', ']'))
.pipe(new streamBuffers.WritableStreamBuffer())
.on('finish', function ()
{
expect(this.getContentsAsString()).to.equal(expected_json);
cb();
});
});
it('restore should support deserializing from JSON', function (cb)
{
let matcher = new qlobber.QlobberDedup(),
buf_stream = new streamBuffers.ReadableStreamBuffer();
buf_stream.put(expected_json);
buf_stream.stop();
buf_stream
.pipe(JSONStream.parse('*'))
.pipe(new qlobber.RestorerStream(matcher)).on('finish', function ()
{
expect(common.get_trie(matcher)).to.eql(common.expected_trie);
cb();
});
});
});