| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 | 6 |
| 7 // Tests that we can call functions through getters which return null. | 7 // Tests that we can call functions through getters which return null. |
| 8 | 8 |
| 9 const TOP_LEVEL_NULL = null; | 9 const dynamic TOP_LEVEL_NULL = null; |
| 10 | 10 |
| 11 var topLevel; | 11 var topLevel; |
| 12 | 12 |
| 13 class CallThroughNullGetterTest { | 13 class CallThroughNullGetterTest { |
| 14 static void testMain() { | 14 static void testMain() { |
| 15 testTopLevel(); | 15 testTopLevel(); |
| 16 testField(); | 16 testField(); |
| 17 testGetter(); | 17 testGetter(); |
| 18 testMethod(); | 18 testMethod(); |
| 19 } | 19 } |
| 20 | 20 |
| 21 static void testTopLevel() { | 21 static void testTopLevel() { |
| 22 topLevel = null; | 22 topLevel = null; |
| 23 expectThrowsNoSuchMethodError(() { | 23 Expect.throwsNoSuchMethodError(() { |
| 24 topLevel(); | 24 topLevel(); |
| 25 }); | 25 }); |
| 26 expectThrowsNoSuchMethodError(() { | 26 Expect.throwsNoSuchMethodError(() { |
| 27 (topLevel)(); | 27 (topLevel)(); |
| 28 }); | 28 }); |
| 29 expectThrowsNoSuchMethodError(() { | 29 Expect.throwsNoSuchMethodError(() { |
| 30 TOP_LEVEL_NULL(); | 30 TOP_LEVEL_NULL(); |
| 31 }); | 31 }); |
| 32 expectThrowsNoSuchMethodError(() { | 32 Expect.throwsNoSuchMethodError(() { |
| 33 (TOP_LEVEL_NULL)(); | 33 (TOP_LEVEL_NULL)(); |
| 34 }); | 34 }); |
| 35 } | 35 } |
| 36 | 36 |
| 37 static void testField() { | 37 static void testField() { |
| 38 A a = new A(); | 38 A a = new A(); |
| 39 | 39 |
| 40 a.field = null; | 40 a.field = null; |
| 41 expectThrowsNoSuchMethodError(() { | 41 Expect.throwsNoSuchMethodError(() { |
| 42 a.field(); | 42 a.field(); |
| 43 }); | 43 }); |
| 44 expectThrowsNoSuchMethodError(() { | 44 Expect.throwsNoSuchMethodError(() { |
| 45 (a.field)(); | 45 (a.field)(); |
| 46 }); | 46 }); |
| 47 } | 47 } |
| 48 | 48 |
| 49 static void testGetter() { | 49 static void testGetter() { |
| 50 A a = new A(); | 50 A a = new A(); |
| 51 | 51 |
| 52 a.field = null; | 52 a.field = null; |
| 53 expectThrowsNoSuchMethodError(() { | 53 Expect.throwsNoSuchMethodError(() { |
| 54 a.getter(); | 54 a.getter(); |
| 55 }); | 55 }); |
| 56 expectThrowsNoSuchMethodError(() { | 56 Expect.throwsNoSuchMethodError(() { |
| 57 (a.getter)(); | 57 (a.getter)(); |
| 58 }); | 58 }); |
| 59 } | 59 } |
| 60 | 60 |
| 61 static void testMethod() { | 61 static void testMethod() { |
| 62 A a = new A(); | 62 A a = new A(); |
| 63 | 63 |
| 64 a.field = null; | 64 a.field = null; |
| 65 expectThrowsNoSuchMethodError(() { | 65 Expect.throwsNoSuchMethodError(() { |
| 66 a.method()(); | 66 a.method()(); |
| 67 }); | 67 }); |
| 68 } | 68 } |
| 69 | |
| 70 static void expectThrowsNoSuchMethodError(fn) { | |
| 71 Expect.throws( | |
| 72 fn, (e) => e is NoSuchMethodError, "Should throw NoSuchMethodError"); | |
| 73 } | |
| 74 } | 69 } |
| 75 | 70 |
| 76 class A { | 71 class A { |
| 77 A() {} | 72 A() {} |
| 78 var field; | 73 var field; |
| 79 get getter { | 74 get getter { |
| 80 return field; | 75 return field; |
| 81 } | 76 } |
| 82 | 77 |
| 83 method() { | 78 method() { |
| 84 return field; | 79 return field; |
| 85 } | 80 } |
| 86 } | 81 } |
| 87 | 82 |
| 88 main() { | 83 main() { |
| 89 CallThroughNullGetterTest.testMain(); | 84 CallThroughNullGetterTest.testMain(); |
| 90 } | 85 } |
| OLD | NEW |