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

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

Issue 10828351: Added the ability to get the names of the options in a set of parsed arguments, and the default val… (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 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 parser.addOption('define', allowMultiple: true); 370 parser.addOption('define', allowMultiple: true);
371 var args = parser.parse(['--define=1']); 371 var args = parser.parse(['--define=1']);
372 expect(args['define'], equals(['1'])); 372 expect(args['define'], equals(['1']));
373 args = parser.parse(['--define=1', '--define=2']); 373 args = parser.parse(['--define=1', '--define=2']);
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 }); 384 });
385 385
386 group('query default values', () {
387 test('queries the default value', () {
388 var parser = new ArgParser();
389 parser.addOption('define', defaultsTo: '0');
390 expect(()=>parser.getDefault('undefine'),
391 throwsIllegalArgumentException);
392 });
393
394 test('queries the default value for an unknown option', () {
395 var parser = new ArgParser();
396 parser.addOption('define', defaultsTo: '0');
397 expect(()=>parser.getDefault('undefine'),
398 throwsIllegalArgumentException);
399 });
400 });
401
402 group('gets the option names from an ArgsResult', () {
403 test('queries the set options', () {
404 var parser = new ArgParser();
405 parser.addFlag('woof', defaultsTo: false);
406 parser.addOption('meow', defaultsTo: 'kitty');
407 var args = parser.parse([]);
408 expect(args.options, hasLength(2));
409 expect(args.options.some((o) => o == 'woof'), isTrue);
410 expect(args.options.some((o) => o == 'meow'), isTrue);
411 });
412 });
413
386 group('remaining args', () { 414 group('remaining args', () {
387 test('stops parsing args when a non-option-like arg is encountered', () { 415 test('stops parsing args when a non-option-like arg is encountered', () {
388 var parser = new ArgParser(); 416 var parser = new ArgParser();
389 parser.addFlag('woof'); 417 parser.addFlag('woof');
390 parser.addOption('meow'); 418 parser.addOption('meow');
391 parser.addOption('tweet', defaultsTo: 'bird'); 419 parser.addOption('tweet', defaultsTo: 'bird');
392 420
393 var results = parser.parse(['--woof', '--meow', 'v', 'not', 'option']); 421 var results = parser.parse(['--woof', '--meow', 'v', 'not', 'option']);
394 expect(results['woof'], isTrue); 422 expect(results['woof'], isTrue);
395 expect(results['meow'], equals('v')); 423 expect(results['meow'], equals('v'));
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 throw new IllegalArgumentException( 657 throw new IllegalArgumentException(
630 'Line "$line" does not have enough indentation.'); 658 'Line "$line" does not have enough indentation.');
631 } 659 }
632 660
633 lines[i] = line.substring(indent); 661 lines[i] = line.substring(indent);
634 } 662 }
635 } 663 }
636 664
637 return Strings.join(lines, '\n'); 665 return Strings.join(lines, '\n');
638 } 666 }
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