-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
48 lines (42 loc) · 1.07 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
'use strict'
var SnappyMsgPackStream = require('./index')
var encodeStream = SnappyMsgPackStream.createEncodeStream()
var decodeStream = SnappyMsgPackStream.createDecodeStream()
require('tape')('simple', function (t) {
var expected = [
1,
0,
// null, // doesn't work
true,
'hello',
'string\nwith\nlines',
{object: true, name: 'no need for a name'},
['this', 'that', {}, [], [null]],
Math.PI,
true,
false,
Infinity,
{obj: {}},
Buffer.from('fööbär'),
NaN
]
var toSend = expected.slice()
var expectedItems = expected.slice()
var actual = []
encodeStream.pipe(decodeStream).on('data', function (obj) {
actual.push(obj)
if (isNaN(obj)) {
t.assert(isNaN(expectedItems.shift()))
} else {
t.deepEqual(obj, expectedItems.shift())
}
}).on('end', function () {
// slicing, as comparing with `NaN` will always equals `false`
t.deepEqual(actual.slice(0, -1), expected.slice(0, -1))
t.end()
})
while (toSend.length) {
encodeStream.write(toSend.shift())
}
encodeStream.end()
})