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 for testing the instanceof operation. | |
5 | |
6 interface I { } | |
7 | |
8 interface AI extends I { } | |
9 | |
10 class A implements AI { | |
11 const A(); | |
12 } | |
13 | |
14 class B implements I { | |
15 const B(); | |
16 } | |
17 | |
18 class C extends A { | |
19 const C() : super(); | |
20 } | |
21 | |
22 class InstanceofTest { | |
23 static testMain() { | |
24 var a = new A(); | |
25 var b = new B(); | |
26 var c = new C(); | |
27 var n = null; | |
28 | |
29 Expect.equals(true, a is A); | |
30 Expect.equals(true, b is B); | |
31 Expect.equals(true, c is C); | |
32 Expect.equals(true, c is A); | |
33 | |
34 Expect.equals(true, a is AI); | |
35 Expect.equals(true, a is I); | |
36 Expect.equals(false, b is AI); | |
37 Expect.equals(true, b is I); | |
38 Expect.equals(true, c is AI); | |
39 Expect.equals(true, c is I); | |
40 Expect.equals(false, n is AI); | |
41 Expect.equals(false, n is I); | |
42 | |
43 Expect.equals(false, a is B); | |
44 Expect.equals(false, a is C); | |
45 Expect.equals(false, b is A); | |
46 Expect.equals(false, b is C); | |
47 Expect.equals(false, c is B); | |
48 Expect.equals(false, n is A); | |
49 | |
50 Expect.equals(false, null is A); | |
51 Expect.equals(false, null is B); | |
52 Expect.equals(false, null is C); | |
53 Expect.equals(false, null is AI); | |
54 Expect.equals(false, null is I); | |
55 | |
56 { | |
57 var a = new List(5); | |
58 Expect.equals(true, a is List); | |
59 Expect.equals(true, a is List<Object>); | |
60 Expect.equals(true, a is List<int>); | |
61 Expect.equals(true, a is List<num>); | |
62 Expect.equals(true, a is List<String>); | |
63 } | |
64 { | |
65 var a = new List<Object>(5); | |
66 Expect.equals(true, a is List); | |
67 Expect.equals(true, a is List<Object>); | |
68 Expect.equals(false, a is List<int>); | |
69 Expect.equals(false, a is List<num>); | |
70 Expect.equals(false, a is List<String>); | |
71 } | |
72 { | |
73 var a = new List<int>(5); | |
74 Expect.equals(true, a is List); | |
75 Expect.equals(true, a is List<Object>); | |
76 Expect.equals(true, a is List<int>); | |
77 Expect.equals(true, a is List<num>); | |
78 Expect.equals(false, a is List<String>); | |
79 } | |
80 { | |
81 var a = new List<num>(5); | |
82 Expect.equals(true, a is List); | |
83 Expect.equals(true, a is List<Object>); | |
84 Expect.equals(false, a is List<int>); | |
85 Expect.equals(true, a is List<num>); | |
86 Expect.equals(false, a is List<String>); | |
87 } | |
88 { | |
89 var a = new List<String>(5); | |
90 Expect.equals(true, a is List); | |
91 Expect.equals(true, a is List<Object>); | |
92 Expect.equals(false, a is List<int>); | |
93 Expect.equals(false, a is List<num>); | |
94 Expect.equals(true, a is List<String>); | |
95 } | |
96 } | |
97 } | |
98 | |
99 main() { | |
100 // Repeat type checks so that inlined tests can be tested as well. | |
101 for (int i = 0; i < 5; i++) { | |
102 InstanceofTest.testMain(); | |
103 } | |
104 } | |
105 | |
OLD | NEW |