提交 8a80ff86 编写于 作者: 杜庆泉's avatar 杜庆泉

修复hello uts 编译告警

上级 813ac9fd
...@@ -221,7 +221,7 @@ ...@@ -221,7 +221,7 @@
quitApp() quitApp()
}, },
testOpenFileWithProvider() { testOpenFileWithProvider() {
openFileWithProvider("apps/__UNI__70BE9D0/www/static/logo.png") openFileWithProvider()
}, },
testArrayConvert() { testArrayConvert() {
let convertRet = arrayConvert() let convertRet = arrayConvert()
......
...@@ -510,7 +510,7 @@ export function arrayConvert():boolean{ ...@@ -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")) let file = new File(UTSAndroid.getResourcePath("static/logo.png"))
const uri = UTSAndroid.getFileProviderUri(file) const uri = UTSAndroid.getFileProviderUri(file)
console.log("uri",uri.toString()) console.log("uri",uri.toString())
......
...@@ -168,6 +168,7 @@ export function gotoSystemPermissionActivityTest() { ...@@ -168,6 +168,7 @@ export function gotoSystemPermissionActivityTest() {
/** /**
* 跳转系统拍照界面,并触发相关生命周期测试 * 跳转系统拍照界面,并触发相关生命周期测试
*/ */
@Suppress("DEPRECATION")
export function gotoCameraTake(imageDone : (event : string) => void) : boolean { export function gotoCameraTake(imageDone : (event : string) => void) : boolean {
let permissionNeed = ["android.permission.CAMERA"] let permissionNeed = ["android.permission.CAMERA"]
......
...@@ -177,7 +177,7 @@ import WindowManager from 'android.view.WindowManager'; ...@@ -177,7 +177,7 @@ import WindowManager from 'android.view.WindowManager';
import ActionMode from 'android.view.ActionMode'; import ActionMode from 'android.view.ActionMode';
// export let onCallBackChange: (event: string) => void = (res) => {}; // 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) { export function onCallbackChange(fn : (eventLog : string) => void) {
callback = fn callback = fn
......
...@@ -119,8 +119,8 @@ export function testJSON() : Result { ...@@ -119,8 +119,8 @@ export function testJSON() : Result {
test('parseObject', () => { test('parseObject', () => {
const json = `{"result":true, "count":42}`; const json = `{"result":true, "count":42}`;
const obj = JSON.parseObject(json); const obj = JSON.parseObject(json);
expect(obj!["count"]).toEqual(42); expect(obj?.["count"]).toEqual(42);
expect(obj!["result"] as boolean).toEqual(true); expect(obj?.["result"] as boolean).toEqual(true);
expect(JSON.parseObject('{}')!).toEqual({}); expect(JSON.parseObject('{}')!).toEqual({});
...@@ -152,10 +152,11 @@ export function testJSON() : Result { ...@@ -152,10 +152,11 @@ export function testJSON() : Result {
expect(array2).toEqual([1, "hello world", 3]); expect(array2).toEqual([1, "hello world", 3]);
// #ifdef APP-ANDROID
const json3 = `[{"name":"John","id":"30"},{"name":"jack","id":"21"}]`; const json3 = `[{"name":"John","id":"30"},{"name":"jack","id":"21"}]`;
const array3 = JSON.parseArray<UTSJSONObject>(json3); const array3 = JSON.parseArray<UTSJSONObject>(json3);
// expect((array3![0])["name"]).toEqual("John"); expect((array3![0])["name"]).toEqual("John");
// #endif
}) })
test('merge-test-1', () => { test('merge-test-1', () => {
...@@ -181,13 +182,13 @@ export function testJSON() : Result { ...@@ -181,13 +182,13 @@ export function testJSON() : Result {
// #endif // #endif
}) })
test('stringify', () => { test('stringify', () => {
const obj = { name: 'John', age: 30 }; // #ifdef APP-ANDROID
const json = JSON.stringify(obj);
// expect(json).toEqual('{"name":"John","age":30}');
const obj1 = { name: 'John', age: 30, address: { city: 'New York', country: 'USA' } }; const obj1 = { name: 'John', age: 30, address: { city: 'New York', country: 'USA' } };
const json1 = JSON.stringify(obj1); 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 obj2 = ['apple', 'banana', 'cherry'];
const json2 = JSON.stringify(obj2); const json2 = JSON.stringify(obj2);
...@@ -223,6 +224,7 @@ export function testJSON() : Result { ...@@ -223,6 +224,7 @@ export function testJSON() : Result {
* add since 2023-09-23 * add since 2023-09-23
* 部分出错过的示例场景 * 部分出错过的示例场景
*/ */
// #ifdef APP-ANDROID
const arr = [{ const arr = [{
"$method": "collection", "$method": "collection",
"$param": ["type"] as Array<any>, "$param": ["type"] as Array<any>,
...@@ -241,26 +243,25 @@ export function testJSON() : Result { ...@@ -241,26 +243,25 @@ export function testJSON() : Result {
let ret = JSON.stringify({ let ret = JSON.stringify({
$db: arr $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 = { type Msg = {
id : string, id : string,
method : string, method : string,
params : any params : any
} }
// type CallUniMethodParams = { type CallUniMethodParams = {
// method : string method : string
// args : com.alibaba.fastjson.JSONArray 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 msg = `{"id":"6fd6ca73-c313-48ac-ad30-87ff4eba2be8","method":"App.callUniMethod","params":{"method":"reLaunch","args":[{"url":"/pages/index/index"}]}}`
const jsonRet2 = JSON.parse<Msg>(msg)! const jsonRet2 = JSON.parse<Msg>(msg)!
const paramsStr = JSON.stringify(jsonRet2.params) const paramsStr = JSON.stringify(jsonRet2.params)
console.log(paramsStr) console.log(paramsStr)
//expect(paramsStr).toEqual('{"method":"reLaunch","args":[{"url":"/pages/index/index"}]}') expect(paramsStr).toEqual('{"method":"reLaunch","args":[{"url":"/pages/index/index"}]}')
// const params = JSON.parse<CallUniMethodParams>(paramsStr)! const params = JSON.parse<CallUniMethodParams>(paramsStr)!
//console.warn('params', JSON.stringify(params)) expect(JSON.stringify(params)).toEqual('{"method":"reLaunch","args":[{"url":"/pages/index/index"}]}')
//expect(JSON.stringify(params)).toEqual('{"method":"reLaunch","args":[{"url":"/pages/index/index"}]}')
class Stage { class Stage {
...@@ -275,9 +276,9 @@ export function testJSON() : Result { ...@@ -275,9 +276,9 @@ export function testJSON() : Result {
const obj22 = { const obj22 = {
data: [new Stage()] as Array<any> data: [new Stage()] as Array<any>
} as UTSJSONObject } as UTSJSONObject
expect(JSON.stringify(obj22)).toEqual('{"data":[{}]}')
console.log(JSON.stringify(obj22)) // #endif
// expect(JSON.stringify(obj22)).toEqual('{"data":[{}]}')
type A = { type A = {
inserted : number inserted : number
......
...@@ -22527,7 +22527,7 @@ export function testJSONLarge() : Result { ...@@ -22527,7 +22527,7 @@ export function testJSONLarge() : Result {
let spendTime = System.currentTimeMillis() - startTime let spendTime = System.currentTimeMillis() - startTime
console.log('指定类型转换耗时',spendTime,listdata!.length) console.log('指定类型转换耗时',spendTime,listdata!.length)
expect(listdata!.length).toEqual(33); expect(listdata.length).toEqual(33);
expect(spendTime < 500).toEqual(true); expect(spendTime < 500).toEqual(true);
startTime = System.currentTimeMillis() startTime = System.currentTimeMillis()
...@@ -22535,7 +22535,7 @@ export function testJSONLarge() : Result { ...@@ -22535,7 +22535,7 @@ export function testJSONLarge() : Result {
spendTime = System.currentTimeMillis() - startTime spendTime = System.currentTimeMillis() - startTime
expect(listdata2 instanceof Array).toEqual(true); expect(listdata2 instanceof Array).toEqual(true);
let parseArray = listdata2 as Array let parseArray = listdata2 as Array
expect(parseArray!.length).toEqual(33); expect(parseArray.length).toEqual(33);
expect(spendTime < 300).toEqual(true); expect(spendTime < 300).toEqual(true);
console.log('不指定类型转换耗时',spendTime,listdata2) console.log('不指定类型转换耗时',spendTime,listdata2)
......
import { describe, test, expect, Result } from './tests.uts' import { describe, test, expect, Result } from './tests.uts'
@Suppress("UnsafeCall")
export function testNumber() : Result { export function testNumber() : Result {
return describe("Number", () => { return describe("Number", () => {
...@@ -69,6 +70,8 @@ export function testNumber() : Result { ...@@ -69,6 +70,8 @@ export function testNumber() : Result {
// #endif // #endif
}) })
test('number-from-json-parse', () => { test('number-from-json-parse', () => {
type A = { type A = {
a:number a:number
...@@ -79,10 +82,10 @@ export function testNumber() : Result { ...@@ -79,10 +82,10 @@ export function testNumber() : Result {
expect(aj?.a == 1.0).toEqual(true); expect(aj?.a == 1.0).toEqual(true);
expect(aj?.a == 1.0 as number).toEqual(true); expect(aj?.a == 1.0 as number).toEqual(true);
// #ifdef APP-ANDROID // #ifdef APP-ANDROID
expect(aj?.a === 1).toEqual(true); expect(numberEquals(aj?.a,1)).toEqual(true);
expect(aj?.a === 1 as number).toEqual(true); expect(numberEquals(aj?.a,1 as number)).toEqual(true);
expect(aj?.a === 1.0).toEqual(true); expect(numberEquals(aj?.a,1.0)).toEqual(true);
expect(aj?.a === 1.0 as number).toEqual(true); expect(numberEquals(aj?.a,1.0 as number)).toEqual(true);
let ki:Int = 1; let ki:Int = 1;
let kd:Double = 1.0; let kd:Double = 1.0;
let kf:Float = (1.0).toFloat(); let kf:Float = (1.0).toFloat();
......
...@@ -116,27 +116,27 @@ export function testString(): Result { ...@@ -116,27 +116,27 @@ export function testString(): Result {
const str = 'The quick brown fox jumps over the lazy dog. It barked.'; const str = 'The quick brown fox jumps over the lazy dog. It barked.';
const result = str.match(new RegExp('[A-Z]', 'g')); const result = str.match(new RegExp('[A-Z]', 'g'));
// expect(result!.length).toEqual(2); // expect(result!.length).toEqual(2);
expect(result![0]).toEqual("T"); expect(result?.[0]).toEqual("T");
expect(result![1]).toEqual("I"); expect(result?.[1]).toEqual("I");
const result2 = str.match(new RegExp('[A-Z]')); const result2 = str.match(new RegExp('[A-Z]'));
// expect(result2!.length).toEqual(1); // expect(result2!.length).toEqual(1);
expect(result2![0]).toEqual("T"); expect(result2?.[0]).toEqual("T");
// #ifdef APP-ANDROID // #ifdef APP-ANDROID
const gradientString = 'linear-gradient(to right, rgb(255, 0, 0), #00FF00, hsl(120, 100%, 50%))'; 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 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); const result3 = gradientString.match(pattern);
expect(result3!.length).toEqual(3); expect(result3?.length).toEqual(3);
expect(result3![0]).toEqual("rgb(255, 0, 0)"); expect(result3?.[0]).toEqual("rgb(255, 0, 0)");
expect(result3![2]).toEqual("hsl(120, 100%, 50%)"); 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 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); const result4 = gradientString.match(pattern2);
expect(result4!.length).toEqual(8); expect(result4?.length).toEqual(8);
expect(result4![0]).toEqual("rgb(255, 0, 0)"); expect(result4?.[0]).toEqual("rgb(255, 0, 0)");
expect(result4![1]).toEqual("255"); expect(result4?.[1]).toEqual("255");
expect(result4![2]).toEqual("0"); expect(result4?.[2]).toEqual("0");
const url = ''; const url = '';
......
...@@ -21,7 +21,7 @@ export function testUTSJSONObject() : Result { ...@@ -21,7 +21,7 @@ export function testUTSJSONObject() : Result {
const source = { b: 4, c: 5 }; const source = { b: 4, c: 5 };
const returnedTarget = UTSJSONObject.assign(target, source); const returnedTarget = UTSJSONObject.assign(target, source);
expect(returnedTarget!.toMap().size).toEqual(3); expect(returnedTarget.toMap().size).toEqual(3);
console.log(returnedTarget) console.log(returnedTarget)
// #endif // #endif
}) })
......
...@@ -27,10 +27,9 @@ export function testConsole() : Result { ...@@ -27,10 +27,9 @@ export function testConsole() : Result {
// #ifdef APP-ANDROID // #ifdef APP-ANDROID
let aj2 = JSON.parse('{"a":1}') as UTSJSONObject; 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("type")).toEqual("number");
expect(obtainInnerObject(aj2!['a']).get("subType")).toEqual("number"); expect(obtainInnerObject(aj2['a']).get("subType")).toEqual("number");
// #endif // #endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册