Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
more "direct" split
  • Loading branch information
CatWithApple committed Jul 28, 2015
1 parent d189dbd commit c2f6b45
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/argument_parser.js
Expand Up @@ -738,9 +738,8 @@ ArgumentParser.prototype._parseOptional = function (argString) {

// if the option string before the "=" is present, return the action
if (argString.indexOf('=') >= 0) {
var argStringSplit = argString.split('=');
optionString = argStringSplit[0];
argExplicit = argStringSplit.slice(1).join('=');
optionString = argString.split('=', 1)[0];
argExplicit = argString.slice(optionString.length + 1);

if (!!this._optionStringActions[optionString]) {
action = this._optionStringActions[optionString];
Expand Down
10 changes: 10 additions & 0 deletions test/base.js
Expand Up @@ -123,6 +123,16 @@ describe('base', function () {
args = parser.parseArgs(['-1']);
assert.equal(args.bar, -1);
});

it("should parse arguments with '='", function () {
parser = new ArgumentParser({debug: true});
parser.addArgument(['-f', '--foo']);
parser.addArgument([ 'bar' ]);

args = parser.parseArgs('-f="foo=nice=path" "bar=nice=path"'.split(' '));
assert.equal(args.foo, '"foo=nice=path"');
assert.equal(args.bar, '"bar=nice=path"');
});

it("No negative number options; neg number is positional argument", function () {
parser = new ArgumentParser({debug: true});
Expand Down

0 comments on commit c2f6b45

Please sign in to comment.