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