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

Side by Side Diff: pkg/matcher/test/pretty_print_test.dart

Issue 208823005: pkg/matcher (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: nit Created 6 years, 9 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
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'package:unittest/src/pretty_print.dart'; 5 import 'package:unittest/unittest.dart' as ut;
6 import 'package:unittest/unittest.dart'; 6
7 import 'package:matcher/matcher.dart';
8 import 'package:matcher/src/pretty_print.dart';
7 9
8 void main() { 10 void main() {
9 test('with primitive objects', () { 11 ut.test('with primitive objects', () {
10 expect(prettyPrint(12), equals('<12>')); 12 expect(prettyPrint(12), equals('<12>'));
11 expect(prettyPrint(12.13), equals('<12.13>')); 13 expect(prettyPrint(12.13), equals('<12.13>'));
12 expect(prettyPrint(true), equals('<true>')); 14 expect(prettyPrint(true), equals('<true>'));
13 expect(prettyPrint(null), equals('<null>')); 15 expect(prettyPrint(null), equals('<null>'));
14 expect(prettyPrint(() => 12), 16 expect(prettyPrint(() => 12),
15 matches(r'<Closure(: \(\) => dynamic)?>')); 17 matches(r'<Closure(: \(\) => dynamic)?>'));
16 }); 18 });
17 19
18 group('with a string', () { 20 ut.group('with a string', () {
19 test('containing simple characters', () { 21 ut.test('containing simple characters', () {
20 expect(prettyPrint('foo'), equals("'foo'")); 22 expect(prettyPrint('foo'), equals("'foo'"));
21 }); 23 });
22 24
23 test('containing newlines', () { 25 ut.test('containing newlines', () {
24 expect(prettyPrint('foo\nbar\nbaz'), equals( 26 expect(prettyPrint('foo\nbar\nbaz'), equals(
25 "'foo\\n'\n" 27 "'foo\\n'\n"
26 " 'bar\\n'\n" 28 " 'bar\\n'\n"
27 " 'baz'")); 29 " 'baz'"));
28 }); 30 });
29 31
30 test('containing escapable characters', () { 32 ut.test('containing escapable characters', () {
31 expect(prettyPrint("foo\rbar\tbaz'qux"), 33 expect(prettyPrint("foo\rbar\tbaz'qux"),
32 equals("'foo\\rbar\\tbaz\\'qux'")); 34 equals("'foo\\rbar\\tbaz\\'qux'"));
33 }); 35 });
34 }); 36 });
35 37
36 group('with an iterable', () { 38 ut.group('with an iterable', () {
37 test('containing primitive objects', () { 39 ut.test('containing primitive objects', () {
38 expect(prettyPrint([1, true, 'foo']), equals("[1, true, 'foo']")); 40 expect(prettyPrint([1, true, 'foo']), equals("[1, true, 'foo']"));
39 }); 41 });
40 42
41 test('containing a multiline string', () { 43 ut.test('containing a multiline string', () {
42 expect(prettyPrint(['foo', 'bar\nbaz\nbip', 'qux']), equals("[\n" 44 expect(prettyPrint(['foo', 'bar\nbaz\nbip', 'qux']), equals("[\n"
43 " 'foo',\n" 45 " 'foo',\n"
44 " 'bar\\n'\n" 46 " 'bar\\n'\n"
45 " 'baz\\n'\n" 47 " 'baz\\n'\n"
46 " 'bip',\n" 48 " 'bip',\n"
47 " 'qux'\n" 49 " 'qux'\n"
48 "]")); 50 "]"));
49 }); 51 });
50 52
51 test('containing a matcher', () { 53 ut.test('containing a matcher', () {
52 expect(prettyPrint(['foo', endsWith('qux')]), 54 expect(prettyPrint(['foo', endsWith('qux')]),
53 equals("['foo', <a string ending with 'qux'>]")); 55 equals("['foo', <a string ending with 'qux'>]"));
54 }); 56 });
55 57
56 test("that's under maxLineLength", () { 58 ut.test("that's under maxLineLength", () {
57 expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxLineLength: 30), 59 expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxLineLength: 30),
58 equals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]")); 60 equals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"));
59 }); 61 });
60 62
61 test("that's over maxLineLength", () { 63 ut.test("that's over maxLineLength", () {
62 expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxLineLength: 29), 64 expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxLineLength: 29),
63 equals("[\n" 65 equals("[\n"
64 " 0,\n" 66 " 0,\n"
65 " 1,\n" 67 " 1,\n"
66 " 2,\n" 68 " 2,\n"
67 " 3,\n" 69 " 3,\n"
68 " 4,\n" 70 " 4,\n"
69 " 5,\n" 71 " 5,\n"
70 " 6,\n" 72 " 6,\n"
71 " 7,\n" 73 " 7,\n"
72 " 8,\n" 74 " 8,\n"
73 " 9\n" 75 " 9\n"
74 "]")); 76 "]"));
75 }); 77 });
76 78
77 test("factors indentation into maxLineLength", () { 79 ut.test("factors indentation into maxLineLength", () {
78 expect(prettyPrint([ 80 expect(prettyPrint([
79 "foo\nbar", 81 "foo\nbar",
80 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 82 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
81 ], maxLineLength: 30), equals("[\n" 83 ], maxLineLength: 30), equals("[\n"
82 " 'foo\\n'\n" 84 " 'foo\\n'\n"
83 " 'bar',\n" 85 " 'bar',\n"
84 " [\n" 86 " [\n"
85 " 0,\n" 87 " 0,\n"
86 " 1,\n" 88 " 1,\n"
87 " 2,\n" 89 " 2,\n"
88 " 3,\n" 90 " 3,\n"
89 " 4,\n" 91 " 4,\n"
90 " 5,\n" 92 " 5,\n"
91 " 6,\n" 93 " 6,\n"
92 " 7,\n" 94 " 7,\n"
93 " 8,\n" 95 " 8,\n"
94 " 9\n" 96 " 9\n"
95 " ]\n" 97 " ]\n"
96 "]")); 98 "]"));
97 }); 99 });
98 100
99 test("that's under maxItems", () { 101 ut.test("that's under maxItems", () {
100 expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxItems: 10), 102 expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxItems: 10),
101 equals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]")); 103 equals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"));
102 }); 104 });
103 105
104 test("that's over maxItems", () { 106 ut.test("that's over maxItems", () {
105 expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxItems: 9), 107 expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxItems: 9),
106 equals("[0, 1, 2, 3, 4, 5, 6, 7, ...]")); 108 equals("[0, 1, 2, 3, 4, 5, 6, 7, ...]"));
107 }); 109 });
108 110
109 test("that's recursive", () { 111 ut.test("that's recursive", () {
110 var list = [1, 2, 3]; 112 var list = [1, 2, 3];
111 list.add(list); 113 list.add(list);
112 expect(prettyPrint(list), equals("[1, 2, 3, (recursive)]")); 114 expect(prettyPrint(list), equals("[1, 2, 3, (recursive)]"));
113 }); 115 });
114 }); 116 });
115 117
116 group("with a map", () { 118 ut.group("with a map", () {
117 test('containing primitive objects', () { 119 ut.test('containing primitive objects', () {
118 expect(prettyPrint({'foo': 1, 'bar': true}), 120 expect(prettyPrint({'foo': 1, 'bar': true}),
119 equals("{'foo': 1, 'bar': true}")); 121 equals("{'foo': 1, 'bar': true}"));
120 }); 122 });
121 123
122 test('containing a multiline string key', () { 124 ut.test('containing a multiline string key', () {
123 expect(prettyPrint({'foo\nbar': 1, 'bar': true}), equals("{\n" 125 expect(prettyPrint({'foo\nbar': 1, 'bar': true}), equals("{\n"
124 " 'foo\\n'\n" 126 " 'foo\\n'\n"
125 " 'bar': 1,\n" 127 " 'bar': 1,\n"
126 " 'bar': true\n" 128 " 'bar': true\n"
127 "}")); 129 "}"));
128 }); 130 });
129 131
130 test('containing a multiline string value', () { 132 ut.test('containing a multiline string value', () {
131 expect(prettyPrint({'foo': 'bar\nbaz', 'qux': true}), equals("{\n" 133 expect(prettyPrint({'foo': 'bar\nbaz', 'qux': true}), equals("{\n"
132 " 'foo': 'bar\\n'\n" 134 " 'foo': 'bar\\n'\n"
133 " 'baz',\n" 135 " 'baz',\n"
134 " 'qux': true\n" 136 " 'qux': true\n"
135 "}")); 137 "}"));
136 }); 138 });
137 139
138 test('containing a multiline string key/value pair', () { 140 ut.test('containing a multiline string key/value pair', () {
139 expect(prettyPrint({'foo\nbar': 'baz\nqux'}), equals("{\n" 141 expect(prettyPrint({'foo\nbar': 'baz\nqux'}), equals("{\n"
140 " 'foo\\n'\n" 142 " 'foo\\n'\n"
141 " 'bar': 'baz\\n'\n" 143 " 'bar': 'baz\\n'\n"
142 " 'qux'\n" 144 " 'qux'\n"
143 "}")); 145 "}"));
144 }); 146 });
145 147
146 test('containing a matcher key', () { 148 ut.test('containing a matcher key', () {
147 expect(prettyPrint({endsWith('bar'): 'qux'}), 149 expect(prettyPrint({endsWith('bar'): 'qux'}),
148 equals("{<a string ending with 'bar'>: 'qux'}")); 150 equals("{<a string ending with 'bar'>: 'qux'}"));
149 }); 151 });
150 152
151 test('containing a matcher value', () { 153 ut.test('containing a matcher value', () {
152 expect(prettyPrint({'foo': endsWith('qux')}), 154 expect(prettyPrint({'foo': endsWith('qux')}),
153 equals("{'foo': <a string ending with 'qux'>}")); 155 equals("{'foo': <a string ending with 'qux'>}"));
154 }); 156 });
155 157
156 test("that's under maxLineLength", () { 158 ut.test("that's under maxLineLength", () {
157 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxLineLength: 32), 159 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxLineLength: 32),
158 equals("{'0': 1, '2': 3, '4': 5, '6': 7}")); 160 equals("{'0': 1, '2': 3, '4': 5, '6': 7}"));
159 }); 161 });
160 162
161 test("that's over maxLineLength", () { 163 ut.test("that's over maxLineLength", () {
162 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxLineLength: 31), 164 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxLineLength: 31),
163 equals("{\n" 165 equals("{\n"
164 " '0': 1,\n" 166 " '0': 1,\n"
165 " '2': 3,\n" 167 " '2': 3,\n"
166 " '4': 5,\n" 168 " '4': 5,\n"
167 " '6': 7\n" 169 " '6': 7\n"
168 "}")); 170 "}"));
169 }); 171 });
170 172
171 test("factors indentation into maxLineLength", () { 173 ut.test("factors indentation into maxLineLength", () {
172 expect(prettyPrint(["foo\nbar", {'0': 1, '2': 3, '4': 5, '6': 7}], 174 expect(prettyPrint(["foo\nbar", {'0': 1, '2': 3, '4': 5, '6': 7}],
173 maxLineLength: 32), 175 maxLineLength: 32),
174 equals("[\n" 176 equals("[\n"
175 " 'foo\\n'\n" 177 " 'foo\\n'\n"
176 " 'bar',\n" 178 " 'bar',\n"
177 " {\n" 179 " {\n"
178 " '0': 1,\n" 180 " '0': 1,\n"
179 " '2': 3,\n" 181 " '2': 3,\n"
180 " '4': 5,\n" 182 " '4': 5,\n"
181 " '6': 7\n" 183 " '6': 7\n"
182 " }\n" 184 " }\n"
183 "]")); 185 "]"));
184 }); 186 });
185 187
186 test("that's under maxItems", () { 188 ut.test("that's under maxItems", () {
187 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 4), 189 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 4),
188 equals("{'0': 1, '2': 3, '4': 5, '6': 7}")); 190 equals("{'0': 1, '2': 3, '4': 5, '6': 7}"));
189 }); 191 });
190 192
191 test("that's over maxItems", () { 193 ut.test("that's over maxItems", () {
192 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 3), 194 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 3),
193 equals("{'0': 1, '2': 3, ...}")); 195 equals("{'0': 1, '2': 3, ...}"));
194 }); 196 });
195 }); 197 });
196 } 198 }
OLDNEW
« no previous file with comments | « pkg/matcher/test/pretty_print_minified_test.dart ('k') | pkg/matcher/test/pretty_print_unminified_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698