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 // Check that initializers of static const fields are compile time constants. | 4 // Check that initializers of static const fields are compile time constants. |
5 | 5 |
6 class CanonicalConstTest { | 6 class CanonicalConstTest { |
7 static const A = const C1(); | 7 static const A = const C1(); |
8 static const B = const C2(); | 8 static const B = const C2(); |
9 | 9 |
10 static testMain() { | 10 static testMain() { |
11 Expect.isTrue(null===null); | 11 Expect.isTrue(identical(null, null)); |
Lasse Reichstein Nielsen
2012/11/12 13:10:41
Use
Expect.identical
and
Expect.isFalse(identic
floitsch
2012/11/12 22:18:43
Done.
| |
12 Expect.isTrue(null!==0); | 12 Expect.isTrue(!identical(null, 0)); |
13 Expect.isTrue(1===1); | 13 Expect.isTrue(identical(1, 1)); |
14 Expect.isTrue(1!==2); | 14 Expect.isTrue(!identical(1, 2)); |
15 Expect.isTrue(true===true); | 15 Expect.isTrue(identical(true, true)); |
16 Expect.isTrue("so"==="so"); | 16 Expect.isTrue(identical("so", "so")); |
17 Expect.isTrue(const Object()===const Object()); | 17 Expect.isTrue(identical(const Object(), const Object())); |
18 Expect.isTrue(const Object()!==const C1()); | 18 Expect.isTrue(!identical(const Object(), const C1())); |
19 Expect.isTrue(const C1()===const C1()); | 19 Expect.isTrue(identical(const C1(), const C1())); |
20 Expect.isTrue(A===const C1()); | 20 Expect.isTrue(identical(A, const C1())); |
21 Expect.isTrue(const C1()!==const C2()); | 21 Expect.isTrue(!identical(const C1(), const C2())); |
22 Expect.isTrue(B===const C2()); | 22 Expect.isTrue(identical(B, const C2())); |
23 // TODO(johnlenz): these two values don't currently have the same type | 23 // TODO(johnlenz): these two values don't currently have the same type |
24 // Expect.isTrue(const [1,2] === const List[1,2]); | 24 // Expect.isTrue(const [1,2] === const List[1,2]); |
25 Expect.isTrue(const [2,1] !== const[1,2]); | 25 Expect.isTrue(!identical(const [2,1], const[1,2])); |
26 Expect.isTrue(const <int>[1,2] === const <int>[1,2]); | 26 Expect.isTrue(identical(const <int>[1,2], const <int>[1,2])); |
27 Expect.isTrue(const <Object>[1,2] === const <Object>[1,2]); | 27 Expect.isTrue(identical(const <Object>[1,2], const <Object>[1,2])); |
28 Expect.isTrue(const <int>[1,2] !== const <double>[1.0,2.0]); | 28 Expect.isTrue(!identical(const <int>[1,2], const <double>[1.0,2.0])); |
29 Expect.isTrue(const {"a":1, "b":2} === const {"a":1, "b":2}); | 29 Expect.isTrue(identical(const {"a":1, "b":2}, const {"a":1, "b":2})); |
30 Expect.isTrue(const {"a":1, "b":2} !== const {"a":2, "b":2}); | 30 Expect.isTrue(!identical(const {"a":1, "b":2}, const {"a":2, "b":2})); |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 class C1 { | 34 class C1 { |
35 const C1(); | 35 const C1(); |
36 } | 36 } |
37 | 37 |
38 class C2 extends C1 { | 38 class C2 extends C1 { |
39 const C2() : super(); | 39 const C2() : super(); |
40 } | 40 } |
41 | 41 |
42 main() { | 42 main() { |
43 CanonicalConstTest.testMain(); | 43 CanonicalConstTest.testMain(); |
44 } | 44 } |
OLD | NEW |