• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (C) 2024 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*/
15
16export class ConcatArrayTest<T> {
17  private arr: ConcatArray<T>;
18
19  constructor(arr: ConcatArray<T>) {
20    this.arr = arr;
21  }
22
23  public slice(start?, end?): any {
24    return this.arr.slice(start, end);
25  }
26
27  public join(separator?): string {
28    return this.arr.join(separator);
29  }
30
31  public length(): number {
32    return this.arr.length;
33  }
34
35  public index(index): T {
36    return this.arr[index];
37  }
38
39  public setLength(length): void {
40    this.arr = {
41      length: length,
42      join: function (separator?: string | undefined): string {
43        throw new Error('Function not implemented.');
44      },
45      slice: function (start?: number | undefined, end?: number | undefined): T[] {
46        throw new Error('Function not implemented.');
47      }
48    };
49  }
50}
51
52export class ArrayLikeTest<T> {
53  private arr: ArrayLike<T>;
54
55  constructor(arr: ArrayLike<T>) {
56    this.arr = arr;
57  }
58
59  public length(): number {
60    return this.arr.length;
61  }
62
63  public index(index): T {
64    return this.arr[index];
65  }
66}
67
68export function sleep(time: number): Promise<void> {
69  return new Promise((re, je) => {
70    setTimeout(() => {
71      re();
72    }, time);
73  });
74}
75
76export class ReadonlyArrayTest<T> {
77  private arr: ReadonlyArray<T>;
78
79  constructor(arr: ReadonlyArray<T>) {
80    this.arr = arr;
81  }
82
83  public length(): number {
84    return this.arr.length;
85  }
86
87  public index(index): T {
88    return this.arr[index];
89  }
90
91  public toString(): string {
92    return this.arr.toString();
93  }
94
95  public toLocaleString(): string {
96    return this.arr.toLocaleString();
97  }
98
99  public forEach(a, b?): void {
100    return this.arr.forEach(a, b);
101  }
102}
103