OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library parse_test; | 5 library parse_test; |
6 | 6 |
7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
8 import 'package:args/args.dart'; | 8 import 'package:args/args.dart'; |
9 import 'utils.dart'; | 9 import 'utils.dart'; |
10 | 10 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 test('for absent, allowMultiple, options are invoked with value ' | 192 test('for absent, allowMultiple, options are invoked with value ' |
193 'as an empty list.', () { | 193 'as an empty list.', () { |
194 var a; | 194 var a; |
195 var parser = new ArgParser(); | 195 var parser = new ArgParser(); |
196 parser.addOption('a', | 196 parser.addOption('a', |
197 allowMultiple: true, callback: (value) => a = value); | 197 allowMultiple: true, callback: (value) => a = value); |
198 | 198 |
199 parser.parse([]); | 199 parser.parse([]); |
200 expect(a, isEmpty); | 200 expect(a, isEmpty); |
201 }); | 201 }); |
202 | |
203 test('allowMultiple parses comma-separated strings', () { | |
204 var a; | |
205 var parser = new ArgParser(); | |
206 parser.addOption('a', | |
207 allowMultiple: true, callback: (value) => a = value); | |
208 | |
209 parser.parse(['--a=v,w', '--a=x']); | |
210 expect(a, equals(['v', 'w', 'x'])); | |
211 }); | |
212 | |
213 test('allowMultiple with allowed parses comma-separated strings', () { | |
214 var a; | |
215 var parser = new ArgParser(); | |
216 parser.addOption('a', | |
217 allowMultiple: true, | |
218 allowed: ['v', 'w', 'x'], | |
219 callback: (value) => a = value); | |
220 | |
221 parser.parse(['--a=v,w', '--a=x']); | |
222 expect(a, equals(['v', 'w', 'x'])); | |
223 }); | |
202 }); | 224 }); |
203 | 225 |
204 group('abbreviations', () { | 226 group('abbreviations', () { |
205 test('are parsed with a preceding "-"', () { | 227 test('are parsed with a preceding "-"', () { |
206 var parser = new ArgParser(); | 228 var parser = new ArgParser(); |
207 parser.addFlag('arg', abbr: 'a'); | 229 parser.addFlag('arg', abbr: 'a'); |
208 | 230 |
209 var args = parser.parse(['-a']); | 231 var args = parser.parse(['-a']); |
210 expect(args['arg'], isTrue); | 232 expect(args['arg'], isTrue); |
211 }); | 233 }); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 throwsFormat(parser, ['-f', '-abbr']); | 302 throwsFormat(parser, ['-f', '-abbr']); |
281 }); | 303 }); |
282 | 304 |
283 test('throw if the value is not allowed', () { | 305 test('throw if the value is not allowed', () { |
284 var parser = new ArgParser(); | 306 var parser = new ArgParser(); |
285 parser.addOption('mode', abbr: 'm', allowed: ['debug', 'release']); | 307 parser.addOption('mode', abbr: 'm', allowed: ['debug', 'release']); |
286 | 308 |
287 throwsFormat(parser, ['-mprofile']); | 309 throwsFormat(parser, ['-mprofile']); |
288 }); | 310 }); |
289 | 311 |
312 test('throw if a comma-separated value is not allowed', () { | |
313 var parser = new ArgParser(); | |
314 parser.addOption('mode', abbr: 'm', allowMultiple: true, | |
315 allowed: ['debug', 'release']); | |
316 | |
317 throwsFormat(parser, ['-mdebug,profile']); | |
318 }); | |
319 | |
Bob Nystrom
2015/03/03 17:36:26
Tests for:
","
"a,,b"
",a"
"a,"
nweiz
2015/03/03 20:22:18
I don't think these should throw... multi-value op
| |
290 test('throw if any but the first is not a flag', () { | 320 test('throw if any but the first is not a flag', () { |
291 var parser = new ArgParser(); | 321 var parser = new ArgParser(); |
292 parser.addFlag('apple', abbr: 'a'); | 322 parser.addFlag('apple', abbr: 'a'); |
293 parser.addOption('banana', abbr: 'b'); // Takes an argument. | 323 parser.addOption('banana', abbr: 'b'); // Takes an argument. |
294 parser.addFlag('cherry', abbr: 'c'); | 324 parser.addFlag('cherry', abbr: 'c'); |
295 | 325 |
296 throwsFormat(parser, ['-abc']); | 326 throwsFormat(parser, ['-abc']); |
297 }); | 327 }); |
298 | 328 |
299 test('throw if it has a value but the option is a flag', () { | 329 test('throw if it has a value but the option is a flag', () { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 var parser = new ArgParser(); | 472 var parser = new ArgParser(); |
443 parser.addFlag('woof'); | 473 parser.addFlag('woof'); |
444 | 474 |
445 var results = parser.parse(['--woof', 'stop', '--', 'arg']); | 475 var results = parser.parse(['--woof', 'stop', '--', 'arg']); |
446 expect(results['woof'], isTrue); | 476 expect(results['woof'], isTrue); |
447 expect(results.rest, equals(['stop', '--', 'arg'])); | 477 expect(results.rest, equals(['stop', '--', 'arg'])); |
448 }); | 478 }); |
449 }); | 479 }); |
450 }); | 480 }); |
451 } | 481 } |
OLD | NEW |