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

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

Issue 12545013: Added the continueParsing option to ArgParser. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 12 changes. Created 7 years, 6 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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_all_test; 5 library parse_all_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() {
11 group('ArgParser.parse() starting with a non-option', () { 11 group('ArgParser.parse(allowTrailingOptions: true) '
12 'starting with a non-option', () {
12 test('followed by flag', () { 13 test('followed by flag', () {
13 var parser = new ArgParser()..addFlag('flag'); 14 var parser = new ArgParser()..addFlag('flag');
14 var args = ['A', '--flag']; 15 var args = ['A', '--flag'];
15 16
16 var results = parser.parse(args); 17 var results = parser.parse(args);
17 expect(results['flag'], isFalse); 18 expect(results['flag'], isFalse);
18 expect(results.rest, orderedEquals(args)); 19 expect(results.rest, orderedEquals(args));
20 var resultsAll = parser.parse(args, allowTrailingOptions: true);
21 expect(resultsAll['flag'], isTrue);
22 expect(resultsAll.rest, equals(['A']));
19 }); 23 });
20 24
21 test('followed by option', () { 25 test('followed by option', () {
22 var parser = new ArgParser()..addOption('opt'); 26 var parser = new ArgParser()..addOption('opt');
23 var args = ['A', '--opt']; 27 var args = ['A', '--opt'];
24 28
25 var results = parser.parse(args); 29 var results = parser.parse(args);
26 expect(results['opt'], isNull); 30 expect(results['opt'], isNull);
27 expect(results.rest, orderedEquals(args)); 31 expect(results.rest, orderedEquals(args));
32
33 expectThrows(parser, args);
28 }); 34 });
29 35
30 test('followed by option and value', () { 36 test('followed by option and value', () {
31 var parser = new ArgParser()..addOption('opt'); 37 var parser = new ArgParser()..addOption('opt');
32 var args = ['A', '--opt', 'V']; 38 var args = ['A', '--opt', 'V'];
33 39
34 var results = parser.parse(args); 40 var results = parser.parse(args);
35 expect(results['opt'], isNull); 41 expect(results['opt'], isNull);
36 expect(results.rest, orderedEquals(args)); 42 expect(results.rest, orderedEquals(args));
43
44 var resultsAll = parser.parse(args, allowTrailingOptions: true);
45 expect(resultsAll['opt'], equals('V'));
46 expect(resultsAll.rest, equals(['A']));
37 }); 47 });
38 48
39 test('followed by unknown flag', () { 49 test('followed by unknown flag', () {
40 var parser = new ArgParser(); 50 var parser = new ArgParser();
41 var args = ['A', '--xflag']; 51 var args = ['A', '--xflag'];
42 var results = parser.parse(args); 52 var results = parser.parse(args);
43 expect(results.rest, orderedEquals(args)); 53 expect(results.rest, orderedEquals(args));
54
55 expectThrows(parser, args);
44 }); 56 });
45 57
46 test('followed by unknown option and value', () { 58 test('followed by unknown option and value', () {
47 var parser = new ArgParser(); 59 var parser = new ArgParser();
48 var args = ['A', '--xopt', 'V']; 60 var args = ['A', '--xopt', 'V'];
49 var results = parser.parse(args); 61 var results = parser.parse(args);
50 expect(results.rest, orderedEquals(args)); 62 expect(results.rest, orderedEquals(args));
63
64 expectThrows(parser, args);
51 }); 65 });
52 66
53 test('followed by command', () { 67 test('followed by command', () {
54 var parser = new ArgParser()..addCommand('com'); 68 var parser = new ArgParser()..addCommand('com');
55 var args = ['A', 'com']; 69 var args = ['A', 'com'];
56 70
57 var results = parser.parse(args); 71 var results = parser.parse(args);
58 expect(results.command, isNull); 72 expect(results.command, isNull);
59 expect(results.rest, orderedEquals(args)); 73 expect(results.rest, orderedEquals(args));
74
75 expectThrows(parser, args);
60 }); 76 });
61 }); 77 });
62 } 78 }
79 expectThrows(ArgParser parser, List<String> args) =>
80 expect(() => parser.parse(args, allowTrailingOptions: true),
81 throwsFormatException,
82 reason: "with allowTrailingOptions: true");
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698