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