Index: pkg/http/test/utils.dart |
diff --git a/pkg/http/test/utils.dart b/pkg/http/test/utils.dart |
index 606bb77cae4e4f0a3e03ccf927c0dca82b9c9b09..4ffa195fd46b0511ae06bf93403800006b28ede1 100644 |
--- a/pkg/http/test/utils.dart |
+++ b/pkg/http/test/utils.dart |
@@ -109,6 +109,33 @@ void stopServer() { |
_server = null; |
} |
+/// Removes eight spaces of leading indentation from a multiline string. |
+/// |
+/// Note that this is very sensitive to how the literals are styled. They should |
+/// be: |
+/// ''' |
+/// Text starts on own line. Lines up with subsequent lines. |
+/// Lines are indented exactly 8 characters from the left margin. |
+/// Close is on the same line.''' |
+/// |
+/// This does nothing if text is only a single line. |
+// TODO(nweiz): Make this auto-detect the indentation level from the first |
+// non-whitespace line. |
+String cleanUpLiteral(String text) { |
+ var lines = text.split('\n'); |
+ if (lines.length <= 1) return text; |
+ |
+ for (var j = 0; j < lines.length; j++) { |
+ if (lines[j].length > 8) { |
+ lines[j] = lines[j].substring(8, lines[j].length); |
+ } else { |
+ lines[j] = ''; |
+ } |
+ } |
+ |
+ return lines.join('\n'); |
+} |
+ |
/// A matcher that matches JSON that parses to a value that matches the inner |
/// matcher. |
Matcher parse(matcher) => new _Parse(matcher); |