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

Side by Side Diff: pkg/args/test/parse_test.dart

Issue 12545013: Added the continueParsing option to ArgParser. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Style + commentary. Created 7 years, 8 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 | « pkg/args/lib/src/parser.dart ('k') | sdk/lib/_internal/dartdoc/bin/dartdoc.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 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
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');
Bob Nystrom 2013/04/22 22:59:03 Why add neigh to this test?
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' ]);
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' ],
Bob Nystrom 2013/04/22 22:59:03 This test is pretty complicated. How about simplif
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']));
422 });
423
Bob Nystrom 2013/04/22 22:59:03 Add a test for what happens if continueParsing is
424 test('with continueParsing, gathers all seen arguments to leaf command',
425 () {
426 var parser = new ArgParser();
427 parser.addFlag('woof');
428 parser.addFlag('neigh');
429 parser.addOption('tweet', defaultsTo: 'bird');
430
431 var command = parser.addCommand('v');
432 command.addCommand('option')
433 ..addOption('tweet', defaultsTo: 'foo')
434 ..addFlag('neigh');
Bob Nystrom 2013/04/22 22:59:03 We should use a consistent style here. How about j
435 command.addCommand('end');
436
437 var results = parser.parse(['--woof', 'meow', 'v', 'not', 'option',
438 '--tweet', 'devrel', '--neigh', 'end' ],
439 continueParsing: true);
440 expect(results['woof'], isTrue);
441 expect(results['tweet'], equals('bird'));
442 expect(results.rest, equals([]));
443 expect(results.command.name, equals('v'));
444 expect(results.command.rest, equals([]));
445 expect(results.command.command['neigh'], isTrue);
446 expect(results.command.command.name, equals('option'));
447 expect(results.command.command.rest, orderedEquals(['meow', 'not', 'end' ]));
Bob Nystrom 2013/04/22 22:59:03 This test is big and hard to read. Split it into a
400 }); 448 });
401 449
402 test('stops parsing at "--"', () { 450 test('stops parsing at "--"', () {
403 var parser = new ArgParser(); 451 var parser = new ArgParser();
404 parser.addFlag('woof', defaultsTo: false); 452 parser.addFlag('woof', defaultsTo: false);
405 parser.addOption('meow', defaultsTo: 'kitty'); 453 parser.addOption('meow', defaultsTo: 'kitty');
406 454
407 var results = parser.parse(['--woof', '--', '--meow']); 455 var results = parser.parse(['--woof', '--', '--meow']);
408 expect(results['woof'], isTrue); 456 expect(results['woof'], isTrue);
409 expect(results['meow'], equals('kitty')); 457 expect(results['meow'], equals('kitty'));
(...skipping 12 matching lines...) Expand all
422 }); 470 });
423 } 471 }
424 472
425 throwsIllegalArg(function) { 473 throwsIllegalArg(function) {
426 expect(function, throwsArgumentError); 474 expect(function, throwsArgumentError);
427 } 475 }
428 476
429 throwsFormat(ArgParser parser, List<String> args) { 477 throwsFormat(ArgParser parser, List<String> args) {
430 expect(() => parser.parse(args), throwsFormatException); 478 expect(() => parser.parse(args), throwsFormatException);
431 } 479 }
OLDNEW
« no previous file with comments | « pkg/args/lib/src/parser.dart ('k') | sdk/lib/_internal/dartdoc/bin/dartdoc.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698