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