Skip to content

Commit

Permalink
two tests for combined boolean/alias opts parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jfhbrook committed Mar 6, 2012
1 parent 49f9047 commit e1e740c
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,47 @@ exports['nested dotted objects'] = function () {
});
assert.deepEqual(argv.beep, { boop : true });
};

exports['boolean and alias with chainable api'] = function () {
var aliased = [ '-h', 'derp' ];
var regular = [ '--herp', 'derp' ];
var opts = {
herp: { alias: 'h', boolean: true }
};
var aliasedArgv = optimist(aliased)
.boolean('herp')
.alias('h')
.argv;
var propertyArgv = optimist(regular)
.boolean('herp')
.alias('h')
.argv;
var expected = {
herp: true,
_: [ 'derp' ],
'$0': expresso,
};

assert.eql(aliasedArgv, expected);
assert.eql(propertyArgv, expected);
};

exports['boolean and alias with options hash'] = function () {
var aliased = [ '-h', 'derp' ];
var regular = [ '--herp', 'derp' ];
var opts = {
herp: { alias: 'h', boolean: true }
};
var aliasedArgv = optimist(aliased)
.options(opts)
.argv;
var regularArgv = optimist(regular).options(opts).argv;
var expected = {
herp: true,
_: [ 'derp' ],
'$0': expresso,
};

assert.eql(aliasedArgv, expected);
assert.eql(propertyArgv, expected);
}

0 comments on commit e1e740c

Please sign in to comment.