-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
120 lines (103 loc) · 1.81 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
111
112
113
114
115
116
117
118
119
120
'use strict';
var test = require('tape');
var pull = require('pull-stream');
var stringify = require('./');
var data = [
{
age: 25,
},
{
age: 24,
},
];
test('Default', function( t ){
t.plan(1);
pull(
pull.values(data),
stringify(),
pull.concat(function( err, data ){
t.equal(data, '{"age":25}\n{"age":24}\n');
})
);
});
test('Options', function( t ){
t.plan(1);
pull(
pull.values(data),
stringify({
indent: '->',
open: '(',
separator: ',',
close: ')',
stringifier: function( value, replacer, indent ){
return indent+value.age;
},
}),
pull.concat(function( err, data ){
t.equal(data, '(->25,->24)');
})
);
});
test('Zero item with defaults', function( t ){
t.plan(1);
pull(
pull.values([]),
stringify(),
pull.concat(function( err, data ){
t.equal(data, '\n');
})
);
});
test('One item with defaults', function( t ){
t.plan(1);
pull(
pull.values([ 'A' ]),
stringify(),
pull.concat(function( err, data ){
t.equal(data, '"A"\n');
})
);
});
test('Zero items with custom `open`, `close` and `separator`', function( t ){
t.plan(1);
pull(
pull.values([]),
stringify({
open: '(',
close: ')',
separator: ',',
}),
pull.concat(function( err, data ){
t.equal(data, '()');
})
);
});
test('One item with custom `open`, `close` and `separator`', function( t ){
t.plan(1);
pull(
pull.values([ 'A' ]),
stringify({
open: '(',
close: ')',
separator: ',',
}),
pull.concat(function( err, data ){
t.equal(data, '("A")');
})
);
});
test('Stream using `undefined` as "end" argument', function( t ){
t.plan(1);
var c = 0
pull(
(end, cb) => {
if (end) return cb(end)
if (c === 3) return cb(true)
cb(undefined, c++)
},
stringify(),
pull.concat(function( err, data ){
t.equal(data, '0\n1\n2\n');
})
);
});