Skip to content

Commit 798a50f

Browse files
committed
better test coverage
1 parent ec979df commit 798a50f

File tree

4 files changed

+114
-20
lines changed

4 files changed

+114
-20
lines changed

test/index.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,25 @@ test('read this file', function (t) {
99
var lines = file.split('\n')
1010
var i = 0, block = 300
1111

12-
pull.pipeableSource(function () {
13-
return function (end, cb) {
12+
pull(
13+
function (end, cb) {
1414
if (i > file.length)
1515
cb(true)
1616
else {
1717
var _i = i
1818
i += block
1919
cb(null, file.substring(_i, _i + block))
2020
}
21-
}
22-
})()
23-
.pipe(split())
24-
.pipe(pull.writeArray(function (err, array){
25-
t.equal(array.length, lines.length)
26-
t.deepEqual(array, lines)
27-
t.end()
28-
}))
21+
},
22+
split(),
23+
pull.collect(function (err, array){
24+
t.equal(array.length, lines.length)
25+
t.deepEqual(array, lines)
26+
t.end()
27+
})
28+
)
2929
})
3030

3131
//haoeunhoeu
32+
33+

test/json.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
var tape = require('tape')
2+
var pull = require('pull-stream')
3+
var Split = require('../')
4+
5+
var input = [
6+
1, 2, {okay: true}, 'whatever'
7+
]
8+
9+
10+
tape('split into json lines', function (t) {
11+
12+
pull(
13+
pull.values([input.map(JSON.stringify).join('\n')]
14+
),
15+
Split(null, JSON.parse),
16+
pull.collect(function (err, ary) {
17+
if(err) throw err
18+
t.deepEqual(ary, input)
19+
t.end()
20+
})
21+
)
22+
23+
})
24+
25+
tape('split into json lines', function (t) {
26+
27+
pull(
28+
pull.values([input.map(function (d) {
29+
return JSON.stringify(d, null, 2)
30+
}).join('\n\n')]
31+
),
32+
Split('\n\n', JSON.parse),
33+
pull.collect(function (err, ary) {
34+
if(err) throw err
35+
t.deepEqual(ary, input)
36+
t.end()
37+
})
38+
)
39+
})
40+
41+
42+
tape('split into json lines', function (t) {
43+
44+
pull(
45+
pull.values([input.map(function (d) {
46+
return JSON.stringify(d, null, 2) + '\n'
47+
}).join('\n')]
48+
),
49+
Split('\n\n', JSON.parse),
50+
pull.collect(function (err, ary) {
51+
if(err) throw err
52+
t.deepEqual(ary, input)
53+
t.end()
54+
})
55+
)
56+
})

test/reverse.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ test('read this file', function (t) {
99
var lines = file.split('\n').reverse()
1010
var i = file.length, block = 300
1111

12-
pull.pipeableSource(function () {
13-
return function (end, cb) {
12+
pull(
13+
function (end, cb) {
1414
if (i <= 0)
1515
cb(true)
1616
else {
@@ -20,14 +20,16 @@ test('read this file', function (t) {
2020
var line = file.substring(_i - block, _i)
2121
cb(null, line)
2222
}
23-
}
24-
})()
25-
.pipe(split('\n', null, true))
26-
.pipe(pull.writeArray(function (err, array){
27-
t.equal(array.length, lines.length)
28-
t.deepEqual(array, lines)
29-
t.end()
30-
}))
23+
},
24+
split('\n', null, true),
25+
pull.collect(function (err, array){
26+
t.equal(array.length, lines.length)
27+
t.deepEqual(array, lines)
28+
t.end()
29+
})
30+
)
3131
})
3232

3333
//haoeunhoeu
34+
35+

test/skip-last.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
var test = require('tape')
2+
var pull = require('pull-stream')
3+
var split = require('../')
4+
5+
test('read this file', function (t) {
6+
7+
var fs = require('fs')
8+
var file = fs.readFileSync(__filename).toString()
9+
var lines = file.split('\n')
10+
t.equal(lines.pop(), '')
11+
var i = 0, block = 300
12+
13+
pull(
14+
function (end, cb) {
15+
if (i > file.length)
16+
cb(true)
17+
else {
18+
var _i = i
19+
i += block
20+
cb(null, file.substring(_i, _i + block))
21+
}
22+
},
23+
split(null, null, null, true),
24+
pull.collect(function (err, array){
25+
t.equal(array.length, lines.length)
26+
t.deepEqual(array, lines)
27+
t.end()
28+
})
29+
)
30+
})
31+
32+
//haoeunhoeu
33+
34+

0 commit comments

Comments
 (0)