Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // Dart test program for testing argument definition test. | 4 // Dart test program for testing argument definition test. |
| 5 | 5 |
| 6 int test(int a, [int b, int c]) { | 6 int test(int a, [int b = 2, int c = 3]) { |
| 7 int result = 0; | 7 int result = 0; |
| 8 ?b; | 8 ?b; |
| 9 ?result; /// 01: compile-time error | 9 ?result; /// 01: compile-time error |
| 10 if (?a) { | 10 if (?a) { |
| 11 result += 100; | 11 result += 100; |
| 12 } | 12 } |
| 13 if (?b) { | 13 if (?b) { |
| 14 result += 20; | 14 result += 20; |
| 15 } | 15 } |
| 16 if (?c) { | 16 if (?c) { |
| 17 var b; ?b; /// 02: compile-time error | 17 var b; ?b; /// 02: compile-time error |
| 18 result += 3; | 18 result += 3; |
| 19 } | 19 } |
| 20 if ((!?a?!?b:!?c) == (?a??b:?c)) { | |
| 21 result += 200; | |
| 22 } | |
| 23 if (!?a?!?b:!?c == ?a??b:?c) { | |
| 24 result += 400; | |
| 25 } | |
| 20 return result; | 26 return result; |
| 21 } | 27 } |
| 22 | 28 |
| 23 closure_test(int a, [int b, int c]) { | 29 closure_test(int a, [int b = 2, int c = 3]) { |
| 24 var x = 0; | 30 var x = 0; |
| 25 return () { | 31 return () { |
| 26 int result = 0; | 32 int result = 0; |
| 27 ?b; | 33 ?b; |
| 28 ?result; /// 03: compile-time error | 34 ?result; /// 03: compile-time error |
| 29 ?x; /// 04: compile-time error | 35 ?x; /// 04: compile-time error |
| 30 if (?a) { | 36 if (?a) { |
| 31 result += 100; | 37 result += 100; |
| 32 } | 38 } |
| 33 if (?b) { | 39 if (?b) { |
| 34 result += 20; | 40 result += 20; |
| 35 } | 41 } |
| 36 if (?c) { | 42 if (?c) { |
| 37 var b; ?b; /// 05: compile-time error | 43 var b; ?b; /// 05: compile-time error |
| 38 result += 3; | 44 result += 3; |
| 39 } | 45 } |
| 46 // Equivalent to: (!?c) == ?b. | |
| 47 if ((!?a?!?b:!?c) == (?a??b:?c)) { | |
| 48 result += 200; | |
| 49 } | |
| 50 // Equivalent to: (!?c) ? ?b : ?c. | |
| 51 if (!?a?!?b:!?c == ?a??b:?c) { | |
| 52 result += 400; | |
| 53 } | |
| 40 return result; | 54 return result; |
| 41 }; | 55 }; |
| 42 } | 56 } |
| 43 | 57 |
| 44 main() { | 58 main() { |
| 45 // Use a loop to test optimized version as well. | 59 // Use a loop to test optimized version as well. |
| 46 for (int i = 0; i < 1000; i++) { | 60 for (int i = 0; i < 1000; i++) { |
| 47 Expect.equals(100, test(1)); | 61 Expect.equals(100, test(1)); |
| 48 Expect.equals(120, test(1, 2)); | 62 Expect.equals(720, test(1, 2)); |
| 49 Expect.equals(123, test(1, 2, 3)); | 63 Expect.equals(523, test(1, 2, 3)); |
| 50 Expect.equals(103, test(1, c:3)); | 64 Expect.equals(703, test(1, c:3)); |
| 51 | 65 |
| 52 Expect.equals(100, closure_test(1)()); | 66 Expect.equals(100, closure_test(1)()); |
| 53 Expect.equals(120, closure_test(1, 2)()); | 67 Expect.equals(720, closure_test(1, 2)()); |
| 54 Expect.equals(123, closure_test(1, 2, 3)()); | 68 Expect.equals(523, closure_test(1, 2, 3)()); |
| 55 Expect.equals(103, closure_test(1, c:3)()); | 69 Expect.equals(703, closure_test(1, c:3)()); |
| 56 } | 70 } |
| 57 } | 71 } |
|
regis
2012/08/31 14:44:50
Matthias wanted me to add this other test yesterda
ahe
2012/08/31 15:08:45
So that's the origin. I took it from Gilad's chat
| |
| OLD | NEW |