• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 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
16
17class A {
18    foo () : Array<int> {
19        let x = new Array<int>()
20        x.push(7)
21        return x
22    }
23}
24
25function foo() : Array<int> {
26    return new Array<int>(1, 2)
27}
28
29function getStringArr() {
30    let x = new Array<string>()
31    x.push("A")
32    return x
33}
34
35function main() {
36    let a = new A()
37    let arr1:Int[] = [...a.foo(), ...foo()]
38    assertEQ(arr1.length, 3)
39    assertEQ(arr1[0], 7)
40    assertEQ(arr1[1], 1)
41    assertEQ(arr1[2], 2)
42
43    let arr2 = [...getStringArr()]
44    assertEQ(arr2.length, 1)
45    assertEQ(arr2[0], "A")
46
47    let getArr = (): string[] => {
48        return ["a", "b"]
49    }
50    let arr3 : string[] = [...arr2, ...getArr(), "B"]
51    assertEQ(arr3.length, 4)
52    assertEQ(arr3[0], "A")
53    assertEQ(arr3[1], "a")
54    assertEQ(arr3[2], "b")
55    assertEQ(arr3[3], "B")
56
57}
58
59