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

Side by Side Diff: pkg/unittest/test/matchers_test.dart

Issue 15492003: Split out unittest tests whose behavior differs in minified mode. (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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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 library unittestTests; 5 import 'dart:async';
6
6 import 'package:unittest/unittest.dart'; 7 import 'package:unittest/unittest.dart';
7 import 'dart:async';
8 import 'dart:collection';
9 part 'test_utils.dart';
10 8
11 doesNotThrow() {} 9 import 'test_utils.dart';
12 doesThrow() { throw 'X'; }
13
14 class PrefixMatcher extends BaseMatcher {
15 final String _prefix;
16 const PrefixMatcher(this._prefix);
17 bool matches(item, MatchState matchState) {
18 return item is String &&
19 (collapseWhitespace(item)).startsWith(collapseWhitespace(_prefix));
20 }
21
22 Description describe(Description description) =>
23 description.add('a string starting with ').
24 addDescriptionOf(collapseWhitespace(_prefix)).
25 add(' ignoring whitespace');
26 }
27
28 class Widget {
29 int price;
30 }
31
32 class HasPrice extends CustomMatcher {
33 HasPrice(matcher) :
34 super("Widget with a price that is", "price", matcher);
35 featureValueOf(actual) => actual.price;
36 }
37
38 class SimpleIterable extends IterableBase {
39 int count;
40 SimpleIterable(this.count);
41
42 bool contains(int val) => count < val ? false : true;
43
44 bool any(bool f(element)) {
45 for(var i = 0; i <= count; i++) {
46 if(f(i)) return true;
47 }
48 return false;
49 }
50
51 String toString() => "<[$count]>";
52
53 Iterator get iterator {
54 return new SimpleIterator(count);
55 }
56 }
57
58 class SimpleIterator implements Iterator {
59 int _count;
60 int _current;
61
62 SimpleIterator(this._count);
63
64 bool moveNext() {
65 if (_count > 0) {
66 _current = _count;
67 _count--;
68 return true;
69 }
70 _current = null;
71 return false;
72 }
73
74 get current => _current;
75 }
76 10
77 void main() { 11 void main() {
78 12
79 initUtils(); 13 initUtils();
80 14
81 // Core matchers 15 // Core matchers
82 16
83 group('Core matchers', () { 17 group('Core matchers', () {
84 18
85 test('isTrue', () { 19 test('isTrue', () {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 test('throwsA', () { 74 test('throwsA', () {
141 shouldPass(doesThrow, throwsA(equals('X'))); 75 shouldPass(doesThrow, throwsA(equals('X')));
142 shouldFail(doesThrow, throwsA(equals('Y')), 76 shouldFail(doesThrow, throwsA(equals('Y')),
143 matches( 77 matches(
144 r"Expected: throws an exception which matches 'Y' +" 78 r"Expected: throws an exception which matches 'Y' +"
145 r"But: exception 'X' does not match 'Y'\." 79 r"But: exception 'X' does not match 'Y'\."
146 r"Actual: <Closure(: \(dynamic\) => dynamic " 80 r"Actual: <Closure(: \(dynamic\) => dynamic "
147 r"from Function 'doesThrow': static\.)?>")); 81 r"from Function 'doesThrow': static\.)?>"));
148 }); 82 });
149 83
150 test('throwsFormatException', () {
151 shouldPass(() { throw new FormatException(''); },
152 throwsFormatException);
153 shouldFail(() { throw new Exception(); },
154 throwsFormatException,
155 matches(
156 r"Expected: throws an exception which matches FormatException +"
157 r"But: exception \?:<Exception> does not match FormatException\."
158 r"Actual: <Closure(: \(dynamic\) => dynamic)?>"));
159 });
160
161 test('throwsArgumentError', () {
162 shouldPass(() { throw new ArgumentError(''); },
163 throwsArgumentError);
164 shouldFail(() { throw new Exception(); },
165 throwsArgumentError,
166 matches(
167 r"Expected: throws an exception which matches ArgumentError +"
168 r"But: exception \?:<Exception> does not match "
169 r"ArgumentError\."
170 r"Actual: <Closure(: \(dynamic\) => dynamic)?>"));
171 });
172
173 test('throwsRangeError', () {
174 shouldPass(() { throw new RangeError(0); },
175 throwsRangeError);
176 shouldFail(() { throw new Exception(); },
177 throwsRangeError,
178 matches(
179 r"Expected: throws an exception which matches RangeError +"
180 r"But: exception \?:<Exception> does not match RangeError\."
181 r"Actual: <Closure(: \(dynamic\) => dynamic)?>"));
182 });
183
184 test('throwsNoSuchMethodError', () {
185 shouldPass(() { throw new NoSuchMethodError(null, '', null, null); },
186 throwsNoSuchMethodError);
187 shouldFail(() { throw new Exception(); },
188 throwsNoSuchMethodError,
189 matches(
190 r"Expected: throws an exception which matches NoSuchMethodError +"
191 r"But: exception \?:<Exception> does not match "
192 r"NoSuchMethodError\."
193 r"Actual: <Closure(: \(dynamic\) => dynamic)?>"));
194 });
195
196 test('throwsUnimplementedError', () {
197 shouldPass(() { throw new UnimplementedError(''); },
198 throwsUnimplementedError);
199 shouldFail(() { throw new Exception(); },
200 throwsUnimplementedError,
201 matches(
202 r"Expected: throws an exception which matches "
203 r"UnimplementedError +"
204 r"But: exception \?:<Exception> does not match "
205 r"UnimplementedError\."
206 r"Actual: <Closure(: \(dynamic\) => dynamic)?>"));
207 });
208
209 test('throwsUnsupportedError', () {
210 shouldPass(() { throw new UnsupportedError(''); },
211 throwsUnsupportedError);
212 shouldFail(() { throw new Exception(); },
213 throwsUnsupportedError,
214 matches(
215 r"Expected: throws an exception which matches UnsupportedError +"
216 r"But: exception \?:<Exception> does not match "
217 r"UnsupportedError\."
218 r"Actual: <Closure(: \(dynamic\) => dynamic)?>"));
219 });
220
221 test('throwsStateError', () {
222 shouldPass(() { throw new StateError(''); },
223 throwsStateError);
224 shouldFail(() { throw new Exception(); },
225 throwsStateError,
226 matches(
227 r"Expected: throws an exception which matches StateError +"
228 r"But: exception \?:<Exception> does not match "
229 r"StateError\."
230 r"Actual: <Closure(: \(dynamic\) => dynamic)?>"));
231 });
232
233 test('returnsNormally', () { 84 test('returnsNormally', () {
234 shouldPass(doesNotThrow, returnsNormally); 85 shouldPass(doesNotThrow, returnsNormally);
235 shouldFail(doesThrow, returnsNormally, 86 shouldFail(doesThrow, returnsNormally,
236 matches( 87 matches(
237 r"Expected: return normally +But: threw 'X'\." 88 r"Expected: return normally +But: threw 'X'\."
238 r"Actual: <Closure(: \(dynamic\) => dynamic " 89 r"Actual: <Closure(: \(dynamic\) => dynamic "
239 r"from Function 'doesThrow': static\.)?>")); 90 r"from Function 'doesThrow': static\.)?>"));
240 }); 91 });
241 92
242 test('hasLength', () { 93 test('hasLength', () {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 326
476 test('matches', () { 327 test('matches', () {
477 shouldPass('c0d', matches('[a-z][0-9][a-z]')); 328 shouldPass('c0d', matches('[a-z][0-9][a-z]'));
478 shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]'))); 329 shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]')));
479 shouldFail('cOd', matches('[a-z][0-9][a-z]'), 330 shouldFail('cOd', matches('[a-z][0-9][a-z]'),
480 "Expected: match '[a-z][0-9][a-z]' But: was 'cOd'."); 331 "Expected: match '[a-z][0-9][a-z]' But: was 'cOd'.");
481 }); 332 });
482 }); 333 });
483 334
484 group('Iterable Matchers', () { 335 group('Iterable Matchers', () {
485 test('isEmpty', () {
486 var d = new SimpleIterable(0);
487 var e = new SimpleIterable(1);
488 shouldPass(d, isEmpty);
489 shouldFail(e, isEmpty, "Expected: empty But: was SimpleIterable:[1].");
490 });
491
492 test('contains', () {
493 var d = new SimpleIterable(3);
494 shouldPass(d, contains(2));
495 shouldFail(d, contains(5),
496 "Expected: contains <5> "
497 "But: was SimpleIterable:[3, 2, 1].");
498 });
499 });
500
501 group('Iterable Matchers', () {
502 336
503 test('isEmpty', () { 337 test('isEmpty', () {
504 shouldPass([], isEmpty); 338 shouldPass([], isEmpty);
505 shouldFail([1], isEmpty, "Expected: empty But: was [1]."); 339 shouldFail([1], isEmpty, "Expected: empty But: was [1].");
506 }); 340 });
507 341
508 test('contains', () { 342 test('contains', () {
509 var d = [1, 2]; 343 var d = [1, 2];
510 shouldPass(d, contains(1)); 344 shouldPass(d, contains(1));
511 shouldFail(d, contains(0), "Expected: contains <0> But: was [1, 2]."); 345 shouldFail(d, contains(0), "Expected: contains <0> But: was [1, 2].");
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 }); 601 });
768 }); 602 });
769 603
770 group('Predicate Matchers', () { 604 group('Predicate Matchers', () {
771 test('isInstanceOf', () { 605 test('isInstanceOf', () {
772 shouldFail(0, predicate((x) => x is String, "an instance of String"), 606 shouldFail(0, predicate((x) => x is String, "an instance of String"),
773 "Expected: an instance of String But: was <0>."); 607 "Expected: an instance of String But: was <0>.");
774 shouldPass('cow', predicate((x) => x is String, "an instance of String")); 608 shouldPass('cow', predicate((x) => x is String, "an instance of String"));
775 }); 609 });
776 }); 610 });
777
778 group('Feature Matchers', () {
779 test("Feature Matcher", () {
780 var w = new Widget();
781 w.price = 10;
782 shouldPass(w, new HasPrice(10));
783 shouldPass(w, new HasPrice(greaterThan(0)));
784 shouldFail(w, new HasPrice(greaterThan(10)),
785 "Expected: Widget with a price that is a value greater than <10> "
786 "But: price was <10>. "
787 "Actual: <Instance of 'Widget'>");
788 });
789 });
790 } 611 }
791 612
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698