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

Side by Side Diff: test/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/command_test.dart ('k') | test/trailing_options_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 parse_test; 5 library 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 throwsFormat(parser, ['--no-strum']); 98 throwsFormat(parser, ['--no-strum']);
99 }); 99 });
100 }); 100 });
101 101
102 group('callbacks', () { 102 group('callbacks', () {
103 test('for present flags are invoked with the value', () { 103 test('for present flags are invoked with the value', () {
104 var a; 104 var a;
105 var parser = new ArgParser(); 105 var parser = new ArgParser();
106 parser.addFlag('a', callback: (value) => a = value); 106 parser.addFlag('a', callback: (value) => a = value);
107 107
108 var args = parser.parse(['--a']); 108 parser.parse(['--a']);
109 expect(a, isTrue); 109 expect(a, isTrue);
110 }); 110 });
111 111
112 test('for absent flags are invoked with the default value', () { 112 test('for absent flags are invoked with the default value', () {
113 var a; 113 var a;
114 var parser = new ArgParser(); 114 var parser = new ArgParser();
115 parser.addFlag('a', defaultsTo: false, 115 parser.addFlag('a', defaultsTo: false, callback: (value) => a = value);
116 callback: (value) => a = value);
117 116
118 var args = parser.parse([]); 117 parser.parse([]);
119 expect(a, isFalse); 118 expect(a, isFalse);
120 }); 119 });
121 120
122 test('are invoked even if the flag is not present', () { 121 test('are invoked even if the flag is not present', () {
123 var a = 'not called'; 122 var a = 'not called';
124 var parser = new ArgParser(); 123 var parser = new ArgParser();
125 parser.addFlag('a', callback: (value) => a = value); 124 parser.addFlag('a', callback: (value) => a = value);
126 125
127 var args = parser.parse([]); 126 parser.parse([]);
128 expect(a, isFalse); 127 expect(a, isFalse);
129 }); 128 });
130 129
131 test('for present options are invoked with the value', () { 130 test('for present options are invoked with the value', () {
132 var a; 131 var a;
133 var parser = new ArgParser(); 132 var parser = new ArgParser();
134 parser.addOption('a', callback: (value) => a = value); 133 parser.addOption('a', callback: (value) => a = value);
135 134
136 var args = parser.parse(['--a=v']); 135 parser.parse(['--a=v']);
137 expect(a, equals('v')); 136 expect(a, equals('v'));
138 }); 137 });
139 138
140 test('for absent options are invoked with the default value', () { 139 test('for absent options are invoked with the default value', () {
141 var a; 140 var a;
142 var parser = new ArgParser(); 141 var parser = new ArgParser();
143 parser.addOption('a', defaultsTo: 'v', 142 parser.addOption('a', defaultsTo: 'v', callback: (value) => a = value);
144 callback: (value) => a = value);
145 143
146 var args = parser.parse([]); 144 parser.parse([]);
147 expect(a, equals('v')); 145 expect(a, equals('v'));
148 }); 146 });
149 147
150 test('are invoked even if the option is not present', () { 148 test('are invoked even if the option is not present', () {
151 var a = 'not called'; 149 var a = 'not called';
152 var parser = new ArgParser(); 150 var parser = new ArgParser();
153 parser.addOption('a', callback: (value) => a = value); 151 parser.addOption('a', callback: (value) => a = value);
154 152
155 var args = parser.parse([]); 153 parser.parse([]);
156 expect(a, isNull); 154 expect(a, isNull);
157 }); 155 });
158 156
159 test('for multiple present, allowMultiple, options are invoked with ' 157 test('for multiple present, allowMultiple, options are invoked with '
160 'value as a list', () { 158 'value as a list', () {
161 var a; 159 var a;
162 var parser = new ArgParser(); 160 var parser = new ArgParser();
163 parser.addOption('a', allowMultiple: true, 161 parser.addOption('a',
164 callback: (value) => a = value); 162 allowMultiple: true, callback: (value) => a = value);
165 163
166 var args = parser.parse(['--a=v', '--a=x']); 164 parser.parse(['--a=v', '--a=x']);
167 expect(a, equals(['v', 'x'])); 165 expect(a, equals(['v', 'x']));
168 }); 166 });
169 167
170 test('for single present, allowMultiple, options are invoked with ' 168 test('for single present, allowMultiple, options are invoked with '
171 ' value as a single element list', () { 169 ' value as a single element list', () {
172 var a; 170 var a;
173 var parser = new ArgParser(); 171 var parser = new ArgParser();
174 parser.addOption('a', allowMultiple: true, 172 parser.addOption('a',
175 callback: (value) => a = value); 173 allowMultiple: true, callback: (value) => a = value);
176 174
177 var args = parser.parse(['--a=v']); 175 parser.parse(['--a=v']);
178 expect(a, equals(['v'])); 176 expect(a, equals(['v']));
179 }); 177 });
180 178
181 test('for absent, allowMultiple, options are invoked with default ' 179 test('for absent, allowMultiple, options are invoked with default '
182 'value as a list.', () { 180 'value as a list.', () {
183 var a; 181 var a;
184 var parser = new ArgParser(); 182 var parser = new ArgParser();
185 parser.addOption('a', allowMultiple: true, defaultsTo: 'v', 183 parser.addOption('a',
184 allowMultiple: true,
185 defaultsTo: 'v',
186 callback: (value) => a = value); 186 callback: (value) => a = value);
187 187
188 var args = parser.parse([]); 188 parser.parse([]);
189 expect(a, equals(['v'])); 189 expect(a, equals(['v']));
190 }); 190 });
191 191
192 test('for absent, allowMultiple, options are invoked with value ' 192 test('for absent, allowMultiple, options are invoked with value '
193 'as an empty list.', () { 193 'as an empty list.', () {
194 var a; 194 var a;
195 var parser = new ArgParser(); 195 var parser = new ArgParser();
196 parser.addOption('a', allowMultiple: true, 196 parser.addOption('a',
197 callback: (value) => a = value); 197 allowMultiple: true, callback: (value) => a = value);
198 198
199 var args = parser.parse([]); 199 parser.parse([]);
200 expect(a, isEmpty); 200 expect(a, isEmpty);
201 }); 201 });
202 }); 202 });
203 203
204 group('abbreviations', () { 204 group('abbreviations', () {
205 test('are parsed with a preceding "-"', () { 205 test('are parsed with a preceding "-"', () {
206 var parser = new ArgParser(); 206 var parser = new ArgParser();
207 parser.addFlag('arg', abbr: 'a'); 207 parser.addFlag('arg', abbr: 'a');
208 208
209 var args = parser.parse(['-a']); 209 var args = parser.parse(['-a']);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 var args = parser.parse(['--define=1', '--define=2']); 385 var args = parser.parse(['--define=1', '--define=2']);
386 expect(args['define'], equals('2')); 386 expect(args['define'], equals('2'));
387 }); 387 });
388 388
389 test('returns a List if multi-valued', () { 389 test('returns a List if multi-valued', () {
390 var parser = new ArgParser(); 390 var parser = new ArgParser();
391 parser.addOption('define', allowMultiple: true); 391 parser.addOption('define', allowMultiple: true);
392 var args = parser.parse(['--define=1']); 392 var args = parser.parse(['--define=1']);
393 expect(args['define'], equals(['1'])); 393 expect(args['define'], equals(['1']));
394 args = parser.parse(['--define=1', '--define=2']); 394 args = parser.parse(['--define=1', '--define=2']);
395 expect(args['define'], equals(['1','2'])); 395 expect(args['define'], equals(['1', '2']));
396 }); 396 });
397 397
398 test('returns the default value for multi-valued arguments ' 398 test('returns the default value for multi-valued arguments '
399 'if not explicitly set', () { 399 'if not explicitly set', () {
400 var parser = new ArgParser(); 400 var parser = new ArgParser();
401 parser.addOption('define', defaultsTo: '0', allowMultiple: true); 401 parser.addOption('define', defaultsTo: '0', allowMultiple: true);
402 var args = parser.parse(['']); 402 var args = parser.parse(['']);
403 expect(args['define'], equals(['0'])); 403 expect(args['define'], equals(['0']));
404 }); 404 });
405 405
406 test('are case-sensitive', () { 406 test('are case-sensitive', () {
407 var parser = new ArgParser(); 407 var parser = new ArgParser();
408 parser.addOption('verbose', defaultsTo: 'no'); 408 parser.addOption('verbose', defaultsTo: 'no');
409 parser.addOption('Verbose', defaultsTo: 'no'); 409 parser.addOption('Verbose', defaultsTo: 'no');
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 var parser = new ArgParser(); 442 var parser = new ArgParser();
443 parser.addFlag('woof'); 443 parser.addFlag('woof');
444 444
445 var results = parser.parse(['--woof', 'stop', '--', 'arg']); 445 var results = parser.parse(['--woof', 'stop', '--', 'arg']);
446 expect(results['woof'], isTrue); 446 expect(results['woof'], isTrue);
447 expect(results.rest, equals(['stop', '--', 'arg'])); 447 expect(results.rest, equals(['stop', '--', 'arg']));
448 }); 448 });
449 }); 449 });
450 }); 450 });
451 } 451 }
OLDNEW
« no previous file with comments | « test/command_test.dart ('k') | test/trailing_options_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698