Skip to content

Commit

Permalink
added numbers detection
Browse files Browse the repository at this point in the history
  • Loading branch information
kof committed Sep 26, 2010
1 parent c755ff0 commit 131788f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 2 additions & 0 deletions lib/argsparser.js
Expand Up @@ -22,6 +22,8 @@ exports.parse = function( args ) {
arg = false;
} else if ( arg === "true" ) {
arg = true;
} else if ( !isNaN( arg ) ) {
arg = parseFloat( arg );
}

if ( curValType === "boolean" ) {
Expand Down
26 changes: 15 additions & 11 deletions test/test.js
Expand Up @@ -8,27 +8,31 @@ sys.print( "Run tests...\n" );

a.deepEqual( parse(), {node: __filename}, "node script.js" );

a.deepEqual( parse(["node", __filename, "-o"]), {node: __filename, "-o": true}, "node script.js -o" );
a.deepEqual( parse(["-o"]), {"-o": true}, "node script.js -o" );

a.deepEqual( parse(["node", __filename, "-o", "true"]), {node: __filename, "-o": true}, "node script.js -o true" );
a.deepEqual( parse(["-o", "true"]), {"-o": true}, "node script.js -o true" );

a.deepEqual( parse(["node", __filename, "-o", "false"]), {node: __filename, "-o": false}, "node script.js -o false" );
a.deepEqual( parse(["-o", "false"]), {"-o": false}, "node script.js -o false" );

a.deepEqual( parse(["node", __filename, "-o", "test"]), {node: __filename, "-o": "test"}, "node script.js -o test" );
a.deepEqual( parse(["-o", "123"]), {"-o": 123}, "node script.js -o 123" );

a.deepEqual( parse(["node", __filename, "-a", "testa", "-b", "testb"]), {node: __filename, "-a": "testa", "-b": "testb"}, "node script.js -a testa -b testb" );
a.deepEqual( parse(["-o", "123.456"]), {"-o": 123.456}, "node script.js -o 123.456" );

a.deepEqual( parse(["node", __filename, "--a", "testa", "--b", "testb"]), {node: __filename, "--a": "testa", "--b": "testb"}, "node script.js --a testa --b testb " );
a.deepEqual( parse(["-o", "test"]), {"-o": "test"}, "node script.js -o test" );

a.deepEqual( parse(["node", __filename, "-a", "testa", "--b", "testb"]), {node: __filename, "-a": "testa", "--b": "testb"}, "node script.js -a testa --b testb" );
a.deepEqual( parse(["-a", "testa", "-b", "testb"]), {"-a": "testa", "-b": "testb"}, "node script.js -a testa -b testb" );

a.deepEqual( parse(["node", __filename, "--a", "testa", "-b", "testb"]), {node: __filename, "--a": "testa", "-b": "testb"}, "node script.js --a testa -b testb" );
a.deepEqual( parse(["--a", "testa", "--b", "testb"]), {"--a": "testa", "--b": "testb"}, "node script.js --a testa --b testb " );

a.deepEqual( parse(["node", __filename, "-paths", "/test.js", "/test1.js"]), {node: __filename, "-paths": ["/test.js", "/test1.js"]}, "node script.js -paths /test.js /test1.js" );
a.deepEqual( parse(["-a", "testa", "--b", "testb"]), {"-a": "testa", "--b": "testb"}, "node script.js -a testa --b testb" );

a.deepEqual( parse(["node", __filename, "--paths", "/test.js", "/test1.js"]), {node: __filename, "--paths": ["/test.js", "/test1.js"]}, "node script.js --paths /test.js /test1.js" );
a.deepEqual( parse(["--a", "testa", "-b", "testb"]), {"--a": "testa", "-b": "testb"}, "node script.js --a testa -b testb" );

a.deepEqual( parse(["node", __filename, "--paths", "/test.js", "/test1.js", "-a", "testa"]), {node: __filename, "--paths": ["/test.js", "/test1.js"], "-a": "testa"}, "node script.js --paths /test.js /test1.js -a testa" );
a.deepEqual( parse(["-paths", "/test.js", "/test1.js"]), {"-paths": ["/test.js", "/test1.js"]}, "node script.js -paths /test.js /test1.js" );

a.deepEqual( parse(["--paths", "/test.js", "/test1.js"]), {"--paths": ["/test.js", "/test1.js"]}, "node script.js --paths /test.js /test1.js" );

a.deepEqual( parse(["--paths", "/test.js", "/test1.js", "-a", "testa"]), {"--paths": ["/test.js", "/test1.js"], "-a": "testa"}, "node script.js --paths /test.js /test1.js -a testa" );


sys.print( "All tests ok\n" );

0 comments on commit 131788f

Please sign in to comment.