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

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

Issue 10914320: change addOption callback argument from bool to Dynamic (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Correct annotations and add tests. Created 8 years, 3 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/args.dart ('k') | no next file » | 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('args_test'); 5 #library('args_test');
6 6
7 #import('../../unittest/unittest.dart'); 7 #import('../../unittest/unittest.dart');
8 8
9 // TODO(rnystrom): Use "package:" URL here when test.dart can handle pub. 9 // TODO(rnystrom): Use "package:" URL here when test.dart can handle pub.
10 #import('../lib/args.dart'); 10 #import('../lib/args.dart');
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 }); 182 });
183 183
184 test('are invoked even if the option is not present', () { 184 test('are invoked even if the option is not present', () {
185 var a = 'not called'; 185 var a = 'not called';
186 var parser = new ArgParser(); 186 var parser = new ArgParser();
187 parser.addOption('a', callback: (value) => a = value); 187 parser.addOption('a', callback: (value) => a = value);
188 188
189 var args = parser.parse([]); 189 var args = parser.parse([]);
190 expect(a, isNull); 190 expect(a, isNull);
191 }); 191 });
192
193 test('for multiple present, allowMultiple, options are invoked with '
194 'value as a list', () {
195 var a;
196 var parser = new ArgParser();
197 parser.addOption('a', allowMultiple: true,
198 callback: (value) => a = value);
199
200 var args = parser.parse(['--a=v', '--a=x']);
201 expect(a, equals(['v', 'x']));
202 });
203
204 test('for single present, allowMultiple, options are invoked with '
205 ' value as a single element list', () {
206 var a;
207 var parser = new ArgParser();
208 parser.addOption('a', allowMultiple: true,
209 callback: (value) => a = value);
210
211 var args = parser.parse(['--a=v']);
212 expect(a, equals(['v']));
213 });
214
215 test('for absent, allowMultiple, options are invoked with default '
216 'value as a list.', () {
217 var a;
218 var parser = new ArgParser();
219 parser.addOption('a', allowMultiple: true, defaultsTo: 'v',
220 callback: (value) => a = value);
221
222 var args = parser.parse([]);
223 expect(a, equals(['v']));
224 });
225
226 test('for absent, allowMultiple, options are invoked with value '
227 'as an empty list.', () {
228 var a;
229 var parser = new ArgParser();
230 parser.addOption('a', allowMultiple: true,
231 callback: (value) => a = value);
232
233 var args = parser.parse([]);
234 expect(a, isEmpty);
235 });
192 }); 236 });
193 237
194 group('abbreviations', () { 238 group('abbreviations', () {
195 test('are parsed with a preceding "-"', () { 239 test('are parsed with a preceding "-"', () {
196 var parser = new ArgParser(); 240 var parser = new ArgParser();
197 parser.addFlag('arg', abbr: 'a'); 241 parser.addFlag('arg', abbr: 'a');
198 242
199 var args = parser.parse(['-a']); 243 var args = parser.parse(['-a']);
200 expect(args['arg'], isTrue); 244 expect(args['arg'], isTrue);
201 }); 245 });
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 throw new IllegalArgumentException( 703 throw new IllegalArgumentException(
660 'Line "$line" does not have enough indentation.'); 704 'Line "$line" does not have enough indentation.');
661 } 705 }
662 706
663 lines[i] = line.substring(indent); 707 lines[i] = line.substring(indent);
664 } 708 }
665 } 709 }
666 710
667 return Strings.join(lines, '\n'); 711 return Strings.join(lines, '\n');
668 } 712 }
OLDNEW
« no previous file with comments | « pkg/args/lib/args.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698