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 TOP_LEVEL_NULL = null; |
10 | 10 |
11 var topLevel; | 11 var topLevel; |
12 | 12 |
13 class CallThroughNullGetterTest { | 13 class CallThroughNullGetterTest { |
14 | |
15 static void testMain() { | 14 static void testMain() { |
16 testTopLevel(); | 15 testTopLevel(); |
17 testField(); | 16 testField(); |
18 testGetter(); | 17 testGetter(); |
19 testMethod(); | 18 testMethod(); |
20 } | 19 } |
21 | 20 |
22 static void testTopLevel() { | 21 static void testTopLevel() { |
23 topLevel = null; | 22 topLevel = null; |
24 expectThrowsNoSuchMethodError(() { topLevel(); }); | 23 expectThrowsNoSuchMethodError(() { |
25 expectThrowsNoSuchMethodError(() { (topLevel)(); }); | 24 topLevel(); |
26 expectThrowsNoSuchMethodError(() { TOP_LEVEL_NULL(); }); | 25 }); |
27 expectThrowsNoSuchMethodError(() { (TOP_LEVEL_NULL)(); }); | 26 expectThrowsNoSuchMethodError(() { |
| 27 (topLevel)(); |
| 28 }); |
| 29 expectThrowsNoSuchMethodError(() { |
| 30 TOP_LEVEL_NULL(); |
| 31 }); |
| 32 expectThrowsNoSuchMethodError(() { |
| 33 (TOP_LEVEL_NULL)(); |
| 34 }); |
28 } | 35 } |
29 | 36 |
30 static void testField() { | 37 static void testField() { |
31 A a = new A(); | 38 A a = new A(); |
32 | 39 |
33 a.field = null; | 40 a.field = null; |
34 expectThrowsNoSuchMethodError(() { a.field(); }); | 41 expectThrowsNoSuchMethodError(() { |
35 expectThrowsNoSuchMethodError(() { (a.field)(); }); | 42 a.field(); |
| 43 }); |
| 44 expectThrowsNoSuchMethodError(() { |
| 45 (a.field)(); |
| 46 }); |
36 } | 47 } |
37 | 48 |
38 static void testGetter() { | 49 static void testGetter() { |
39 A a = new A(); | 50 A a = new A(); |
40 | 51 |
41 a.field = null; | 52 a.field = null; |
42 expectThrowsNoSuchMethodError(() { a.getter(); }); | 53 expectThrowsNoSuchMethodError(() { |
43 expectThrowsNoSuchMethodError(() { (a.getter)(); }); | 54 a.getter(); |
| 55 }); |
| 56 expectThrowsNoSuchMethodError(() { |
| 57 (a.getter)(); |
| 58 }); |
44 } | 59 } |
45 | 60 |
46 static void testMethod() { | 61 static void testMethod() { |
47 A a = new A(); | 62 A a = new A(); |
48 | 63 |
49 a.field = null; | 64 a.field = null; |
50 expectThrowsNoSuchMethodError(() { a.method()(); }); | 65 expectThrowsNoSuchMethodError(() { |
| 66 a.method()(); |
| 67 }); |
51 } | 68 } |
52 | 69 |
53 static void expectThrowsNoSuchMethodError(fn) { | 70 static void expectThrowsNoSuchMethodError(fn) { |
54 Expect.throws(fn, (e) => e is NoSuchMethodError, | 71 Expect.throws( |
55 "Should throw NoSuchMethodError"); | 72 fn, (e) => e is NoSuchMethodError, "Should throw NoSuchMethodError"); |
56 } | 73 } |
57 } | 74 } |
58 | 75 |
| 76 class A { |
| 77 A() {} |
| 78 var field; |
| 79 get getter { |
| 80 return field; |
| 81 } |
59 | 82 |
60 class A { | 83 method() { |
61 | 84 return field; |
62 A() { } | 85 } |
63 var field; | |
64 get getter { return field; } | |
65 method() { return field; } | |
66 | |
67 } | 86 } |
68 | 87 |
69 main() { | 88 main() { |
70 CallThroughNullGetterTest.testMain(); | 89 CallThroughNullGetterTest.testMain(); |
71 } | 90 } |
OLD | NEW |