OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011, 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 // Dart test program testing that NoSuchMethod is properly called. |
| 5 |
| 6 import "package:expect/expect.dart"; |
| 7 |
| 8 class Cat { |
| 9 bool eatFood(String food) => true; |
| 10 int scratch(String furniture) => 100; |
| 11 } |
| 12 |
| 13 class MockCat implements Cat { |
| 14 dynamic noSuchMethod(Invocation invocation) { |
| 15 return (invocation.positionalArguments[0] as String).isNotEmpty; |
| 16 } |
| 17 } |
| 18 |
| 19 void main() { |
| 20 MockCat mock = new MockCat(); |
| 21 Expect.isTrue((mock as dynamic).eatFood("food")); |
| 22 Expect.isFalse(mock.eatFood("")); |
| 23 |
| 24 // In strong mode this will be a runtime type error: |
| 25 // bool is not an int. VM will fail with noSuchMethod +. |
| 26 Expect.throws(() => mock.scratch("couch") + 0); |
| 27 } |
OLD | NEW |