-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
69 lines (55 loc) · 1.29 KB
/
test.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
69
var test = require('tape')
var flag = require('./')
var alias = require('cmd-alias')
var handler = require('cmd-handler')
test('flag()', function (t) {
var fn1 = function () {}
var f = flag(
alias('-t'),
handler(fn1)
)
t.equal(typeof f, 'function', 'returns a function')
t.equal(f().type, 'flag', 'type')
t.deepEqual(f().value, {
alias: ['t'],
handler: [fn1]
}, 'value')
t.equal(f().options, undefined, 'no options')
t.deepEqual(f({key: 'value'}).options, {key: 'value'}, 'with options')
t.end()
})
test('combines multiple values', function (t) {
var fn1 = function () {}
var fn2 = function () {}
var f = flag(
alias('--one'),
alias('-t'),
handler(fn1),
handler(fn2)
)
t.deepEqual(f().value, {
alias: ['one', 't'],
handler: [fn1, fn2]
}, 'value')
t.end()
})
test('custom arguments', function (t) {
var f1 = flag(alias('-t'))
var f2 = flag(alias('--test', '-t'))
t.deepEqual(
f1().args([], {t: 't small', test: 't full'}),
['t small'],
'args function first flag'
)
t.deepEqual(
f2().args([], {t: 't small', test: 't full'}),
['t full', 't small'],
'args function second flag'
)
t.deepEqual(
f2().args([], {t: 't small'}),
['t small'],
'removes undefined values'
)
t.end()
})