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:test/test.dart'; | 7 import 'package:test/test.dart'; |
8 import 'package:args/args.dart'; | 8 import 'package:args/args.dart'; |
9 import 'utils.dart'; | 9 import 'utils.dart'; |
10 | 10 |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 throwsFormat(parser, ['-f']); | 308 throwsFormat(parser, ['-f']); |
309 }); | 309 }); |
310 | 310 |
311 test('throw if the value is missing', () { | 311 test('throw if the value is missing', () { |
312 var parser = new ArgParser(); | 312 var parser = new ArgParser(); |
313 parser.addOption('file', abbr: 'f'); | 313 parser.addOption('file', abbr: 'f'); |
314 | 314 |
315 throwsFormat(parser, ['-f']); | 315 throwsFormat(parser, ['-f']); |
316 }); | 316 }); |
317 | 317 |
318 test('throw if the value looks like an option', () { | 318 test('does not throw if the value looks like an option', () { |
319 var parser = new ArgParser(); | 319 var parser = new ArgParser(); |
320 parser.addOption('file', abbr: 'f'); | 320 parser.addOption('file', abbr: 'f'); |
321 parser.addOption('other'); | 321 parser.addOption('other'); |
322 | 322 |
323 throwsFormat(parser, ['-f', '--other']); | 323 expect(parser.parse(['-f', '--other'])['file'], equals('--other')); |
324 throwsFormat(parser, ['-f', '--unknown']); | 324 expect(parser.parse(['-f', '--unknown'])['file'], equals('--unknown')); |
325 throwsFormat(parser, ['-f', '-abbr']); | 325 expect(parser.parse(['-f', '-abbr'])['file'], equals('-abbr')); |
| 326 expect(parser.parse(['-f', '--'])['file'], equals('--')); |
326 }); | 327 }); |
327 | 328 |
328 test('throw if the value is not allowed', () { | 329 test('throw if the value is not allowed', () { |
329 var parser = new ArgParser(); | 330 var parser = new ArgParser(); |
330 parser.addOption('mode', abbr: 'm', allowed: ['debug', 'release']); | 331 parser.addOption('mode', abbr: 'm', allowed: ['debug', 'release']); |
331 | 332 |
332 throwsFormat(parser, ['-mprofile']); | 333 throwsFormat(parser, ['-mprofile']); |
333 }); | 334 }); |
334 | 335 |
335 test('throw if a comma-separated value is not allowed', () { | 336 test('throw if a comma-separated value is not allowed', () { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 throwsFormat(parser, ['--unknown']); | 403 throwsFormat(parser, ['--unknown']); |
403 throwsFormat(parser, ['--nobody']); // Starts with "no". | 404 throwsFormat(parser, ['--nobody']); // Starts with "no". |
404 }); | 405 }); |
405 | 406 |
406 test('throw if the arg does not include a value', () { | 407 test('throw if the arg does not include a value', () { |
407 var parser = new ArgParser(); | 408 var parser = new ArgParser(); |
408 parser.addOption('mode'); | 409 parser.addOption('mode'); |
409 throwsFormat(parser, ['--mode']); | 410 throwsFormat(parser, ['--mode']); |
410 }); | 411 }); |
411 | 412 |
412 test('throw if the value looks like an option', () { | 413 test('do not throw if the value looks like an option', () { |
413 var parser = new ArgParser(); | 414 var parser = new ArgParser(); |
414 parser.addOption('mode'); | 415 parser.addOption('mode'); |
415 parser.addOption('other'); | 416 parser.addOption('other'); |
416 | 417 |
417 throwsFormat(parser, ['--mode', '--other']); | 418 expect(parser.parse(['--mode', '--other'])['mode'], equals('--other')); |
418 throwsFormat(parser, ['--mode', '--unknown']); | 419 expect(parser.parse(['--mode', '--unknown'])['mode'], |
419 throwsFormat(parser, ['--mode', '-abbr']); | 420 equals('--unknown')); |
| 421 expect(parser.parse(['--mode', '-abbr'])['mode'], equals('-abbr')); |
| 422 expect(parser.parse(['--mode', '--'])['mode'], equals('--')); |
420 }); | 423 }); |
421 | 424 |
422 test('do not throw if the value is in the allowed set', () { | 425 test('do not throw if the value is in the allowed set', () { |
423 var parser = new ArgParser(); | 426 var parser = new ArgParser(); |
424 parser.addOption('mode', allowed: ['debug', 'release']); | 427 parser.addOption('mode', allowed: ['debug', 'release']); |
425 var args = parser.parse(['--mode=debug']); | 428 var args = parser.parse(['--mode=debug']); |
426 expect(args['mode'], equals('debug')); | 429 expect(args['mode'], equals('debug')); |
427 }); | 430 }); |
428 | 431 |
429 test('throw if the value is not in the allowed set', () { | 432 test('throw if the value is not in the allowed set', () { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 var parser = new ArgParser(); | 498 var parser = new ArgParser(); |
496 parser.addFlag('woof'); | 499 parser.addFlag('woof'); |
497 | 500 |
498 var results = parser.parse(['--woof', 'stop', '--', 'arg']); | 501 var results = parser.parse(['--woof', 'stop', '--', 'arg']); |
499 expect(results['woof'], isTrue); | 502 expect(results['woof'], isTrue); |
500 expect(results.rest, equals(['stop', '--', 'arg'])); | 503 expect(results.rest, equals(['stop', '--', 'arg'])); |
501 }); | 504 }); |
502 }); | 505 }); |
503 }); | 506 }); |
504 } | 507 } |
OLD | NEW |