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