OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 // Dart test program for testing named parameters with various values that might | |
6 // be implemented as 'falsy' values in a JavaScript implementation. | |
7 | |
8 | |
9 class TestClass { | |
10 TestClass(); | |
11 | |
12 method([value = 100]) => value; | |
13 | |
14 static staticMethod([value = 200]) => value; | |
15 } | |
16 | |
17 globalMethod([value = 300]) => value; | |
18 | |
19 final testValues = const [0, 0.0, '', false, null]; | |
20 | |
21 testFunction(f) { | |
22 Expect.isTrue(f() >= 100); | |
23 for (var v in testValues) { | |
24 Expect.equals(v, f(v)); | |
25 Expect.equals(v, f(value: v)); | |
26 } | |
27 } | |
28 | |
29 main() { | |
30 var obj = new TestClass(); | |
31 | |
32 Expect.equals(100, obj.method()); | |
33 Expect.equals(200, TestClass.staticMethod()); | |
34 Expect.equals(300, globalMethod()); | |
35 | |
36 for (var v in testValues) { | |
37 Expect.equals(v, obj.method(v)); | |
38 Expect.equals(v, obj.method(value: v)); | |
39 Expect.equals(v, TestClass.staticMethod(v)); | |
40 Expect.equals(v, TestClass.staticMethod(value: v)); | |
41 Expect.equals(v, globalMethod(v)); | |
42 Expect.equals(v, globalMethod(value: v)); | |
43 } | |
44 | |
45 // Test via indirect call. | |
46 testFunction(obj.method); | |
47 testFunction(TestClass.staticMethod); | |
48 testFunction(globalMethod); | |
49 } | |
OLD | NEW |