-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
110 lines (95 loc) · 3.88 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
var test = require('tape');
var loner = require('.');
var bequal = require('buffer-equal');
test('Single sequence', function(t) {
var d = [];
var l = loner(Buffer([10]));
l.on('data', function(data) {d.push(data);});
l.on('end', function() {
t.equal(d.length, 3, 'Should emit three chunks');
t.ok(bequal(d[0], Buffer.from('Hello')), '1st chunk should be correct');
t.ok(bequal(d[1], Buffer.from([10])), '2nd chunk should be correct');
t.ok(bequal(d[2], Buffer.from('World')), '3nd chunk should be correct');
t.end();
});
l.write(Buffer.from('Hello\nWorld'));
l.end();
});
test('Two sequences (one buffer, one string)', function(t) {
var d = [];
var l = loner(Buffer([10]), "Hell");
l.on('data', function(data) {
console.log(data);
d.push(data);
});
l.on('end', function() {
t.equal(d.length, 4, 'Should emit 4 chunks');
t.ok(bequal(d[0], Buffer.from('Hell')), '1st chunk should be correct');
t.ok(bequal(d[1], Buffer.from('o')), '2st chunk should be correct');
t.ok(bequal(d[2], Buffer.from([10])), '3nd chunk should be correct');
t.ok(bequal(d[3], Buffer.from('World')), '4th chunk should be correct');
t.end();
});
l.write(Buffer.from('Hello\nWorld'));
l.end();
});
test('Three sequences', function(t) {
var d = [];
var l = loner(Buffer([10]), "Hell", "Wo");
l.on('data', function(data) {
console.log(data);
d.push(data);
});
l.on('end', function() {
t.equal(d.length, 5, 'Should emit 5 chunks');
t.ok(bequal(d[0], Buffer.from('Hell')), '1st chunk should be correct');
t.ok(bequal(d[1], Buffer.from('o')), '2st chunk should be correct');
t.ok(bequal(d[2], Buffer.from([10])), '3nd chunk should be correct');
t.ok(bequal(d[3], Buffer.from('Wo')), '4th chunk should be correct');
t.ok(bequal(d[4], Buffer.from('rld')), '5th chunk should be correct');
t.end();
});
l.write(Buffer.from('Hello\nWorld'));
l.end();
});
test('Three sequences, multiple occurances', function(t) {
var d = [];
var l = loner(Buffer([10]), "Hell", "Wo");
l.on('data', function(data) {
console.log(data);
d.push(data);
});
l.on('end', function() {
t.equal(d.length, 8, 'Should emit 8 chunks');
t.ok(bequal(d[0], Buffer.from('Hell')), '1st chunk should be correct');
t.ok(bequal(d[1], Buffer.from('o')), '2st chunk should be correct');
t.ok(bequal(d[2], Buffer.from([10])), '3nd chunk should be correct');
t.ok(bequal(d[3], Buffer.from('Wo')), '4th chunk should be correct');
t.ok(bequal(d[4], Buffer.from('rld,')), '5th chunk should be correct');
t.ok(bequal(d[5], Buffer.from([10])), '6th chunk should be correct');
t.ok(bequal(d[6], Buffer.from('Good-Bye, ')), '7th chunk should be correct');
t.ok(bequal(d[7], Buffer.from('Hell')), '8th chunk should be correct');
t.end();
});
l.write(Buffer.from('Hello\nWorld,\nGood-Bye, Hell'));
l.end();
});
test('Three sequences, restricted to one occurance', function(t) {
var d = [];
var l = loner.only(1)(Buffer([10]), "Hell", "Wo");
l.on('data', function(data) {
console.log(data);
d.push(data);
});
l.on('end', function() {
t.equal(d.length, 5, 'Should emit 5 chunks');
t.ok(bequal(d[0], Buffer.from('Hell')), '1st chunk should be correct');
t.ok(bequal(d[1], Buffer.from('o')), '2st chunk should be correct');
t.ok(bequal(d[2], Buffer.from([10])), '3nd chunk should be correct');
t.ok(bequal(d[3], Buffer.from('Wo')), '4th chunk should be correct');
t.ok(bequal(d[4], Buffer.from('rld,\nGood-Bye, Hell')), '5th chunk should be correct');
t.end();
});
l.write(Buffer.from('Hello\nWorld,\nGood-Bye, Hell'));
l.end();
});