提交 9fd3d4db 编写于 作者: dcloud_wdl's avatar dcloud_wdl

[转正] git merge origin/alpha

......@@ -6,14 +6,15 @@
>
<!--meta-data-->
<meta-data android:name="TencentMapSDK" android:value="您申请的腾讯定位App Key" />
<activity android:name="uni.UNI70BE9D0.RootPackageActivity"
android:launchMode="singleTask"
android:exported="true">
<intent-filter>
<action android:name="uni.UNI70BE9D0.RootPackageActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!--需要替换成开发者自己的包名-->
<activity android:name="uni.UNI70BE9D0.RootPackageActivity"
android:launchMode="singleTask"
android:exported="true">
<intent-filter>
<!--需要替换成开发者自己的包名-->
<action android:name="uni.UNI70BE9D0.RootPackageActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
## 1.0.8
* update 4.06.2024032403-alpha
## 1.0.7
* update 4.05.2024032021-alpha
## 1.0.6
* update 4.04.2024031519-alpha
## 1.0.5
* update 4.03.2024031101-alpha
## 1.0.4
* update 4.02.2024030621-alpha
## 1.0.3
* update 4.01.2024020211-alpha
## 1.0.2
* update 4.0.2024012711-alpha
## 1.0.1(2023-12-19)
更多详情查看:[https://gitcode.net/dcloud/hello-uts/-/commits/alpha](https://gitcode.net/dcloud/hello-uts/-/commits/alpha)
......@@ -43,6 +43,7 @@ module.exports = {
reporters: [
'default'
],
setupFiles: ['./jest.global.js'],
globals: {
describes: parseDescribes()
},
......@@ -51,4 +52,4 @@ module.exports = {
rootDir: __dirname,
testMatch: ["<rootDir>/pages/**/*test.[jt]s?(x)"],
testPathIgnorePatterns: ['/node_modules/']
}
}
const {
readFileSync,
readdirSync
} = require('fs')
const {
extname,
resolve
} = require('path')
module.exports = async function (globalConfig, projectConfig) {
const describeRE = /describe\(["|'](.*)["|']/
const testsRE = /test\(["|'](.*)["|']/g
function parse(content) {
const describes = content.match(describeRE)
if (!describes) {
return
}
const describe = describes[1]
const tests = []
let test
while (test = testsRE.exec(content)) {
tests.push(test[1])
}
return {
describe,
tests
}
}
function parseDescribes() {
const dir = resolve(__dirname, 'uni_modules/uts-tests/utssdk')
const describes = []
readdirSync(dir).forEach(file => {
if (extname(file) === '.uts') {
describes.push(parse(readFileSync(resolve(dir, file), 'utf8')))
}
})
return describes
};
global.describes = parseDescribes();
};
\ No newline at end of file
import App from './App'
// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
...App
})
app.$mount()
// #endif
// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
const app = createSSRApp(App)
return {
app
}
}
\ No newline at end of file
}
// #endif
{
"id": "hello-uts",
"name": "Hello uts",
"displayName": "Hello uts",
"version": "1.1.1",
"description": "UTS插件示例项目",
"repository": "https://gitcode.net/dcloud/hello-uts",
"keywords": [
"uts",
"示例工程"
],
"author": "",
"license": "MIT",
"dependencies": {},
"engines": {
"HBuilderX": "^3.99"
},
"dcloudext": {
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "不采集任何数据",
"permissions": "- android.permission.INTERNET \n- android.permission.READ_EXTERNAL_STORAGE \n- android.permission.WRITE_EXTERNAL_STORAGE \n- android.permission.ACCESS_FINE_LOCATION \n- android.permission.ACCESS_COARSE_LOCATION \n- android.permission.ACCESS_NETWORK_STATE \n- android.permission.READ_MEDIA_IMAGES \n- android.permission.READ_MEDIA_VIDEO"
},
"npmurl": "",
"type": "uniapp-template-project"
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
},
"client": {
"App": {
"app-vue": "y",
"app-nvue": "n",
"app-uvue": "n"
},
"H5-mobile": {
"Safari": "n",
"Android Browser": "n",
"微信浏览器(Android)": "n",
"QQ浏览器(Android)": "n"
},
"H5-pc": {
"Chrome": "n",
"IE": "n",
"Edge": "n",
"Firefox": "n",
"Safari": "n"
},
"小程序": {
"微信": "n",
"阿里": "n",
"百度": "n",
"字节跳动": "n",
"QQ": "n",
"京东": "n",
"钉钉": "n",
"快手": "n",
"飞书": "n"
},
"快应用": {
"华为": "n",
"联盟": "n"
},
"Vue": {
"vue2": "y",
"vue3": "y"
}
}
}
}
{
"id": "hello-uts-alpha",
"name": "hello-uts-alpha",
"displayName": "hello-uts-alpha",
"version": "1.0.8",
"description": "UTS插件示例项目",
"repository": "https://gitcode.net/dcloud/hello-uts",
"keywords": [
"uts",
"示例工程"
],
"author": "",
"license": "MIT",
"dependencies": {},
"engines": {
"HBuilderX": "^3.99"
},
"dcloudext": {
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "不采集任何数据",
"permissions": "- android.permission.INTERNET \n- android.permission.READ_EXTERNAL_STORAGE \n- android.permission.WRITE_EXTERNAL_STORAGE \n- android.permission.ACCESS_FINE_LOCATION \n- android.permission.ACCESS_COARSE_LOCATION \n- android.permission.ACCESS_NETWORK_STATE \n- android.permission.READ_MEDIA_IMAGES \n- android.permission.READ_MEDIA_VIDEO"
},
"npmurl": "",
"type": "uniapp-template-project"
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
},
"client": {
"App": {
"app-vue": "y",
"app-nvue": "n",
"app-uvue": "n"
},
"H5-mobile": {
"Safari": "n",
"Android Browser": "n",
"微信浏览器(Android)": "n",
"QQ浏览器(Android)": "n"
},
"H5-pc": {
"Chrome": "n",
"IE": "n",
"Edge": "n",
"Firefox": "n",
"Safari": "n"
},
"小程序": {
"微信": "n",
"阿里": "n",
"百度": "n",
"字节跳动": "n",
"QQ": "n",
"京东": "n",
"钉钉": "n",
"快手": "n",
"飞书": "n"
},
"快应用": {
"华为": "n",
"联盟": "n"
},
"Vue": {
"vue2": "y",
"vue3": "y"
}
}
}
}
}
\ No newline at end of file
......@@ -14,7 +14,9 @@
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
}
// #ifndef WEB
,
{
"path": "pages/advance/advance",
"style": {
......@@ -171,6 +173,7 @@
}
}
// #endif
],
"tabBar": {
......
......@@ -11,13 +11,13 @@
</view>
</template>
<script>
import {
checkHasIntegration
} from "@/uni_modules/uts-tencentgeolocation";
import {
checkHasLottieIntegration
} from "@/uni_modules/uts-animation-view";
import {
checkHasIntegration
} from "@/uni_modules/uts-tencentgeolocation";
import {
checkHasLottieIntegration
} from "@/uni_modules/uts-animation-view";
export default {
data() {
......@@ -50,17 +50,17 @@
url: `/pages/${e.url}`
})
},
gotoLottie: function(e) {
if (checkHasLottieIntegration()) {
uni.navigateTo({
url: '/pages/SDKIntegration/Lottie/index'
})
} else {
uni.showToast({
icon: 'none',
title: '需要在自定义基座中运行'
})
}
gotoLottie: function(e) {
if (checkHasLottieIntegration()) {
uni.navigateTo({
url: '/pages/SDKIntegration/Lottie/index'
})
} else {
uni.showToast({
icon: 'none',
title: '需要在自定义基座中运行'
})
}
},
gotoTencentLocation: function(e) {
......
......@@ -21,15 +21,15 @@
</view>
</template>
<script>
<script>
import {
checkHasIntegration,
requestPremission,
getLocation,
watchPosition,
clearWatch
} from "@/uni_modules/uts-tencentgeolocation";
} from "@/uni_modules/uts-tencentgeolocation";
export default {
data() {
return {
......
......@@ -16,9 +16,9 @@
</template>
<script>
import { showToast } from '@/uni_modules/uts-toast'
export default {
data() {
......
<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>
<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>
<div>
<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>
......@@ -49,16 +53,18 @@
<button @click="testAll">点击测试所有</button>
</view>
</template>
<script>
<script>
// #ifndef H5
import {
MAX,
testSync,
testSyncWithCallback,
testAsync,
testAsync,
testAsyncParam3,
Test,
request,
} from "../../uni_modules/uts-syntaxcase";
// #endif
let test
let id = 0
export default {
......@@ -76,6 +82,12 @@
success: null,
fail: null,
complete: null,
},
testUtsAsyncMulitParamResult: {
return: null,
success: null,
fail: null,
complete: null,
},
testUtsClassConstructorResult: {
callback: null
......@@ -123,7 +135,8 @@
testAll() {
this.testUtsSync();
this.testUtsSyncWithCallback();
this.testUtsAsync();
this.testUtsAsync();
this.testUtsAsyncMulitParam()
this.testUtsClassConstructor();
this.testUtsClassStaticProp();
this.testUtsClassStaticSyncWithCallback();
......@@ -194,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
......
......@@ -22,12 +22,11 @@
instanceCreate() {
const user1 = new User("张三", 20);
let userText1 = user1.describeSelf()
const user2 = new User("李四", 30);
let userText2 = user2.describeSelf()
const user3 = new User("王五", 40);
let userText1 = user1.describeSelf()
let userText2 = user2.describeSelf()
let userText3 = user3.describeSelf()
......
<template>
{{ret}}
<button @click="instanceCreate">多实例创建测试</button>
<div>
{{ret}}
<button @click="instanceCreate">多实例创建测试</button>
</div>
</template>
......@@ -22,12 +24,11 @@
instanceCreate() {
const user1 = new User("张三", 20);
let userText1 = user1.describeSelf()
const user2 = new User("李四", 30);
let userText2 = user2.describeSelf()
const user3 = new User("王五", 40);
let userText1 = user1.describeSelf()
let userText2 = user2.describeSelf()
let userText3 = user3.describeSelf()
......
<template>
<button @click="inputArrayTest">传入数组参数</button>
<button @click="inputParamTest">传入复杂对象参数</button>
<button @click="returnArrayTest">返回数组参数</button>
<button @click="returnParamTest">返回复杂对象参数</button>
<button @click="callbackArrayTest">异步返回数组</button>
<button @click="callbackParamTest">异步返回复杂对象</button>
<div>
<button @click="inputArrayTest">传入数组参数</button>
<button @click="inputParamTest">传入复杂对象参数</button>
<button @click="returnArrayTest">返回数组参数</button>
<button @click="returnParamTest">返回复杂对象参数</button>
<button @click="callbackArrayTest">异步返回数组</button>
<button @click="callbackParamTest">异步返回复杂对象</button>
</div>
</template>
<script>
......
......@@ -9,6 +9,7 @@
<button @click="getAppContextClick">getAppContext</button>
<button @click="getUniActivityClick">getUniActivity</button>
<button @click="getJavaClassClick">getJavaClass</button>
<button @click="getAppTempPathClick">getAppTempPath</button>
<button @click="typeofClick">typeof</button>
<button @click="arrayPermissionFlowClick">组权限申请流程测试</button>
......@@ -50,6 +51,7 @@
import {
getAppContextTest,
getUniActivityTest,
getJavaClassTest,
getAppTempPathTest,
typeofClickTest,
gotoSystemPermissionActivityTest,
......@@ -123,6 +125,18 @@ export default {
// 取消注册生命周期
unRegLifecycle()
},
getJavaClassClick() {
if (getJavaClassTest()) {
uni.showToast({
title: '测试通过'
})
} else {
uni.showToast({
icon: 'error',
title: '测试失败'
})
}
},
getAppContextClick() {
if (getAppContextTest()) {
uni.showToast({
......
<template>
<view>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-hello-text">
逐一点击执行,观察测试反馈
......@@ -8,6 +9,7 @@
<button @click="getAppContextClick">getAppContext</button>
<button @click="getUniActivityClick">getUniActivity</button>
<button @click="getJavaClassClick">getJavaClass</button>
<button @click="getAppTempPathClick">getAppTempPath</button>
<button @click="typeofClick">typeof</button>
<button @click="arrayPermissionFlowClick">组权限申请流程测试</button>
......@@ -38,6 +40,7 @@
</view>
</view>
<button @tap="getDeviceInfoClick">获取设备基础信息</button>
</view>
</template>
......@@ -45,6 +48,7 @@
import {
getAppContextTest,
getUniActivityTest,
getJavaClassTest,
getAppTempPathTest,
typeofClickTest,
gotoSystemPermissionActivityTest,
......@@ -58,7 +62,6 @@
getDeviceInfoTest,
privacyStateTest
} from '@/uni_modules/uts-platform-api'
/**
* 测试在页面生命周期之外,使用api
*/
......@@ -114,6 +117,18 @@
// 取消注册生命周期
unRegLifecycle();
},
getJavaClassClick() {
if (getJavaClassTest()) {
uni.showToast({
title: '测试通过'
})
} else {
uni.showToast({
icon: 'error',
title: '测试失败'
})
}
},
getAppContextClick() {
if (getAppContextTest()) {
uni.showToast({
......
......@@ -33,19 +33,19 @@
</template>
<script>
import {
getCurrentVCTest,
getKeyWindowTest,
colorWithStringTest,
getResourcePathTest,
getDeviceInfoTest,
getAppInfoTest,
getSystemSettingTest,
tepeofTest,
dataConvertTest,
} from "@/uni_modules/uts-platform-api"
import {
getCurrentVCTest,
getKeyWindowTest,
colorWithStringTest,
getResourcePathTest,
getDeviceInfoTest,
getAppInfoTest,
getSystemSettingTest,
tepeofTest,
dataConvertTest,
} from "@/uni_modules/uts-platform-api"
export default {
data() {
return {
......
......@@ -10,7 +10,9 @@
</template>
<script>
// #ifdef APP
import { showAlert,showPrompt } from '@/uni_modules/uts-alert'
// #endif
export default {
data() {
......
......@@ -10,7 +10,9 @@
</template>
<script>
// #ifdef APP
import { showAlert,showPrompt } from '@/uni_modules/uts-alert'
// #endif
export default {
data() {
......
......@@ -11,11 +11,12 @@
</template>
<script>
// #ifndef H5
import {
onUserCaptureScreen,
offUserCaptureScreen
} from "@/uni_modules/uts-screenshot-listener";
// #endif
export default {
data() {
return {
......
......@@ -17,8 +17,8 @@
</view>
</view>
</template>·
<script>
import { gotoDemoActivity } from "@/uni_modules/uts-nativepage";
<script>
import { gotoDemoActivity } from "@/uni_modules/uts-nativepage";
import { getBatteryInfo } from "@/uni_modules/uts-getbatteryinfo";
export default {
......@@ -87,7 +87,7 @@
testGetBatteryCapacity() {
getBatteryInfo({
success(res) {
console.log(res)
console.log(res)
uni.showToast({
title: "当前电量:" + res.level + '%',
icon: 'none'
......@@ -95,14 +95,14 @@
}
})
},
testGotoDemoActivity() {
testGotoDemoActivity() {
let ret = gotoDemoActivity();
if (!ret) {
uni.showToast({
icon: 'none',
title: '需要在自定义基座中运行'
})
}
}
}
}
}
......
......@@ -21,7 +21,6 @@
</template>
<script lang="ts">
import { runTests, Result } from '../../uni_modules/uts-tests'
export default {
data() {
return {
......
......@@ -16,10 +16,10 @@
</view>
</view>
</template>
<script>
<script>
import {
runTests
} from '../../uni_modules/uts-tests'
} from '../../uni_modules/uts-tests'
export default {
data() {
return {
......
......@@ -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()," 以上是日期信息")
}
/**
......
......@@ -215,3 +215,20 @@ export function logFunctionTest(){
}
console.log(testFun)
}
export class User {
private name : string;
private age : Int;
constructor(hostP : string, port : Int) {
this.name = hostP;
this.age = port;
}
describeSelf():string{
let text = "name = " + this.name + ";age = " + `${this.age}`
return text
}
}
\ No newline at end of file
export function addViewToDecorView() { }
export function removeViewToDecorView() { }
export function initAppLifecycle() { }
export function getLogoPath() {}
export function playAssetAudio(){}
{
"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';
......@@ -194,8 +194,9 @@ class RootActivityStartListener extends OnClickListener{
}
override onClick(v?: View):void{
let intent = Intent("uni.UNI70BE9D0.RootPackageActivity")
host.startActivity(intent)
// 需要开发者替换成自己的包名,并且与AndroidManifest.xml 中保持一致
let intent = Intent("uni.UNI70BE9D0.RootPackageActivity")
host.startActivity(intent)
}
}
......
......@@ -23,6 +23,20 @@ export function getAppContextTest() : boolean {
return true
}
export function getJavaClassTest() : boolean {
let dispatcherClass = UTSAndroid.getJavaClass(UTSAndroid.getDispatcher())
if("io.dcloud.uts.task.UTSTaskDispatcher" == dispatcherClass.name){
return true
}
let applicationClass = UTSAndroid.getJavaClass(UTSAndroid.getAppContext()!)
if("io.dcloud.uniapp.UniApplication" == applicationClass.name){
return true
}
return false
}
/**
* UTSAndroid.getUniActivity 测试示例
* https://uniapp.dcloud.net.cn/plugin/uts-for-android.html#_4-2-1-getuniactivity
......@@ -79,10 +93,15 @@ export function getAppTempPathTest() : boolean {
if (UTSAndroid.getAppCachePath()!.contains("uni.UNI70BE9D0/apps/__UNI__70BE9D0/temp")) {
return true
}
let cachePath = UTSAndroid.getAppCachePath()!
// 2.0的路径
if (UTSAndroid.getAppCachePath()!.contains("cache/temp")) {
if (cachePath.contains("io.dcloud.uniappx/cache")) {
return true
}
// 2.0 自定义基座的情况
if (cachePath.contains("uni.UNI70BE9D0/cache")) {
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;
......
......@@ -13,7 +13,7 @@
3. 打包自定义基座
目前UTS只支持云端打包
注意将`uts-tencentgeolocation/utssdk/app-android/libs/androix-core-1.0.0.jar`先移到其他目录。
4. 运行自定义基座
......@@ -47,4 +47,4 @@
## 相关开发文档
- [UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
- [UTS 原生插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
- [UTS 原生插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
\ No newline at end of file
import { describe, test, expect, Result } from './tests.uts'
export function testArray(): Result {
return describe("Array", () => {
......@@ -14,12 +16,12 @@ export function testArray(): Result {
// swift 中字面量创建数组,仅支持同一类型的元素
// #ifndef APP-IOS
expect(a3).toEqual(new Array(1,2,3));
let a4 = new Array(1,'2',3);
expect(a4).toEqual(new Array(1,'2',3));
let a4 = new Array<any>(1,'2',3);
expect(a4).toEqual(new Array<any>(1,'2',3));
let a5 = Array(1,2,3);
expect(a5).toEqual(Array(1,2,3));
let a6 = Array(1,'2','3')
expect(a6).toEqual(Array(1,'2','3'));
let a6 = Array<any>(1,'2','3')
expect(a6).toEqual(Array<any>(1,'2','3'));
// #endif
})
......@@ -177,6 +179,24 @@ export function testArray(): Result {
const array2: string[] = ['a', 'b', 'c'];
expect(array2.includes('c', 3)).toEqual(false);
expect(array2.includes('c', 100)).toEqual(false);
type P = {
x : number
y : number
}
// #ifndef APP-IOS
const s = JSON.parse<P[]>(JSON.stringify([{ x: 0, y: 0 }])) as P[]
s[0].x += 0;
const clearList = s.map((v : P, _, _a) : number => v.x)
expect(clearList.includes(0)).toEqual(true);
// #endif
// #ifdef APP-IOS
const s = JSON.parse<P[]>(JSON.stringify([{ x: 0, y: 0 }])!) as P[]
s[0].x += 0;
const clearList = s.map((v : P, index: number, _a) : number => v.x)
expect(clearList.includes(0)).toEqual(true);
// #endif
})
test("indexOf", () => {
......
......@@ -9,7 +9,16 @@ export function testDate() : Result {
const secondsElapsed = Math.floor(millis / 1000)
expect(secondsElapsed).toEqual(2);
}, 2000)
})
})
test('new Date', () => {
let date1 = new Date('1992-02-02');
console.log("1111",date1.getTime())
expect(date1.getTime()).toEqual(696988800000);
let date2 = new Date('1992-2-02');
console.log("2222",date2.getTime())
expect(date2.getTime()).toEqual(696960000000);
})
test('valueOf', () => {
const date1 = new Date('December 17, 1995 03:24:00');
expect(date1.valueOf()).toEqual(819141840000);
......@@ -57,7 +66,10 @@ export function testDate() : Result {
// final millisecond (month boundary)
expect(new Date(2016, 1, 29, 23, 59, 59, 999).getDate()).toEqual(29);
// subsequent millisecond (month boundary)
expect(new Date(2016, 1, 29, 23, 59, 59, 1000).getDate()).toEqual(1);
expect(new Date(2016, 1, 29, 23, 59, 59, 1000).getDate()).toEqual(1);
expect(Date.parse("2024-01-09 22:00:00")).toEqual(1704808800000);
})
test('getDay', () => {
const birthday = new Date('August 19, 1975 23:15:30');
......@@ -104,7 +116,8 @@ export function testDate() : Result {
expect(new Date(2016, 6, 6, 13, 59, 59, 999).getHours()).toEqual(13);
// subsequent millisecond
expect(new Date(2016, 6, 6, 13, 59, 59, 1000).getHours()).toEqual(14);
})
})
test('getMilliseconds', () => {
const moonLanding = new Date('July 20, 69 00:20:18');
moonLanding.setMilliseconds(123);
......
......@@ -6,7 +6,7 @@ export function testError(): Result {
try {
throw new Error('Whoops!')
} catch (e) {
expect(e.message).toEqual("Whoops!");
expect((e as Error).message).toEqual("Whoops!");
}
})
// test('name', () => {
......
......@@ -32,9 +32,9 @@ export function testGlobal(): Result {
expect(isNaN(parseInt("345", 2))).toEqual(true)
expect(isNaN(parseInt("hello"))).toEqual(true)
expect(parseInt("6.022e23")).toEqual(6)
expect(parseInt("9223372036854775807")).toEqual(9.223372036854778e+18)
expect(parseInt("9223372036854775807000")).toEqual(9.223372036854777e+21)
expect(parseInt("922337203685477580700099999999999999999999999999999999999999999999999999999999999999999")).toEqual(9.223372036854776e+86)
expect(parseInt("9223372036854775807")).toEqualNumber(9.223372036854778e+18)
expect(parseInt("9223372036854775807000")).toEqualNumber(9.223372036854777e+21)
expect(parseInt("922337203685477580700099999999999999999999999999999999999999999999999999999999999999999")).toEqualNumber(9.223372036854776e+86)
expect(parseInt("50") / 100).toEqualNumber(0.5);
expect(parseInt("500") / 100).toEqualNumber(5);
......
......@@ -89,6 +89,8 @@ export function testKeyWord() : Result {
expect(typeof (0.0)).toEqual('Double')
// #endif
expect(typeof (NaN)).toEqual('number')
expect(typeof (Infinity)).toEqual('number')
expect(typeof ("hello world")).toEqual('string')
expect(typeof ([1, 2, 3])).toEqual('object')
expect(typeof (new Array<any>())).toEqual('object')
......
......@@ -113,7 +113,7 @@ export function testMath(): Result {
test('clz32', () => {
expect(Math.clz32(1)).toEqual(31);
expect(Math.clz32(1000)).toEqual(22);
expect(Math.clz32()).toEqual(32);
expect(Math.clz32(0)).toEqual(32);
expect(Math.clz32(3.5)).toEqual(30);
})
test('cos', () => {
......
......@@ -84,7 +84,28 @@ export function testNumber() : Result {
expect((6).toString(2)).toEqual("110");
expect((254).toString(16)).toEqual("fe");
expect((-10).toString(2)).toEqual("-1010");
expect((10.22).toString(8)).toEqual("12.16050753412172704");
expect((-10.22).toString(8)).toEqual("-12.16050753412172704");
expect((123456789987654).toString(16)).toEqual("7048861cc146");
expect((-0xff).toString(2)).toEqual("-11111111");
const a = 1e38
expect(a.toString(16).substring(0,12)).toEqual("4b3b4ca85a86");
expect(a.toString(16).length).toEqual(32);
expect(a.toString(16).substring(23)).toEqual("000000000");
expect(a.toString(2).length).toEqual(127);
expect(a.toString(2).substring(0,32)).toEqual("10010110011101101001100101010000");
expect(a.toString(2).substring(100)).toEqual("000000000000000000000000000");
const b = 1e22
const bStr12 = b.toString(12)
/**
* 移动端: 27373a86ba1a194a65054
* 浏览器端:27373a86ba1a195400000
*/
expect(bStr12.length).toEqual(21);
expect(bStr12.substring(0,14)).toEqual("27373a86ba1a19");
})
test('valueOf', () => {
......
......@@ -125,7 +125,7 @@ export function testOperators(): Result {
})
test('/=', () => {
let a:Number = 3;
let a:number = 3;
a /= 2;
expect(a).toEqual(1.5);
})
......
......@@ -3,7 +3,7 @@ import { describe, test, expect, Result } from './tests.uts'
export function testSet(): Result {
return describe("Set", () => {
test('size', () => {
const set1 = new Set<Any>();
const set1 = new Set<any>();
const object1 = {};
set1.add(42);
set1.add('forty two');
......
......@@ -10,14 +10,14 @@ export function testString(): Result {
expect(empty.length).toEqual(0);
// const adlam = "𞤲𞥋𞤣𞤫";
// expect(adlam.length).toEqual(8);
// const formula = "∀𝑥∈ℝ,𝑥²≥0";
// const formula = "��𝑥∈ℝ,𝑥²��";
// expect(formula.length).toEqual(11);
// 1. web: 大长度和js引擎有关,在v8中为 2^29 - 24
// 1. web: ��大长度和js引擎有关,在v8中为 2^29 - 24
// 超出边界报错: RangeError: Invalid string length
// 2. kotlin: 最大长度 2^31-1
// 2. kotlin: ��大长��2^31-1
// 超出边界报错: Error: targetMethod error::java.lang.OutOfMemoryError: char[] of length
// 3. swift: 大长度和内存有关
// 3. swift: ��大长度和内存有关
// 超出边界没有返回信息
// const length = Math.pow(2, 29) - 24
// const str = 'x'.repeat(length);
......@@ -63,10 +63,15 @@ export function testString(): Result {
expect("ABC".charCodeAt(0)).toEqual(65);
expect("ABC".charCodeAt(1)).toEqual(66);
expect("ABC".charCodeAt(2)).toEqual(67);
expect("ABC".charCodeAt(3)).toEqual(null);
expect("ABC".charCodeAt(3)).toEqual(NaN);
const empty = "";
expect(empty.charCodeAt(0)).toEqual(null);
expect(empty.charCodeAt(0)).toEqual(NaN);
})
test('fromCharCode', () => {
expect(String.fromCharCode(65, 66, 67)).toEqual("ABC");
expect(String.fromCharCode(0x12014)).toEqual("—");
expect(String.fromCharCode(0xd834, 0xdf06, 0x61, 0xd834, 0xdf07)).toEqual("𝌆a𝌇");
})
test('concat', () => {
let hello = 'Hello, '
......@@ -193,7 +198,7 @@ export function testString(): Result {
const str = 'The quick brown fox jumps over the lazy dog.';
expect(str.slice(31)).toEqual("the lazy dog.");
let str1 = 'The morning is upon us.', // str1 的长度 length 是 23。
let str1 = 'The morning is upon us.', // str1 的长��length ��23��
str2 = str1.slice(1, 8),
str3 = str1.slice(4, -2),
str4 = str1.slice(12),
......@@ -245,8 +250,8 @@ export function testString(): Result {
expect(str4.split(re4)).toEqual(["a", " b", " {c, d, e}", " f", " g", " h"]);
})
test('toLowerCase', () => {
const str1 = '中文简体 zh-CN || zh-Hans';
expect(str1.toLowerCase()).toEqual("中文简体 zh-cn || zh-hans");
const str1 = '中文����zh-CN || zh-Hans';
expect(str1.toLowerCase()).toEqual("中文����zh-cn || zh-hans");
const str2 = 'ALPHABET';
expect(str2.toLowerCase()).toEqual("alphabet");
})
......
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
......@@ -24,7 +24,7 @@ export function test(name: string, fn: () => void) {
result.passed.push(name)
// console.log('push....',result.passed.length)
} catch (e) {
result.failed.push(`${name}:\n${e.message}`)
result.failed.push(`${name}:\n${(e as Error).message}`)
}
result.total++
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册