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

Unified Diff: lib/unittest/description.dart

Issue 10441104: New expectation functions plus convert old tests to use these. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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/unittest/core_matchers.dart ('k') | lib/unittest/expect.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/unittest/description.dart
===================================================================
--- lib/unittest/description.dart (revision 0)
+++ lib/unittest/description.dart (revision 0)
@@ -0,0 +1,92 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+/**
+ * The default implementation of IDescription. This should rarely need
+ * substitution, although conceivably it is a place where other languages
+ * could be supported.
+ */
+
+class StringDescription implements Description {
+ var _out = '';
+
+ /**
+ * Get the description as a string.
+ */
+ String toString() => _out;
+
+ /**
+ * Append some plain [text] to the description.
+ */
+ Description add(String text) {
+ _out = '${_out}${text}';
+ return this;
+ }
+
+ /**
+ * Appends a description of [value]. If it is an IMatcher use its
+ * describe method; if it is a string use its literal value after
+ * escaping any embedded control characters; otherwise use its
+ * toString() value and wrap it in angular "quotes".
+ */
+ Description addDescriptionOf(value) {
+ if (value is Matcher) {
+ value.describe(this);
+ } else if (value is String) {
+ _addEscapedString(value);
+ } else {
+ String description = (value == null) ? "null" : value.toString();
+ if (description.startsWith('<') && description.endsWith('>')) {
+ add(description);
+ } else {
+ add('<');
+ add(description);
+ add('>');
+ }
+ }
+ return this;
+ }
+
+ /**
+ * Append an [Iterable] [list] of objects to the description, using the
+ * specified [separator] and framing the list with [start]
+ * and [end].
+ */
+ Description addAll(String start, String separator, String end,
+ Iterable list) {
+ var separate = false;
+ add(start);
+ for (var item in list) {
+ if (separate) {
+ add(separator);
+ }
+ addDescriptionOf(item);
+ separate = true;
+ }
+ add(end);
+ return this;
+ }
+
+ /** Escape the control characters in [string] so that they are visible. */
+ _addEscapedString(String string) {
+ add("'");
+ for (var i = 0; i < string.length; i++) {
+ add(_escape(string[i]));
+ }
+ add("'");
+ }
+
+ /** Return the escaped form of a character [ch]. */
+ _escape(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;
+ }
+}
« no previous file with comments | « lib/unittest/core_matchers.dart ('k') | lib/unittest/expect.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698