| OLD | NEW |
| 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() { |
| 11 group('ArgParser.getUsage()', () { | 11 group('ArgParser.usage', () { |
| 12 test('negatable flags show "no-" in title', () { | 12 test('negatable flags show "no-" in title', () { |
| 13 var parser = new ArgParser(); | 13 var parser = new ArgParser(); |
| 14 parser.addFlag('mode', help: 'The mode'); | 14 parser.addFlag('mode', help: 'The mode'); |
| 15 | 15 |
| 16 validateUsage(parser, | 16 validateUsage(parser, |
| 17 ''' | 17 ''' |
| 18 --[no-]mode The mode | 18 --[no-]mode The mode |
| 19 '''); | 19 '''); |
| 20 }); | 20 }); |
| 21 | 21 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 ''' | 218 ''' |
| 219 --[no-]first The first flag | 219 --[no-]first The first flag |
| 220 --[no-]third The third flag | 220 --[no-]third The third flag |
| 221 '''); | 221 '''); |
| 222 }); | 222 }); |
| 223 }); | 223 }); |
| 224 } | 224 } |
| 225 | 225 |
| 226 void validateUsage(ArgParser parser, String expected) { | 226 void validateUsage(ArgParser parser, String expected) { |
| 227 expected = unindentString(expected); | 227 expected = unindentString(expected); |
| 228 expect(parser.getUsage(), equals(expected)); | 228 expect(parser.usage, equals(expected)); |
| 229 } | 229 } |
| 230 | 230 |
| 231 // TODO(rnystrom): Replace one in test_utils. | 231 // TODO(rnystrom): Replace one in test_utils. |
| 232 String unindentString(String text) { | 232 String unindentString(String text) { |
| 233 var lines = text.split('\n'); | 233 var lines = text.split('\n'); |
| 234 | 234 |
| 235 // Count the indentation of the last line. | 235 // Count the indentation of the last line. |
| 236 var whitespace = new RegExp('^ *'); | 236 var whitespace = new RegExp('^ *'); |
| 237 var indent = whitespace.firstMatch(lines[lines.length - 1])[0].length; | 237 var indent = whitespace.firstMatch(lines[lines.length - 1])[0].length; |
| 238 | 238 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 255 throw new ArgumentError( | 255 throw new ArgumentError( |
| 256 'Line "$line" does not have enough indentation.'); | 256 'Line "$line" does not have enough indentation.'); |
| 257 } | 257 } |
| 258 | 258 |
| 259 lines[i] = line.substring(indent); | 259 lines[i] = line.substring(indent); |
| 260 } | 260 } |
| 261 } | 261 } |
| 262 | 262 |
| 263 return lines.join('\n'); | 263 return lines.join('\n'); |
| 264 } | 264 } |
| OLD | NEW |