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

Side by Side Diff: tests/utils/src/test_utils.dart

Issue 10153004: Add a basic YAML processor. Much of the language is still unimplemented. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: More code review changes. Created 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #library('test_utils');
6
7 /**
8 * Removes eight spaces of leading indentation from a multiline string.
9 *
10 * Note that this is very sensitive to how the literals are styled. They should
11 * be:
12 * '''
13 * Text starts on own line. Lines up with subsequent lines.
14 * Lines are indented exactly 8 characters from the left margin.
15 * Close is on the same line.'''
16 *
17 * This does nothing if text is only a single line.
18 */
19 String cleanUpLiteral(String text) {
20 var lines = text.split('\n');
21 if (lines.length <= 1) return text;
22
23 for (var j = 0; j < lines.length; j++) {
24 if (lines[j].length > 8) {
25 lines[j] = lines[j].substring(8, lines[j].length);
26 } else {
27 lines[j] = '';
28 }
29 }
30
31 return Strings.join(lines, '\n');
32 }
33
34 /**
35 * Indents each line of [text] so that, when passed to [cleanUpLiteral], it will
36 * produce output identical to [text].
37 *
38 * This is useful for literals that need to include newlines but can't be
39 * conveniently represented as multi-line strings.
40 */
41 String indentLiteral(String text) {
42 var lines = text.split('\n');
43 if (lines.length <= 1) return text;
44
45 for (var i = 0; i < lines.length; i++) {
46 lines[i] = " ${lines[i]}";
47 }
48
49 return Strings.join(lines, "\n");
50 }
OLDNEW
« no previous file with comments | « tests/utils/src/YamlTest.dart ('k') | tests/utils/utils.status » ('j') | tools/test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698