OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012, 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 "package:expect/expect.dart"; | |
6 | |
7 // simple test with no types in signature | |
8 class A1 { | |
9 call() => 42; | |
10 } | |
11 | |
12 // same test, include return type | |
13 class A2 { | |
14 int call() => 35; | |
15 } | |
16 | |
17 class B { | |
18 call() => 28; | |
19 } | |
20 | |
21 // A call() operator can have any arity | |
22 class C { | |
23 call(arg) => 7 * arg; | |
24 } | |
25 | |
26 // Test named arguments | |
27 class D { | |
28 call([arg = 6]) => 7 * arg; | |
29 } | |
30 | |
31 // Non-trivial method body combination of positional and named. | |
32 class E { | |
33 String call(String str, {int count: 1}) { | |
34 StringBuffer buffer = new StringBuffer(); | |
35 for (var i = 0; i < count; i++) { | |
36 buffer.write(str); | |
37 if (i < count - 1) { | |
38 buffer.write(":"); | |
39 } | |
40 } | |
41 return buffer.toString(); | |
42 } | |
43 } | |
44 | |
45 main() { | |
46 var a1 = new A1(); | |
47 Expect.equals(42, a1()); | |
48 Expect.equals(42, a1.call()); | |
49 | |
50 var a2 = new A2(); | |
51 Expect.equals(35, a2()); | |
52 Expect.equals(35, a2.call()); | |
53 | |
54 var b = new B(); | |
55 Expect.equals(28, b()); | |
56 Expect.equals(28, b.call()); | |
57 | |
58 var c = new C(); | |
59 Expect.equals(42, c(6)); | |
60 Expect.equals(42, c.call(6)); | |
61 | |
62 var d = new D(); | |
63 Expect.equals(42, d()); | |
64 Expect.equals(7, d(1)); | |
65 Expect.equals(14, d(2)); | |
66 Expect.equals(42, d.call()); | |
67 Expect.equals(7, d.call(1)); | |
68 Expect.equals(14, d.call(2)); | |
69 | |
70 var e = new E(); | |
71 Expect.equals("foo", e("foo")); | |
72 Expect.equals("foo:foo", e("foo", count: 2)); | |
73 Expect.equals("foo:foo:foo", e("foo", count: 3)); | |
74 Expect.equals("foo", e.call("foo")); | |
75 Expect.equals("foo:foo", e.call("foo", count: 2)); | |
76 Expect.equals("foo:foo:foo", e.call("foo", count: 3)); | |
77 | |
78 Expect.isTrue(a1 is Function); | |
79 Expect.isTrue(e is Function); | |
80 } | |
OLD | NEW |