Chromium Code Reviews| 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 | 9 |
| 10 main() { | 10 main() { |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 parser.addOption('define', defaultsTo: '0', allowMultiple: true); | 382 parser.addOption('define', defaultsTo: '0', allowMultiple: true); |
| 383 var args = parser.parse(['']); | 383 var args = parser.parse(['']); |
| 384 expect(args['define'], equals(['0'])); | 384 expect(args['define'], equals(['0'])); |
| 385 }); | 385 }); |
| 386 }); | 386 }); |
| 387 | 387 |
| 388 group('remaining args', () { | 388 group('remaining args', () { |
| 389 test('stops parsing args when a non-option-like arg is encountered', () { | 389 test('stops parsing args when a non-option-like arg is encountered', () { |
| 390 var parser = new ArgParser(); | 390 var parser = new ArgParser(); |
| 391 parser.addFlag('woof'); | 391 parser.addFlag('woof'); |
| 392 parser.addFlag('neigh'); | |
| 392 parser.addOption('meow'); | 393 parser.addOption('meow'); |
| 393 parser.addOption('tweet', defaultsTo: 'bird'); | 394 parser.addOption('tweet', defaultsTo: 'bird'); |
| 394 | 395 |
| 395 var results = parser.parse(['--woof', '--meow', 'v', 'not', 'option']); | 396 var results = parser.parse(['--woof', '--meow', 'v', 'not', 'option', |
| 397 '--tweet', 'devrel', '--neigh', 'end' ]); | |
|
Bob Nystrom
2013/04/19 22:13:18
Indent +2.
| |
| 396 expect(results['woof'], isTrue); | 398 expect(results['woof'], isTrue); |
| 399 expect(results['neigh'], isFalse); | |
| 397 expect(results['meow'], equals('v')); | 400 expect(results['meow'], equals('v')); |
| 398 expect(results['tweet'], equals('bird')); | 401 expect(results['tweet'], equals('bird')); |
| 399 expect(results.rest, orderedEquals(['not', 'option'])); | 402 expect(results.rest, orderedEquals(['not', 'option', '--tweet', |
| 403 'devrel', '--neigh', 'end'])); | |
| 404 }); | |
| 405 | |
| 406 test('with continueParsing, continues parsing when non-option-like' | |
| 407 ' arg is encountered', () { | |
| 408 var parser = new ArgParser(); | |
| 409 parser.addFlag('woof'); | |
| 410 parser.addFlag('neigh'); | |
| 411 parser.addOption('meow'); | |
| 412 parser.addOption('tweet', defaultsTo: 'bird'); | |
| 413 | |
| 414 var results = parser.parse(['--woof', '--meow', 'v', 'not', 'option', | |
| 415 '--tweet', 'devrel', '--neigh', 'end' ], | |
| 416 continueParsing: true); | |
| 417 expect(results['woof'], isTrue); | |
| 418 expect(results['neigh'], isTrue); | |
| 419 expect(results['meow'], equals('v')); | |
| 420 expect(results['tweet'], equals('devrel')); | |
| 421 expect(results.rest, orderedEquals(['not', 'option', 'end'])); | |
| 400 }); | 422 }); |
| 401 | 423 |
| 402 test('stops parsing at "--"', () { | 424 test('stops parsing at "--"', () { |
| 403 var parser = new ArgParser(); | 425 var parser = new ArgParser(); |
| 404 parser.addFlag('woof', defaultsTo: false); | 426 parser.addFlag('woof', defaultsTo: false); |
| 405 parser.addOption('meow', defaultsTo: 'kitty'); | 427 parser.addOption('meow', defaultsTo: 'kitty'); |
| 406 | 428 |
| 407 var results = parser.parse(['--woof', '--', '--meow']); | 429 var results = parser.parse(['--woof', '--', '--meow']); |
| 408 expect(results['woof'], isTrue); | 430 expect(results['woof'], isTrue); |
| 409 expect(results['meow'], equals('kitty')); | 431 expect(results['meow'], equals('kitty')); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 422 }); | 444 }); |
| 423 } | 445 } |
| 424 | 446 |
| 425 throwsIllegalArg(function) { | 447 throwsIllegalArg(function) { |
| 426 expect(function, throwsArgumentError); | 448 expect(function, throwsArgumentError); |
| 427 } | 449 } |
| 428 | 450 |
| 429 throwsFormat(ArgParser parser, List<String> args) { | 451 throwsFormat(ArgParser parser, List<String> args) { |
| 430 expect(() => parser.parse(args), throwsFormatException); | 452 expect(() => parser.parse(args), throwsFormatException); |
| 431 } | 453 } |
| OLD | NEW |