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

Side by Side Diff: test/command_parse_test.dart

Issue 849023002: format code, removed unused variables and deprecated usage (Closed) Base URL: https://github.com/dart-lang/args.git@master
Patch Set: nits Created 5 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 unified diff | Download patch
« no previous file with comments | « test/args_test.dart ('k') | test/command_runner_test.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 command_parse_test; 5 library command_parse_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 import 'utils.dart'; 9 import 'utils.dart';
10 10
(...skipping 16 matching lines...) Expand all
27 27
28 test('throws on a duplicate command name', () { 28 test('throws on a duplicate command name', () {
29 var parser = new ArgParser(); 29 var parser = new ArgParser();
30 parser.addCommand('install'); 30 parser.addCommand('install');
31 throwsIllegalArg(() => parser.addCommand('install')); 31 throwsIllegalArg(() => parser.addCommand('install'));
32 }); 32 });
33 }); 33 });
34 34
35 group('ArgParser.parse()', () { 35 group('ArgParser.parse()', () {
36 test('parses a command', () { 36 test('parses a command', () {
37 var parser = new ArgParser(); 37 var parser = new ArgParser()..addCommand('install');
38 var command = parser.addCommand('install');
39 38
40 var args = parser.parse(['install']); 39 var args = parser.parse(['install']);
41 40
42 expect(args.command.name, equals('install')); 41 expect(args.command.name, equals('install'));
43 expect(args.rest, isEmpty); 42 expect(args.rest, isEmpty);
44 }); 43 });
45 44
46 test('parses a command option', () { 45 test('parses a command option', () {
47 var parser = new ArgParser(); 46 var parser = new ArgParser();
48 var command = parser.addCommand('install'); 47 var command = parser.addCommand('install');
49 command.addOption('path'); 48 command.addOption('path');
50 49
51 var args = parser.parse(['install', '--path', 'some/path']); 50 var args = parser.parse(['install', '--path', 'some/path']);
52 expect(args.command['path'], equals('some/path')); 51 expect(args.command['path'], equals('some/path'));
53 }); 52 });
54 53
55 test('parses a parent solo option before the command', () { 54 test('parses a parent solo option before the command', () {
56 var parser = new ArgParser(); 55 var parser = new ArgParser()
57 parser.addOption('mode', abbr: 'm'); 56 ..addOption('mode', abbr: 'm')
58 var command = parser.addCommand('install'); 57 ..addCommand('install');
59 58
60 var args = parser.parse(['-m', 'debug', 'install']); 59 var args = parser.parse(['-m', 'debug', 'install']);
61 expect(args['mode'], equals('debug')); 60 expect(args['mode'], equals('debug'));
62 expect(args.command.name, equals('install')); 61 expect(args.command.name, equals('install'));
63 }); 62 });
64 63
65 test('parses a parent solo option after the command', () { 64 test('parses a parent solo option after the command', () {
66 var parser = new ArgParser(); 65 var parser = new ArgParser()
67 parser.addOption('mode', abbr: 'm'); 66 ..addOption('mode', abbr: 'm')
68 var command = parser.addCommand('install'); 67 ..addCommand('install');
69 68
70 var args = parser.parse(['install', '-m', 'debug']); 69 var args = parser.parse(['install', '-m', 'debug']);
71 expect(args['mode'], equals('debug')); 70 expect(args['mode'], equals('debug'));
72 expect(args.command.name, equals('install')); 71 expect(args.command.name, equals('install'));
73 }); 72 });
74 73
75 test('parses a parent option before the command', () { 74 test('parses a parent option before the command', () {
76 var parser = new ArgParser(); 75 var parser = new ArgParser()
77 parser.addFlag('verbose'); 76 ..addFlag('verbose')
78 var command = parser.addCommand('install'); 77 ..addCommand('install');
79 78
80 var args = parser.parse(['--verbose', 'install']); 79 var args = parser.parse(['--verbose', 'install']);
81 expect(args['verbose'], isTrue); 80 expect(args['verbose'], isTrue);
82 expect(args.command.name, equals('install')); 81 expect(args.command.name, equals('install'));
83 }); 82 });
84 83
85 test('parses a parent option after the command', () { 84 test('parses a parent option after the command', () {
86 var parser = new ArgParser(); 85 var parser = new ArgParser()
87 parser.addFlag('verbose'); 86 ..addFlag('verbose')
88 var command = parser.addCommand('install'); 87 ..addCommand('install');
89 88
90 var args = parser.parse(['install', '--verbose']); 89 var args = parser.parse(['install', '--verbose']);
91 expect(args['verbose'], isTrue); 90 expect(args['verbose'], isTrue);
92 expect(args.command.name, equals('install')); 91 expect(args.command.name, equals('install'));
93 }); 92 });
94 93
95 test('parses a parent negated option before the command', () { 94 test('parses a parent negated option before the command', () {
96 var parser = new ArgParser(); 95 var parser = new ArgParser()
97 parser.addFlag('verbose', defaultsTo: true); 96 ..addFlag('verbose', defaultsTo: true)
98 var command = parser.addCommand('install'); 97 ..addCommand('install');
99 98
100 var args = parser.parse(['--no-verbose', 'install']); 99 var args = parser.parse(['--no-verbose', 'install']);
101 expect(args['verbose'], isFalse); 100 expect(args['verbose'], isFalse);
102 expect(args.command.name, equals('install')); 101 expect(args.command.name, equals('install'));
103 }); 102 });
104 103
105 test('parses a parent negated option after the command', () { 104 test('parses a parent negated option after the command', () {
106 var parser = new ArgParser(); 105 var parser = new ArgParser()
107 parser.addFlag('verbose', defaultsTo: true); 106 ..addFlag('verbose', defaultsTo: true)
108 var command = parser.addCommand('install'); 107 ..addCommand('install');
109 108
110 var args = parser.parse(['install', '--no-verbose']); 109 var args = parser.parse(['install', '--no-verbose']);
111 expect(args['verbose'], isFalse); 110 expect(args['verbose'], isFalse);
112 expect(args.command.name, equals('install')); 111 expect(args.command.name, equals('install'));
113 }); 112 });
114 113
115 test('parses a parent abbreviation before the command', () { 114 test('parses a parent abbreviation before the command', () {
116 var parser = new ArgParser(); 115 var parser = new ArgParser()
117 parser.addFlag('debug', abbr: 'd'); 116 ..addFlag('debug', abbr: 'd')
118 parser.addFlag('verbose', abbr: 'v'); 117 ..addFlag('verbose', abbr: 'v')
119 var command = parser.addCommand('install'); 118 ..addCommand('install');
120 119
121 var args = parser.parse(['-dv', 'install']); 120 var args = parser.parse(['-dv', 'install']);
122 expect(args['debug'], isTrue); 121 expect(args['debug'], isTrue);
123 expect(args['verbose'], isTrue); 122 expect(args['verbose'], isTrue);
124 expect(args.command.name, equals('install')); 123 expect(args.command.name, equals('install'));
125 }); 124 });
126 125
127 test('parses a parent abbreviation after the command', () { 126 test('parses a parent abbreviation after the command', () {
128 var parser = new ArgParser(); 127 var parser = new ArgParser()
129 parser.addFlag('debug', abbr: 'd'); 128 ..addFlag('debug', abbr: 'd')
130 parser.addFlag('verbose', abbr: 'v'); 129 ..addFlag('verbose', abbr: 'v')
131 var command = parser.addCommand('install'); 130 ..addCommand('install');
132 131
133 var args = parser.parse(['install', '-dv']); 132 var args = parser.parse(['install', '-dv']);
134 expect(args['debug'], isTrue); 133 expect(args['debug'], isTrue);
135 expect(args['verbose'], isTrue); 134 expect(args['verbose'], isTrue);
136 expect(args.command.name, equals('install')); 135 expect(args.command.name, equals('install'));
137 }); 136 });
138 137
139 test('does not parse a solo command option before the command', () { 138 test('does not parse a solo command option before the command', () {
140 var parser = new ArgParser(); 139 var parser = new ArgParser();
141 var command = parser.addCommand('install'); 140 var command = parser.addCommand('install');
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 expect(args['apple'], isTrue); 172 expect(args['apple'], isTrue);
174 expect(args.command.name, equals('cmd')); 173 expect(args.command.name, equals('cmd'));
175 expect(args.command['banana'], isTrue); 174 expect(args.command['banana'], isTrue);
176 expect(args.command.command.name, equals('subcmd')); 175 expect(args.command.command.name, equals('subcmd'));
177 expect(args.command.command['cherry'], isTrue); 176 expect(args.command.command['cherry'], isTrue);
178 }); 177 });
179 178
180 test('option is given to innermost command that can take it', () { 179 test('option is given to innermost command that can take it', () {
181 var parser = new ArgParser(); 180 var parser = new ArgParser();
182 parser.addFlag('verbose'); 181 parser.addFlag('verbose');
183 var command = parser.addCommand('cmd'); 182 parser.addCommand('cmd')
184 command.addFlag('verbose'); 183 ..addFlag('verbose')
185 var subcommand = command.addCommand('subcmd'); 184 ..addCommand('subcmd');
186 185
187 var args = parser.parse(['cmd', 'subcmd', '--verbose']); 186 var args = parser.parse(['cmd', 'subcmd', '--verbose']);
188 expect(args['verbose'], isFalse); 187 expect(args['verbose'], isFalse);
189 expect(args.command.name, equals('cmd')); 188 expect(args.command.name, equals('cmd'));
190 expect(args.command['verbose'], isTrue); 189 expect(args.command['verbose'], isTrue);
191 expect(args.command.command.name, equals('subcmd')); 190 expect(args.command.command.name, equals('subcmd'));
192 }); 191 });
193 192
194 test('remaining arguments are given to the innermost command', () { 193 test('remaining arguments are given to the innermost command', () {
195 var parser = new ArgParser(); 194 var parser = new ArgParser();
196 var command = parser.addCommand('cmd'); 195 parser.addCommand('cmd')..addCommand('subcmd');
197 var subcommand = command.addCommand('subcmd');
198 196
199 var args = parser.parse(['cmd', 'subcmd', 'other', 'stuff']); 197 var args = parser.parse(['cmd', 'subcmd', 'other', 'stuff']);
200 expect(args.command.name, equals('cmd')); 198 expect(args.command.name, equals('cmd'));
201 expect(args.rest, isEmpty); 199 expect(args.rest, isEmpty);
202 expect(args.command.command.name, equals('subcmd')); 200 expect(args.command.command.name, equals('subcmd'));
203 expect(args.command.rest, isEmpty); 201 expect(args.command.rest, isEmpty);
204 expect(args.command.command.rest, equals(['other', 'stuff'])); 202 expect(args.command.command.rest, equals(['other', 'stuff']));
205 }); 203 });
206 }); 204 });
207 } 205 }
OLDNEW
« no previous file with comments | « test/args_test.dart ('k') | test/command_runner_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698