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 test1(bool passed, [a = 42]) { |
| 6 if (passed) { |
| 7 Expect.equals(54, a); |
| 8 Expect.isTrue(?a); |
| 9 } else { |
| 10 Expect.equals(42, a); |
| 11 Expect.isFalse(?a); |
| 12 } |
| 13 Expect.isTrue(?passed); |
| 14 } |
| 15 |
| 16 test2() { |
| 17 var closure = (passed, [a = 42]) { |
| 18 if (passed) { |
| 19 Expect.equals(54, a); |
| 20 Expect.isTrue(?a); |
| 21 } else { |
| 22 Expect.equals(42, a); |
| 23 Expect.isFalse(?a); |
| 24 } |
| 25 Expect.isTrue(?passed); |
| 26 }; |
| 27 closure(true, 54); |
| 28 closure(false); |
| 29 } |
| 30 |
| 31 class A { |
| 32 test3(bool passed, [a = 42]) { |
| 33 if (passed) { |
| 34 Expect.equals(54, a); |
| 35 Expect.isTrue(?a); |
| 36 } else { |
| 37 Expect.equals(42, a); |
| 38 Expect.isFalse(?a); |
| 39 } |
| 40 Expect.isTrue(?passed); |
| 41 } |
| 42 } |
| 43 |
| 44 int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1)); |
| 45 |
| 46 main() { |
| 47 test1(true, 54); |
| 48 test1(false); |
| 49 test2(); |
| 50 new A().test3(true, 54); |
| 51 new A().test3(false); |
| 52 |
| 53 var things = [test1, test2, new A().test3]; |
| 54 |
| 55 var closure = things[inscrutable(0)]; |
| 56 closure(true, 54); |
| 57 closure(false); |
| 58 |
| 59 closure = things[inscrutable(1)]; |
| 60 closure(); |
| 61 |
| 62 closure = things[inscrutable(2)]; |
| 63 closure(true, 54); |
| 64 closure(false); |
| 65 } |
OLD | NEW |