| 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 args_test; | 5 library args_test; |
| 6 | 6 |
| 7 import '../../../pkg/unittest/lib/unittest.dart'; | 7 import '../../../pkg/unittest/lib/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 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 validateUsage(ArgParser parser, String expected) { | 674 validateUsage(ArgParser parser, String expected) { |
| 675 expected = unindentString(expected); | 675 expected = unindentString(expected); |
| 676 expect(parser.getUsage(), equals(expected)); | 676 expect(parser.getUsage(), equals(expected)); |
| 677 } | 677 } |
| 678 | 678 |
| 679 // TODO(rnystrom): Replace one in test_utils. | 679 // TODO(rnystrom): Replace one in test_utils. |
| 680 String unindentString(String text) { | 680 String unindentString(String text) { |
| 681 var lines = text.split('\n'); | 681 var lines = text.split('\n'); |
| 682 | 682 |
| 683 // Count the indentation of the last line. | 683 // Count the indentation of the last line. |
| 684 var whitespace = new RegExp('^ *'); | 684 var whitespace = const RegExp('^ *'); |
| 685 var indent = whitespace.firstMatch(lines[lines.length - 1])[0].length; | 685 var indent = whitespace.firstMatch(lines[lines.length - 1])[0].length; |
| 686 | 686 |
| 687 // Drop the last line. It only exists for specifying indentation. | 687 // Drop the last line. It only exists for specifying indentation. |
| 688 lines.removeLast(); | 688 lines.removeLast(); |
| 689 | 689 |
| 690 // Strip indentation from the remaining lines. | 690 // Strip indentation from the remaining lines. |
| 691 for (var i = 0; i < lines.length; i++) { | 691 for (var i = 0; i < lines.length; i++) { |
| 692 var line = lines[i]; | 692 var line = lines[i]; |
| 693 if (line.length <= indent) { | 693 if (line.length <= indent) { |
| 694 // It's short, so it must be nothing but whitespace. | 694 // It's short, so it must be nothing but whitespace. |
| 695 if (line.trim() != '') { | 695 if (line.trim() != '') { |
| 696 throw new ArgumentError( | 696 throw new ArgumentError( |
| 697 'Line "$line" does not have enough indentation.'); | 697 'Line "$line" does not have enough indentation.'); |
| 698 } | 698 } |
| 699 | 699 |
| 700 lines[i] = ''; | 700 lines[i] = ''; |
| 701 } else { | 701 } else { |
| 702 if (line.substring(0, indent).trim() != '') { | 702 if (line.substring(0, indent).trim() != '') { |
| 703 throw new ArgumentError( | 703 throw new ArgumentError( |
| 704 'Line "$line" does not have enough indentation.'); | 704 'Line "$line" does not have enough indentation.'); |
| 705 } | 705 } |
| 706 | 706 |
| 707 lines[i] = line.substring(indent); | 707 lines[i] = line.substring(indent); |
| 708 } | 708 } |
| 709 } | 709 } |
| 710 | 710 |
| 711 return Strings.join(lines, '\n'); | 711 return Strings.join(lines, '\n'); |
| 712 } | 712 } |
| OLD | NEW |