OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013, 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 library dynamic_type_helper; |
| 6 |
| 7 import 'package:expect/expect.dart'; |
| 8 |
| 9 /// Checks that a dynamic type error is thrown when [f] is executed |
| 10 /// and [expectTypeError] is `true`. |
| 11 void testDynamicTypeError(bool expectTypeError, f(), [String message]) { |
| 12 if (expectTypeError) { |
| 13 checkDynamicTypeError(f, message); |
| 14 } else { |
| 15 checkNoDynamicTypeError(f, message); |
| 16 } |
| 17 } |
| 18 |
| 19 /// Checks that a dynamic type error is thrown when f is executed. |
| 20 void checkDynamicTypeError(f(), [String message]) { |
| 21 message = message != null ? ': $message' : ''; |
| 22 try { |
| 23 f(); |
| 24 Expect.fail('Missing type error$message.'); |
| 25 } on TypeError catch (e) {} |
| 26 } |
| 27 |
| 28 /// Checks that no dynamic type error is thrown when [f] is executed. |
| 29 void checkNoDynamicTypeError(f(), [String message]) { |
| 30 message = message != null ? ': $message' : ''; |
| 31 try { |
| 32 f(); |
| 33 } on TypeError catch (e) { |
| 34 Expect.fail('Unexpected type error$message.'); |
| 35 } |
| 36 } |
OLD | NEW |