1/* 2 * Copyright (c) 2023 - 2024-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(), "a") 19 assertEQ(foo3(), true) 20 21 assertEQ(foo4(), 30) 22 assertEQ(foo4(new Int(5)), 25) 23 24 assertEQ(foo5(new Int(5)), 55) 25 assertEQ(foo5(new Int(5),new Int(10)), 45) 26 27 28 assertEQ(foo6(), undefined) 29 assertEQ(foo7(), undefined) 30 assertEQ(foo8(), undefined) 31 32 assertEQ(foo9(), 0) 33 assertEQ(foo9(new Int(5)), -1) 34 35 assertEQ(foo10(new Int(5)), 0) 36 assertEQ(foo10(new Int(5),new Int(10)), -1) 37 38 assertEQ(foo11(), 0) 39 assertEQ(foo12(), 0) 40 41 assertEQ(foo13(new Int(10)), 15) 42 assertEQ(foo14(new Int(10)), 25) 43 44 assertEQ(foo15(new Int(10),new Int(5)), 20) 45 assertEQ(foo16(new Int(10),new Int(5)), 30) 46} 47 48function foo1(a : Int = 10) : Int { 49 return a; 50} 51 52function foo2(a : string = "a") : string { 53 return a; 54} 55 56function foo3(a : Boolean = true) : Boolean { 57 return a; 58} 59 60function foo4(a : Int = 10, b : Int = 20) : Int { 61 return a + b; 62} 63 64function foo5(a : Int = 10, b : Int = 20, c : Int = 30) : Int { 65 assertEQ(a, 5) 66 67 return a + b + c; 68} 69 70function foo6(a? : Int) : Int|undefined { 71 return a; 72} 73 74function foo7(a? : string) : string|undefined { 75 return a; 76} 77 78function foo8(a? : Boolean) : Boolean|undefined { 79 return a; 80} 81 82function foo9(a? : Int, b? : Int) : Int { 83 if(a == undefined && b == undefined){ 84 return 0; 85 } 86 if(b == undefined){ 87 return -1; 88 } 89 return a! + b; 90} 91 92function foo10(a? : Int, b? : Int, c? : Int) : Int { 93 assertEQ(a!, 5) 94 if(b == undefined && c == undefined){ 95 return 0; 96 } 97 if(c == undefined){ 98 return -1; 99 } 100 101 return a! + b! + c; 102} 103 104function foo11(a : Int = 5, b? : Int) : Int { 105 if(b == undefined){ 106 return 0; 107 } 108 return a + b; 109} 110 111function foo12(a? : Int, b : Int = 5, c? : Int) : Int { 112 assertEQ(b, 5) 113 114 if(a == undefined && c == undefined){ 115 return 0; 116 } 117 118 return a! + b + c!; 119} 120 121function foo13(a : Int, b : Int = 5) : Int { 122 return a + b; 123} 124 125function foo14(a : Int, b : Int = 5, c : Int = 10) : Int { 126 return a + b + c; 127} 128 129function foo15(a : Int, b : Int, c : Int = 5) : Int { 130 return a + b + c; 131} 132 133function foo16(a : Int, b : Int, c : Int = 10, d : Int = 5) : Int { 134 return a + b + c + d; 135} 136