index.uts 4.5 KB
Newer Older
Y
yurj26 已提交
1 2 3 4
import { testArray } from './Array.uts'
import { testDate } from './Date.uts'
import { testString } from './String.uts'
import { testError } from './Error.uts'
杜庆泉's avatar
杜庆泉 已提交
5
import { testKeyWord } from './KeyWord.uts'
M
mahaifeng 已提交
6 7 8 9
import { testJSON } from './JSON.uts'
import { testJSONLarge } from './JSON_large.uts'
import { testUTSJSONObject } from './UTSJSONObject.uts'
import { testConsole } from './console.uts'
Y
yurj26 已提交
10 11 12 13 14 15
import { testNumber } from './Number.uts'
import { testMap } from './Map.uts'
import { testSet } from './Set.uts'
import { testOperators } from './Operators.uts'
import { testMath } from './Math.uts'
import { testRegExp } from './RegExp.uts'
16
import { testForLoop } from './ForLoop.uts'
lizhongyi_'s avatar
lizhongyi_ 已提交
17
import { testGlobal } from './Global.uts'
18
import { testType } from './Type.uts'
M
mahaifeng 已提交
19 20 21
export { Result } from './tests.uts'
import { testArrayBuffer } from './ArrayBuffer.uts'
import { testNativeCode } from './NativeCode.uts'
M
mahaifeng 已提交
22
import { testEncoder} from "./TextEncoder.uts"
23
import { testDecoder} from "./TextDecoder.uts"
Y
yurj26 已提交
24 25
// Promise、Proxy、Reflect、Weakmap、WeakSet 不支持
export function runTests() : UTSJSONObject {
Y
yurj26 已提交
26 27 28 29 30 31 32 33 34 35 36 37
  const ArrayRes = testArray();
  const DateRes = testDate();
  const StringRes = testString();
  const ErrorRes = testError();
  const JsonRes = testJSON();
  const NumberRes = testNumber();
  const MapRes = testMap();
  const SetRes = testSet();
  const OperatorsRes = testOperators();
  const MathRes = testMath();
  const RegExpRes = testRegExp();
  const KeyWordRes = testKeyWord();
38
  const ForLoopRes = testForLoop();
lizhongyi_'s avatar
lizhongyi_ 已提交
39
  const GlobalRes = testGlobal();
M
mahaifeng 已提交
40
  const TypeRes = testType();
41
  const JSONLargeRes = testJSONLarge();
M
mahaifeng 已提交
42 43 44 45 46 47
  const consoleRes = testConsole();
  const UTSJSONObjectRes = testUTSJSONObject();

  // #ifdef  APP-ANDROID || WEB
  const ArrayBufferRes = testArrayBuffer();
  // #endif
M
mahaifeng 已提交
48 49 50
  const NativeCodeRes = testNativeCode();
  // #ifdef  APP-ANDROID || WEB
  const TextEncoderRes = testEncoder();
51
  const TextDecoderRes = testDecoder();
M
mahaifeng 已提交
52
  // #endif
Y
yurj26 已提交
53 54 55 56 57
  return {
    Array: ArrayRes,
    Date: DateRes,
    String: StringRes,
    Error: ErrorRes,
M
mahaifeng 已提交
58 59
    Json: JsonRes,
    JSONLarge: JSONLargeRes,
Y
yurj26 已提交
60 61 62 63 64 65 66
    Number: NumberRes,
    Map: MapRes,
    Set: SetRes,
    Operators: OperatorsRes,
    Math: MathRes,
    RegExp: RegExpRes,
    KeyWord: KeyWordRes,
67
    ForLoop: ForLoopRes,
M
mahaifeng 已提交
68 69 70 71 72
    Global: GlobalRes,
    Type: TypeRes,
    console: consoleRes,
    UTSJSONObject: UTSJSONObjectRes,
    // #ifdef  APP-ANDROID || WEB
M
mahaifeng 已提交
73
    ArrayBuffer: ArrayBufferRes,
74 75
    TextEncoder: TextEncoderRes,
    TextDecoder: TextDecoderRes,
M
mahaifeng 已提交
76 77
    // #endif
    NativeCode: NativeCodeRes
Y
yurj26 已提交
78
  }
lizhongyi_'s avatar
lizhongyi_ 已提交
79 80
}

81
// #ifdef APP
lizhongyi_'s avatar
lizhongyi_ 已提交
82 83 84 85 86 87
import { expect } from './tests.uts'

export type TestKeepAliveCallback = (res: string) => void

export function onTest1(callback: TestKeepAliveCallback) {
  callback("1")
88
  callback("2")
lizhongyi_'s avatar
lizhongyi_ 已提交
89 90 91 92
}

@UTSJS.keepAlive
export function testKeepAlive(callback: TestKeepAliveCallback) {
93 94
  callback("1")
  callback("2")
lizhongyi_'s avatar
lizhongyi_ 已提交
95 96 97 98 99 100 101 102 103 104
}

export type TestKeepAliveOption = {
  a: string
  success: TestKeepAliveCallback | null
}

@UTSJS.keepAlive
export function testKeepAliveOption(option: TestKeepAliveOption) {
  console.log(option.a);
105 106
  option.success?.("1")
  option.success?.("2")
lizhongyi_'s avatar
lizhongyi_ 已提交
107 108 109 110 111
}

export class TestKeepAliveClass {
  
  constructor() {
lizhongyi_'s avatar
lizhongyi_ 已提交
112
    super()
lizhongyi_'s avatar
lizhongyi_ 已提交
113 114 115
  }
  onTest(callback: TestKeepAliveCallback) {
    callback("1")
116
    callback("2")
lizhongyi_'s avatar
lizhongyi_ 已提交
117 118 119 120
  }
  
  @UTSJS.keepAlive
  testKeepAlive(callback: TestKeepAliveCallback) {
121 122
    callback("1")
    callback("2")
lizhongyi_'s avatar
lizhongyi_ 已提交
123 124 125 126 127
  }
  
  @UTSJS.keepAlive
  testKeepAliveOption(option: TestKeepAliveOption) {
    console.log(option.a);
128 129
    option.success?.("1")
    option.success?.("2")
lizhongyi_'s avatar
lizhongyi_ 已提交
130 131 132 133
  }
  
  static onTestStatic(callback: TestKeepAliveCallback) {
    callback("1")
134
    callback("2")
lizhongyi_'s avatar
lizhongyi_ 已提交
135 136 137 138
  }
  
  @UTSJS.keepAlive
  static testKeepAliveStatic(callback: TestKeepAliveCallback) {
139 140
    callback("1")
    callback("2")
lizhongyi_'s avatar
lizhongyi_ 已提交
141 142 143
  }
  
  @UTSJS.keepAlive
144
  static testKeepAliveOptionStatic(option: TestKeepAliveOption) {
lizhongyi_'s avatar
lizhongyi_ 已提交
145
    console.log(option.a);
146 147
    option.success?.("1")
    option.success?.("2")
lizhongyi_'s avatar
lizhongyi_ 已提交
148 149
  }
}
F
fxy060608 已提交
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166


interface ITest {
    test(callback : (msg : string) => void) : void
}

class TestImpl implements ITest {
    @UTSJS.keepAlive
    test(callback : (msg : string) => void) : void {
        callback("1")
        callback("2")
    }
}

export function createTest() : ITest {
    return new TestImpl()
}
F
fxy060608 已提交
167 168 169 170 171 172 173 174 175 176 177 178 179

export function testNonKeepAlive(callback: (res: string) => void){
  setTimeout(()=>{
    callback("1")
  },10)
}

export function testNonKeepAliveOption(option: TestKeepAliveOption) {
  console.log(option.a);
  setTimeout(()=>{
    option.success?.("1")
  },10)
}
lizhongyi_'s avatar
lizhongyi_ 已提交
180 181
// #endif