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

Side by Side Diff: pkg/unittest/lib/src/utils.dart

Issue 14600029: Add pretty-printing to unittest and more thoroughly print values. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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) 2013, 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 utils;
6
7 /**
8 * Returns the name of the type of [x], or "Unknown" if the type name can't be
9 * determined.
10 */
11 String typeName(x) {
12 // dart2js blows up on some objects (e.g. window.navigator).
13 // So we play safe here.
14 try {
15 if (x == null) return "null";
16 return x.runtimeType.toString();
17 } catch (e) {
18 return "Unknown";
19 }
20 }
21
22 /**
23 * Returns [source] with any control characters replaced by their escape
24 * sequences.
25 *
26 * This doesn't add quotes to the string, but it does escape single quote
27 * characters so that single quotes can be applied externally.
28 */
29 String escapeString(String source) =>
30 source.split("").map(_escapeChar).join("");
31
32 /** Return the escaped form of a character [ch]. */
33 String _escapeChar(String ch) {
34 if (ch == "'")
35 return "\\'";
36 else if (ch == '\n')
37 return '\\n';
38 else if (ch == '\r')
39 return '\\r';
40 else if (ch == '\t')
41 return '\\t';
42 else
43 return ch;
44 }
45
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698