/
test.js
55 lines (46 loc) · 1.11 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
'use strict'
var test = require('tape')
var pull = require('pull-stream')
var limit = require('./')
var byte = Buffer.from([ 0xff ])
var doubleByte = Buffer.from([ 0xff, 0xff ])
test(function(t){
t.equals(typeof limit, 'function', 'default export is a function')
t.equals(typeof limit.Error, 'function', 'A .Error is exposed')
t.end()
})
test('Too much', function(t){
t.plan(4)
pull(
pull.values([ byte, doubleByte ]),
limit(2),
pull.collect(function(err, chunks){
t.ok(err instanceof Error, 'error is instance of Error')
t.ok(err instanceof limit.Error, 'error is instanceof .Error')
t.equals(err.message, 'Maximum size reached', 'error message')
t.deepEquals(chunks, [ byte ])
})
)
})
test('Exact', function(t){
t.plan(2)
pull(
pull.values([ doubleByte ]),
limit(2),
pull.collect(function(err, chunks){
t.equals(err, null, 'no error')
t.deepEquals(chunks, [ doubleByte ])
})
)
})
test('Less', function(t){
t.plan(2)
pull(
pull.values([ byte ]),
limit(2),
pull.collect(function(err, chunks){
t.equals(err, null, 'no error')
t.deepEquals(chunks, [ byte ])
})
)
})