1/* 2 * Copyright (c) 2023-2024 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 assert foo1() == 10; 18 assert foo2() == c'a'; 19 assert foo3() == true; 20 21 assert foo4() == 30; 22 assert foo4(5) == 25; 23 24 assert foo5(5) == 55; 25 assert foo5(5, 10) == 45; 26 27 28 assert foo6() == undefined; 29 assert foo7() == undefined; 30 assert foo8() == undefined; 31 32 33 assert foo13(10) == 15; 34 assert foo14(10) == 25; 35 36 assert foo15(10, 5) == 20; 37 assert 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 assert 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