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

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

Issue 260963007: Move allowTrailingOptions into ArgParser. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise and bump package versions. Created 6 years, 7 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 void main() {
11 group('ArgParser.parse(allowTrailingOptions: true) '
12 'starting with a non-option', () {
13 test('followed by flag', () {
14 var parser = new ArgParser()..addFlag('flag');
15 var args = ['A', '--flag'];
16
17 var resultsAll = parser.parse(args, allowTrailingOptions: true);
18 expect(resultsAll['flag'], isTrue);
19 expect(resultsAll.rest, equals(['A']));
20 });
21
22 test('followed by option', () {
23 var parser = new ArgParser()..addOption('opt');
24 var args = ['A', '--opt'];
25
26 expectThrows(parser, args);
27 });
28
29 test('followed by option and value', () {
30 var parser = new ArgParser()..addOption('opt');
31 var args = ['A', '--opt', 'V'];
32
33 var resultsAll = parser.parse(args, allowTrailingOptions: true);
34 expect(resultsAll['opt'], equals('V'));
35 expect(resultsAll.rest, equals(['A']));
36 });
37
38 test('followed by unknown flag', () {
39 var parser = new ArgParser();
40 var args = ['A', '--xflag'];
41
42 expectThrows(parser, args);
43 });
44
45 test('followed by unknown option and value', () {
46 var parser = new ArgParser();
47 var args = ['A', '--xopt', 'V'];
48
49 expectThrows(parser, args);
50 });
51
52 test('followed by command', () {
53 var parser = new ArgParser()..addCommand('com');
54 var args = ['A', 'com'];
55
56 expectThrows(parser, args);
57 });
58 });
59 }
60
61 void expectThrows(ArgParser parser, List<String> args) =>
62 expect(() => parser.parse(args, allowTrailingOptions: true),
63 throwsFormatException,
64 reason: "with allowTrailingOptions: true");
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698