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

Unified Diff: pkg/kernel/testcases/interpreter/object_fields_test.dart

Issue 2875023002: Add test for initialization of instance fields with initializer expressions (Closed)
Patch Set: Add test with field initializer and redirecting Created 3 years, 7 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
« no previous file with comments | « no previous file | pkg/kernel/testcases/interpreter/object_fields_test.dart.expect » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/kernel/testcases/interpreter/object_fields_test.dart
diff --git a/pkg/kernel/testcases/interpreter/object_fields_test.dart b/pkg/kernel/testcases/interpreter/object_fields_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..45a031638d78405fec8a067f1f67d7d8c4811981
--- /dev/null
+++ b/pkg/kernel/testcases/interpreter/object_fields_test.dart
@@ -0,0 +1,49 @@
+// Copyright (c) 2017, 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.
+
+library object_fields_test;
+
+/// Simple program creating an object and accessing its initialized fields.
+void main() {
+ var a = new A();
+ print(a.f1);
+ print(a.f2);
+
+ new B(0);
+ new B.redirecting1(0);
+ new B.redirecting2(0);
+
+ var c = new C.redirecting1(0);
+ print(c.f1);
+ print(c.f2);
+}
+
+class A {
+ int f1 = 37;
+ String f2 = 'hello world';
+}
+
+class B {
+ B(int i);
+ B.redirecting1(int i) : this(redirecting(i, 'B.redirecting1'));
+ B.redirecting2(int i) : this.redirecting1(redirecting(i, 'B.redirecting2'));
+}
+
+class C {
+ int f1 = fieldInitializer(0, 'C.f1');
+ int f2 = fieldInitializer(1, 'C.f2');
+
+ C(int i);
+ C.redirecting1(int i) : this(redirecting(i, 'C.redirecting1'));
+}
+
+int redirecting(int i, String s) {
+ print('$s: $i');
+ return i + 1;
+}
+
+int fieldInitializer(int f, String s) {
+ print('$s: $f');
+ return f;
+}
« no previous file with comments | « no previous file | pkg/kernel/testcases/interpreter/object_fields_test.dart.expect » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698