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

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

Issue 10756011: Have Pub make use of the arg parser. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add tests for non-negatable flags. Created 8 years, 5 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') | utils/pub/pub.dart » ('j') | 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 115
116 test('are not preferred over a colliding one without', () { 116 test('are not preferred over a colliding one without', () {
117 var parser = new ArgParser(); 117 var parser = new ArgParser();
118 parser.addFlag('no-strum'); 118 parser.addFlag('no-strum');
119 parser.addFlag('strum'); 119 parser.addFlag('strum');
120 120
121 var args = parser.parse(['--no-strum']); 121 var args = parser.parse(['--no-strum']);
122 expect(args['no-strum'], isTrue); 122 expect(args['no-strum'], isTrue);
123 expect(args['strum'], isFalse); 123 expect(args['strum'], isFalse);
124 }); 124 });
125
126 test('fail for non-negatable flags', () {
127 var parser = new ArgParser();
128 parser.addFlag('strum', negatable: false);
129
130 throwsBadFormat(parser, ['--no-strum']);
131 });
125 }); 132 });
126 133
127 group('callbacks', () { 134 group('callbacks', () {
128 test('for present flags are invoked with the value', () { 135 test('for present flags are invoked with the value', () {
129 var a; 136 var a;
130 var parser = new ArgParser(); 137 var parser = new ArgParser();
131 parser.addFlag('a', callback: (value) => a = value); 138 parser.addFlag('a', callback: (value) => a = value);
132 139
133 var args = parser.parse(['--a']); 140 var args = parser.parse(['--a']);
134 expect(a, isTrue); 141 expect(a, isTrue);
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 380
374 var results = parser.parse(['--woof', '--', '--meow']); 381 var results = parser.parse(['--woof', '--', '--meow']);
375 expect(results['woof'], isTrue); 382 expect(results['woof'], isTrue);
376 expect(results['meow'], equals('kitty')); 383 expect(results['meow'], equals('kitty'));
377 expect(results.rest, orderedEquals(['--meow'])); 384 expect(results.rest, orderedEquals(['--meow']));
378 }); 385 });
379 }); 386 });
380 }); 387 });
381 388
382 group('ArgParser.getUsage()', () { 389 group('ArgParser.getUsage()', () {
383 test('flags show "no-" in title', () { 390 test('negatable flags show "no-" in title', () {
384 var parser = new ArgParser(); 391 var parser = new ArgParser();
385 parser.addFlag('mode', help: 'The mode'); 392 parser.addFlag('mode', help: 'The mode');
386 393
387 validateUsage(parser, 394 validateUsage(parser,
388 ''' 395 '''
389 --[no-]mode The mode 396 --[no-]mode The mode
390 '''); 397 ''');
391 }); 398 });
392 399
400 test('non-negatable flags don\'t show "no-" in title', () {
401 var parser = new ArgParser();
402 parser.addFlag('mode', negatable: false, help: 'The mode');
403
404 validateUsage(parser,
405 '''
406 --mode The mode
407 ''');
408 });
409
393 test('if there are no abbreviations, there is no column for them', () { 410 test('if there are no abbreviations, there is no column for them', () {
394 var parser = new ArgParser(); 411 var parser = new ArgParser();
395 parser.addFlag('mode', help: 'The mode'); 412 parser.addFlag('mode', help: 'The mode');
396 413
397 validateUsage(parser, 414 validateUsage(parser,
398 ''' 415 '''
399 --[no-]mode The mode 416 --[no-]mode The mode
400 '''); 417 ''');
401 }); 418 });
402 419
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 throw new IllegalArgumentException( 597 throw new IllegalArgumentException(
581 'Line "$line" does not have enough indentation.'); 598 'Line "$line" does not have enough indentation.');
582 } 599 }
583 600
584 lines[i] = line.substring(indent); 601 lines[i] = line.substring(indent);
585 } 602 }
586 } 603 }
587 604
588 return Strings.join(lines, '\n'); 605 return Strings.join(lines, '\n');
589 } 606 }
OLDNEW
« no previous file with comments | « lib/args/args.dart ('k') | utils/pub/pub.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698