-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-dwim.js
69 lines (58 loc) · 1.22 KB
/
test-dwim.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
56
57
58
59
60
61
62
63
64
65
66
67
68
const test = require('tape')
const { mapper } = require('.')
test('dwim args to mapper.add()', t => {
const m = mapper()
let out = []
// hook addPair to see how it's called
m.addPair = (...args) => { out.push(args) }
out = []
m.add({ input: 1, output: 2 },'x')
t.deepEqual(out, [[{ input: 1, output: 2 }, 'x']])
out = []
m.add('x')
t.deepEqual(out, [[null, 'x']])
class MyClass {}
MyClass.definition = 'x'
out = []
m.add(MyClass)
// console.error('out = %O', out)
{
const [local, text] = out[0]
t.equal(text, 'x')
t.equal(local.class, MyClass)
t.ok(local.input)
}
MyClass.definitions = ['x', 'y']
out = []
m.add(MyClass)
t.equal(out.length, 2)
{
const [local, text] = out[0]
t.equal(text, 'x')
t.equal(local.class, MyClass)
t.ok(local.input)
}
{
const [local, text] = out[1]
t.equal(text, 'y')
t.equal(local.class, MyClass)
t.ok(local.input)
}
out = []
m.add(MyClass, 'z')
{
const [local, text] = out[0]
t.equal(out.length, 1)
t.equal(text, 'z')
t.equal(local.class, MyClass)
t.ok(local.input)
}
out = []
try {
m.add({ input: 1, output: 2 })
t.fail()
} catch (e) {
t.pass()
}
t.end()
})