• 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
16function fn(callback: (() => void) | ((n: number) => void) | ((n: number, n2: number) => void)): void {
17    callback(1, 2)
18}
19
20// test for lambda as param.
21let emptyArg: number = 0;
22let oneArg: number = 0;
23let twoArgs: number = 0;
24fn(() => { emptyArg = emptyArg - 1; })
25fn((n:number) => { oneArg = oneArg + n; })
26fn((n:number, n2: number) => { twoArgs = twoArgs + n + n2; })
27arktest.assertEQ(emptyArg, -1)
28arktest.assertEQ(oneArg, 1)
29arktest.assertEQ(twoArgs, 3)
30
31// test for named function as param.
32emptyArg = 0;
33oneArg = 0;
34twoArgs = 0;
35function foo() { emptyArg = emptyArg - 1; }
36function foo1(n: number) { oneArg = oneArg + n; }
37function foo2(n:number, n2: number) { twoArgs = twoArgs + n + n2; }
38fn(foo);
39fn(foo1);
40fn(foo2);
41arktest.assertEQ(emptyArg, -1)
42arktest.assertEQ(oneArg, 1)
43arktest.assertEQ(twoArgs, 3)
44
45// test for class method and static class method as param
46class A {
47    goo() { emptyArg = emptyArg - 1; }
48    goo1(n: number) { oneArg = oneArg + n; }
49    goo2(n:number, n2: number) { twoArgs = twoArgs + n + n2; }
50
51    static zoo() { emptyArg = emptyArg - 1; }
52    static zoo1(n: number) { oneArg = oneArg + n; }
53    static zoo2(n:number, n2: number) { twoArgs = twoArgs + n + n2; }
54}
55
56let a = new A();
57emptyArg = 0;
58oneArg = 0;
59twoArgs = 0;
60fn(a.goo);
61fn(a.goo1);
62fn(a.goo2);
63arktest.assertEQ(emptyArg, -1)
64arktest.assertEQ(oneArg, 1)
65arktest.assertEQ(twoArgs, 3)
66
67emptyArg = 0;
68oneArg = 0;
69twoArgs = 0;
70fn(A.zoo);
71fn(A.zoo1);
72fn(A.zoo2);
73arktest.assertEQ(emptyArg, -1)
74arktest.assertEQ(oneArg, 1)
75arktest.assertEQ(twoArgs, 3)
76