| 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 an exception which matches FormatException +" |
| 28 r"But: exception " + _minifiedName + r":<Exception> " |
| 29 r"does not match FormatException\." |
| 30 r"Actual: <Closure>")); |
| 31 }); |
| 32 |
| 33 test('throwsArgumentError', () { |
| 34 shouldPass(() { throw new ArgumentError(''); }, |
| 35 throwsArgumentError); |
| 36 shouldFail(() { throw new Exception(); }, |
| 37 throwsArgumentError, |
| 38 matches( |
| 39 r"Expected: throws an exception which matches ArgumentError +" |
| 40 r"But: exception " + _minifiedName + r":<Exception> " |
| 41 r"does not match ArgumentError\." |
| 42 r"Actual: <Closure>")); |
| 43 }); |
| 44 |
| 45 test('throwsRangeError', () { |
| 46 shouldPass(() { throw new RangeError(0); }, |
| 47 throwsRangeError); |
| 48 shouldFail(() { throw new Exception(); }, |
| 49 throwsRangeError, |
| 50 matches( |
| 51 r"Expected: throws an exception which matches RangeError +" |
| 52 r"But: exception " + _minifiedName + r":<Exception> " |
| 53 r"does not match RangeError\." |
| 54 r"Actual: <Closure(: \(dynamic\) => dynamic)?>")); |
| 55 }); |
| 56 |
| 57 test('throwsNoSuchMethodError', () { |
| 58 shouldPass(() { throw new NoSuchMethodError(null, '', null, null); }, |
| 59 throwsNoSuchMethodError); |
| 60 shouldFail(() { throw new Exception(); }, |
| 61 throwsNoSuchMethodError, |
| 62 matches( |
| 63 r"Expected: throws an exception which matches NoSuchMethodError +" |
| 64 r"But: exception " + _minifiedName + r":<Exception> " |
| 65 r"does not match NoSuchMethodError\." |
| 66 r"Actual: <Closure(: \(dynamic\) => dynamic)?>")); |
| 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 an exception which matches " |
| 76 r"UnimplementedError +" |
| 77 r"But: exception " + _minifiedName + r":<Exception> " |
| 78 r"does not match UnimplementedError\." |
| 79 r"Actual: <Closure(: \(dynamic\) => dynamic)?>")); |
| 80 }); |
| 81 |
| 82 test('throwsUnsupportedError', () { |
| 83 shouldPass(() { throw new UnsupportedError(''); }, |
| 84 throwsUnsupportedError); |
| 85 shouldFail(() { throw new Exception(); }, |
| 86 throwsUnsupportedError, |
| 87 matches( |
| 88 r"Expected: throws an exception which matches UnsupportedError +" |
| 89 r"But: exception " + _minifiedName + r":<Exception> " |
| 90 r"does not match UnsupportedError\." |
| 91 r"Actual: <Closure(: \(dynamic\) => dynamic)?>")); |
| 92 }); |
| 93 |
| 94 test('throwsStateError', () { |
| 95 shouldPass(() { throw new StateError(''); }, |
| 96 throwsStateError); |
| 97 shouldFail(() { throw new Exception(); }, |
| 98 throwsStateError, |
| 99 matches( |
| 100 r"Expected: throws an exception which matches StateError +" |
| 101 r"But: exception " + _minifiedName + r":<Exception> " |
| 102 r"does not match StateError\." |
| 103 r"Actual: <Closure(: \(dynamic\) => dynamic)?>")); |
| 104 }); |
| 105 }); |
| 106 |
| 107 group('Iterable Matchers', () { |
| 108 test('isEmpty', () { |
| 109 var d = new SimpleIterable(0); |
| 110 var e = new SimpleIterable(1); |
| 111 shouldPass(d, isEmpty); |
| 112 shouldFail(e, isEmpty, |
| 113 matches(r"Expected: empty +But: was " + _minifiedName + r":\[1\]\.")); |
| 114 }); |
| 115 |
| 116 test('contains', () { |
| 117 var d = new SimpleIterable(3); |
| 118 shouldPass(d, contains(2)); |
| 119 shouldFail(d, contains(5), |
| 120 matches( |
| 121 r"Expected: contains <5> +" |
| 122 r"But: was " + _minifiedName + r":\[3, 2, 1\]\.")); |
| 123 }); |
| 124 }); |
| 125 |
| 126 group('Feature Matchers', () { |
| 127 test("Feature Matcher", () { |
| 128 var w = new Widget(); |
| 129 w.price = 10; |
| 130 shouldPass(w, new HasPrice(10)); |
| 131 shouldPass(w, new HasPrice(greaterThan(0))); |
| 132 shouldFail(w, new HasPrice(greaterThan(10)), |
| 133 matches( |
| 134 r"Expected: Widget with a price that is a value greater than " |
| 135 r"<10> +" |
| 136 r"But: price was <10>\." |
| 137 r"Actual: <Instance of '" + _minifiedName + r"'>")); |
| 138 }); |
| 139 }); |
| 140 } |
| OLD | NEW |