Skip to content

Commit

Permalink
tests updated for $0
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Oct 13, 2010
1 parent 12ae108 commit cf14e87
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
33 changes: 20 additions & 13 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,92 +3,98 @@ var optimist = require('optimist');
exports['short boolean'] = function (assert) {
assert.deepEqual(
optimist.parse([ '-b' ]),
{ b : true, _ : [] }
{ b : true, _ : [], $0 : 'expresso' }
);
};

exports['long boolean'] = function (assert) {
assert.deepEqual(
optimist.parse([ '--bool' ]),
{ bool : true, _ : [] }
{ bool : true, _ : [], $0 : 'expresso' }
);
};

exports.bare = function (assert) {
assert.deepEqual(
optimist.parse([ 'foo', 'bar', 'baz' ]),
{ _ : [ 'foo', 'bar', 'baz' ] }
{ _ : [ 'foo', 'bar', 'baz' ], $0 : 'expresso' }
);
};

exports['short group'] = function (assert) {
assert.deepEqual(
optimist.parse([ '-cats' ]),
{ c : true, a : true, t : true, s : true, _ : [] }
{ c : true, a : true, t : true, s : true, _ : [], $0 : 'expresso' }
);
};

exports['short group next'] = function (assert) {
assert.deepEqual(
optimist.parse([ '-cats', 'meow' ]),
{ c : true, a : true, t : true, s : 'meow', _ : [] }
{ c : true, a : true, t : true, s : 'meow', _ : [], $0 : 'expresso' }
);
};

exports['short capture'] = function (assert) {
assert.deepEqual(
optimist.parse([ '-h', 'localhost' ]),
{ h : 'localhost', _ : [] }
{ h : 'localhost', _ : [], $0 : 'expresso' }
);
};

exports['short captures'] = function (assert) {
assert.deepEqual(
optimist.parse([ '-h', 'localhost', '-p', '555' ]),
{ h : 'localhost', p : '555', _ : [] }
{ h : 'localhost', p : '555', _ : [], $0 : 'expresso' }
);
};


exports['long capture'] = function (assert) {
assert.deepEqual(
optimist.parse([ '--pow=xixxle' ]),
{ pow : 'xixxle', _ : [] }
{ pow : 'xixxle', _ : [], $0 : 'expresso' }
);
};

exports['long captures'] = function (assert) {
assert.deepEqual(
optimist.parse([ '--host=localhost', '--port=555' ]),
{ host : 'localhost', port : '555', _ : [] }
{ host : 'localhost', port : '555', _ : [], $0 : 'expresso' }
);
};

exports['mixed short bool and capture'] = function (assert) {
assert.deepEqual(
optimist.parse([ '-h', 'localhost', '-fp', '555', 'script.js' ]),
{ f : true, p : 555, h : 'localhost', _ : [ 'script.js' ] }
{
f : true, p : 555, h : 'localhost',
_ : [ 'script.js' ], $0 : 'expresso',
}
);
};

exports['short and long'] = function (assert) {
assert.deepEqual(
optimist.parse([ '-h', 'localhost', '-fp', '555', 'script.js' ]),
{ f : true, p : 555, h : 'localhost', _ : [ 'script.js' ] }
{
f : true, p : 555, h : 'localhost',
_ : [ 'script.js' ], $0 : 'expresso',
}
);
};

exports.no = function (assert) {
assert.deepEqual(
optimist.parse([ '--no-moo' ]),
{ moo : false, _ : [] }
{ moo : false, _ : [], $0 : 'expresso' }
);
};

exports.multi = function (assert) {
assert.deepEqual(
optimist.parse([ '-v', 'a', '-v', 'b', '-v', 'c' ]),
{ v : ['a','b','c'], _ : [] }
{ v : ['a','b','c'], _ : [], $0 : 'expresso' }
);
};

Expand All @@ -112,6 +118,7 @@ exports.comprehensive = function (assert) {
meep : false,
name : 'meowmers',
_ : [ 'bare', '--not-a-flag', 'eek' ],
$0 : 'expresso'
}
);
};
8 changes: 4 additions & 4 deletions test/usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exports.usageFail = function (assert) {
.argv;
});
assert.deepEqual(r, {
result : { _ : [], x : 10, z : 20 },
result : { x : 10, z : 20, _ : [], $0 : './usage' },
errors : [ 'Usage: ./usage -x NUM -y NUM', 'Missing arguments: y' ],
logs : [],
exit: true,
Expand All @@ -24,7 +24,7 @@ exports.usagePass = function (assert) {
.argv;
});
assert.deepEqual(r, {
result : { _ : [], x : 10, y : 20 },
result : { x : 10, y : 20, _ : [], $0 : './usage' },
errors : [],
logs : [],
exit : false,
Expand All @@ -41,7 +41,7 @@ exports.checkPass = function (assert) {
.argv;
});
assert.deepEqual(r, {
result : { _ : [], x : 10, y : 20 },
result : { x : 10, y : 20, _ : [], $0 : './usage' },
errors : [],
logs : [],
exit : false,
Expand All @@ -59,7 +59,7 @@ exports.checkFail = function (assert) {
.argv;
});
assert.deepEqual(r, {
result : { _ : [], x : 10, z : 20 },
result : { x : 10, z : 20, _ : [], $0 : './usage' },
errors : [ 'Usage: ./usage -x NUM -y NUM', 'You forgot about -y' ],
logs : [],
exit: true,
Expand Down

0 comments on commit cf14e87

Please sign in to comment.