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

Unified Diff: lib/src/pretty_print.dart

Issue 840133003: matcher: fixed status file, formatting, tweaks to readme (Closed) Base URL: https://github.com/dart-lang/matcher.git@master
Patch Set: nits Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/operator_matchers.dart ('k') | lib/src/prints_matcher.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/pretty_print.dart
diff --git a/lib/src/pretty_print.dart b/lib/src/pretty_print.dart
index eb13448bfa07fe26ed6df88c94c2fc6634647c89..df93dbb013fe3af7a815c19e17529e280a4343ce 100644
--- a/lib/src/pretty_print.dart
+++ b/lib/src/pretty_print.dart
@@ -80,8 +80,9 @@ String prettyPrint(object, {int maxLineLength, int maxItems}) {
} else if (object is String) {
// Escape strings and print each line on its own line.
var lines = object.split("\n");
- return "'" + lines.map(_escapeString)
- .join("\\n'\n${_indent(indent + 2)}'") + "'";
+ return "'" +
+ lines.map(_escapeString).join("\\n'\n${_indent(indent + 2)}'") +
+ "'";
} else {
var value = object.toString().replaceAll("\n", _indent(indent) + "\n");
var defaultToString = value.startsWith("Instance of ");
@@ -93,8 +94,11 @@ String prettyPrint(object, {int maxLineLength, int maxItems}) {
// Print the type of objects with custom [toString] methods. Primitive
// objects and objects that don't implement a custom [toString] don't need
// to have their types printed.
- if (object is num || object is bool || object is Function ||
- object == null || defaultToString) {
+ if (object is num ||
+ object is bool ||
+ object is Function ||
+ object == null ||
+ defaultToString) {
return value;
} else {
return "${_typeName(object)}:$value";
@@ -129,19 +133,20 @@ String _typeName(x) {
/// This doesn't add quotes to the string, but it does escape single quote
/// characters so that single quotes can be applied externally.
String _escapeString(String source) =>
- source.split("").map(_escapeChar).join("");
+ source.split("").map(_escapeChar).join("");
/// Return the escaped form of a character [ch].
String _escapeChar(String ch) {
- if (ch == "'")
- return "\\'";
- else if (ch == '\n')
- return '\\n';
- else if (ch == '\r')
- return '\\r';
- else if (ch == '\t')
- return '\\t';
- else
- return ch;
+ switch (ch) {
+ case "'":
+ return "\\'";
+ case '\n':
+ return '\\n';
+ case '\r':
+ return '\\r';
+ case '\t':
+ return '\\t';
+ default:
+ return ch;
+ }
}
-
« no previous file with comments | « lib/src/operator_matchers.dart ('k') | lib/src/prints_matcher.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698