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('args_test'); | 5 #library('args_test'); |
| 6 | 6 |
| 7 #import('../../../lib/unittest/unittest.dart'); | 7 #import('../../../lib/unittest/unittest.dart'); |
| 8 #import('../../../lib/args/args.dart'); | 8 #import('../../../lib/args/args.dart'); |
| 9 | 9 |
| 10 main() { | 10 main() { |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 expect(args['define'], equals(['1','2'])); | 374 expect(args['define'], equals(['1','2'])); |
| 375 }); | 375 }); |
| 376 | 376 |
| 377 test('returns the default value for multi-valued arguments ' | 377 test('returns the default value for multi-valued arguments ' |
| 378 'if not explicitly set', () { | 378 'if not explicitly set', () { |
| 379 var parser = new ArgParser(); | 379 var parser = new ArgParser(); |
| 380 parser.addOption('define', defaultsTo:'0', allowMultiple: true); | 380 parser.addOption('define', defaultsTo:'0', allowMultiple: true); |
| 381 var args = parser.parse(['']); | 381 var args = parser.parse(['']); |
| 382 expect(args['define'], equals(['0'])); | 382 expect(args['define'], equals(['0'])); |
| 383 }); | 383 }); |
| 384 | |
| 385 test('queries the default value', () { | |
|
Bob Nystrom
2012/08/16 22:22:10
Move these to a separate group for the getDefault(
gram
2012/08/16 23:20:17
Done.
| |
| 386 var parser = new ArgParser(); | |
| 387 parser.addOption('define', defaultsTo:'0', allowMultiple: true); | |
|
Bob Nystrom
2012/08/16 22:22:10
Space after ":".
gram
2012/08/16 23:20:17
Done.
| |
| 388 expect(parser.getDefault('define'), equals('0')); | |
| 389 expect(()=>parser.getDefault('undefine'), | |
|
Bob Nystrom
2012/08/16 22:22:10
If it's OK with you, I would make this a separate
gram
2012/08/16 23:20:17
Done.
| |
| 390 throwsIllegalArgumentException); | |
| 391 }); | |
| 392 | |
| 393 test('queries the set options', () { | |
|
Bob Nystrom
2012/08/16 22:22:10
This should be a separate group for the ".options"
gram
2012/08/16 23:20:17
Done.
| |
| 394 var parser = new ArgParser(); | |
| 395 parser.addFlag('woof', defaultsTo: false); | |
| 396 parser.addOption('meow', defaultsTo: 'kitty'); | |
| 397 var args = parser.parse([]); | |
| 398 expect(args.options, hasLength(2)); | |
| 399 }); | |
| 384 }); | 400 }); |
| 385 | 401 |
| 386 group('remaining args', () { | 402 group('remaining args', () { |
| 387 test('stops parsing args when a non-option-like arg is encountered', () { | 403 test('stops parsing args when a non-option-like arg is encountered', () { |
| 388 var parser = new ArgParser(); | 404 var parser = new ArgParser(); |
| 389 parser.addFlag('woof'); | 405 parser.addFlag('woof'); |
| 390 parser.addOption('meow'); | 406 parser.addOption('meow'); |
| 391 parser.addOption('tweet', defaultsTo: 'bird'); | 407 parser.addOption('tweet', defaultsTo: 'bird'); |
| 392 | 408 |
| 393 var results = parser.parse(['--woof', '--meow', 'v', 'not', 'option']); | 409 var results = parser.parse(['--woof', '--meow', 'v', 'not', 'option']); |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 629 throw new IllegalArgumentException( | 645 throw new IllegalArgumentException( |
| 630 'Line "$line" does not have enough indentation.'); | 646 'Line "$line" does not have enough indentation.'); |
| 631 } | 647 } |
| 632 | 648 |
| 633 lines[i] = line.substring(indent); | 649 lines[i] = line.substring(indent); |
| 634 } | 650 } |
| 635 } | 651 } |
| 636 | 652 |
| 637 return Strings.join(lines, '\n'); | 653 return Strings.join(lines, '\n'); |
| 638 } | 654 } |
| OLD | NEW |