skip.js
1.44 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var binary = require('../');
var test = require('tap').test;
var EventEmitter = require('events').EventEmitter;
var seq = require('seq');
test('skip', function (t) {
t.plan(7);
var em = new EventEmitter;
var state = 0;
binary(em)
.word16lu('a')
.tap(function () { state = 1 })
.skip(7)
.tap(function () { state = 2 })
.word8('b')
.tap(function () { state = 3 })
.tap(function (vars) {
t.same(state, 3);
t.same(vars, {
a : 2569,
b : 8,
});
})
;
seq()
.seq(setTimeout, seq, 20)
.seq(function () {
t.same(state, 0);
em.emit('data', new Buffer([ 9 ]));
this(null);
})
.seq(setTimeout, seq, 5)
.seq(function () {
t.same(state, 0);
em.emit('data', new Buffer([ 10, 1, 2 ]));
this(null);
})
.seq(setTimeout, seq, 30)
.seq(function () {
t.same(state, 1);
em.emit('data', new Buffer([ 3, 4, 5 ]));
this(null);
})
.seq(setTimeout, seq, 15)
.seq(function () {
t.same(state, 1);
em.emit('data', new Buffer([ 6, 7 ]));
this(null);
})
.seq(function () {
t.same(state, 2);
em.emit('data', new Buffer([ 8 ]));
this(null);
})
;
});