Commit 34316572 343165726a87c656f188e3bb9f68341ae2f76e8c by Nicolas Perriault

added type checks to cli test suite

1 parent b1d4a2b0
...@@ -70,6 +70,12 @@ exports.parse = function(phantomArgs) { ...@@ -70,6 +70,12 @@ exports.parse = function(phantomArgs) {
70 return extract; 70 return extract;
71 }; 71 };
72 72
73 /**
74 * Cast a string argument to its typed equivalent.
75 *
76 * @param String arg
77 * @return Mixed
78 */
73 function castArgument(arg) { 79 function castArgument(arg) {
74 if (arg.match(/^-?\d+$/)) { 80 if (arg.match(/^-?\d+$/)) {
75 return parseInt(arg, 10); 81 return parseInt(arg, 10);
......
...@@ -35,8 +35,10 @@ ...@@ -35,8 +35,10 @@
35 t.assertEquals(parsed.options, { universe: 42, lap: 13.37, chucknorris: true, oops: false }, 'parse() returns expected options object'); 35 t.assertEquals(parsed.options, { universe: 42, lap: 13.37, chucknorris: true, oops: false }, 'parse() returns expected options object');
36 t.assertEquals(parsed.get('universe'), 42, 'parse() can cast a numeric option value'); 36 t.assertEquals(parsed.get('universe'), 42, 'parse() can cast a numeric option value');
37 t.assertEquals(parsed.get('lap'), 13.37, 'parse() can cast a float option value'); 37 t.assertEquals(parsed.get('lap'), 13.37, 'parse() can cast a float option value');
38 t.assertType(parsed.get('lap'), "number", 'parse() can cast a boolean value');
38 t.assert(parsed.get('chucknorris'), 'parse() can get a flag value by its option name'); 39 t.assert(parsed.get('chucknorris'), 'parse() can get a flag value by its option name');
39 t.assert(!parsed.get('oops'), 'parse() can cast a boolean value'); 40 t.assertType(parsed.get('oops'), "boolean", 'parse() can cast a boolean value');
41 t.assertEquals(parsed.get('oops'), false, 'parse() can cast a boolean value');
40 })(cli.parse(['foo & bar', 'baz & boz', '--universe=42', '--lap=13.37', '--chucknorris', '--oops=false'])); 42 })(cli.parse(['foo & bar', 'baz & boz', '--universe=42', '--lap=13.37', '--chucknorris', '--oops=false']));
41 43
42 t.done(); 44 t.done();
......