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

Unified Diff: pkg/args/test/parse_test.dart

Issue 11824044: Ignore unhandled arguments instead of stopping parsing. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/args/lib/args.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/args/test/parse_test.dart
diff --git a/pkg/args/test/parse_test.dart b/pkg/args/test/parse_test.dart
index ab1d1306f8db81e5749ce59be81f6d7a7b2a9ff9..828c2aefc5d0a9991fca9ceb57270e43b6d0fac4 100644
--- a/pkg/args/test/parse_test.dart
+++ b/pkg/args/test/parse_test.dart
@@ -36,7 +36,7 @@ main() {
expect(args['verbose'], isFalse);
});
- test('throws if given a value', () {
+ test('throw if given a value', () {
var parser = new ArgParser();
parser.addFlag('verbose');
@@ -238,6 +238,17 @@ main() {
expect(args['apple'], equals('b?!c'));
});
+ test('are case-sensitive', () {
+ var parser = new ArgParser();
+ parser.addFlag('recurse', defaultsTo: false, abbr:'R');
+
+ var results = parser.parse(['-R']);
+ expect(results['recurse'], isTrue);
+ expect(results.rest, []);
+
+ throwsFormat(parser, ['-r']);
+ });
+
test('throw if unknown', () {
var parser = new ArgParser();
throwsFormat(parser, ['-f']);
@@ -350,14 +361,14 @@ main() {
throwsFormat(parser, ['--mode=profile']);
});
- test('returns last provided value', () {
+ test('return last provided value', () {
var parser = new ArgParser();
parser.addOption('define');
var args = parser.parse(['--define=1', '--define=2']);
expect(args['define'], equals('2'));
});
- test('returns a List if multi-valued', () {
+ test('return a list if multi-valued', () {
var parser = new ArgParser();
parser.addOption('define', allowMultiple: true);
var args = parser.parse(['--define=1']);
@@ -366,8 +377,8 @@ main() {
expect(args['define'], equals(['1','2']));
});
- test('returns the default value for multi-valued arguments '
- 'if not explicitly set', () {
+ test('return the default value for multi-valued arguments if not '
+ 'explicitly set', () {
var parser = new ArgParser();
parser.addOption('define', defaultsTo: '0', allowMultiple: true);
var args = parser.parse(['']);
@@ -376,17 +387,14 @@ main() {
});
group('remaining args', () {
- test('stops parsing args when a non-option-like arg is encountered', () {
+ test('accumulates unhandled arguments', () {
var parser = new ArgParser();
parser.addFlag('woof');
parser.addOption('meow');
- parser.addOption('tweet', defaultsTo: 'bird');
-
- var results = parser.parse(['--woof', '--meow', 'v', 'not', 'option']);
+ var results = parser.parse(['a', '--woof', 'b', '--meow', 'c', 'd']);
expect(results['woof'], isTrue);
- expect(results['meow'], equals('v'));
- expect(results['tweet'], equals('bird'));
- expect(results.rest, orderedEquals(['not', 'option']));
+ expect(results['meow'], equals('c'));
+ expect(results.rest, orderedEquals(['a', 'b', 'd']));
ahe 2013/01/10 19:51:40 Could you add a test that you reject unknown argum
Bob Nystrom 2013/01/10 23:16:40 The tests on 252 and 329 should cover that, I thin
ahe 2013/01/11 05:37:28 Yes. I guess I was skipping exceptions when I scan
});
test('stops parsing at "--"', () {
@@ -399,15 +407,6 @@ main() {
expect(results['meow'], equals('kitty'));
expect(results.rest, orderedEquals(['--meow']));
});
-
- test('handles options with case-sensitivity', () {
- var parser = new ArgParser();
- parser.addFlag('recurse', defaultsTo: false, abbr:'R');
- var results = parser.parse(['-R']);
- expect(results['recurse'], isTrue);
- expect(results.rest, [ ]);
- throwsFormat(parser, ['-r']);
- });
});
});
}
« no previous file with comments | « pkg/args/lib/args.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698