-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
96 lines (85 loc) · 2.15 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
var test = require('tape');
var fs = require('fs');
var choppa = require('./');
test('basic test', function(t) {
var chars = [];
var chp = choppa();
fs.createReadStream('./fixtures').pipe(chp).on('data', function(data) {
chars.push(data.toString());
});
chp.on('finish', function() {
t.equal(chars[0], 'W');
t.equal(chars[1], 'h');
t.equal(chars[2], 'e');
t.equal(chars[3], 'n');
t.equal(chars[4], ' ');
t.equal(chars[5], 'G');
t.equal(chars[6], 'r');
t.equal(chars[7], 'e');
t.equal(chars[8], 'g');
t.equal(chars[9], 'o');
t.equal(chars[10], 'r');
t.end();
});
});
test('test limit', function(t) {
var chars = [];
var chp = choppa(3);
fs.createReadStream('./fixtures').pipe(chp).on('data', function(data) {
chars.push(data.toString());
});
chp.on('finish', function() {
t.equal(chars[0], 'Whe');
t.equal(chars[1], 'n G');
t.equal(chars[2], 'reg');
t.equal(chars[3], 'or ');
t.end();
});
});
test('async pipe', function(t) {
var chars = [];
var chp = choppa();
setTimeout(function() {
chp.on('data', function(data) {
chars.push(data.toString());
});
}, 400);
chp.on('end', function() {
t.equal(chars[0], 'W');
t.equal(chars[1], 'h');
t.equal(chars[2], 'e');
t.equal(chars[3], 'n');
t.equal(chars[4], ' ');
t.equal(chars[5], 'G');
t.equal(chars[6], 'r');
t.equal(chars[7], 'e');
t.equal(chars[8], 'g');
t.equal(chars[9], 'o');
t.equal(chars[10], 'r');
t.end();
});
fs.createReadStream('./fixtures').pipe(chp);
});
test('strings instead of buffers', function(t) {
var chars = [];
var chp = choppa();
chp.on('data', function(data) {
chars.push(data.toString());
});
chp.write('When Gregor Samsa');
chp.end();
chp.on('end', function() {
t.equal(chars[0], 'W');
t.equal(chars[1], 'h');
t.equal(chars[2], 'e');
t.equal(chars[3], 'n');
t.equal(chars[4], ' ');
t.equal(chars[5], 'G');
t.equal(chars[6], 'r');
t.equal(chars[7], 'e');
t.equal(chars[8], 'g');
t.equal(chars[9], 'o');
t.equal(chars[10], 'r');
t.end();
});
});