| 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 | 6 |
| 7 // Test that 'identical(a,b)' is a compile-time constant. | 7 // Test that 'identical(a,b)' is a compile-time constant. |
| 8 | 8 |
| 9 class C { | 9 class C { |
| 10 final x; | 10 final x; |
| 11 const C(this.x); | 11 const C(this.x); |
| 12 static f3() {} | 12 static f3(){} |
| 13 static f4() {} | 13 static f4(){} |
| 14 } | 14 } |
| 15 | 15 |
| 16 const i1 = 1; | 16 const i1 = 1; |
| 17 const i2 = 2; | 17 const i2 = 2; |
| 18 const d1 = 1.5; | 18 const d1 = 1.5; |
| 19 const d2 = 2.5; | 19 const d2 = 2.5; |
| 20 const b1 = true; | 20 const b1 = true; |
| 21 const b2 = false; | 21 const b2 = false; |
| 22 const s1 = "1"; | 22 const s1 = "1"; |
| 23 const s2 = "2"; | 23 const s2 = "2"; |
| 24 const l1 = const [1, 2]; | 24 const l1 = const [1,2]; |
| 25 const l2 = const [2, 3]; | 25 const l2 = const [2,3]; |
| 26 const m1 = const {"x": 1}; | 26 const m1 = const {"x": 1}; |
| 27 const m2 = const {"x": 2}; | 27 const m2 = const {"x": 2}; |
| 28 const c1 = const C(1); | 28 const c1 = const C(1); |
| 29 const c2 = const C(2); | 29 const c2 = const C(2); |
| 30 f1() {} | 30 f1(){} |
| 31 f2() {} | 31 f2(){} |
| 32 const id = identical; | 32 const id = identical; |
| 33 | 33 |
| 34 class CT { | 34 class CT { |
| 35 final x1; | 35 final x1; |
| 36 final x2; | 36 final x2; |
| 37 final bool id; | 37 final bool id; |
| 38 const CT(var x1, var x2) | 38 const CT(var x1, var x2) |
| 39 : this.x1 = x1, | 39 : this.x1 = x1, this.x2 = x2, this.id = identical(x1, x2); |
| 40 this.x2 = x2, | 40 void test(void expect(a,b), name) { |
| 41 this.id = identical(x1, x2); | |
| 42 void test(void expect(a, b), name) { | |
| 43 expect(id, "$name: identical($x1,$x2)"); | 41 expect(id, "$name: identical($x1,$x2)"); |
| 44 } | 42 } |
| 45 } | 43 } |
| 46 | 44 |
| 47 const trueTests = const [ | 45 const trueTests = const [ |
| 48 const CT(2 - 1, i1), | 46 const CT(2 - 1, i1), |
| 49 const CT(1 + 1, i2), | 47 const CT(1 + 1, i2), |
| 50 const CT(2.5 - 1.0, d1), | 48 const CT(2.5 - 1.0, d1), |
| 51 const CT(1.5 + 1.0, d2), | 49 const CT(1.5 + 1.0, d2), |
| 52 const CT(false || true, b1), | 50 const CT(false || true, b1), |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 for (int i = 0; i < trueTests.length; i++) { | 99 for (int i = 0; i < trueTests.length; i++) { |
| 102 trueTests[i].test(Expect.isTrue, "true[$i]"); | 100 trueTests[i].test(Expect.isTrue, "true[$i]"); |
| 103 } | 101 } |
| 104 for (int i = 0; i < falseTests.length; i++) { | 102 for (int i = 0; i < falseTests.length; i++) { |
| 105 falseTests[i].test(Expect.isFalse, "false[$i]"); | 103 falseTests[i].test(Expect.isFalse, "false[$i]"); |
| 106 } | 104 } |
| 107 | 105 |
| 108 var x = idtest; // //# 01: continued | 106 var x = idtest; // //# 01: continued |
| 109 var x = T.idtest2; // //# 02: continued | 107 var x = T.idtest2; // //# 02: continued |
| 110 } | 108 } |
| 109 |
| OLD | NEW |