| Index: tests/language/local_function_test.dart
|
| diff --git a/tests/language/local_function_test.dart b/tests/language/local_function_test.dart
|
| index 8051fe2cf0d5caa02bf4e588c30def0d0702b0af..05ac410e8340d7b40bb2aecb0118c55f73fd1f33 100644
|
| --- a/tests/language/local_function_test.dart
|
| +++ b/tests/language/local_function_test.dart
|
| @@ -6,16 +6,20 @@
|
| import "package:expect/expect.dart";
|
|
|
| class LocalFunctionTest {
|
| - LocalFunctionTest() : field1 = 100, field2_ = 200 { }
|
| + LocalFunctionTest()
|
| + : field1 = 100,
|
| + field2_ = 200 {}
|
| static int f(int n) {
|
| int a = 0;
|
| g(int m) {
|
| - a = 3*n + m + 1; // Capture parameter n and local a.
|
| + a = 3 * n + m + 1; // Capture parameter n and local a.
|
| return a;
|
| }
|
| +
|
| var b = g(n);
|
| return a + b;
|
| }
|
| +
|
| static int h(int n) {
|
| k(int n) {
|
| var a = new List(n);
|
| @@ -23,8 +27,8 @@ class LocalFunctionTest {
|
| int i;
|
| for (i = 0; i < n; i++) {
|
| var j = i;
|
| - a[i] = () => i; // Captured i is always n.
|
| - b[i] = () => j; // Captured j varies from 0 to n-1.
|
| + a[i] = () => i; // Captured i is always n.
|
| + b[i] = () => j; // Captured j varies from 0 to n-1.
|
| }
|
| var a_sum = 0;
|
| var b_sum = 0;
|
| @@ -34,16 +38,18 @@ class LocalFunctionTest {
|
| }
|
| return a_sum + b_sum;
|
| }
|
| +
|
| return k(n);
|
| }
|
| +
|
| static int h2(int n) {
|
| k(int n) {
|
| var a = new List(n);
|
| var b = new List(n);
|
| for (int i = 0; i < n; i++) {
|
| var j = i;
|
| - a[i] = () => i; // Captured i varies from 0 to n-1.
|
| - b[i] = () => j; // Captured j varies from 0 to n-1.
|
| + a[i] = () => i; // Captured i varies from 0 to n-1.
|
| + b[i] = () => j; // Captured j varies from 0 to n-1.
|
| }
|
| var a_sum = 0;
|
| var b_sum = 0;
|
| @@ -53,65 +59,90 @@ class LocalFunctionTest {
|
| }
|
| return a_sum + b_sum;
|
| }
|
| +
|
| return k(n);
|
| }
|
| +
|
| int field1;
|
| int field2_;
|
| - int get field2 { return field2_; }
|
| - void set field2(int value) { field2_ = value; }
|
| + int get field2 {
|
| + return field2_;
|
| + }
|
| +
|
| + void set field2(int value) {
|
| + field2_ = value;
|
| + }
|
|
|
| int method(int n) {
|
| - incField1() { field1++; }
|
| - incField2() { field2++; }
|
| + incField1() {
|
| + field1++;
|
| + }
|
| +
|
| + incField2() {
|
| + field2++;
|
| + }
|
| +
|
| for (int i = 0; i < n; i++) {
|
| incField1();
|
| incField2();
|
| }
|
| return field1 + field2;
|
| }
|
| +
|
| int execute(int times, apply(int x)) {
|
| for (int i = 0; i < times; i++) {
|
| apply(i);
|
| }
|
| return field1;
|
| }
|
| +
|
| int testExecute(int n) {
|
| - execute(n, (int x) { field1 += x; });
|
| + execute(n, (int x) {
|
| + field1 += x;
|
| + });
|
| return field1;
|
| }
|
| +
|
| static int foo(int n) {
|
| - return -100; // Wrong foo.
|
| + return -100; // Wrong foo.
|
| }
|
| +
|
| static testSelfReference1(int n) {
|
| int foo(int n) {
|
| if (n == 0) {
|
| return 0;
|
| } else {
|
| - return 1 + foo(n - 1); // Local foo, not static foo.
|
| + return 1 + foo(n - 1); // Local foo, not static foo.
|
| }
|
| - };
|
| - return foo(n); // Local foo, not static foo.
|
| + }
|
| +
|
| + ;
|
| + return foo(n); // Local foo, not static foo.
|
| }
|
| +
|
| static void hep(Function f) {
|
| f();
|
| }
|
| +
|
| static testNesting(int n) {
|
| - var a = new List(n*n);
|
| + var a = new List(n * n);
|
| f0() {
|
| for (int i = 0; i < n; i++) {
|
| int vi = i;
|
| f1() {
|
| for (int j = 0; j < n; j++) {
|
| int vj = j;
|
| - a[i*n + j] = () => vi*n + vj;
|
| + a[i * n + j] = () => vi * n + vj;
|
| }
|
| }
|
| +
|
| f1();
|
| }
|
| }
|
| +
|
| f0();
|
| int result = 0;
|
| - for (int k = 0; k < n*n; k++) {
|
| + for (int k = 0; k < n * n; k++) {
|
| Expect.equals(k, a[k]());
|
| result += a[k]();
|
| }
|
| @@ -121,7 +152,9 @@ class LocalFunctionTest {
|
| static var field5;
|
| static var set_field5_func;
|
| static testClosureCallStatement(int x) {
|
| - LocalFunctionTest.set_field5_func = (int n) { field5 = n * n; };
|
| + LocalFunctionTest.set_field5_func = (int n) {
|
| + field5 = n * n;
|
| + };
|
| (LocalFunctionTest.set_field5_func)(x);
|
| Expect.equals(x * x, LocalFunctionTest.field5);
|
| return true;
|
| @@ -176,13 +209,13 @@ class LocalFunctionTest {
|
| }
|
|
|
| static testMain() {
|
| - Expect.equals(2*(3*2 + 2 + 1), f(2));
|
| - Expect.equals(10*10 + 10*9/2, h(10));
|
| + Expect.equals(2 * (3 * 2 + 2 + 1), f(2));
|
| + Expect.equals(10 * 10 + 10 * 9 / 2, h(10));
|
| Expect.equals(90, h2(10));
|
| Expect.equals(320, new LocalFunctionTest().method(10));
|
| Expect.equals(145, new LocalFunctionTest().testExecute(10));
|
| Expect.equals(5, testSelfReference1(5));
|
| - Expect.equals(24*25/2, testNesting(5));
|
| + Expect.equals(24 * 25 / 2, testNesting(5));
|
| Expect.equals(true, testClosureCallStatement(7));
|
| Expect.equals(99, doThis(10, (n) => n * n - 1));
|
| testExceptions();
|
|
|