Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: tests/language/compile_time_constant10_test.dart

Issue 3002573002: Migrating another batch of tests to dart 2. (Closed)
Patch Set: Removed library closure_type_test from test_file Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/language/comparison_test.dart ('k') | tests/language/compile_time_constant11_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import "package:expect/expect.dart";
6
7 // Test that 'identical(a,b)' is a compile-time constant.
8
9 class C {
10 final x;
11 const C(this.x);
12 static f3() {}
13 static f4() {}
14 }
15
16 const i1 = 1;
17 const i2 = 2;
18 const d1 = 1.5;
19 const d2 = 2.5;
20 const b1 = true;
21 const b2 = false;
22 const s1 = "1";
23 const s2 = "2";
24 const l1 = const [1, 2];
25 const l2 = const [2, 3];
26 const m1 = const {"x": 1};
27 const m2 = const {"x": 2};
28 const c1 = const C(1);
29 const c2 = const C(2);
30 f1() {}
31 f2() {}
32 const id = identical;
33
34 class CT {
35 final x1;
36 final x2;
37 final bool id;
38 const CT(var x1, var x2)
39 : this.x1 = x1,
40 this.x2 = x2,
41 this.id = identical(x1, x2);
42 void test(void expect(a, b), name) {
43 expect(id, "$name: identical($x1,$x2)");
44 }
45 }
46
47 const trueTests = const [
48 const CT(2 - 1, i1),
49 const CT(1 + 1, i2),
50 const CT(2.5 - 1.0, d1),
51 const CT(1.5 + 1.0, d2),
52 const CT(false || true, b1),
53 const CT(true && false, b2),
54 const CT('$i1', s1),
55 const CT('$i2', s2),
56 const CT(const [i1, 2], l1),
57 const CT(const [i2, 3], l2),
58 const CT(const {"x": i1}, m1),
59 const CT(const {"x": i2}, m2),
60 const CT(const C(i1), c1),
61 const CT(const C(i2), c2),
62 const CT(f1, f1),
63 const CT(f2, f2),
64 const CT(C.f3, C.f3),
65 const CT(C.f4, C.f4),
66 const CT(id, identical),
67 ];
68
69 const falseTests = const [
70 const CT(i1, i2),
71 const CT(d1, d2),
72 const CT(b1, b2),
73 const CT(s1, s2),
74 const CT(l1, l2),
75 const CT(m1, m2),
76 const CT(c1, c2),
77 const CT(f1, f2),
78 const CT(i1, d1),
79 const CT(d1, b1),
80 const CT(b1, s1),
81 const CT(s1, l1),
82 const CT(l1, m1),
83 const CT(m1, c1),
84 const CT(c1, f1),
85 const CT(f1, C.f3),
86 const CT(C.f3, identical),
87 const CT(identical, i1),
88 ];
89
90 // Not a constant if it's not written 'identical'.
91 const idtest = id(i1, i2); // //# 01: compile-time error
92
93 // Not a constant if aliased? (Current interpretation, waiting for
94 // confirmation).
95 class T { // //# 02: compile-time error
96 static const identical = id; // //# 02: continued
97 static const idtest2 = identical(i1, i2); // //# 02: continued
98 } // //# 02: continued
99
100 main() {
101 for (int i = 0; i < trueTests.length; i++) {
102 trueTests[i].test(Expect.isTrue, "true[$i]");
103 }
104 for (int i = 0; i < falseTests.length; i++) {
105 falseTests[i].test(Expect.isFalse, "false[$i]");
106 }
107
108 var x = idtest; // //# 01: continued
109 var x = T.idtest2; // //# 02: continued
110 }
OLDNEW
« no previous file with comments | « tests/language/comparison_test.dart ('k') | tests/language/compile_time_constant11_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698