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

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

Issue 2883823003: Add tests for initializer list execution in object initialization (Closed)
Patch Set: 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
Index: pkg/kernel/testcases/interpreter/object_initializers_test.dart
diff --git a/pkg/kernel/testcases/interpreter/object_initializers_test.dart b/pkg/kernel/testcases/interpreter/object_initializers_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..aa2a70e6af17a8eb95b7a833d72bc533c9c36f7b
--- /dev/null
+++ b/pkg/kernel/testcases/interpreter/object_initializers_test.dart
@@ -0,0 +1,41 @@
+// 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_initializers_test;
+
+/// Simple program creating an object with field initializers.
+void main() {
+ var a = new A('foo1', 'foo2');
+ print(a.foo1);
+ print(a.foo2);
+
+ var b = new B(fieldInitializer(0, 'foo1'), fieldInitializer(0, 'foo2'));
+ print(b.foo1);
+ print(b.foo2);
+ print(b.foo3);
+}
+
+class A {
+ String foo1;
+ String foo2;
+
+ A(String foo1, String foo2)
+ : foo1 = foo1,
+ foo2 = foo2;
+}
+
+class B {
+ String foo1 = fieldInitializer(1, 'foo1');
+ String foo2 = fieldInitializer(1, 'foo2');
+ String foo3 = fieldInitializer(1, 'foo3');
+
+ // TODO: uncomment when support for *this* in initializer list is added.
+ // B(this.foo1, this.foo2) : foo3 = foo2;
+ B(this.foo1, this.foo2) : foo3 = fieldInitializer(2, 'foo3');
+}
+
+String fieldInitializer(int f, String s) {
+ print('$s: $f');
+ return '$s: $f';
+}
« no previous file with comments | « pkg/kernel/lib/interpreter/interpreter.dart ('k') | pkg/kernel/testcases/interpreter/object_initializers_test.dart.expect » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698