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

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: Fixed up documentation and the like. 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library parse_all_test;
6
7 import 'package:unittest/unittest.dart';
8 import 'package:args/args.dart';
9
10 main() {
11 group('ArgParser.parse()', () {
Bob Nystrom 2013/06/20 00:33:36 "ArgParser.parse(parseAllOptions: true)"
Andrei Mouravski 2013/06/22 00:54:02 Done.
12 var parser;
13 var args;
14
15 setUp(() {
16 parser = new ArgParser();
17 args = <String>[];
18 });
19
20 group('starting with a non-option', () {
21 test('followed by flag', () {
22 parser.addFlag('flag');
23 args = ['A', '--flag'];
24
25 var results = parser.parse(args);
26 expect(results['flag'], isFalse);
27 expect(results.rest, orderedEquals(args));
Bob Nystrom 2013/06/20 00:33:36 Don't other tests cover this?
Andrei Mouravski 2013/06/22 00:54:02 Not quite.
Bob Nystrom 2013/06/24 15:53:20 Can you be more specific? There are existing compr
Andrei Mouravski 2013/06/24 20:41:03 Done.
28
29 var resultsAll = parseAll(parser, args);
30 expect(resultsAll['flag'], isTrue);
31 expect(resultsAll.rest, equals(['A']));
32 });
33
34 test('followed by option', () {
35 parser.addOption('opt');
36 args = ['A', '--opt'];
37
38 var results = parser.parse(args);
39 expect(results['opt'], isNull);
40 expect(results.rest, orderedEquals(args));
41
42 expectThrows(parser, args, parseAllOptions: true);
43 });
44
45 test('followed by option and value', () {
46 parser.addOption('opt');
47 args = ['A', '--opt', 'V'];
48
49 var results = parser.parse(args);
50 expect(results['opt'], isNull);
51 expect(results.rest, orderedEquals(args));
52
53 var resultsAll = parseAll(parser, args);
54 expect(resultsAll['opt'], equals('V'));
55 expect(resultsAll.rest, equals(['A']));
56 });
57
58 test('followed by unknown flag', () {
59 args = ['A', '--xflag'];
60 var results = parser.parse(args);
61 expect(results.rest, orderedEquals(args));
62
63 expectThrows(parser, args, parseAllOptions: true);
64 });
65
66 test('followed by unknown option and value', () {
67 args = ['A', '--xopt', 'V'];
68 var results = parser.parse(args);
69 expect(results.rest, orderedEquals(args));
70
71 expectThrows(parser, args, parseAllOptions: true);
72 });
73
74 test('followed by command', () {
75 parser.addCommand('com');
76 args = ['A', 'com'];
77
78 var results = parser.parse(args);
79 expect(results.command, isNull);
80 expect(results.rest, orderedEquals(args));
81
82 expectThrows(parser, args, parseAllOptions: true);
83 });
84 });
85 });
86 }
87 ArgResults parseAll(ArgParser parser, List<String> args) =>
88 parser.parse(args, parseAllOptions: true);
Bob Nystrom 2013/06/20 00:33:36 I'd probably just inline this in the tests to make
Andrei Mouravski 2013/06/22 00:54:02 Done.
89
90 expectThrows(ArgParser parser, List<String> args, {parseAllOptions: false}) =>
Bob Nystrom 2013/06/20 00:33:36 You're always passing true for parseAllOptions. Ju
Andrei Mouravski 2013/06/22 00:54:02 Done.
91 expect(() => parser.parse(args, parseAllOptions: parseAllOptions),
92 throwsFormatException, reason: "with parseAllOptions: $parseAllOptions");
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698