-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c55975e
commit 9d5ebe6
Showing
2 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
var namespace = require('tessed').namespace | ||
var flag = require('./') | ||
var alias = require('@cli/alias') | ||
var handler = require('@cli/handler') | ||
|
||
var test = namespace('flag') | ||
|
||
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') | ||
}) | ||
|
||
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') | ||
}) | ||
|
||
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' | ||
) | ||
}) |