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 // Dart test program for testing the instanceof operation. | 4 // Dart test program for testing the instanceof operation. |
5 | 5 |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 abstract class I { } | 8 abstract class I {} |
9 | 9 |
10 abstract class AI implements I { } | 10 abstract class AI implements I {} |
11 | 11 |
12 class A implements AI { | 12 class A implements AI { |
13 const A(); | 13 const A(); |
14 } | 14 } |
15 | 15 |
16 class B implements I { | 16 class B implements I { |
17 const B(); | 17 const B(); |
18 } | 18 } |
19 | 19 |
20 class C extends A { | 20 class C extends A { |
21 const C() : super(); | 21 const C() : super(); |
22 } | 22 } |
23 | 23 |
24 class InstanceofTest { | 24 class InstanceofTest { |
25 static testMain() { | 25 static testMain() { |
26 var a = new A(); | 26 var a = new A(); |
27 var b = new B(); | 27 var b = new B(); |
28 var c = new C(); | 28 var c = new C(); |
29 var n = null; | 29 var n = null; |
30 | 30 |
31 Expect.equals(true, a is A); | 31 Expect.equals(true, a is A); |
32 Expect.equals(true, b is B); | 32 Expect.equals(true, b is B); |
33 Expect.equals(true, c is C); | 33 Expect.equals(true, c is C); |
34 Expect.equals(true, c is A); | 34 Expect.equals(true, c is A); |
35 | 35 |
36 Expect.equals(true, a is AI); | 36 Expect.equals(true, a is AI); |
37 Expect.equals(true, a is I); | 37 Expect.equals(true, a is I); |
38 Expect.equals(false, b is AI); | 38 Expect.equals(false, b is AI); |
39 Expect.equals(true, b is I); | 39 Expect.equals(true, b is I); |
40 Expect.equals(true, c is AI); | 40 Expect.equals(true, c is AI); |
41 Expect.equals(true, c is I); | 41 Expect.equals(true, c is I); |
42 Expect.equals(false, n is AI); | 42 Expect.equals(false, n is AI); |
43 Expect.equals(false, n is I); | 43 Expect.equals(false, n is I); |
44 | 44 |
45 Expect.equals(false, a is B); | 45 Expect.equals(false, a is B); |
46 Expect.equals(false, a is C); | 46 Expect.equals(false, a is C); |
47 Expect.equals(false, b is A); | 47 Expect.equals(false, b is A); |
48 Expect.equals(false, b is C); | 48 Expect.equals(false, b is C); |
49 Expect.equals(false, c is B); | 49 Expect.equals(false, c is B); |
50 Expect.equals(false, n is A); | 50 Expect.equals(false, n is A); |
51 | 51 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 97 } |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 main() { | 101 main() { |
102 // Repeat type checks so that inlined tests can be tested as well. | 102 // Repeat type checks so that inlined tests can be tested as well. |
103 for (int i = 0; i < 5; i++) { | 103 for (int i = 0; i < 5; i++) { |
104 InstanceofTest.testMain(); | 104 InstanceofTest.testMain(); |
105 } | 105 } |
106 } | 106 } |
107 | |
OLD | NEW |