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