| 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 main() { | 10 void main() { |
| 11 group('ArgParser.getUsage()', () { | 11 group('ArgParser.getUsage()', () { |
| 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 }); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 177 |
| 178 validateUsage(parser, | 178 validateUsage(parser, |
| 179 ''' | 179 ''' |
| 180 --first The first option | 180 --first The first option |
| 181 --third The third option | 181 --third The third option |
| 182 '''); | 182 '''); |
| 183 }); | 183 }); |
| 184 }); | 184 }); |
| 185 } | 185 } |
| 186 | 186 |
| 187 throwsIllegalArg(function) { | 187 void validateUsage(ArgParser parser, String expected) { |
| 188 expect(function, throwsArgumentError); | |
| 189 } | |
| 190 | |
| 191 validateUsage(ArgParser parser, String expected) { | |
| 192 expected = unindentString(expected); | 188 expected = unindentString(expected); |
| 193 expect(parser.getUsage(), equals(expected)); | 189 expect(parser.getUsage(), equals(expected)); |
| 194 } | 190 } |
| 195 | 191 |
| 196 // TODO(rnystrom): Replace one in test_utils. | 192 // TODO(rnystrom): Replace one in test_utils. |
| 197 String unindentString(String text) { | 193 String unindentString(String text) { |
| 198 var lines = text.split('\n'); | 194 var lines = text.split('\n'); |
| 199 | 195 |
| 200 // Count the indentation of the last line. | 196 // Count the indentation of the last line. |
| 201 var whitespace = new RegExp('^ *'); | 197 var whitespace = new RegExp('^ *'); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 220 throw new ArgumentError( | 216 throw new ArgumentError( |
| 221 'Line "$line" does not have enough indentation.'); | 217 'Line "$line" does not have enough indentation.'); |
| 222 } | 218 } |
| 223 | 219 |
| 224 lines[i] = line.substring(indent); | 220 lines[i] = line.substring(indent); |
| 225 } | 221 } |
| 226 } | 222 } |
| 227 | 223 |
| 228 return lines.join('\n'); | 224 return lines.join('\n'); |
| 229 } | 225 } |
| OLD | NEW |