OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 test_utils; | 5 library test_utils; |
6 | 6 |
7 /** | 7 /** |
8 * Removes eight spaces of leading indentation from a multiline string. | 8 * Removes eight spaces of leading indentation from a multiline string. |
9 * | 9 * |
10 * Note that this is very sensitive to how the literals are styled. They should | 10 * Note that this is very sensitive to how the literals are styled. They should |
(...skipping 12 matching lines...) Expand all Loading... |
23 if (lines.length <= 1) return text; | 23 if (lines.length <= 1) return text; |
24 | 24 |
25 for (var j = 0; j < lines.length; j++) { | 25 for (var j = 0; j < lines.length; j++) { |
26 if (lines[j].length > 8) { | 26 if (lines[j].length > 8) { |
27 lines[j] = lines[j].substring(8, lines[j].length); | 27 lines[j] = lines[j].substring(8, lines[j].length); |
28 } else { | 28 } else { |
29 lines[j] = ''; | 29 lines[j] = ''; |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
33 return Strings.join(lines, '\n'); | 33 return lines.join('\n'); |
34 } | 34 } |
35 | 35 |
36 /** | 36 /** |
37 * Indents each line of [text] so that, when passed to [cleanUpLiteral], it will | 37 * Indents each line of [text] so that, when passed to [cleanUpLiteral], it will |
38 * produce output identical to [text]. | 38 * produce output identical to [text]. |
39 * | 39 * |
40 * This is useful for literals that need to include newlines but can't be | 40 * This is useful for literals that need to include newlines but can't be |
41 * conveniently represented as multi-line strings. | 41 * conveniently represented as multi-line strings. |
42 */ | 42 */ |
43 // TODO(nweiz): Once cleanUpLiteral is fixed, get rid of this. | 43 // TODO(nweiz): Once cleanUpLiteral is fixed, get rid of this. |
44 String indentLiteral(String text) { | 44 String indentLiteral(String text) { |
45 var lines = text.split('\n'); | 45 var lines = text.split('\n'); |
46 if (lines.length <= 1) return text; | 46 if (lines.length <= 1) return text; |
47 | 47 |
48 for (var i = 0; i < lines.length; i++) { | 48 for (var i = 0; i < lines.length; i++) { |
49 lines[i] = " ${lines[i]}"; | 49 lines[i] = " ${lines[i]}"; |
50 } | 50 } |
51 | 51 |
52 return Strings.join(lines, "\n"); | 52 return lines.join("\n"); |
53 } | 53 } |
OLD | NEW |