1/* 2 * Copyright (c) 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 compMultiArray<T>(arrayMulti1: T[][], arrayMulti2: T[][]) { 17 let i : int = 0 18 for (let element1 of arrayMulti1) { 19 compArray<T>(element1, arrayMulti2[i]) 20 i++ 21 } 22} 23 24function compArray<T>(array1: T[], array2: T[]) { 25 let i : int = 0 26 for (let element1 of array1) { 27 assert element1 == array2[i] 28 i++ 29 } 30} 31 32function main() { 33 let intArray : int[] = [77, 88, 99] 34 35 // Array variable declaration with multi spread 36 let expectedVarDecl : Int[] = [1, 2, 77, 88, 99, 4, 6, 77, 88, 99] 37 let arrayVarDecl : Int[] = [1, 2, ...intArray, 4, 6, ...intArray] 38 compArray<Int>(arrayVarDecl, expectedVarDecl) 39 40 // Array assignment expression with multi spread 41 let expectedAssignment : Int[] = [100, 200, 77, 88, 99, 400, 600, 77, 88, 99] 42 let arrayAssignment : Int[] 43 arrayAssignment = [100, 200, ...intArray, 400, 600, ...intArray] 44 compArray<Int>(arrayAssignment, expectedAssignment) 45 46 // Multi dimensional array 47 let expectedArray : Int[][] = [[7, 8], [10, 77, 88, 99]] 48 let arrayMulti : Int[][] = [[7, 8], [10, ...intArray]] 49 compMultiArray<Int>(arrayMulti, expectedArray) 50 51 // Union type array 52 type unionType = (int|string|null) 53 let unionArray : unionType[] = ["first", "second"] 54 let expectedUnion : unionType[] = [100, 200, "first", "second", 500, 600, "first", "second"] 55 let arrayUnion: unionType[] = [100, 200, ...unionArray, 500, 600, ...unionArray] 56 compArray<unionType>(arrayUnion, expectedUnion) 57 58 // Object array 59 let obj : Object = new Object(); 60 let objectArray : Object[] = [obj, obj] 61 let expectedObject : Object[] = [obj, obj, obj] 62 let arrayObject : Object[] = [obj, ...objectArray] 63 compArray<Object>(arrayObject, expectedObject) 64} 65