| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // Dart test program testing closures. | 4 // Dart test program testing closures. |
| 5 | 5 |
| 6 class LocalFunctionTest { | 6 class LocalFunctionTest { |
| 7 LocalFunctionTest() : field1 = 100, field2_ = 200 { } | 7 LocalFunctionTest() : field1 = 100, field2_ = 200 { } |
| 8 static int f(int n) { | 8 static int f(int n) { |
| 9 int a = 0; | 9 int a = 0; |
| 10 g(int m) { | 10 g(int m) { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } on NoSuchMethodError catch (e) { | 159 } on NoSuchMethodError catch (e) { |
| 160 exception_caught = true; | 160 exception_caught = true; |
| 161 } | 161 } |
| 162 Expect.equals(true, exception_caught); | 162 Expect.equals(true, exception_caught); |
| 163 | 163 |
| 164 // Overwrite closure value. | 164 // Overwrite closure value. |
| 165 f = 3; | 165 f = 3; |
| 166 exception_caught = false; | 166 exception_caught = false; |
| 167 try { | 167 try { |
| 168 f(1); | 168 f(1); |
| 169 } on ObjectNotClosureException catch (e) { | 169 } on NoSuchMethodError catch (e) { |
| 170 exception_caught = true; | 170 exception_caught = true; |
| 171 } | 171 } |
| 172 Expect.equals(true, exception_caught); | 172 Expect.equals(true, exception_caught); |
| 173 | 173 |
| 174 // Do not expect any exceptions to be thrown. | 174 // Do not expect any exceptions to be thrown. |
| 175 var g = ([int n = 1]) => n + 1; | 175 var g = ([int n = 1]) => n + 1; |
| 176 Expect.equals(2, g()); | 176 Expect.equals(2, g()); |
| 177 Expect.equals(3, g(2)); | 177 Expect.equals(3, g(2)); |
| 178 } | 178 } |
| 179 | 179 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 195 Expect.equals(99, doThis(10, int f(n) => n * n - 1)); | 195 Expect.equals(99, doThis(10, int f(n) => n * n - 1)); |
| 196 Expect.equals(99, doThis(10, (n) => n * n - 1)); | 196 Expect.equals(99, doThis(10, (n) => n * n - 1)); |
| 197 Expect.equals(99, doThis(10, f(n) => n * n - 1)); | 197 Expect.equals(99, doThis(10, f(n) => n * n - 1)); |
| 198 testExceptions(); | 198 testExceptions(); |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 | 201 |
| 202 main() { | 202 main() { |
| 203 LocalFunctionTest.testMain(); | 203 LocalFunctionTest.testMain(); |
| 204 } | 204 } |
| OLD | NEW |