| 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 library matcher.core_matchers_test; | 5 library matcher.core_matchers_test; |
| 6 | 6 |
| 7 import 'package:matcher/matcher.dart'; | 7 import 'package:matcher/matcher.dart'; |
| 8 import 'package:unittest/unittest.dart' show test, group; | 8 import 'package:unittest/unittest.dart' show test, group; |
| 9 | 9 |
| 10 import 'test_utils.dart'; | 10 import 'test_utils.dart'; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 }); | 76 }); |
| 77 | 77 |
| 78 test('anything', () { | 78 test('anything', () { |
| 79 var a = new Map(); | 79 var a = new Map(); |
| 80 shouldPass(0, anything); | 80 shouldPass(0, anything); |
| 81 shouldPass(null, anything); | 81 shouldPass(null, anything); |
| 82 shouldPass(a, anything); | 82 shouldPass(a, anything); |
| 83 shouldFail(a, isNot(anything), "Expected: not anything Actual: {}"); | 83 shouldFail(a, isNot(anything), "Expected: not anything Actual: {}"); |
| 84 }); | 84 }); |
| 85 | 85 |
| 86 test('throws', () { | |
| 87 shouldFail(doesNotThrow, throws, | |
| 88 matches( | |
| 89 r"Expected: throws" | |
| 90 r" Actual: <Closure(: \(\) => dynamic " | |
| 91 r"from Function 'doesNotThrow': static\.)?>" | |
| 92 r" Which: did not throw")); | |
| 93 shouldPass(doesThrow, throws); | |
| 94 shouldFail(true, throws, | |
| 95 "Expected: throws" | |
| 96 " Actual: <true>" | |
| 97 " Which: is not a Function or Future"); | |
| 98 }); | |
| 99 | |
| 100 test('throwsA', () { | |
| 101 shouldPass(doesThrow, throwsA(equals('X'))); | |
| 102 shouldFail(doesThrow, throwsA(equals('Y')), | |
| 103 matches( | |
| 104 r"Expected: throws 'Y'" | |
| 105 r" Actual: <Closure(: \(\) => dynamic " | |
| 106 r"from Function 'doesThrow': static\.)?>" | |
| 107 r" Which: threw 'X'")); | |
| 108 }); | |
| 109 | |
| 110 test('throwsA', () { | |
| 111 shouldPass(doesThrow, throwsA(equals('X'))); | |
| 112 shouldFail(doesThrow, throwsA(equals('Y')), | |
| 113 matches("Expected: throws 'Y'.*" | |
| 114 "Actual: <Closure.*" | |
| 115 "Which: threw 'X'")); | |
| 116 }); | |
| 117 | |
| 118 test('returnsNormally', () { | 86 test('returnsNormally', () { |
| 119 shouldPass(doesNotThrow, returnsNormally); | 87 shouldPass(doesNotThrow, returnsNormally); |
| 120 shouldFail(doesThrow, returnsNormally, | 88 shouldFail(doesThrow, returnsNormally, |
| 121 matches( | 89 matches( |
| 122 r"Expected: return normally" | 90 r"Expected: return normally" |
| 123 r" Actual: <Closure(: \(\) => dynamic " | 91 r" Actual: <Closure(: \(\) => dynamic " |
| 124 r"from Function 'doesThrow': static\.)?>" | 92 r"from Function 'doesThrow': static\.)?>" |
| 125 r" Which: threw 'X'")); | 93 r" Which: threw 'X'")); |
| 126 }); | 94 }); |
| 127 | 95 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 shouldPass('cow', new isInstanceOf<String>('String')); | 170 shouldPass('cow', new isInstanceOf<String>('String')); |
| 203 }); | 171 }); |
| 204 | 172 |
| 205 group('Predicate Matchers', () { | 173 group('Predicate Matchers', () { |
| 206 test('isInstanceOf', () { | 174 test('isInstanceOf', () { |
| 207 shouldFail(0, predicate((x) => x is String, "an instance of String"), | 175 shouldFail(0, predicate((x) => x is String, "an instance of String"), |
| 208 "Expected: an instance of String Actual: <0>"); | 176 "Expected: an instance of String Actual: <0>"); |
| 209 shouldPass('cow', predicate((x) => x is String, "an instance of String")); | 177 shouldPass('cow', predicate((x) => x is String, "an instance of String")); |
| 210 }); | 178 }); |
| 211 }); | 179 }); |
| 212 | |
| 213 group('exception/error matchers', () { | |
| 214 test('throwsCyclicInitializationError', () { | |
| 215 expect(() => _Bicycle.foo, throwsCyclicInitializationError); | |
| 216 }); | |
| 217 | |
| 218 test('throwsConcurrentModificationError', () { | |
| 219 expect(() { | |
| 220 var a = { 'foo': 'bar' }; | |
| 221 for (var k in a.keys) { | |
| 222 a.remove(k); | |
| 223 } | |
| 224 }, throwsConcurrentModificationError); | |
| 225 }); | |
| 226 | |
| 227 test('throwsNullThrownError', () { | |
| 228 expect(() => throw null, throwsNullThrownError); | |
| 229 }); | |
| 230 }); | |
| 231 } | 180 } |
| 232 | |
| 233 class _Bicycle { | |
| 234 static final foo = bar(); | |
| 235 | |
| 236 static bar() { | |
| 237 return foo + 1; | |
| 238 } | |
| 239 } | |
| OLD | NEW |