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

修复hello uts 编译告警

上级 813ac9fd
......@@ -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({
......
......@@ -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())
......
......@@ -168,6 +168,7 @@ export function gotoSystemPermissionActivityTest() {
/**
* 跳转系统拍照界面,并触发相关生命周期测试
*/
@Suppress("DEPRECATION")
export function gotoCameraTake(imageDone : (event : string) => void) : boolean {
let permissionNeed = ["android.permission.CAMERA"]
......
......@@ -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
......
......@@ -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<UTSJSONObject>(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<any>,
......@@ -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>(msg)!
const paramsStr = JSON.stringify(jsonRet2.params)
console.log(paramsStr)
//expect(paramsStr).toEqual('{"method":"reLaunch","args":[{"url":"/pages/index/index"}]}')
// 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(paramsStr).toEqual('{"method":"reLaunch","args":[{"url":"/pages/index/index"}]}')
const params = JSON.parse<CallUniMethodParams>(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<any>
} as UTSJSONObject
expect(JSON.stringify(obj22)).toEqual('{"data":[{}]}')
console.log(JSON.stringify(obj22))
// expect(JSON.stringify(obj22)).toEqual('{"data":[{}]}')
// #endif
type A = {
inserted : number
}
......
......@@ -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)
......
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();
......
......@@ -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 = '';
......
......@@ -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
})
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册