• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (C) 2025 HiHope Open Source Organization.
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*/
15export async function sleep(time: number): Promise<number> {
16  return new Promise<number>((resolve): void => {
17    setTimeout((): void => {
18      resolve(1);
19    }, time);
20  });
21}
22
23export async function exportTest1(): Promise<number> {
24  const num = 66;
25  return num;
26}
27;
28
29export let exportTest2 = async (): Promise<number> => {
30  const num = 66;
31  return num;
32};
33
34export async function exportTest3(): Promise<void> {
35  throw new Error('For test');
36}
37;
38
39export async function exportTest4(): Promise<void> {
40  throw new Error('For test');
41}
42;
43
44export async function exportTest5(param: null): Promise<void> {
45  throw new Error('For test');
46}
47;
48
49export async function exportTest6(): Promise<string> {
50  const num = '66';
51  return num;
52}
53;
54
55export async function exportTest7(name?: string): Promise<string> {
56  const num = '66';
57  return num;
58}
59;
60
61export async function exportTest8(name?: string): Promise<number> {
62  const num = 66;
63  return num;
64}
65;
66
67export async function exportTest9(name?: string): Promise<boolean> {
68  const num = true;
69  return num;
70}
71;
72
73export async function exportTest10(name?: string): Promise<bigint> {
74  const num: bigint = 66n;
75  return num;
76}
77;
78
79
80interface testObject {
81  age: number;
82};
83
84export async function exportTest11(name?: string): Promise<testObject> {
85  return {
86    age: 30
87  };
88}
89;
90
91export async function exportTest12(name?: string): Promise<testObject> {
92  return {
93    age: 30
94  };
95}
96;
97
98export async function exportTest13(name?: string): Promise<number[]> {
99  const arr = [65, 66, 67];
100  return arr;
101}
102;
103
104export async function exportTest14(name?: string): Promise<() => string> {
105  return () => 'Hello World!';
106}
107;
108
109export async function exportTest15(name?: string): Promise<void> {
110  throw new Error('For test');
111  return;
112}
113;
114
115export async function exportTest16(name?: string): Promise<null> {
116  throw new Error('For test');
117  return null;
118}
119;
120
121export async function exportTest17(name?: string): Promise<undefined> {
122  throw new Error('For test');
123  return undefined;
124}
125;
126
127export async function exportTest18(name?: string): Promise<Error> {
128  return new Error('For test');
129}
130;
131
132
133class Person {
134  name: string = '';
135  surname: string = '';
136
137  constructor(n: string, sn: string) {
138    this.name = n;
139    this.surname = sn;
140  }
141
142  fullName(): string {
143    return this.name + ' ' + this.surname;
144  }
145};
146
147export async function exportTest19(name?: string): Promise<Person> {
148  let p = new Person('John', 'Smith');
149  return p;
150}
151;
152
153export async function exportTest20(): Promise<never> {
154  throw new Error('For test');
155}
156;
157
158async function for21exportTest(): Promise<number> {
159  console.log('For test');
160  return 66;
161};
162
163export async function exportTest21(): Promise<number> {
164  const result = for21exportTest();
165  return result;
166}
167;
168
169async function for22exportTest(): Promise<number> {
170  console.log('For test');
171  return 66;
172};
173
174export async function exportTest22(): Promise<number> {
175  const result = await for22exportTest();
176  return result;
177}
178;
179
180export async function exportTest23(): Promise<number> {
181  let num = 0;
182  setTimeout(() => {
183    num = 66;
184  }, 1000);
185  while (num !== 66) {
186    await sleep(300);
187  }
188  return num;
189}
190;
191
192export async function exportTest24(): Promise<number> {
193  let num = 0;
194  await new Promise<void>((resolve, reject) => {
195    num = 66;
196    resolve();
197  });
198  return num;
199}
200;
201
202class For25ExportTest {
203  name: string = '';
204  age: number = 0;
205
206  constructor(n: string, age: number) {
207    this.name = n;
208    this.age = age;
209  }
210
211  fullName(): string {
212    return this.name;
213  }
214
215  getAge(): number {
216    return this.age;
217  }
218};
219
220export async function exportTest25(): Promise<number> {
221  let p = new For25ExportTest('John', 66);
222  let result = p.getAge();
223  return result;
224}
225;