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

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: Done 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
« 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) 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 resultsAll = parser.parse(args, allowTrailingOptions: true);
17 expect(results['flag'], isFalse); 18 expect(resultsAll['flag'], isTrue);
18 expect(results.rest, orderedEquals(args)); 19 expect(resultsAll.rest, equals(['A']));
19 }); 20 });
20 21
21 test('followed by option', () { 22 test('followed by option', () {
22 var parser = new ArgParser()..addOption('opt'); 23 var parser = new ArgParser()..addOption('opt');
23 var args = ['A', '--opt']; 24 var args = ['A', '--opt'];
24 25
25 var results = parser.parse(args); 26 expectThrows(parser, args);
26 expect(results['opt'], isNull);
27 expect(results.rest, orderedEquals(args));
28 }); 27 });
29 28
30 test('followed by option and value', () { 29 test('followed by option and value', () {
31 var parser = new ArgParser()..addOption('opt'); 30 var parser = new ArgParser()..addOption('opt');
32 var args = ['A', '--opt', 'V']; 31 var args = ['A', '--opt', 'V'];
33 32
34 var results = parser.parse(args); 33 var resultsAll = parser.parse(args, allowTrailingOptions: true);
35 expect(results['opt'], isNull); 34 expect(resultsAll['opt'], equals('V'));
36 expect(results.rest, orderedEquals(args)); 35 expect(resultsAll.rest, equals(['A']));
37 }); 36 });
38 37
39 test('followed by unknown flag', () { 38 test('followed by unknown flag', () {
40 var parser = new ArgParser(); 39 var parser = new ArgParser();
41 var args = ['A', '--xflag']; 40 var args = ['A', '--xflag'];
42 var results = parser.parse(args); 41
43 expect(results.rest, orderedEquals(args)); 42 expectThrows(parser, args);
44 }); 43 });
45 44
46 test('followed by unknown option and value', () { 45 test('followed by unknown option and value', () {
47 var parser = new ArgParser(); 46 var parser = new ArgParser();
48 var args = ['A', '--xopt', 'V']; 47 var args = ['A', '--xopt', 'V'];
49 var results = parser.parse(args); 48
50 expect(results.rest, orderedEquals(args)); 49 expectThrows(parser, args);
51 }); 50 });
52 51
53 test('followed by command', () { 52 test('followed by command', () {
54 var parser = new ArgParser()..addCommand('com'); 53 var parser = new ArgParser()..addCommand('com');
55 var args = ['A', 'com']; 54 var args = ['A', 'com'];
56 55
57 var results = parser.parse(args); 56 expectThrows(parser, args);
58 expect(results.command, isNull);
59 expect(results.rest, orderedEquals(args));
60 }); 57 });
61 }); 58 });
62 } 59 }
60 expectThrows(ArgParser parser, List<String> args) =>
61 expect(() => parser.parse(args, allowTrailingOptions: true),
62 throwsFormatException,
63 reason: "with allowTrailingOptions: true");
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