提交 b79125fe 编写于 作者: 雪洛's avatar 雪洛

Merge branch 'dev' into alpha

<template>
<button @click="logStr">打印字符串</button>
<button @click="logFloat">打印浮点数</button>
<button @click="logInt">打印整数</button>
<button @click="logObject">打印对象</button>
<button @click="logFunction">打印函数</button>
<div>
<button @click="doLogTest">打印测试</button>
<text>{{testRet}}</text>
</div>
</template>
<script>
import {
logStrTest,
logIntTest,
logFloatTest,
logObjectTest,
logFunctionTest
} from '@/uni_modules/uts-advance'
import { getLog,logObjectTest,logClassTest,logFunctionTest,logFileTest,logDateTest } from '../../uni_modules/uts-api-test'
export default {
data() {
return {}
return {
testRet:''
}
},
methods: {
logStr() {
logStrTest()
},
logFloat() {
logFloatTest()
},
logInt() {
logIntTest()
},
logObject() {
logObjectTest()
},
logFunction() {
logFunctionTest()
},
doLogTest() {
if(getLog("") != '{"type":"string","value":""}'){
this.testRet = "测试失败"
return;
}
if(getLog("字符串打印测试") != '{"type":"string","value":"字符串打印测试"}'){
this.testRet = "测试失败"
return;
}
if(getLog(2023) != '{"type":"number","value":"2023"}'){
this.testRet = "测试失败"
return;
}
// console.log(getLog(2023.0))
// if(getLog(2023.0) != '{"type":"number","value":"2023"}'){
// this.testRet = "测试失败"
// return;
// }
if(getLog(2023.002) != '{"type":"number","value":"2023.002"}'){
this.testRet = "测试失败"
return;
}
if(logObjectTest() != '{"className":"uts.sdk.modules.utsApiTest.ParamOptions","subType":"object","__$originalPosition":"","type":"object","value":{"methods":[],"properties":[{"name":"array","subType":"array","className":"io.dcloud.uts.UTSArray","type":"object","value":{"properties":[{"name":0,"type":"string","value":"1"},{"name":1,"type":"string","value":"2"},{"name":2,"type":"string","value":"3"}]}},{"name":"title","type":"string","value":"logObjectTest"}]}}'){
this.testRet = "测试失败"
return;
}
if(logFunctionTest() != '{"parameter":[],"type":"function"}'){
this.testRet = "测试失败"
return;
}
if(logClassTest() != '{"className":"uts.sdk.modules.utsApiTest.C","subType":"object","__$originalPosition":"","type":"object","value":{"methods":[],"properties":[{"name":"name","type":"string","value":"ccc"},{"parameter":["string"],"name":"sayBye","type":"function"}]}}'){
this.testRet = "测试失败"
return;
}
/**
* uvue 和 vue 因为 java 版本不同,所以这里的打印格式可能存在差异
*/
if(logFileTest() != '{"className":"java.io.File","subType":"object","type":"object","value":{"methods":[],"properties":[]}}'){
this.testRet = "测试失败"
return;
}
if(logDateTest() != '{"className":"io.dcloud.uts.Date","subType":"date","type":"object","value":"Sat Aug 08 1998 08:00:00 GMT+0800"}'){
this.testRet = "测试失败"
return;
}
this.testRet = "测试完成"
}
}
}
......
<template>
<div>
<button @click="logStr">打印字符串</button>
<button @click="logFloat">打印浮点数</button>
<button @click="logInt">打印整数</button>
<button @click="logObject">打印对象</button>
<button @click="logFunction">打印函数</button>
<button @click="logFile">打印文件</button>
<button @click="logDate">打印日期</button>
<button @click="logDateCombine">组合打印日期</button>
<button @click="doLogTest">打印测试</button>
<text>{{testRet}}</text>
</div>
</template>
<script>
import {
logStrTest,
logIntTest,
logFloatTest,
logObjectTest,
logFunctionTest,
logDateTest,
logFileTest,
logDateCombineTest
} from '@/uni_modules/uts-advance'
import { getLog,logObjectTest,logClassTest,logFunctionTest,logFileTest,logDateTest } from '../../uni_modules/uts-api-test'
export default {
data() {
return {}
return {
testRet:''
}
},
methods: {
logStr() {
logStrTest()
},
logFloat() {
logFloatTest()
},
logInt() {
logIntTest()
},
logObject() {
logObjectTest()
},
logFunction() {
logFunctionTest()
},
logFile() {
logFileTest()
},
logDate() {
logDateTest()
},
logDateCombine() {
logDateCombineTest()
},
doLogTest() {
if(getLog("") != '{"type":"string","value":""}'){
this.testRet = "测试失败"
return;
}
if(getLog("字符串打印测试") != '{"type":"string","value":"字符串打印测试"}'){
this.testRet = "测试失败"
return;
}
if(getLog(2023) != '{"type":"number","value":"2023"}'){
this.testRet = "测试失败"
return;
}
if(getLog(2023.0) != '{"type":"number","value":"2023"}'){
this.testRet = "测试失败"
return;
}
if(getLog(2023.002) != '{"type":"number","value":"2023.002"}'){
this.testRet = "测试失败"
return;
}
if(logObjectTest() != '{"className":"uts.sdk.modules.utsApiTest.ParamOptions","subType":"object","__$originalPosition":"","type":"object","value":{"methods":[],"properties":[{"name":"array","subType":"array","className":"io.dcloud.uts.UTSArray","type":"object","value":{"properties":[{"name":0,"type":"string","value":"1"},{"name":1,"type":"string","value":"2"},{"name":2,"type":"string","value":"3"}]}},{"name":"title","type":"string","value":"logObjectTest"}]}}'){
this.testRet = "测试失败"
return;
}
if(logFunctionTest() != '{"parameter":[],"type":"function"}'){
this.testRet = "测试失败"
return;
}
if(logClassTest() != '{"className":"uts.sdk.modules.utsApiTest.C","subType":"object","__$originalPosition":"","type":"object","value":{"methods":[],"properties":[{"name":"name","type":"string","value":"ccc"},{"parameter":["string"],"name":"sayBye","type":"function"}]}}'){
this.testRet = "测试失败"
return;
}
if(logFileTest() != '{"className":"java.io.File","subType":"object","type":"object","value":{"methods":[],"properties":[{"name":"filePath","type":"null","value":"null"},{"name":"path","type":"string","value":"/sdcard/temp/1.txt"},{"name":"prefixLength","subType":"number","type":"Int","value":"1"},{"name":"status","type":"null","value":"null"}]}}'){
this.testRet = "测试失败"
return;
}
if(logDateTest() != '{"className":"io.dcloud.uts.Date","subType":"date","type":"object","value":"Sat Aug 08 1998 08:00:00 GMT+0800"}'){
this.testRet = "测试失败"
return;
}
this.testRet = "测试完成"
}
}
}
......
......@@ -13,7 +13,11 @@
<button @click="testUtsAsync">点击测试uts异步方法</button>
<view>测试return:{{ format(testUtsAsyncResult.return) }}</view>
<view>测试success:{{ format(testUtsAsyncResult.success) }}</view>
<view>测试complete:{{ format(testUtsAsyncResult.complete) }}</view>
<view>测试complete:{{ format(testUtsAsyncResult.complete) }}</view>
<button @click="testUtsAsyncMulitParam">点击测试uts异步方法-多参数</button>
<view>测试return:{{ format(testUtsAsyncMulitParamResult.return) }}</view>
<view>测试success:{{ format(testUtsAsyncMulitParamResult.success) }}</view>
<view>测试complete:{{ format(testUtsAsyncMulitParamResult.complete) }}</view>
<button @click="testUtsClassConstructor">点击测试uts class构造函数</button>
<view>测试callback:{{ format(testUtsClassConstructorResult.callback) }}</view>
<button @click="testUtsClassStaticProp">点击测试uts class静态属性</button>
......@@ -55,7 +59,8 @@
MAX,
testSync,
testSyncWithCallback,
testAsync,
testAsync,
testAsyncParam3,
Test,
request,
} from "../../uni_modules/uts-syntaxcase";
......@@ -77,6 +82,12 @@
success: null,
fail: null,
complete: null,
},
testUtsAsyncMulitParamResult: {
return: null,
success: null,
fail: null,
complete: null,
},
testUtsClassConstructorResult: {
callback: null
......@@ -124,7 +135,8 @@
testAll() {
this.testUtsSync();
this.testUtsSyncWithCallback();
this.testUtsAsync();
this.testUtsAsync();
this.testUtsAsyncMulitParam()
this.testUtsClassConstructor();
this.testUtsClassStaticProp();
this.testUtsClassStaticSyncWithCallback();
......@@ -195,6 +207,31 @@
this.testUtsAsyncResult.return = true;
}
} catch (e) {}
},
async testUtsAsyncMulitParam() {
this.testUtsAsyncMulitParamResult.return = false;
this.testUtsAsyncMulitParamResult.success = false;
// testUtsAsyncResult.fail = false;
this.testUtsAsyncMulitParamResult.complete = false;
try {
const res = await testAsyncParam3(100,"hello",{
type: "success",
success: (res) => {
console.log("testUtsAsyncMulitParam.success.callback", res);
this.testUtsAsyncMulitParamResult.success = true;
},
fail: (res) => {
console.log("testUtsAsyncMulitParam.fail.callback", res);
},
complete: (res) => {
console.log("testUtsAsyncMulitParam.complete.callback", res);
this.testUtsAsyncMulitParamResult.complete = true;
},
});
if (res.name === "testUtsAsyncMulitParam") {
this.testUtsAsyncMulitParamResult.return = true;
}
} catch (e) {}
},
testUtsClassConstructor() {
this.testUtsClassConstructorResult.callback = false
......
......@@ -433,53 +433,6 @@ export function callbackParam(callback : ParamCallback) {
}
callback(ret)
}
/**
* 打印测试方法
*/
export function logStrTest() {
console.log("logStrTest 字符串打印测试")
}
export function logFloatTest() {
console.log(3.1415926)
}
export function logIntTest() {
console.log(2023)
console.log(2023.0)
console.log(2023.002)
}
export function logObjectTest(){
let ret : ParamOptions = {
title: "logObjectTest",
array: ['1', '2', '3']
}
console.log(ret)
}
export function logFunctionTest(){
let testFun = function(){
console.log("testFun")
}
console.log(testFun)
}
export function logFileTest(){
console.log(new File("/sdcard/temp/1.txt"))
}
export function logDateTest(){
console.log(new Date())
}
export function logDateCombineTest(){
console.log("现在的日期是",new Date()," 以上是日期信息")
}
/**
......
{
"id": "uts-test",
"displayName": "uts-test",
"version": "1.0.0",
"description": "uts-test",
"keywords": [
"uts-test"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u",
"alipay": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
\ No newline at end of file
# uts-test
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[UTS 组件插件](https://uniapp.dcloud.net.cn/plugin/uts-component.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts)
\ No newline at end of file
{
"minSdkVersion": "21"
}
\ No newline at end of file
/* 引入 interface.uts 文件中定义的变量 */
import { GetLog } from '../interface.uts';
import File from 'java.io.File';
export const getLog : GetLog = function (param : Any|null) : string {
let allLog = console.getLogV2(param);
/**
* 移除掉干扰因素,仅返回打印对象本身的序列化结果
*/
if(!allLog.startsWith("---BEGIN:CONSOLE---")){
return ""
}
if(!allLog.endsWith("---END:CONSOLE---")){
return ""
}
let jsonLog = allLog
jsonLog = jsonLog.replace("---BEGIN:CONSOLE---", "")
jsonLog = jsonLog.replace("---END:CONSOLE---", "")
let jsonArrayObj = JSON.parse<UTSArray<UTSJSONObject>>(jsonLog)
return jsonArrayObj![0].toJSONString()
}
type ParamOptions = {
title : string,
array : Array<string>
}
class C {
name:string = "default"
sayBye = function(word:string){
console.log("sayBye",word)
}
sayHello(word:string){
console.log("sayHello",word)
}
}
export function logObjectTest():string{
let ret : ParamOptions = {
title: "logObjectTest",
array: ['1', '2', '3']
}
let typeLogRet = getLog(ret)
let typeLogObj = JSON.parseObject(typeLogRet)!
let typeLogObjPos = typeLogObj.getJSON("__$originalPosition")!
if("ParamOptions" != typeLogObjPos['name']){
return ""
}
/**
* 编译出来的位置信息可能有差异,排除单独验证后,排除掉这个字段
*/
typeLogObj.set("__$originalPosition","")
return typeLogObj.toJSONString()
}
export function logFunctionTest():string{
let testFun = function(){
console.log("testFun")
}
return getLog(testFun)
}
export function logFileTest():string{
return getLog(new File("/sdcard/temp/1.txt"))
}
export function logDateTest():string{
return getLog(new Date('1998-08-08'))
}
export function logClassTest():string{
let c = new C()
c.name="ccc"
let classLogRet = getLog(c)
let classLogObj = JSON.parseObject(classLogRet)!
let classLogObjPos = classLogObj.getJSON("__$originalPosition")!
if("C" != classLogObjPos['name']){
return ""
}
/**
* 编译出来的位置信息可能有差异,排除单独验证后,排除掉这个字段
*/
classLogObj.set("__$originalPosition","")
return classLogObj.toJSONString()
}
/* 同步函数定义 */
export type GetLog = (logObject : Any|null) => string
\ No newline at end of file
/* 此规范为 uni 规范,可以按照自己的需要选择是否实现 */
/**
* 错误主题
* 注意:错误主题一般为插件名称,每个组件不同,需要使用时请更改。
* [可选实现]
*/
export const UniErrorSubject = 'uts-test';
......@@ -25,12 +25,12 @@ export function getAppContextTest() : boolean {
export function getJavaClassTest() : boolean {
let classObj1 = UTSAndroid.getJavaClass(UTSAndroid.getDispatcher())
if("io.dcloud.uts.task.UTSTaskDispatcher" == classObj1.name){
let dispatcherClass = UTSAndroid.getJavaClass(UTSAndroid.getDispatcher())
if("io.dcloud.uts.task.UTSTaskDispatcher" == dispatcherClass.name){
return true
}
let classObj2 = UTSAndroid.getJavaClass(UTSAndroid.getAppContext()!)
if("io.dcloud.uniapp.UniApplication" == classObj2.name){
let applicationClass = UTSAndroid.getJavaClass(UTSAndroid.getAppContext()!)
if("io.dcloud.uniapp.UniApplication" == applicationClass.name){
return true
}
return false
......
......@@ -95,7 +95,25 @@ export async function testAsync(opts : AsyncOptions) : Promise<SyntaxResult> {
}
return await testAwaitPromise(res);
// return { name: "testAsync" };
}
}
export async function testAsyncParam3(id:number,name:string,opts : AsyncOptions) : Promise<SyntaxResult> {
console.log("id",id,"name",name)
if (opts.type == "success") {
opts.success("success");
} else {
opts.fail("fail");
}
opts.complete("complete");
const res : SyntaxResult = {
name: "testUtsAsyncMulitParam"
}
return await testAwaitPromise(res);
// return { name: "testAsync" };
}
export type TestOptions = {
name : string;
......
import { describe, test, expect, Result } from './tests.uts'
export function testType() : Result {
return describe("Type", () => {
test("Object literal to type instance", () => {
type Person = {
age: number
}
const a: Person = {
age: 1
}
const b = {
age: 2
} as Person
expect(a instanceof Person).toEqual(true);
expect(b instanceof Person).toEqual(true);
})
test("Type with any[]", () => {
type Person = {
age: number,
friends: any[]
}
const a: Person = {
age: 1,
friends: ['b']
}
const b = {
age: 2,
friends: ['a']
} as Person
expect(a instanceof Person).toEqual(true);
expect(b instanceof Person).toEqual(true);
})
})
}
\ No newline at end of file
......@@ -10,8 +10,9 @@ import { testSet } from './Set.uts'
import { testOperators } from './Operators.uts'
import { testMath } from './Math.uts'
import { testRegExp } from './RegExp.uts'
import { testForLoop } from './ForLoop.uts'
import { testForLoop } from './ForLoop.uts'
import { testGlobal } from './Global.uts'
import { testType } from './Type.uts'
export { Result } from './tests.uts'
// Promise、Proxy、Reflect、Weakmap、WeakSet 不支持
......@@ -28,8 +29,9 @@ export function runTests() : UTSJSONObject {
const MathRes = testMath();
const RegExpRes = testRegExp();
const KeyWordRes = testKeyWord();
const ForLoopRes = testForLoop();
const ForLoopRes = testForLoop();
const GlobalRes = testGlobal();
const TypeRes = testType();
return {
Array: ArrayRes,
......@@ -44,7 +46,8 @@ export function runTests() : UTSJSONObject {
Math: MathRes,
RegExp: RegExpRes,
KeyWord: KeyWordRes,
ForLoop: ForLoopRes,
Global: GlobalRes,
ForLoop: ForLoopRes,
Global: GlobalRes,
Type: TypeRes
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册