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

Side by Side Diff: test/usage_test.dart

Issue 1145413002: Add support for separators. (Closed) Base URL: git@github.com:dart-lang/args@master
Patch Set: Code review changes Created 5 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
« no previous file with comments | « pubspec.yaml ('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 usage_test; 5 library usage_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 9
10 void main() { 10 void main() {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 var parser = new ArgParser(); 198 var parser = new ArgParser();
199 parser.addFlag('first', help: 'The first flag'); 199 parser.addFlag('first', help: 'The first flag');
200 parser.addFlag('second-very-long-option', hide: true); 200 parser.addFlag('second-very-long-option', hide: true);
201 parser.addFlag('third', help: 'The third flag'); 201 parser.addFlag('third', help: 'The third flag');
202 202
203 validateUsage(parser, ''' 203 validateUsage(parser, '''
204 --[no-]first The first flag 204 --[no-]first The first flag
205 --[no-]third The third flag 205 --[no-]third The third flag
206 '''); 206 ''');
207 }); 207 });
208
209 group("separators", () {
210 test("separates options where it's placed", () {
211 var parser = new ArgParser();
212 parser.addFlag('zebra', help: 'First');
213 parser.addSeparator('Primate:');
214 parser.addFlag('monkey', help: 'Second');
215 parser.addSeparator('Marsupial:');
216 parser.addFlag('wombat', help: 'Third');
217
218 validateUsage(parser, '''
219 --[no-]zebra First
220
221 Primate:
222 --[no-]monkey Second
223
224 Marsupial:
225 --[no-]wombat Third
226 ''');
227 });
228
229 test("doesn't add extra newlines after a multiline option", () {
230 var parser = new ArgParser();
231 parser.addFlag('zebra', help: 'Multi\nline');
232 parser.addSeparator('Primate:');
233 parser.addFlag('monkey', help: 'Second');
234
235 validateUsage(parser, '''
236 --[no-]zebra Multi
237 line
238
239 Primate:
240 --[no-]monkey Second
241 ''');
242 });
243
244 test("doesn't add newlines if it's the first component", () {
245 var parser = new ArgParser();
246 parser.addSeparator('Equine:');
247 parser.addFlag('zebra', help: 'First');
248
249 validateUsage(parser, '''
250 Equine:
251 --[no-]zebra First
252 ''');
253 });
254
255 test("doesn't add trailing newlines if it's the last component", () {
256 var parser = new ArgParser();
257 parser.addFlag('zebra', help: 'First');
258 parser.addSeparator('Primate:');
259
260 validateUsage(parser, '''
261 --[no-]zebra First
262
263 Primate:
264 ''');
265 });
266
267 test("adds a newline after another separator", () {
268 var parser = new ArgParser();
269 parser.addSeparator('First');
270 parser.addSeparator('Second');
271
272 validateUsage(parser, '''
273 First
274
275 Second
276 ''');
277 });
278 });
208 }); 279 });
209 } 280 }
210 281
211 void validateUsage(ArgParser parser, String expected) { 282 void validateUsage(ArgParser parser, String expected) {
212 expected = unindentString(expected); 283 expected = unindentString(expected);
213 expect(parser.usage, equals(expected)); 284 expect(parser.usage, equals(expected));
214 } 285 }
215 286
216 // TODO(rnystrom): Replace one in test_utils. 287 // TODO(rnystrom): Replace one in test_utils.
217 String unindentString(String text) { 288 String unindentString(String text) {
(...skipping 22 matching lines...) Expand all
240 throw new ArgumentError( 311 throw new ArgumentError(
241 'Line "$line" does not have enough indentation.'); 312 'Line "$line" does not have enough indentation.');
242 } 313 }
243 314
244 lines[i] = line.substring(indent); 315 lines[i] = line.substring(indent);
245 } 316 }
246 } 317 }
247 318
248 return lines.join('\n'); 319 return lines.join('\n');
249 } 320 }
OLDNEW
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698