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

Unified Diff: tests/kernel/unsorted/closures_test.dart

Issue 2451623006: Reland "Merge more Kernel infrastructure from kernel_sdk SDK fork." (Closed)
Patch Set: Fix Created 4 years, 2 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 | « tests/kernel/unsorted/closures_regression_test.dart ('k') | tests/kernel/unsorted/conditional_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/kernel/unsorted/closures_test.dart
diff --git a/tests/kernel/unsorted/closures_test.dart b/tests/kernel/unsorted/closures_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..da1279404f4b985d19a6f0b2a2efc298ddcc452f
--- /dev/null
+++ b/tests/kernel/unsorted/closures_test.dart
@@ -0,0 +1,65 @@
+// Copyright (c) 2016, 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.
+
+import 'expect.dart';
+
+class Base {
+ int constant1000() => 1000;
+}
+
+class Foo extends Base {
+ final int base;
+ Foo(this.base);
+
+ nestedAdderFunction(a, b, c, d, e) {
+ var result = a + b;
+ return () {
+ var result2 = c + d;
+ return () {
+ return base + result + result2 + e;
+ };
+ };
+ }
+
+ nestedAdderFunction2(a, b, c, d, e) {
+ var result = a + b;
+ return () {
+ var base = super.constant1000;
+ var result2 = c + d;
+ return () {
+ return base() + result + result2 + e;
+ };
+ };
+ }
+}
+
+nestedAdderFunction(a, b, c, d, e) {
+ var result = a + b;
+ return () {
+ var result2 = c + d;
+ return () {
+ return result + result2 + e;
+ };
+ };
+}
+
+main() {
+ Expect.isTrue(nestedAdderFunction(1, 2, 3, 4, 5)()() == 15);
+
+ var foo = new Foo(100);
+ Expect.isTrue(foo.nestedAdderFunction(1, 2, 3, 4, 5)()() == 115);
+ Expect.isTrue(foo.nestedAdderFunction2(1, 2, 3, 4, 5)()() == 1015);
+
+ var funs = [];
+ for (int i = 0; i < 3; i++) {
+ funs.add(() => i);
+ }
+ Expect.isTrue((funs[0]() + funs[1]() + funs[2]()) == 3);
+
+ var funs2 = [];
+ for (var i in [0, 1, 2]) {
+ funs2.add(() => i);
+ }
+ Expect.isTrue((funs2[0]() + funs2[1]() + funs2[2]()) == 3);
+}
« no previous file with comments | « tests/kernel/unsorted/closures_regression_test.dart ('k') | tests/kernel/unsorted/conditional_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698