Skip to content

Commit

Permalink
tests for demandCount, back up to 100% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Oct 19, 2010
1 parent 073b776 commit 857bd2d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "optimist",
"version" : "0.0.4",
"version" : "0.0.5",
"description" : "Light-weight option parsing with an argv hash. No optstrings attached.",
"modules" : {
"index" : "./lib/optimist.js",
Expand Down
36 changes: 27 additions & 9 deletions test/usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ exports.checkPass = function (assert) {
});
};

exports.checkFail = function (assert) {
var r = checkUsage(function () {
return optimist('-x 10 -z 20'.split(' '))
.usage('Usage: $0 -x NUM -y NUM')
.check(function (argv) {
if (!('x' in argv)) throw 'You forgot about -x';
if (!('y' in argv)) throw 'You forgot about -y';
})
.argv;
});
assert.deepEqual(r, {
result : { x : 10, z : 20, _ : [], $0 : './usage' },
errors : [ 'Usage: ./usage -x NUM -y NUM', 'You forgot about -y' ],
logs : [],
exit: true,
});
};

exports.countPass = function (assert) {
var r = checkUsage(function () {
return optimist('1 2 3 --moo'.split(' '))
Expand All @@ -63,19 +81,19 @@ exports.countPass = function (assert) {
});
};

exports.checkFail = function (assert) {
exports.countFail = function (assert) {
var r = checkUsage(function () {
return optimist('-x 10 -z 20'.split(' '))
.usage('Usage: $0 -x NUM -y NUM')
.check(function (argv) {
if (!('x' in argv)) throw 'You forgot about -x';
if (!('y' in argv)) throw 'You forgot about -y';
})
return optimist('1 2 --moo'.split(' '))
.usage('Usage: $0 [x] [y] [z] {OPTIONS}')
.demand(3)
.argv;
});
assert.deepEqual(r, {
result : { x : 10, z : 20, _ : [], $0 : './usage' },
errors : [ 'Usage: ./usage -x NUM -y NUM', 'You forgot about -y' ],
result : { _ : [ '1', '2' ], moo : true, $0 : './usage' },
errors : [
'Usage: ./usage [x] [y] [z] {OPTIONS}',
'Not enough arguments, expected 3, but only found 2'
],
logs : [],
exit: true,
});
Expand Down

0 comments on commit 857bd2d

Please sign in to comment.