diff --git a/pages/advance/advance.vue b/pages/advance/advance.vue index 494e01a4c45043bc2965ef54db727b2e603d85e4..473f7e3f0fb84cbad2db898e76a162976b5d67db 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 4154af850d34f47c858a35b36cbfaea605ad401d..1d5801cfa0af8e7dd01cdbab01c7b070d3679556 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 9d7d941c2e4134db27fdc628798869cb5448c58a..3a7b08549db9f18a3662f7b752550f91ec54ea92 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 3e206dcb6276a01fbd2ca9d1b2b5e51d980043dc..7c1de1ec77cc12aa3b3697e0c82f5430ef358f50 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 ad362a3ed0ab3038f55b3afce49c6ef6f7719ac2..fc6c0e9212d0ff33241754bef4f8fe85aa7f8c86 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 edb38a37e007c6751c9f2e8856acbf840bfd9a23..00dafea90b44469e1a7e19797b809e998fc9d203 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 7c33dd79f2ec6b7f1413283b3cd9ee29682e8b77..590f9347f28885e7a62ff866a8feb96317589c74 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 543ca5b7fac35538a32e75b5a7c373821144104f..d208e8a319b3e2e9bac31f5a7e18ee020021a3e8 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 6b38239e40155556316aa55f9a90288363c018cc..f9a208297d33b345b3e94cc5d8207e80649932a1 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 787979c9cb6cd4a286bbe396ca6c4e3c01faf64d..ef08a5ac39f73b5c393e5c53aba586751e9b2a43 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