get.js
1.15 KB
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
var pipeline = require('../');
var through = require('through2');
var test = require('tape');
test('get', function (t) {
var a = through.obj();
var b = through.obj();
var c = through.obj();
var pipe = pipeline([ a, b, c ]);
t.equal(pipe.get(0), a, '0');
t.equal(pipe.get(1), b, '1');
t.equal(pipe.get(2), c, '2');
t.equal(pipe.get(3), undefined, '3');
t.equal(pipe.get(4), undefined, '4');
t.equal(pipe.get(5), undefined, '5');
t.equal(pipe.get(-1), c, '-1');
t.equal(pipe.get(-1), c, '-1');
t.equal(pipe.get(-2), b, '-2');
t.equal(pipe.get(-3), a, '-3');
t.equal(pipe.get(-4), undefined, '-4');
t.equal(pipe.get(-5), undefined, '-5');
t.end();
});
test('nested get', function (t) {
var a = through.obj();
var b = through.obj();
var c = through.obj();
var d = through.obj();
var e = through.obj();
var f = through.obj();
var g = through.obj();
var pipe = pipeline([ a, [ b, c, [ d, [ e ], f ] ], g ]);
t.equal(pipe.get(0), a);
t.equal(pipe.get(1, -1, 1, 0), e);
t.equal(pipe.get(1, 3), undefined);
t.equal(pipe.get(4, 3), undefined);
t.end();
});