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

Unified Diff: tests/language/src/CompileTimeConstantITest.dart

Issue 9753001: super and this in compile-time constants. (Closed) Base URL: /home/flo/programming/dart2/../dart/dart@master
Patch Set: Address comments. Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: tests/language/src/CompileTimeConstantITest.dart
diff --git a/tests/language/src/CompileTimeConstantITest.dart b/tests/language/src/CompileTimeConstantITest.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f2d33c9d2ec1c05847c6963b45b754df29d3d520
--- /dev/null
+++ b/tests/language/src/CompileTimeConstantITest.dart
@@ -0,0 +1,105 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+class A {
+ final x = 4;
+ const A(this.x);
+ const A.redirect(x) : this(x + 1);
+ const A.optional([this.x = 5]);
+}
+
+class B extends A {
+ const B(x, this.y) : super(x);
+ const B.redirect(x, y) : this(x + 22, y + 22);
+ const B.redirect2(x, y) : this.redirect3(x + 122, y + 122);
+ const B.redirect3(x, y) : this.y = y, super.redirect(x);
+ const B.optional(x, [this.y]) : super(x);
+ const B.optional2([x, this.y]) : super(x);
+ final y;
+}
+
+class C extends B {
+ const C(x, y, this.z) : super(x, y);
+ const C.redirect(x, y, z) : this(x + 33, y + 33, z + 33);
+ const C.redirect2(x, y, z) : this.redirect3(x + 333, y + 333, z + 333);
+ const C.redirect3(x, y, z) : this.z = z, super.redirect2(x, y);
+ const C.optional(x, [y, this.z]) : super(x, y);
+ const C.optional2([x, y, z]): this.z = z, super(x, y);
+ const C.optional3([this.z]) : super.optional2();
+ final z;
+}
+
+final a1 = const A(499);
+final a2 = const A.redirect(10499);
+final a3 = const A.optional();
+final a1b = const A.redirect(498);
+final a3b = const A(5);
+
+final b1 = const B(99499, -99499);
+final b2 = const B.redirect(1234, 5678);
+final b3 = const B.redirect2(112233, 556677);
+final b4 = const B.redirect3(332211, 776655);
+final b5 = const B.optional(43526);
+final b6 = const B.optional2(y: 9753, x:8642);
+final b3b = const B(112233 + 122 + 1, 556677 + 122);
+final b6b = const B(8642, 9753);
+
+final c1 = const C(121, 232, 343);
+final c2 = const C.redirect(12321, 23432, 34543);
+final c3 = const C.redirect2(32123, 43234, 54345);
+final c4 = const C.redirect3(313, 424, 535);
+final c5 = const C.optional(191, 181, 171);
+final c6 = const C.optional(-191);
+final c7 = const C.optional2();
+final c8 = const C.optional3(9911);
+final c3b = const C(32123 + 333 + 122 + 1, 43234 + 333 + 122, 54345 + 333);
+
+main() {
+ Expect.equals(499, a1.x);
+ Expect.equals(10500, a2.x);
+ Expect.equals(5, a3.x);
+ Expect.identical(a1, a1b);
+ Expect.identical(a3, a3b);
+
+ Expect.equals(99499, b1.x);
+ Expect.equals(-99499, b1.y);
+ Expect.equals(1256, b2.x);
+ Expect.equals(5700, b2.y);
+ Expect.equals(112233 + 122 + 1, b3.x);
+ Expect.equals(556677 + 122, b3.y);
+ Expect.equals(332211 + 1, b4.x);
+ Expect.equals(776655, b4.y);
+ Expect.equals(43526, b5.x);
+ Expect.equals(null, b5.y);
+ Expect.equals(8642, b6.x);
+ Expect.equals(9753, b6.y);
+ Expect.identical(b3, b3b);
+ Expect.identical(b6, b6b);
+
+ Expect.equals(121, c1.x);
+ Expect.equals(232, c1.y);
+ Expect.equals(343, c1.z);
+ Expect.equals(12321 + 33, c2.x);
+ Expect.equals(23432 + 33, c2.y);
+ Expect.equals(34543 + 33, c2.z);
+ Expect.equals(32123 + 333 + 122 + 1, c3.x);
+ Expect.equals(43234 + 333 + 122, c3.y);
+ Expect.equals(54345 + 333, c3.z);
+ Expect.equals(313 + 122 + 1, c4.x);
+ Expect.equals(424 + 122, c4.y);
+ Expect.equals(535, c4.z);
+ Expect.equals(191, c5.x);
+ Expect.equals(181, c5.y);
+ Expect.equals(171, c5.z);
+ Expect.equals(-191, c6.x);
+ Expect.equals(null, c6.y);
+ Expect.equals(null, c6.z);
+ Expect.equals(null, c7.x);
+ Expect.equals(null, c7.y);
+ Expect.equals(null, c7.z);
+ Expect.equals(null, c8.x);
+ Expect.equals(null, c8.y);
+ Expect.equals(9911, c8.z);
+ Expect.identical(c3, c3b);
+}

Powered by Google App Engine
This is Rietveld 408576698