forked from LRH1993/android_interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrap.js
More file actions
89 lines (75 loc) · 2.02 KB
/
Copy pathwrap.js
File metadata and controls
89 lines (75 loc) · 2.02 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
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
var test = require('tap').test;
var proto = require('../');
var traverse = require('traverse');
test('proto hashes', function (t) {
t.plan(10);
var pending = 5;
var times = { s : 0, c : 0 };
function done () {
t.same(times.s, 2); // f, g
t.same(times.c, 1); // x(f,g)
t.end();
}
function swrapper (fn) {
// 1 of these
t.equal(typeof fn, 'function');
times.s ++;
if (--pending === 0) done();
return fn;
}
function cwrapper (fn) {
// 2 of these
t.equal(typeof fn, 'function');
times.c ++;
if (--pending === 0) done();
return fn;
}
var s = proto({
x : function (f, g) {
setTimeout(f.bind({}, 7, 8, 9), 25);
setTimeout(g.bind({}, [ 'q', 'r' ]), 50);
},
y : 555
}, { wrap : swrapper });
var c = proto({}, { wrap : cwrapper });
var sreqs = [];
s.on('request', function (req) {
sreqs.push(traverse.clone(req));
c.handle(req);
});
var creqs = [];
c.on('request', function (req) {
creqs.push(traverse.clone(req));
s.handle(req);
});
s.start();
t.deepEqual(sreqs, [ {
method : 'methods',
arguments : [ { x : '[Function]', y : 555 } ],
callbacks : { 0 : [ '0', 'x' ] },
links : [],
} ]);
c.start();
t.deepEqual(creqs, [ {
method : 'methods',
arguments : [ {} ],
callbacks : {},
links : [],
} ]);
c.request('x', [
function (x, y , z) {
t.deepEqual([ x, y, z ], [ 7, 8, 9 ]);
if (--pending === 0) done();
},
function (qr) {
t.deepEqual(qr, [ 'q', 'r' ]);
if (--pending === 0) done();
}
]);
t.deepEqual(creqs.slice(1), [ {
method : 'x',
arguments : [ '[Function]', '[Function]' ],
callbacks : { 0 : [ '0' ], 1 : [ '1' ] },
links : [],
} ]);
});