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

Unified Diff: tests/language/field_initialization_order_test.dart

Issue 10873033: Support non-const instance field initializers. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
Index: tests/language/field_initialization_order_test.dart
===================================================================
--- tests/language/field_initialization_order_test.dart (revision 0)
+++ tests/language/field_initialization_order_test.dart (revision 0)
@@ -0,0 +1,106 @@
+// 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.
+// Test that field initializers are evaluated in the right order.
+
+int counter = 0;
kasperl 2012/08/24 11:50:23 Counting is fun, but when you're dealing with orde
ngeoffray 2012/08/24 13:01:41 Thanks for the suggestion. Done.
+
+class Incr {
+ int value;
+ Incr() {
+ value = counter++;
+ }
+}
+
+class OneField {
+ var a = new Incr();
+
+ OneField(int expectedValue) {
+ Expect.equals(expectedValue, a.value);
+ }
+
+ OneField.init(int expectedValue) : a = new Incr() {
+ Expect.equals(expectedValue, a.value);
+ }
+}
+
+class TwoFields {
+ var b = new Incr();
+ var a = new Incr();
+
+ TwoFields(int expectedValueForA, int expectedValueForB) {
+ Expect.equals(expectedValueForA, a.value);
+ Expect.equals(expectedValueForB, b.value);
+ }
+
+ TwoFields.initA(int expectedValueForA, int expectedValueForB)
+ : a = new Incr() {
+ Expect.equals(expectedValueForA, a.value);
+ Expect.equals(expectedValueForB, b.value);
+ }
+
+ TwoFields.initB(int expectedValueForA, int expectedValueForB)
+ : b = new Incr() {
+ Expect.equals(expectedValueForA, a.value);
+ Expect.equals(expectedValueForB, b.value);
+ }
+
+ TwoFields.initBoth(int expectedValueForA, int expectedValueForB)
+ : a = new Incr(), b = new Incr() {
+ Expect.equals(expectedValueForA, a.value);
+ Expect.equals(expectedValueForB, b.value);
+ }
+}
+
+class InheritOneField extends OneField {
+ var b = new Incr();
+
+ InheritOneField(int expectedValueForA, int expectedValueForB)
+ : super(expectedValueForA) {
+ Expect.equals(expectedValueForB, b.value);
+ }
+
+ InheritOneField.init(int expectedValueForA, int expectedValueForB)
+ : b = new Incr(), super(expectedValueForA) {
+ Expect.equals(expectedValueForB, b.value);
+ }
+
+ InheritOneField.justSuper(int expectedValueForA, int expectedValueForB)
+ : super(expectedValueForA) {
+ Expect.equals(expectedValueForB, b.value);
+ }
+
+ InheritOneField.superWithInit(int expectedValueForA, int expectedValueForB)
+ : super.init(expectedValueForA) {
+ Expect.equals(expectedValueForB, b.value);
+ }
+
+ InheritOneField.initWithSuperInit(int expectedValueForA,
+ int expectedValueForB)
+ : b = new Incr(), super.init(expectedValueForA) {
+ Expect.equals(expectedValueForB, b.value);
+ }
+
+ InheritOneField.initWithSuperInit2(int expectedValueForA,
+ int expectedValueForB)
+ : super.init(expectedValueForA), b = new Incr() {
+ Expect.equals(expectedValueForB, b.value);
+ }
+}
+
+main() {
+ new OneField(0); counter = 0;
+ new OneField.init(1); counter = 0;
+
+ new TwoFields(1, 0); counter = 0;
+ new TwoFields.initA(2, 0); counter = 0;
+ new TwoFields.initB(1, 2); counter = 0;
+ new TwoFields.initBoth(2, 3); counter = 0;
+
+ new InheritOneField(1, 0); counter = 0;
+ new InheritOneField.init(2, 1); counter = 0;
+ new InheritOneField.justSuper(1, 0); counter = 0;
+ new InheritOneField.superWithInit(2, 0); counter = 0;
+ new InheritOneField.initWithSuperInit(3, 1); counter = 0;
+ new InheritOneField.initWithSuperInit2(2, 3); counter = 0;
+}
« lib/compiler/implementation/resolver.dart ('K') | « tests/co19/co19-dart2js.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698