forked from LRH1993/android_interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfn.js
More file actions
76 lines (62 loc) · 1.77 KB
/
Copy pathfn.js
File metadata and controls
76 lines (62 loc) · 1.77 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
var test;
try { test = require('tap').test; }
catch (e) { test = require('testling') }
var proto = require('../');
var traverse = require('traverse');
var EventEmitter = require('events').EventEmitter;
test('protoFn', function (t) {
t.plan(7);
var s = proto(function (remote, conn) {
t.ok(conn);
conn.on('ready', function () {
t.deepEqual(remote, { a : 1, b : 2 });
});
this.x = function (f, g) {
setTimeout(f.bind({}, 7, 8, 9), 25);
setTimeout(g.bind({}, [ 'q', 'r' ]), 50);
};
this.y = 555;
});
var c = proto({ a : 1, b : 2 });
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 : [ { a : 1, b : 2 } ],
callbacks : {},
links : []
} ]);
var pending = 2;
c.request('x', [
function (x, y , z) {
t.deepEqual([ x, y, z ], [ 7, 8, 9 ]);
if (--pending === 0) t.end();
},
function (qr) {
t.deepEqual(qr, [ 'q', 'r' ]);
if (--pending === 0) t.end();
}
]);
t.deepEqual(creqs.slice(1), [ {
method : 'x',
arguments : [ '[Function]', '[Function]' ],
callbacks : { 0 : [ '0' ], 1 : [ '1' ] },
links : []
} ]);
});