From 8a80ff861284826bf83ed65972aa2a59f88b0b42 Mon Sep 17 00:00:00 2001 From: duqingquan Date: Wed, 26 Jun 2024 17:18:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dhello=20uts=20=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/advance/advance.vue | 22 +++++----- .../uts-advance/utssdk/app-android/index.uts | 2 +- .../utssdk/app-android/index.uts | 1 + uni_modules/uts-syntaxcase/utssdk/index.uts | 2 +- uni_modules/uts-tests/utssdk/JSON.uts | 43 ++++++++++--------- uni_modules/uts-tests/utssdk/JSON_large.uts | 4 +- uni_modules/uts-tests/utssdk/Number.uts | 11 +++-- uni_modules/uts-tests/utssdk/String.uts | 20 ++++----- .../uts-tests/utssdk/UTSJSONObject.uts | 2 +- uni_modules/uts-tests/utssdk/console.uts | 5 +-- 10 files changed, 58 insertions(+), 54 deletions(-) diff --git a/pages/advance/advance.vue b/pages/advance/advance.vue index 494e01a..473f7e3 100644 --- a/pages/advance/advance.vue +++ b/pages/advance/advance.vue @@ -220,18 +220,18 @@ testQuitApp() { quitApp() }, - testOpenFileWithProvider() { - openFileWithProvider("apps/__UNI__70BE9D0/www/static/logo.png") + testOpenFileWithProvider() { + openFileWithProvider() + }, + testArrayConvert() { + let convertRet = arrayConvert() + if(convertRet){ + uni.showToast({ + icon: "none", + title: '数组转换成功' + }); + } }, - testArrayConvert() { - let convertRet = arrayConvert() - if(convertRet){ - uni.showToast({ - icon: "none", - title: '数组转换成功' - }); - } - }, testMetaRead() { let ret = getMetaConfig(); uni.showToast({ diff --git a/uni_modules/uts-advance/utssdk/app-android/index.uts b/uni_modules/uts-advance/utssdk/app-android/index.uts index 4154af8..1d5801c 100644 --- a/uni_modules/uts-advance/utssdk/app-android/index.uts +++ b/uni_modules/uts-advance/utssdk/app-android/index.uts @@ -510,7 +510,7 @@ export function arrayConvert():boolean{ } -export function openFileWithProvider(url:String){ +export function openFileWithProvider(){ let file = new File(UTSAndroid.getResourcePath("static/logo.png")) const uri = UTSAndroid.getFileProviderUri(file) console.log("uri",uri.toString()) diff --git a/uni_modules/uts-platform-api/utssdk/app-android/index.uts b/uni_modules/uts-platform-api/utssdk/app-android/index.uts index 9d7d941..3a7b085 100644 --- a/uni_modules/uts-platform-api/utssdk/app-android/index.uts +++ b/uni_modules/uts-platform-api/utssdk/app-android/index.uts @@ -168,6 +168,7 @@ export function gotoSystemPermissionActivityTest() { /** * 跳转系统拍照界面,并触发相关生命周期测试 */ +@Suppress("DEPRECATION") export function gotoCameraTake(imageDone : (event : string) => void) : boolean { let permissionNeed = ["android.permission.CAMERA"] diff --git a/uni_modules/uts-syntaxcase/utssdk/index.uts b/uni_modules/uts-syntaxcase/utssdk/index.uts index 3e206dc..7c1de1e 100644 --- a/uni_modules/uts-syntaxcase/utssdk/index.uts +++ b/uni_modules/uts-syntaxcase/utssdk/index.uts @@ -177,7 +177,7 @@ import WindowManager from 'android.view.WindowManager'; import ActionMode from 'android.view.ActionMode'; // export let onCallBackChange: (event: string) => void = (res) => {}; -let callback : (eventLog : string) => void = (res) => { }; +let callback : (eventLog : string) => void = (_) => { }; export function onCallbackChange(fn : (eventLog : string) => void) { callback = fn diff --git a/uni_modules/uts-tests/utssdk/JSON.uts b/uni_modules/uts-tests/utssdk/JSON.uts index ad362a3..fc6c0e9 100644 --- a/uni_modules/uts-tests/utssdk/JSON.uts +++ b/uni_modules/uts-tests/utssdk/JSON.uts @@ -119,8 +119,8 @@ export function testJSON() : Result { test('parseObject', () => { const json = `{"result":true, "count":42}`; const obj = JSON.parseObject(json); - expect(obj!["count"]).toEqual(42); - expect(obj!["result"] as boolean).toEqual(true); + expect(obj?.["count"]).toEqual(42); + expect(obj?.["result"] as boolean).toEqual(true); expect(JSON.parseObject('{}')!).toEqual({}); @@ -152,10 +152,11 @@ export function testJSON() : Result { expect(array2).toEqual([1, "hello world", 3]); + // #ifdef APP-ANDROID const json3 = `[{"name":"John","id":"30"},{"name":"jack","id":"21"}]`; const array3 = JSON.parseArray(json3); - // expect((array3![0])["name"]).toEqual("John"); - + expect((array3![0])["name"]).toEqual("John"); + // #endif }) test('merge-test-1', () => { @@ -181,14 +182,14 @@ export function testJSON() : Result { // #endif }) test('stringify', () => { - const obj = { name: 'John', age: 30 }; - const json = JSON.stringify(obj); - // expect(json).toEqual('{"name":"John","age":30}'); + // #ifdef APP-ANDROID const obj1 = { name: 'John', age: 30, address: { city: 'New York', country: 'USA' } }; const json1 = JSON.stringify(obj1); - // expect(json1).toEqual('{"address":{"country":"USA","city":"New York"},"name":"John","age":30}'); - + expect(json1).toEqual('{"address":{"country":"USA","city":"New York"},"name":"John","age":30}'); + + // #endif + const obj2 = ['apple', 'banana', 'cherry']; const json2 = JSON.stringify(obj2); expect(json2).toEqual('["apple","banana","cherry"]'); @@ -223,6 +224,7 @@ export function testJSON() : Result { * add since 2023-09-23 * 部分出错过的示例场景 */ + // #ifdef APP-ANDROID const arr = [{ "$method": "collection", "$param": ["type"] as Array, @@ -241,26 +243,25 @@ export function testJSON() : Result { let ret = JSON.stringify({ $db: arr }) - // expect(ret).toEqual('{"$db":[{"$method":"collection","$param":["type"]},{"$method":"add","$param":[[{"num":2,"tag":"default-tag"},{"num":3,"tag":"default-tag"}]]}]}') + expect(ret).toEqual('{"$db":[{"$method":"collection","$param":["type"]},{"$method":"add","$param":[[{"num":2,"tag":"default-tag"},{"num":3,"tag":"default-tag"}]]}]}') type Msg = { id : string, method : string, params : any } - // type CallUniMethodParams = { - // method : string - // args : com.alibaba.fastjson.JSONArray - // } + type CallUniMethodParams = { + method : string + args : com.alibaba.fastjson.JSONArray + } const msg = `{"id":"6fd6ca73-c313-48ac-ad30-87ff4eba2be8","method":"App.callUniMethod","params":{"method":"reLaunch","args":[{"url":"/pages/index/index"}]}}` const jsonRet2 = JSON.parse(msg)! const paramsStr = JSON.stringify(jsonRet2.params) console.log(paramsStr) - //expect(paramsStr).toEqual('{"method":"reLaunch","args":[{"url":"/pages/index/index"}]}') - // const params = JSON.parse(paramsStr)! - //console.warn('params', JSON.stringify(params)) - //expect(JSON.stringify(params)).toEqual('{"method":"reLaunch","args":[{"url":"/pages/index/index"}]}') + expect(paramsStr).toEqual('{"method":"reLaunch","args":[{"url":"/pages/index/index"}]}') + const params = JSON.parse(paramsStr)! + expect(JSON.stringify(params)).toEqual('{"method":"reLaunch","args":[{"url":"/pages/index/index"}]}') class Stage { @@ -275,10 +276,10 @@ export function testJSON() : Result { const obj22 = { data: [new Stage()] as Array } as UTSJSONObject + expect(JSON.stringify(obj22)).toEqual('{"data":[{}]}') - console.log(JSON.stringify(obj22)) - // expect(JSON.stringify(obj22)).toEqual('{"data":[{}]}') - + // #endif + type A = { inserted : number } diff --git a/uni_modules/uts-tests/utssdk/JSON_large.uts b/uni_modules/uts-tests/utssdk/JSON_large.uts index edb38a3..00dafea 100644 --- a/uni_modules/uts-tests/utssdk/JSON_large.uts +++ b/uni_modules/uts-tests/utssdk/JSON_large.uts @@ -22527,7 +22527,7 @@ export function testJSONLarge() : Result { let spendTime = System.currentTimeMillis() - startTime console.log('指定类型转换耗时',spendTime,listdata!.length) - expect(listdata!.length).toEqual(33); + expect(listdata.length).toEqual(33); expect(spendTime < 500).toEqual(true); startTime = System.currentTimeMillis() @@ -22535,7 +22535,7 @@ export function testJSONLarge() : Result { spendTime = System.currentTimeMillis() - startTime expect(listdata2 instanceof Array).toEqual(true); let parseArray = listdata2 as Array - expect(parseArray!.length).toEqual(33); + expect(parseArray.length).toEqual(33); expect(spendTime < 300).toEqual(true); console.log('不指定类型转换耗时',spendTime,listdata2) diff --git a/uni_modules/uts-tests/utssdk/Number.uts b/uni_modules/uts-tests/utssdk/Number.uts index 7c33dd7..590f934 100644 --- a/uni_modules/uts-tests/utssdk/Number.uts +++ b/uni_modules/uts-tests/utssdk/Number.uts @@ -1,5 +1,6 @@ import { describe, test, expect, Result } from './tests.uts' +@Suppress("UnsafeCall") export function testNumber() : Result { return describe("Number", () => { @@ -69,6 +70,8 @@ export function testNumber() : Result { // #endif }) + + test('number-from-json-parse', () => { type A = { a:number @@ -79,10 +82,10 @@ export function testNumber() : Result { expect(aj?.a == 1.0).toEqual(true); expect(aj?.a == 1.0 as number).toEqual(true); // #ifdef APP-ANDROID - expect(aj?.a === 1).toEqual(true); - expect(aj?.a === 1 as number).toEqual(true); - expect(aj?.a === 1.0).toEqual(true); - expect(aj?.a === 1.0 as number).toEqual(true); + expect(numberEquals(aj?.a,1)).toEqual(true); + expect(numberEquals(aj?.a,1 as number)).toEqual(true); + expect(numberEquals(aj?.a,1.0)).toEqual(true); + expect(numberEquals(aj?.a,1.0 as number)).toEqual(true); let ki:Int = 1; let kd:Double = 1.0; let kf:Float = (1.0).toFloat(); diff --git a/uni_modules/uts-tests/utssdk/String.uts b/uni_modules/uts-tests/utssdk/String.uts index 543ca5b..d208e8a 100644 --- a/uni_modules/uts-tests/utssdk/String.uts +++ b/uni_modules/uts-tests/utssdk/String.uts @@ -116,27 +116,27 @@ export function testString(): Result { const str = 'The quick brown fox jumps over the lazy dog. It barked.'; const result = str.match(new RegExp('[A-Z]', 'g')); // expect(result!.length).toEqual(2); - expect(result![0]).toEqual("T"); - expect(result![1]).toEqual("I"); + expect(result?.[0]).toEqual("T"); + expect(result?.[1]).toEqual("I"); const result2 = str.match(new RegExp('[A-Z]')); // expect(result2!.length).toEqual(1); - expect(result2![0]).toEqual("T"); + expect(result2?.[0]).toEqual("T"); // #ifdef APP-ANDROID const gradientString = 'linear-gradient(to right, rgb(255, 0, 0), #00FF00, hsl(120, 100%, 50%))'; const pattern = /rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)|#([a-fA-F0-9]{2}){3}|hsl\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\)/g; const result3 = gradientString.match(pattern); - expect(result3!.length).toEqual(3); - expect(result3![0]).toEqual("rgb(255, 0, 0)"); - expect(result3![2]).toEqual("hsl(120, 100%, 50%)"); + expect(result3?.length).toEqual(3); + expect(result3?.[0]).toEqual("rgb(255, 0, 0)"); + expect(result3?.[2]).toEqual("hsl(120, 100%, 50%)"); const pattern2 = /rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)|#([a-fA-F0-9]{2}){3}|hsl\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\)/; const result4 = gradientString.match(pattern2); - expect(result4!.length).toEqual(8); - expect(result4![0]).toEqual("rgb(255, 0, 0)"); - expect(result4![1]).toEqual("255"); - expect(result4![2]).toEqual("0"); + expect(result4?.length).toEqual(8); + expect(result4?.[0]).toEqual("rgb(255, 0, 0)"); + expect(result4?.[1]).toEqual("255"); + expect(result4?.[2]).toEqual("0"); const url = ''; diff --git a/uni_modules/uts-tests/utssdk/UTSJSONObject.uts b/uni_modules/uts-tests/utssdk/UTSJSONObject.uts index 6b38239..f9a2082 100644 --- a/uni_modules/uts-tests/utssdk/UTSJSONObject.uts +++ b/uni_modules/uts-tests/utssdk/UTSJSONObject.uts @@ -21,7 +21,7 @@ export function testUTSJSONObject() : Result { const source = { b: 4, c: 5 }; const returnedTarget = UTSJSONObject.assign(target, source); - expect(returnedTarget!.toMap().size).toEqual(3); + expect(returnedTarget.toMap().size).toEqual(3); console.log(returnedTarget) // #endif }) diff --git a/uni_modules/uts-tests/utssdk/console.uts b/uni_modules/uts-tests/utssdk/console.uts index 787979c..ef08a5a 100644 --- a/uni_modules/uts-tests/utssdk/console.uts +++ b/uni_modules/uts-tests/utssdk/console.uts @@ -27,10 +27,9 @@ export function testConsole() : Result { // #ifdef APP-ANDROID let aj2 = JSON.parse('{"a":1}') as UTSJSONObject; - console.log(aj2!['a']) - expect(obtainInnerObject(aj2!['a']).get("type")).toEqual("number"); - expect(obtainInnerObject(aj2!['a']).get("subType")).toEqual("number"); + expect(obtainInnerObject(aj2['a']).get("type")).toEqual("number"); + expect(obtainInnerObject(aj2['a']).get("subType")).toEqual("number"); // #endif -- GitLab