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

Unified Diff: dart/tools/testing/dart/utils.dart

Issue 36913002: test.py: Sending JSON between test_controller.js <-> browser_controller (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dart/tools/testing/dart/test_runner.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/tools/testing/dart/utils.dart
diff --git a/dart/tools/testing/dart/utils.dart b/dart/tools/testing/dart/utils.dart
index 661cd638032f0307dc6bcacef6bc99c4b399da2b..fb71f3fbef5c57d25696ed7304dc1fdaa5cba298 100644
--- a/dart/tools/testing/dart/utils.dart
+++ b/dart/tools/testing/dart/utils.dart
@@ -65,6 +65,53 @@ class DebugLogger {
static String get _datetime => "${new DateTime.now()}";
}
+String prettifyJson(Object json, {int startIndentation: 0, int shiftWidth: 6}) {
+ int currentIndentation = startIndentation;
+ var buffer = new StringBuffer();
+
+ String indentationString() {
+ return new List.filled(currentIndentation, ' ').join('');
+ }
+
+ addString(String s, {bool indentation: true, bool newLine: true}) {
+ if (indentation) {
+ buffer.write(indentationString());
+ }
+ buffer.write(s.replaceAll("\n", "\n${indentationString()}"));
+ if (newLine) buffer.write("\n");
+ }
+
+ prettifyJsonInternal(
+ Object obj, {bool indentation: true, bool newLine: true}) {
+ if (obj is List) {
+ addString("[", indentation: indentation);
+ currentIndentation += shiftWidth;
+ for (var item in obj) {
+
+ prettifyJsonInternal(item, indentation: indentation, newLine: false);
+ addString(",", indentation: false);
+ }
+ currentIndentation -= shiftWidth;
+ addString("]", indentation: indentation);
+ } else if (obj is Map) {
+ addString("{", indentation: indentation);
+ currentIndentation += shiftWidth;
+ for (var key in obj.keys) {
+ addString("$key: ", indentation: indentation, newLine: false);
+ currentIndentation += shiftWidth;
+ prettifyJsonInternal(obj[key], indentation: false);
+ currentIndentation -= shiftWidth;
+ }
+ currentIndentation -= shiftWidth;
+ addString("}", indentation: indentation, newLine: newLine);
+ } else {
+ addString("$obj", indentation: indentation, newLine: newLine);
+ }
+ }
+ prettifyJsonInternal(json);
+ return buffer.toString();
+}
+
/**
* [areByteArraysEqual] compares a range of bytes from [buffer1] with a
« no previous file with comments | « dart/tools/testing/dart/test_runner.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698