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

Side by Side Diff: pkg/matcher/lib/src/description.dart

Issue 814953002: Remove unittest and matcher from the repo. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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
« no previous file with comments | « pkg/matcher/lib/src/core_matchers.dart ('k') | pkg/matcher/lib/src/error_matchers.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, 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 matcher.description;
6
7 import 'interfaces.dart';
8 import 'pretty_print.dart';
9
10 /// The default implementation of [Description]. This should rarely need
11 /// substitution, although conceivably it is a place where other languages
12 /// could be supported.
13 class StringDescription implements Description {
14 final StringBuffer _out = new StringBuffer();
15
16 /// Initialize the description with initial contents [init].
17 StringDescription([String init = '']) {
18 _out.write(init);
19 }
20
21 int get length => _out.length;
22
23 /// Get the description as a string.
24 String toString() => _out.toString();
25
26 /// Append [text] to the description.
27 Description add(String text) {
28 _out.write(text);
29 return this;
30 }
31
32 /// Change the value of the description.
33 Description replace(String text) {
34 _out.clear();
35 return add(text);
36 }
37
38 /// Appends a description of [value]. If it is an IMatcher use its
39 /// describe method; if it is a string use its literal value after
40 /// escaping any embedded control characters; otherwise use its
41 /// toString() value and wrap it in angular "quotes".
42 Description addDescriptionOf(value) {
43 if (value is Matcher) {
44 value.describe(this);
45 } else {
46 add(prettyPrint(value, maxLineLength: 80, maxItems: 25));
47 }
48 return this;
49 }
50
51 /// Append an [Iterable] [list] of objects to the description, using the
52 /// specified [separator] and framing the list with [start]
53 /// and [end].
54 Description addAll(String start, String separator, String end,
55 Iterable list) {
56 var separate = false;
57 add(start);
58 for (var item in list) {
59 if (separate) {
60 add(separator);
61 }
62 addDescriptionOf(item);
63 separate = true;
64 }
65 add(end);
66 return this;
67 }
68 }
OLDNEW
« no previous file with comments | « pkg/matcher/lib/src/core_matchers.dart ('k') | pkg/matcher/lib/src/error_matchers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698