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