OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, 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.md file. |
| 4 |
| 5 f_1_1_no_default(a, [b]) => a + b; |
| 6 |
| 7 f_1_1_default(a, [b = 2]) => a + b; |
| 8 |
| 9 f_1_b_no_default(a, {b}) => a + b; |
| 10 |
| 11 f_1_b_default(a, {b: 2}) => a + b; |
| 12 |
| 13 test_1_1(Function f, bool hasDefault) { |
| 14 var result = f(40, 2); |
| 15 if (42 != result) throw "Unexpected result: $result"; |
| 16 test_1(f, hasDefault); |
| 17 } |
| 18 |
| 19 test_1_b(Function f, bool hasDefault) { |
| 20 var result = f(40, b: 2); |
| 21 if (42 != result) throw "Unexpected result: $result"; |
| 22 test_1(f, hasDefault); |
| 23 } |
| 24 |
| 25 test_1(Function f, bool hasDefault) { |
| 26 var result = 0; |
| 27 bool threw = true; |
| 28 try { |
| 29 result = f(40); |
| 30 threw = false; |
| 31 } catch (_) { |
| 32 // Ignored. |
| 33 } |
| 34 if (hasDefault) { |
| 35 if (threw) throw "Unexpected exception."; |
| 36 if (42 != result) throw "Unexpected result: $result."; |
| 37 } else { |
| 38 if (!threw) throw "Expected exception missing."; |
| 39 if (0 != result) throw "Unexpected result: $result."; |
| 40 } |
| 41 } |
| 42 |
| 43 main(arguments) { |
| 44 test_1_1(f_1_1_no_default, false); |
| 45 test_1_1(f_1_1_default, true); |
| 46 test_1_b(f_1_b_no_default, false); |
| 47 test_1_b(f_1_b_default, true); |
| 48 } |
OLD | NEW |