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 | 4 |
5 class C<T> {} | 5 class C<T> {} |
6 | 6 |
7 class D {} | 7 class D {} |
8 | 8 |
9 typedef int Foo(bool b); | 9 typedef int Foo(bool b); |
10 | 10 |
11 sameType(a, b) { | 11 sameType(a, b) { |
12 Expect.identical(a.runtimeType, b.runtimeType); | 12 Expect.identical(a.runtimeType, b.runtimeType); |
13 } | 13 } |
14 | 14 |
15 differentType(a, b) { | |
16 print("a: ${a.runtimeType}"); | |
17 print("b: ${b.runtimeType}"); | |
18 Expect.isFalse(a.runtimeType === b.runtimeType); | |
19 } | |
20 | |
21 main() { | 15 main() { |
22 // Test type literals. | 16 // Test type literals. |
23 Expect.identical(int, int); | 17 Expect.identical(int, int); |
24 Expect.isFalse(int === num); | 18 Expect.isFalse(identical(int, num)); |
25 Expect.identical(Foo, Foo); | 19 Expect.identical(Foo, Foo); |
26 | 20 |
27 // Test that class literals return instances of Type. | 21 // Test that class literals return instances of Type. |
28 Expect.isTrue((D).runtimeType is Type); | 22 Expect.isTrue((D).runtimeType is Type); |
29 | 23 |
30 // Test that types from runtimeType and literals agree. | 24 // Test that types from runtimeType and literals agree. |
31 Expect.identical(int, 1.runtimeType); | 25 Expect.identical(int, 1.runtimeType); |
32 Expect.identical(C, new C().runtimeType); | 26 Expect.identical(C, new C().runtimeType); |
33 Expect.identical(D, new D().runtimeType); | 27 Expect.identical(D, new D().runtimeType); |
34 | 28 |
35 // runtimeType on type is idempotent. | 29 // runtimeType on type is idempotent. |
36 Expect.identical((D).runtimeType, (D).runtimeType.runtimeType); | 30 Expect.identical((D).runtimeType, (D).runtimeType.runtimeType); |
37 | 31 |
38 // Test that operator calls on class literals go to Type. | 32 // Test that operator calls on class literals go to Type. |
39 Expect.throws(() => C = 1, (e) => e is NoSuchMethodError); | 33 Expect.throws(() => C = 1, (e) => e is NoSuchMethodError); |
40 Expect.throws(() => C++, (e) => e is NoSuchMethodError); | 34 Expect.throws(() => C++, (e) => e is NoSuchMethodError); |
41 Expect.throws(() => C + 1, (e) => e is NoSuchMethodError); | 35 Expect.throws(() => C + 1, (e) => e is NoSuchMethodError); |
42 Expect.throws(() => C[2], (e) => e is NoSuchMethodError); | 36 Expect.throws(() => C[2], (e) => e is NoSuchMethodError); |
43 Expect.throws(() => C[2] = 'hest', (e) => e is NoSuchMethodError); | 37 Expect.throws(() => C[2] = 'hest', (e) => e is NoSuchMethodError); |
44 } | 38 } |
OLD | NEW |