From 3daea108b730fa86061084159a5f7ace23b11194 Mon Sep 17 00:00:00 2001 From: m0_75226990 Date: Fri, 13 Sep 2024 16:00:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=83=A8=E5=88=86=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=E9=81=BF=E5=85=8DiOS=E7=BC=96=E8=AF=91=E6=8A=A5?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uni_modules/uts-syntaxcase/utssdk/index.uts | 51 +++++++++---------- uni_modules/uts-tests/utssdk/String.uts | 11 ++-- .../uts-tests/utssdk/UTSJSONObject.uts | 2 +- 3 files changed, 33 insertions(+), 31 deletions(-) diff --git a/uni_modules/uts-syntaxcase/utssdk/index.uts b/uni_modules/uts-syntaxcase/utssdk/index.uts index 60350dd..d84bac0 100644 --- a/uni_modules/uts-syntaxcase/utssdk/index.uts +++ b/uni_modules/uts-syntaxcase/utssdk/index.uts @@ -52,14 +52,11 @@ export function testSyncWithCallback(opts : AsyncOptions) : SyntaxResult { async function testAwaitPromise(res : SyntaxResult) : Promise { - // #ifdef APP-ANDROID return await new Promise(function (resolve : (res : SyntaxResult) => void) { - resolve(res) + setTimeout(() => { + resolve(res) + }, 2000) }) - // #endif - // #ifndef APP-ANDROID - return res - // #endif } /** * 导出一个异步方法 @@ -100,7 +97,7 @@ export async function testAsyncParam3(id : number, name : string, opts : AsyncOp export class Test { id : number; - name : string; + name : string; static type : string = "Test"; constructor(id : number, options : TestOptions) { @@ -122,21 +119,21 @@ export class Test { const res = await testAsync(opts); return res; } -} - -export class SetterTest { - - private _nickName: string = ''; - - get nickName (): string { - console.log('get nickName'); - return this._nickName; - } - set nickName (value: string) { - console.log('set nickName'); - this._nickName = value; - } - +} + +export class SetterTest { + + private _nickName: string = ''; + + get nickName (): string { + console.log('get nickName'); + return this._nickName; + } + set nickName (value: string) { + console.log('set nickName'); + this._nickName = value; + } + } class RequestTaskImpl implements RequestTask { @@ -161,15 +158,15 @@ export function request(url : string) : RequestTask | null { return new RequestTaskImpl(url) } // #ifdef APP-ANDROID -// #ifdef UNI-APP-X +// #ifdef UNI-APP-X export function callKotlinMethodGetInfo():String { return NativeCode.getPhoneInfo() -} - +} + export function callJavaMethodGetInfo():String { return new JavaUser("jack",12).name -} - +} + import KeyEvent from 'android.view.KeyEvent'; import Configuration from 'android.content.res.Configuration'; diff --git a/uni_modules/uts-tests/utssdk/String.uts b/uni_modules/uts-tests/utssdk/String.uts index 2d48942..5560cd8 100644 --- a/uni_modules/uts-tests/utssdk/String.uts +++ b/uni_modules/uts-tests/utssdk/String.uts @@ -7,10 +7,10 @@ export function testString() : Result { const x = "Mozilla"; const e = ""; - console.log("Mozilla is " + x.length + " code units long"); + console.log("Mozilla is " + `${x.length}` + " code units long"); /* "Mozilla is 7 code units long" */ - console.log("The empty string is has a length of " + e.length); + console.log("The empty string is has a length of " + `${e.length}`); /* "The e string is has a length of 0" */ // #END @@ -335,6 +335,7 @@ export function testString() : Result { // #TEST String.replace_1 + // #ifdef APP-ANDROID // 不包含捕捉组的示例 let a = "The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?" let b = a.replace(RegExp("fox"), function (match : string, offset : number, string : string) : string { @@ -344,7 +345,7 @@ export function testString() : Result { return "cat" }) console.log("b:", b) - + // 包含一个捕获组的示例。注意,目前android仅支持最多五个捕获组 let a1 = "The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?" let b1 = a1.replace(RegExp("(fox)"), function (match : string, p1 : string, offset : number, string : string) : string { @@ -355,6 +356,8 @@ export function testString() : Result { return "cat" }) console.log("b1", b1) + // #endif + // #END // const REGEX_FORMAT = /[YMDHhms]o|\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a{1,2}|A{1,2}|m{1,2}|s{1,2}|Z{1,2}|SSS/g @@ -374,10 +377,12 @@ export function testString() : Result { // #TEST String.search const paragraph = 'The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?'; const regex = /[^\w\s]/g; + // #ifdef APP-ANDROID console.log(paragraph.search(regex)); // expected output: 43 console.log(paragraph[paragraph.search(regex)]); // expected output: "." + // #endif // #END expect(paragraph.search(regex)).toEqual(43); diff --git a/uni_modules/uts-tests/utssdk/UTSJSONObject.uts b/uni_modules/uts-tests/utssdk/UTSJSONObject.uts index 2aa51f8..2d3b967 100644 --- a/uni_modules/uts-tests/utssdk/UTSJSONObject.uts +++ b/uni_modules/uts-tests/utssdk/UTSJSONObject.uts @@ -163,7 +163,7 @@ export function testUTSJSONObject() : Result { } } //返回指定键对应的值,如果对象中不存在此键则返回 null。 - let name : string = person.get('name') as string + let name : string = person["name"] as String //get 方法可以简化为使用下标运算符 `[]` 访问 name = person['name'] as string //增加或更新指定键对应的值。 -- GitLab