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