Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: tests/lib/args/args_test.dart

Issue 10855084: Added support for multi-valued options (options that can occur more than once). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/args/args.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 parser.addOption('mode', allowed: ['debug', 'release']); 350 parser.addOption('mode', allowed: ['debug', 'release']);
351 var args = parser.parse(['--mode=debug']); 351 var args = parser.parse(['--mode=debug']);
352 expect(args['mode'], equals('debug')); 352 expect(args['mode'], equals('debug'));
353 }); 353 });
354 354
355 test('throw if the value is not in the allowed set', () { 355 test('throw if the value is not in the allowed set', () {
356 var parser = new ArgParser(); 356 var parser = new ArgParser();
357 parser.addOption('mode', allowed: ['debug', 'release']); 357 parser.addOption('mode', allowed: ['debug', 'release']);
358 throwsFormat(parser, ['--mode=profile']); 358 throwsFormat(parser, ['--mode=profile']);
359 }); 359 });
360
361 test('returns last provided value', () {
362 var parser = new ArgParser();
363 parser.addOption('define');
364 var args = parser.parse(['--define=1', '--define=2']);
365 expect(args['define'], equals('2'));
366 });
367
368 test('returns a List if multi-valued', () {
369 var parser = new ArgParser();
370 parser.addOption('define', allowMultiple: true);
371 var args = parser.parse(['--define=1']);
372 expect(args['define'], equals(['1']));
373 args = parser.parse(['--define=1', '--define=2']);
374 expect(args['define'], equals(['1','2']));
375 });
376
377 test('returns the default value for multi-valued arguments '
378 'if not explicitly set', () {
379 var parser = new ArgParser();
380 parser.addOption('define', defaultsTo:'0', allowMultiple: true);
381 var args = parser.parse(['']);
382 expect(args['define'], equals(['0']));
383 });
360 }); 384 });
361 385
362 group('remaining args', () { 386 group('remaining args', () {
363 test('stops parsing args when a non-option-like arg is encountered', () { 387 test('stops parsing args when a non-option-like arg is encountered', () {
364 var parser = new ArgParser(); 388 var parser = new ArgParser();
365 parser.addFlag('woof'); 389 parser.addFlag('woof');
366 parser.addOption('meow'); 390 parser.addOption('meow');
367 parser.addOption('tweet', defaultsTo: 'bird'); 391 parser.addOption('tweet', defaultsTo: 'bird');
368 392
369 var results = parser.parse(['--woof', '--meow', 'v', 'not', 'option']); 393 var results = parser.parse(['--woof', '--meow', 'v', 'not', 'option']);
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 group('ArgResults[]', () { 574 group('ArgResults[]', () {
551 test('throws if the name is not an option', () { 575 test('throws if the name is not an option', () {
552 var parser = new ArgParser(); 576 var parser = new ArgParser();
553 var results = parser.parse([]); 577 var results = parser.parse([]);
554 throwsIllegalArg(() => results['unknown']); 578 throwsIllegalArg(() => results['unknown']);
555 }); 579 });
556 }); 580 });
557 } 581 }
558 582
559 throwsIllegalArg(function) { 583 throwsIllegalArg(function) {
560 expect(function, throwsA(new isInstanceOf<IllegalArgumentException>())); 584 expect(function, throwsIllegalArgumentException);
561 } 585 }
562 586
563 throwsFormat(ArgParser parser, List<String> args) { 587 throwsFormat(ArgParser parser, List<String> args) {
564 expect(() => parser.parse(args), throwsFormatException); 588 expect(() => parser.parse(args), throwsFormatException);
565 } 589 }
566 590
567 validateUsage(ArgParser parser, String expected) { 591 validateUsage(ArgParser parser, String expected) {
568 expected = unindentString(expected); 592 expected = unindentString(expected);
569 expect(parser.getUsage(), equals(expected)); 593 expect(parser.getUsage(), equals(expected));
570 } 594 }
(...skipping 25 matching lines...) Expand all
596 throw new IllegalArgumentException( 620 throw new IllegalArgumentException(
597 'Line "$line" does not have enough indentation.'); 621 'Line "$line" does not have enough indentation.');
598 } 622 }
599 623
600 lines[i] = line.substring(indent); 624 lines[i] = line.substring(indent);
601 } 625 }
602 } 626 }
603 627
604 return Strings.join(lines, '\n'); 628 return Strings.join(lines, '\n');
605 } 629 }
OLDNEW
« no previous file with comments | « lib/args/args.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698