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