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