OLD | NEW |
| (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 // This file is for matcher tests that rely on the names of various Dart types. | |
6 // These tests normally fail when run in minified dart2js, since the names will | |
7 // be mangled. This version of the file is modified to expect minified names. | |
8 | |
9 library matcher.minified_test; | |
10 | |
11 import 'package:matcher/matcher.dart'; | |
12 import 'package:unittest/unittest.dart' show test, group; | |
13 | |
14 import 'test_common.dart'; | |
15 import 'test_utils.dart'; | |
16 | |
17 // A regexp fragment matching a minified name. | |
18 const _MINIFIED_NAME = r"[A-Za-z0-9]{1,3}"; | |
19 | |
20 void main() { | |
21 initUtils(); | |
22 | |
23 group('Core matchers', () { | |
24 test('throwsFormatException', () { | |
25 shouldPass(() { throw new FormatException(''); }, | |
26 throwsFormatException); | |
27 shouldFail(() { throw new Exception(); }, | |
28 throwsFormatException, | |
29 matches( | |
30 r"Expected: throws FormatException +" | |
31 r"Actual: <Closure(: \(\) => dynamic)?> +" | |
32 r"Which: threw " + _MINIFIED_NAME + r":<Exception>")); | |
33 }); | |
34 | |
35 test('throwsArgumentError', () { | |
36 shouldPass(() { throw new ArgumentError(''); }, | |
37 throwsArgumentError); | |
38 shouldFail(() { throw new Exception(); }, | |
39 throwsArgumentError, | |
40 matches( | |
41 r"Expected: throws ArgumentError +" | |
42 r"Actual: <Closure(: \(\) => dynamic)?> +" | |
43 r"Which: threw " + _MINIFIED_NAME + r":<Exception>")); | |
44 }); | |
45 | |
46 test('throwsRangeError', () { | |
47 shouldPass(() { throw new RangeError(0); }, | |
48 throwsRangeError); | |
49 shouldFail(() { throw new Exception(); }, | |
50 throwsRangeError, | |
51 matches( | |
52 r"Expected: throws RangeError +" | |
53 r"Actual: <Closure(: \(\) => dynamic)?> +" | |
54 r"Which: threw " + _MINIFIED_NAME + r":<Exception>")); | |
55 }); | |
56 | |
57 test('throwsNoSuchMethodError', () { | |
58 shouldPass(() { | |
59 throw new NoSuchMethodError(null, const Symbol(''), null, null); | |
60 }, throwsNoSuchMethodError); | |
61 shouldFail(() { throw new Exception(); }, | |
62 throwsNoSuchMethodError, | |
63 matches( | |
64 r"Expected: throws NoSuchMethodError +" | |
65 r"Actual: <Closure(: \(\) => dynamic)?> +" | |
66 r"Which: threw " + _MINIFIED_NAME + r":<Exception>")); | |
67 }); | |
68 | |
69 test('throwsUnimplementedError', () { | |
70 shouldPass(() { throw new UnimplementedError(''); }, | |
71 throwsUnimplementedError); | |
72 shouldFail(() { throw new Exception(); }, | |
73 throwsUnimplementedError, | |
74 matches( | |
75 r"Expected: throws UnimplementedError +" | |
76 r"Actual: <Closure(: \(\) => dynamic)?> +" | |
77 r"Which: threw " + _MINIFIED_NAME + r":<Exception>")); | |
78 }); | |
79 | |
80 test('throwsUnsupportedError', () { | |
81 shouldPass(() { throw new UnsupportedError(''); }, | |
82 throwsUnsupportedError); | |
83 shouldFail(() { throw new Exception(); }, | |
84 throwsUnsupportedError, | |
85 matches( | |
86 r"Expected: throws UnsupportedError +" | |
87 r"Actual: <Closure(: \(\) => dynamic)?> +" | |
88 r"Which: threw " + _MINIFIED_NAME + r":<Exception>")); | |
89 }); | |
90 | |
91 test('throwsStateError', () { | |
92 shouldPass(() { throw new StateError(''); }, | |
93 throwsStateError); | |
94 shouldFail(() { throw new Exception(); }, | |
95 throwsStateError, | |
96 matches( | |
97 r"Expected: throws StateError +" | |
98 r"Actual: <Closure(: \(\) => dynamic)?> +" | |
99 r"Which: threw " + _MINIFIED_NAME + r":<Exception>")); | |
100 }); | |
101 }); | |
102 | |
103 group('Iterable Matchers', () { | |
104 test('isEmpty', () { | |
105 var d = new SimpleIterable(0); | |
106 var e = new SimpleIterable(1); | |
107 shouldPass(d, isEmpty); | |
108 shouldFail(e, isEmpty, | |
109 matches(r"Expected: empty +Actual: " + _MINIFIED_NAME + r":\[1\]")); | |
110 }); | |
111 | |
112 test('isNotEmpty', () { | |
113 var d = new SimpleIterable(0); | |
114 var e = new SimpleIterable(1); | |
115 shouldPass(e, isNotEmpty); | |
116 shouldFail(d, isNotEmpty, | |
117 matches(r"Expected: non-empty +Actual: " + _MINIFIED_NAME + r":\[\]"))
; | |
118 }); | |
119 | |
120 test('contains', () { | |
121 var d = new SimpleIterable(3); | |
122 shouldPass(d, contains(2)); | |
123 shouldFail(d, contains(5), | |
124 matches( | |
125 r"Expected: contains <5> +" | |
126 r"Actual: " + _MINIFIED_NAME + r":\[3, 2, 1\]")); | |
127 }); | |
128 }); | |
129 | |
130 group('Feature Matchers', () { | |
131 test("Feature Matcher", () { | |
132 var w = new Widget(); | |
133 w.price = 10; | |
134 shouldPass(w, new HasPrice(10)); | |
135 shouldPass(w, new HasPrice(greaterThan(0))); | |
136 shouldFail(w, new HasPrice(greaterThan(10)), | |
137 matches( | |
138 r"Expected: Widget with a price that is a value greater than " | |
139 r"<10> +" | |
140 r"Actual: <Instance of '" + _MINIFIED_NAME + r"'> +" | |
141 r"Which: has price with value <10> which is not " | |
142 r"a value greater than <10>")); | |
143 }); | |
144 }); | |
145 } | |
OLD | NEW |