| 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(() { | |
| 24 throw new FormatException(''); | |
| 25 }, throwsFormatException); | |
| 26 shouldFail(() { | |
| 27 throw new Exception(); | |
| 28 }, throwsFormatException, matches(r"Expected: throws FormatException +" | |
| 29 r"Actual: <Closure(: \(\) => dynamic)?> +" | |
| 30 r"Which: threw \?:<Exception>")); | |
| 31 }); | |
| 32 | |
| 33 test('throwsArgumentError', () { | |
| 34 shouldPass(() { | |
| 35 throw new ArgumentError(''); | |
| 36 }, throwsArgumentError); | |
| 37 shouldFail(() { | |
| 38 throw new Exception(); | |
| 39 }, throwsArgumentError, matches(r"Expected: throws ArgumentError +" | |
| 40 r"Actual: <Closure(: \(\) => dynamic)?> +" | |
| 41 r"Which: threw \?:<Exception>")); | |
| 42 }); | |
| 43 | |
| 44 test('throwsRangeError', () { | |
| 45 shouldPass(() { | |
| 46 throw new RangeError(0); | |
| 47 }, throwsRangeError); | |
| 48 shouldFail(() { | |
| 49 throw new Exception(); | |
| 50 }, throwsRangeError, matches(r"Expected: throws RangeError +" | |
| 51 r"Actual: <Closure(: \(\) => dynamic)?> +" | |
| 52 r"Which: threw \?:<Exception>")); | |
| 53 }); | |
| 54 | |
| 55 test('throwsNoSuchMethodError', () { | |
| 56 shouldPass(() { | |
| 57 throw new NoSuchMethodError(null, const Symbol(''), null, null); | |
| 58 }, throwsNoSuchMethodError); | |
| 59 shouldFail(() { | |
| 60 throw new Exception(); | |
| 61 }, throwsNoSuchMethodError, matches( | |
| 62 r"Expected: throws NoSuchMethodError +" | |
| 63 r"Actual: <Closure(: \(\) => dynamic)?> +" | |
| 64 r"Which: threw \?:<Exception>")); | |
| 65 }); | |
| 66 | |
| 67 test('throwsUnimplementedError', () { | |
| 68 shouldPass(() { | |
| 69 throw new UnimplementedError(''); | |
| 70 }, throwsUnimplementedError); | |
| 71 shouldFail(() { | |
| 72 throw new Exception(); | |
| 73 }, throwsUnimplementedError, matches( | |
| 74 r"Expected: throws UnimplementedError +" | |
| 75 r"Actual: <Closure(: \(\) => dynamic)?> +" | |
| 76 r"Which: threw \?:<Exception>")); | |
| 77 }); | |
| 78 | |
| 79 test('throwsUnsupportedError', () { | |
| 80 shouldPass(() { | |
| 81 throw new UnsupportedError(''); | |
| 82 }, throwsUnsupportedError); | |
| 83 shouldFail(() { | |
| 84 throw new Exception(); | |
| 85 }, throwsUnsupportedError, matches(r"Expected: throws UnsupportedError +" | |
| 86 r"Actual: <Closure(: \(\) => dynamic)?> +" | |
| 87 r"Which: threw \?:<Exception>")); | |
| 88 }); | |
| 89 | |
| 90 test('throwsStateError', () { | |
| 91 shouldPass(() { | |
| 92 throw new StateError(''); | |
| 93 }, throwsStateError); | |
| 94 shouldFail(() { | |
| 95 throw new Exception(); | |
| 96 }, throwsStateError, matches(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 test('contains', () { | |
| 120 var d = new SimpleIterable(3); | |
| 121 shouldPass(d, contains(2)); | |
| 122 shouldFail(d, contains(5), "Expected: contains <5> " | |
| 123 "Actual: SimpleIterable:[3, 2, 1]"); | |
| 124 }); | |
| 125 }); | |
| 126 | |
| 127 group('Feature Matchers', () { | |
| 128 test("Feature Matcher", () { | |
| 129 var w = new Widget(); | |
| 130 w.price = 10; | |
| 131 shouldPass(w, new HasPrice(10)); | |
| 132 shouldPass(w, new HasPrice(greaterThan(0))); | |
| 133 shouldFail(w, new HasPrice(greaterThan(10)), | |
| 134 "Expected: Widget with a price that is a value greater than <10> " | |
| 135 "Actual: <Instance of 'Widget'> " | |
| 136 "Which: has price with value <10> which is not " | |
| 137 "a value greater than <10>"); | |
| 138 }); | |
| 139 }); | |
| 140 } | |
| OLD | NEW |