OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 import 'expect.dart'; |
| 6 |
| 7 class A { |
| 8 Function fun; |
| 9 A(this.fun); |
| 10 } |
| 11 |
| 12 globalFunctionPositional(int a, [int b = 42]) => a + b; |
| 13 |
| 14 globalFunctionNamed(int a, {int b: 42}) => a + b; |
| 15 |
| 16 class Foo { |
| 17 int base; |
| 18 |
| 19 Foo(this.base); |
| 20 |
| 21 methodFunctionPositional(int a, [int b = 42]) => base + a + b; |
| 22 |
| 23 methodFunctionNamed(int a, {int b: 42}) => base + a + b; |
| 24 } |
| 25 |
| 26 main() { |
| 27 Expect.isTrue(new A(globalFunctionPositional).fun(1, 2) == 3); |
| 28 Expect.isTrue(new A(globalFunctionPositional).fun(1) == 43); |
| 29 Expect.isTrue(new A(globalFunctionNamed).fun(1, b: 2) == 3); |
| 30 Expect.isTrue(new A(globalFunctionNamed).fun(1) == 43); |
| 31 |
| 32 var foo = new Foo(100); |
| 33 Expect.isTrue(new A(foo.methodFunctionPositional).fun(1, 2) == 103); |
| 34 Expect.isTrue(new A(foo.methodFunctionPositional).fun(1) == 143); |
| 35 Expect.isTrue(new A(foo.methodFunctionNamed).fun(1, b: 2) == 103); |
| 36 Expect.isTrue(new A(foo.methodFunctionNamed).fun(1) == 143); |
| 37 } |
OLD | NEW |