1/* 2 * Copyright (c) 2023-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16function main(): void { 17 assertEQ(foo1(), 10) 18 assertEQ(foo2(), c'a') 19 assertEQ(foo3(), true) 20 21 assertEQ(foo4(), 30) 22 assertEQ(foo4(5), 25) 23 24 assertEQ(foo5(5), 55) 25 assertEQ(foo5(5, 10), 45) 26 27 28 assertEQ(foo6(), undefined) 29 assertEQ(foo7(), undefined) 30 assertEQ(foo8(), undefined) 31 32 33 assertEQ(foo13(10), 15) 34 assertEQ(foo14(10), 25) 35 36 assertEQ(foo15(10, 5), 20) 37 assertEQ(foo16(10, 5), 30) 38} 39 40function foo1(a: int = 10): int { 41 return a; 42} 43 44function foo2(a: char = c'a'): char { 45 return a; 46} 47 48function foo3(a: boolean = true): boolean { 49 return a; 50} 51 52function foo4(a: int = 10, b: int = 20): int { 53 return a + b; 54} 55 56function foo5(a: int = 10, b: int = 20, c: int = 30): int { 57 assertEQ(a, 5) 58 59 return a + b + c; 60} 61 62function foo6(a?: int): int | undefined { 63 return a; 64} 65 66function foo7(a?: boolean): boolean | undefined { 67 return a; 68} 69 70function foo8(a?: char): char | undefined { 71 return a; 72} 73 74function foo13(a: int, b: int = 5): int { 75 return a + b; 76} 77 78function foo14(a: int, b: int = 5, c: int = 10): int { 79 return a + b + c; 80} 81 82function foo15(a: int, b: int, c: int = 5): int { 83 return a + b + c; 84} 85 86function foo16(a: int, b: int, c: int = 10, d: int = 5): int { 87 return a + b + c + d; 88} 89