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