cli: drop() arg or option now reflected in raw version
Showing
5 changed files
with
40 additions
and
15 deletions
... | @@ -111,6 +111,7 @@ Last, all the casper test suites have been upgraded to use the new testing featu | ... | @@ -111,6 +111,7 @@ Last, all the casper test suites have been upgraded to use the new testing featu |
111 | - fixes [#410](https://github.com/n1k0/casperjs/issues/410) - trigger `mousedown` and `mousedown` events on click | 111 | - fixes [#410](https://github.com/n1k0/casperjs/issues/410) - trigger `mousedown` and `mousedown` events on click |
112 | - Added [`Tester#skip`](http://docs.casperjs.org/en/latest/modules/tester.html#skip) method | 112 | - Added [`Tester#skip`](http://docs.casperjs.org/en/latest/modules/tester.html#skip) method |
113 | - Added [`Casper#eachThen()`](http://docs.casperjs.org/en/latest/modules/casper.html#eachThen) | 113 | - Added [`Casper#eachThen()`](http://docs.casperjs.org/en/latest/modules/casper.html#eachThen) |
114 | - `cli`: Now dropping an arg or an option will be reflected in their *raw* equivalent | ||
114 | 115 | ||
115 | 2013-02-08, v1.0.2 | 116 | 2013-02-08, v1.0.2 |
116 | ------------------ | 117 | ------------------ | ... | ... |
... | @@ -166,7 +166,7 @@ CasperError.prototype = Object.getPrototypeOf(new Error()); | ... | @@ -166,7 +166,7 @@ CasperError.prototype = Object.getPrototypeOf(new Error()); |
166 | 166 | ||
167 | /** | 167 | /** |
168 | * Patched require to allow loading of native casperjs modules. | 168 | * Patched require to allow loading of native casperjs modules. |
169 | * Every casperjs native module have to first call this function in order to | 169 | * Every casperjs module have to first call this function in order to |
170 | * load a native casperjs module: | 170 | * load a native casperjs module: |
171 | * | 171 | * |
172 | * var require = patchRequire(require); | 172 | * var require = patchRequire(require); | ... | ... |
... | @@ -56,20 +56,28 @@ exports.parse = function parse(phantomArgs) { | ... | @@ -56,20 +56,28 @@ exports.parse = function parse(phantomArgs) { |
56 | this.args = this.args.filter(function _filter(arg, index) { | 56 | this.args = this.args.filter(function _filter(arg, index) { |
57 | return index !== what; | 57 | return index !== what; |
58 | }); | 58 | }); |
59 | // raw | ||
60 | if ('raw' in this) { | ||
61 | this.raw.args = this.raw.args.filter(function _filter(arg, index) { | ||
62 | return index !== what; | ||
63 | }); | ||
64 | } | ||
59 | } else if (utils.isString(what)) { | 65 | } else if (utils.isString(what)) { |
60 | // deleting an arg by its value | 66 | // deleting an arg by its value |
61 | this.args = this.args.filter(function _filter(arg) { | 67 | this.args = this.args.filter(function _filter(arg) { |
62 | return arg !== what; | 68 | return arg !== what; |
63 | }); | 69 | }); |
64 | // deleting an option by its name (key) | 70 | // deleting an option by its name (key) |
65 | var self = this; | 71 | delete this.options[what]; |
66 | Object.keys(this.options).forEach(function _forEach(option) { | 72 | // raw |
67 | if (option === what) { | 73 | if ('raw' in this) { |
68 | delete self.options[what]; | 74 | this.raw.args = this.raw.args.filter(function _filter(arg) { |
69 | } | 75 | return arg !== what; |
70 | }); | 76 | }); |
77 | delete this.raw.options[what]; | ||
78 | } | ||
71 | } else { | 79 | } else { |
72 | throw new CasperError("cannot drop argument of type " + typeof what); | 80 | throw new CasperError("Cannot drop argument of type " + typeof what); |
73 | } | 81 | } |
74 | }, | 82 | }, |
75 | has: function has(what) { | 83 | has: function has(what) { |
... | @@ -112,7 +120,9 @@ exports.parse = function parse(phantomArgs) { | ... | @@ -112,7 +120,9 @@ exports.parse = function parse(phantomArgs) { |
112 | } | 120 | } |
113 | }); | 121 | }); |
114 | extract.raw = utils.mergeObjects(extract.raw, { | 122 | extract.raw = utils.mergeObjects(extract.raw, { |
115 | drop: extract.drop, | 123 | drop: function() { |
124 | return extract.drop.apply(extract, arguments); | ||
125 | }, | ||
116 | has: extract.has, | 126 | has: extract.has, |
117 | get: extract.get | 127 | get: extract.get |
118 | }); | 128 | }); | ... | ... |
... | @@ -21,4 +21,10 @@ dump(casper.cli.args); | ... | @@ -21,4 +21,10 @@ dump(casper.cli.args); |
21 | casper.echo("Casper CLI passed options:"); | 21 | casper.echo("Casper CLI passed options:"); |
22 | dump(casper.cli.options); | 22 | dump(casper.cli.options); |
23 | 23 | ||
24 | casper.echo("Casper CLI passed RAW args:"); | ||
25 | dump(casper.cli.raw.args); | ||
26 | |||
27 | casper.echo("Casper CLI passed RAW options:"); | ||
28 | dump(casper.cli.raw.options); | ||
29 | |||
24 | casper.exit(); | 30 | casper.exit(); | ... | ... |
... | @@ -76,7 +76,7 @@ casper.test.begin('parsing an empty argument list', 8, function(test) { | ... | @@ -76,7 +76,7 @@ casper.test.begin('parsing an empty argument list', 8, function(test) { |
76 | test.done(); | 76 | test.done(); |
77 | }); | 77 | }); |
78 | 78 | ||
79 | casper.test.begin('parsing commands containing args and options', 30, function(test) { | 79 | casper.test.begin('parsing commands containing args and options', 34, function(test) { |
80 | var parsed = cli.parse(['foo & bar', 'baz & boz', '--universe=42', | 80 | var parsed = cli.parse(['foo & bar', 'baz & boz', '--universe=42', |
81 | '--lap=13.37', '--chucknorris', '--oops=false']); | 81 | '--lap=13.37', '--chucknorris', '--oops=false']); |
82 | // clean | 82 | // clean |
... | @@ -104,6 +104,7 @@ casper.test.begin('parsing commands containing args and options', 30, function(t | ... | @@ -104,6 +104,7 @@ casper.test.begin('parsing commands containing args and options', 30, function(t |
104 | test.assertEquals(parsed.get(0), 'baz & boz', 'drop() dropped arg'); | 104 | test.assertEquals(parsed.get(0), 'baz & boz', 'drop() dropped arg'); |
105 | parsed.drop("universe"); | 105 | parsed.drop("universe"); |
106 | test.assert(!parsed.has("universe"), 'drop() dropped option'); | 106 | test.assert(!parsed.has("universe"), 'drop() dropped option'); |
107 | test.assert(!parsed.raw.has("universe"), 'drop() dropped raw option'); | ||
107 | test.assertEquals(parsed.args, ["baz & boz"], 'drop() did not affect other args'); | 108 | test.assertEquals(parsed.args, ["baz & boz"], 'drop() did not affect other args'); |
108 | test.assertEquals(parsed.options, { | 109 | test.assertEquals(parsed.options, { |
109 | lap: 13.37, | 110 | lap: 13.37, |
... | @@ -112,14 +113,17 @@ casper.test.begin('parsing commands containing args and options', 30, function(t | ... | @@ -112,14 +113,17 @@ casper.test.begin('parsing commands containing args and options', 30, function(t |
112 | }, 'drop() did not affect other options'); | 113 | }, 'drop() did not affect other options'); |
113 | 114 | ||
114 | // raw | 115 | // raw |
115 | test.assertEquals(parsed.raw.args, ['foo & bar', 'baz & boz'], | 116 | test.assertEquals(parsed.args.length, parsed.raw.args.length, |
117 | 'parse() cast and raw args share same length'); | ||
118 | test.assertEquals(Object.keys(parsed.options).length, Object.keys(parsed.raw.options).length, | ||
119 | 'parse() cast and raw options share same length'); | ||
120 | test.assertEquals(parsed.raw.args, ['baz & boz'], | ||
116 | 'parse() returns expected positional raw args array'); | 121 | 'parse() returns expected positional raw args array'); |
117 | test.assertEquals(parsed.raw.options, { | 122 | test.assertEquals(parsed.raw.options, { |
118 | universe: "42", | ||
119 | lap: "13.37", | 123 | lap: "13.37", |
120 | chucknorris: true, | 124 | chucknorris: true, |
121 | oops: "false" }, 'parse() returns expected options raw object'); | 125 | oops: "false" |
122 | test.assertEquals(parsed.raw.get('universe'), "42", 'parse() does not a raw numeric option value'); | 126 | }, 'parse() returns expected options raw object'); |
123 | test.assertEquals(parsed.raw.get('lap'), "13.37", 'parse() does not cast a raw float option value'); | 127 | test.assertEquals(parsed.raw.get('lap'), "13.37", 'parse() does not cast a raw float option value'); |
124 | test.assertType(parsed.raw.get('lap'), "string", 'parse() does not cast a numeric value'); | 128 | test.assertType(parsed.raw.get('lap'), "string", 'parse() does not cast a numeric value'); |
125 | test.assert(parsed.raw.get('chucknorris'), 'parse() can get a flag value by its option name'); | 129 | test.assert(parsed.raw.get('chucknorris'), 'parse() can get a flag value by its option name'); |
... | @@ -128,14 +132,18 @@ casper.test.begin('parsing commands containing args and options', 30, function(t | ... | @@ -128,14 +132,18 @@ casper.test.begin('parsing commands containing args and options', 30, function(t |
128 | 132 | ||
129 | // drop() for raw | 133 | // drop() for raw |
130 | parsed.raw.drop(0); | 134 | parsed.raw.drop(0); |
131 | test.assertEquals(parsed.raw.get(0), 'baz & boz', 'drop() dropped raw arg'); | 135 | test.assertEquals(parsed.raw.get(0), undefined, 'drop() dropped raw arg'); |
132 | parsed.raw.drop("universe"); | 136 | parsed.raw.drop("universe"); |
133 | test.assert(!parsed.raw.has("universe"), 'drop() dropped raw option'); | 137 | test.assert(!parsed.raw.has("universe"), 'drop() dropped raw option'); |
134 | test.assertEquals(parsed.raw.args, ["baz & boz"], 'drop() did not affect other raw args'); | 138 | test.assertEquals(parsed.raw.args, [], 'drop() did not affect other raw args'); |
135 | test.assertEquals(parsed.raw.options, { | 139 | test.assertEquals(parsed.raw.options, { |
136 | lap: "13.37", | 140 | lap: "13.37", |
137 | chucknorris: true, | 141 | chucknorris: true, |
138 | oops: "false" | 142 | oops: "false" |
139 | }, 'drop() did not affect other raw options'); | 143 | }, 'drop() did not affect other raw options'); |
144 | parsed.raw.drop("lap"); | ||
145 | test.assert(!parsed.raw.has("lap"), 'drop() dropped raw option'); | ||
146 | test.assert(!parsed.has("lap"), 'drop() dropped cast option as well'); | ||
147 | |||
140 | test.done(); | 148 | test.done(); |
141 | }); | 149 | }); | ... | ... |
-
Please register or sign in to post a comment