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