From 4f39a3f7d7ddf302a8802c9a97b965a3bf390a00 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-helloworld/utssdk/index.uts | 2 +- uni_modules/uts-syntaxcase/utssdk/index.uts | 4 +-- uni_modules/uts-tests/utssdk/Math.uts | 36 +++++++++++++++---- uni_modules/uts-tests/utssdk/String.uts | 11 ++++-- .../uts-tests/utssdk/UTSJSONObject.uts | 2 +- 5 files changed, 41 insertions(+), 14 deletions(-) diff --git a/uni_modules/uts-helloworld/utssdk/index.uts b/uni_modules/uts-helloworld/utssdk/index.uts index 33851b0..101059d 100644 --- a/uni_modules/uts-helloworld/utssdk/index.uts +++ b/uni_modules/uts-helloworld/utssdk/index.uts @@ -53,7 +53,7 @@ export function onCallback(callback: (sth:string) => void) { let count = 1 let taskId = -1 taskId = setInterval(function() { - callback("第" + count + "次回调") + callback(`第 ${count} 次回调`) count++; console.log("count",count) if(count > 3){ diff --git a/uni_modules/uts-syntaxcase/utssdk/index.uts b/uni_modules/uts-syntaxcase/utssdk/index.uts index 113a951..a86c4b3 100644 --- a/uni_modules/uts-syntaxcase/utssdk/index.uts +++ b/uni_modules/uts-syntaxcase/utssdk/index.uts @@ -440,7 +440,7 @@ export function Scan1(timeMillis ?: Number):string { if(timeMillis == null){ return "null" } - return timeMillis.toString() + return timeMillis!.toString() } export function Scan2(timeMillis ?: Number | null):string { @@ -448,7 +448,7 @@ export function Scan2(timeMillis ?: Number | null):string { if(timeMillis == null){ return "null" } - return timeMillis.toString() + return timeMillis!.toString() } export class myClass { diff --git a/uni_modules/uts-tests/utssdk/Math.uts b/uni_modules/uts-tests/utssdk/Math.uts index ff91cff..ab2764c 100644 --- a/uni_modules/uts-tests/utssdk/Math.uts +++ b/uni_modules/uts-tests/utssdk/Math.uts @@ -112,8 +112,9 @@ export function testMath() : Result { // #TEST Math.acos console.log(Math.acos(-1)); // expected output: 3.141592653589793 - + // #ifdef APP-ANDROID console.log(Math.acos(NaN)); + // #endif // expected output: NaN console.log(Math.acos(0)); @@ -133,8 +134,9 @@ export function testMath() : Result { // #TEST Math.acosh console.log(Math.acosh(1)); // expected output: 0 - + // #ifdef APP-ANDROID console.log(Math.acosh(NaN)); + // #endif // expected output: NaN console.log(Math.acosh(2)); @@ -152,7 +154,9 @@ export function testMath() : Result { test('asin', () => { // #TEST Math.asin + // #ifdef APP-ANDROID console.log(Math.asin(NaN)); + // #endif // expected output: NaN console.log(Math.asin(-1)); @@ -177,7 +181,9 @@ export function testMath() : Result { test('asinh', () => { // #TEST Math.asinh + // #ifdef APP-ANDROID console.log(Math.asinh(NaN)); + // #endif // expected output: NaN console.log(Math.asinh(1)); @@ -202,7 +208,9 @@ export function testMath() : Result { test('atan', () => { // #TEST Math.atan + // #ifdef APP-ANDROID console.log(Math.atan(NaN)); + // #endif // expected output: NaN console.log(Math.atan(1)); @@ -231,7 +239,9 @@ export function testMath() : Result { test('atanh', () => { // #TEST Math.atanh + // #ifdef APP-ANDROID console.log(Math.atanh(NaN)); + // #endif // expected output: NaN console.log(Math.atanh(0)); @@ -253,8 +263,9 @@ export function testMath() : Result { // #TEST Math.ceil console.log(Math.ceil(0.95)); // expected output: 1 - + // #ifdef APP-ANDROID console.log(Math.ceil(NaN)); + // #endif // expected output: NaN console.log(Math.ceil(4)); @@ -383,7 +394,9 @@ export function testMath() : Result { test('fround', () => { // #TEST Math.fround + // #ifdef APP-ANDROID console.log(Math.fround(NaN)); + // #endif // expected output: NaN console.log(Math.fround(1.5)); @@ -626,23 +639,28 @@ export function testMath() : Result { test('round', () => { // #TEST Math.round + // #ifdef APP-ANDROID console.log(Math.round(NaN)); + // #endif // expected output: NaN console.log(Math.round(Math.E)); // expected output: 3 - + + // #ifdef APP-ANDROID console.log(Math.round(Number.MAX_VALUE)); // expected output: 1.7976931348623157e+308 - + console.log(Math.round(Number.MIN_VALUE)); // expected output: 0 - + console.log(Math.round(Number.NEGATIVE_INFINITY)); // expected output: -Infinity - + console.log(Math.round(Number.POSITIVE_INFINITY)); // expected output: Infinity + + // #endif console.log(Math.round(0.9)); // expected output: 1 @@ -661,10 +679,14 @@ export function testMath() : Result { // #END expect(Math.round(NaN)).toEqual(NaN); expect(Math.round(Math.E)).toEqual(3); + + // #ifdef APP-ANDROID expectNumber(Math.round(Number.MAX_VALUE)).toEqualDouble(1.7976931348623157e+308); expect(Math.round(Number.MIN_VALUE)).toEqual(0); expect(Math.round(Number.NEGATIVE_INFINITY)).toEqual(-Infinity); expect(Math.round(Number.POSITIVE_INFINITY)).toEqual(Infinity); + // #endif + expect(Math.round(0.9)).toEqual(1); expect(Math.round(5.95)).toEqual(6); expect(Math.round(-5.05)).toEqual(-5); 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 eff9e26..f97827f 100644 --- a/uni_modules/uts-tests/utssdk/UTSJSONObject.uts +++ b/uni_modules/uts-tests/utssdk/UTSJSONObject.uts @@ -170,7 +170,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