13af6ab5fSopenharmony_ci/*
23af6ab5fSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
33af6ab5fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
43af6ab5fSopenharmony_ci * you may not use this file except in compliance with the License.
53af6ab5fSopenharmony_ci * You may obtain a copy of the License at
63af6ab5fSopenharmony_ci *
73af6ab5fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
83af6ab5fSopenharmony_ci *
93af6ab5fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
103af6ab5fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
113af6ab5fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
123af6ab5fSopenharmony_ci * See the License for the specific language governing permissions and
133af6ab5fSopenharmony_ci * limitations under the License.
143af6ab5fSopenharmony_ci */
153af6ab5fSopenharmony_ci
163af6ab5fSopenharmony_cifunction compMultiArray<T>(arrayMulti1: T[][], arrayMulti2: T[][]) {
173af6ab5fSopenharmony_ci    let i : int = 0
183af6ab5fSopenharmony_ci    for (let element1 of arrayMulti1) {
193af6ab5fSopenharmony_ci        compArray<T>(element1, arrayMulti2[i])
203af6ab5fSopenharmony_ci        i++
213af6ab5fSopenharmony_ci    }
223af6ab5fSopenharmony_ci}
233af6ab5fSopenharmony_ci
243af6ab5fSopenharmony_cifunction compArray<T>(array1: T[], array2: T[]) {
253af6ab5fSopenharmony_ci    let i : int = 0
263af6ab5fSopenharmony_ci    for (let element1 of array1) {
273af6ab5fSopenharmony_ci        assert element1 == array2[i]
283af6ab5fSopenharmony_ci        i++
293af6ab5fSopenharmony_ci    }
303af6ab5fSopenharmony_ci}
313af6ab5fSopenharmony_ci
323af6ab5fSopenharmony_cifunction main() {
333af6ab5fSopenharmony_ci    let intArray : int[] = [77, 88, 99]
343af6ab5fSopenharmony_ci
353af6ab5fSopenharmony_ci    // Array variable declaration with multi spread
363af6ab5fSopenharmony_ci    let expectedVarDecl : Int[] = [1, 2, 77, 88, 99, 4, 6, 77, 88, 99]
373af6ab5fSopenharmony_ci    let arrayVarDecl : Int[] = [1, 2, ...intArray, 4, 6, ...intArray]
383af6ab5fSopenharmony_ci    compArray<Int>(arrayVarDecl, expectedVarDecl)
393af6ab5fSopenharmony_ci
403af6ab5fSopenharmony_ci    // Array assignment expression with multi spread
413af6ab5fSopenharmony_ci    let expectedAssignment : Int[] = [100, 200, 77, 88, 99, 400, 600, 77, 88, 99]
423af6ab5fSopenharmony_ci    let arrayAssignment : Int[]
433af6ab5fSopenharmony_ci    arrayAssignment = [100, 200, ...intArray, 400, 600, ...intArray]
443af6ab5fSopenharmony_ci    compArray<Int>(arrayAssignment, expectedAssignment)
453af6ab5fSopenharmony_ci
463af6ab5fSopenharmony_ci    // Multi dimensional array
473af6ab5fSopenharmony_ci    let expectedArray : Int[][] = [[7, 8], [10, 77, 88, 99]]
483af6ab5fSopenharmony_ci    let arrayMulti : Int[][] = [[7, 8], [10, ...intArray]]
493af6ab5fSopenharmony_ci    compMultiArray<Int>(arrayMulti, expectedArray)
503af6ab5fSopenharmony_ci
513af6ab5fSopenharmony_ci    // Union type array
523af6ab5fSopenharmony_ci    type unionType = (int|string|null)
533af6ab5fSopenharmony_ci    let unionArray : unionType[] = ["first", "second"]
543af6ab5fSopenharmony_ci    let expectedUnion : unionType[] = [100, 200, "first", "second", 500, 600, "first", "second"]
553af6ab5fSopenharmony_ci    let arrayUnion: unionType[] = [100, 200, ...unionArray, 500, 600, ...unionArray]
563af6ab5fSopenharmony_ci    compArray<unionType>(arrayUnion, expectedUnion)
573af6ab5fSopenharmony_ci
583af6ab5fSopenharmony_ci    // Object array
593af6ab5fSopenharmony_ci    let obj : Object = new Object();
603af6ab5fSopenharmony_ci    let objectArray : Object[] = [obj, obj]
613af6ab5fSopenharmony_ci    let expectedObject : Object[] = [obj, obj, obj]
623af6ab5fSopenharmony_ci    let arrayObject : Object[] = [obj, ...objectArray]
633af6ab5fSopenharmony_ci    compArray<Object>(arrayObject, expectedObject)
643af6ab5fSopenharmony_ci}
65