Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
def25552
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1625
Star
27
Fork
9
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
Hello UTS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
def25552
编写于
11月 27, 2024
作者:
dcloud_wdl
浏览文件
操作
浏览文件
下载
差异文件
[转正] git merge origin/alpha
上级
57c2f2ad
3cec87c7
变更
49
隐藏空白更改
内联
并排
Showing
49 changed file
with
1477 addition
and
681 deletion
+1477
-681
changelog.md
changelog.md
+12
-15
index.html
index.html
+1
-1
nativeResources/android/google-services.json
nativeResources/android/google-services.json
+1
-0
package.json
package.json
+4
-4
pages.json
pages.json
+9
-2
pages/SyntaxCase/MixNativeCode.uvue
pages/SyntaxCase/MixNativeCode.uvue
+16
-1
pages/SyntaxCase/MixNativeCode.vue
pages/SyntaxCase/MixNativeCode.vue
+15
-1
pages/SyntaxCase/defaultValueTest.vue
pages/SyntaxCase/defaultValueTest.vue
+65
-0
pages/SyntaxCase/index.uvue
pages/SyntaxCase/index.uvue
+37
-6
pages/SyntaxCase/index.vue
pages/SyntaxCase/index.vue
+22
-4
pages/SyntaxCase/instanceTest.vue
pages/SyntaxCase/instanceTest.vue
+35
-1
pages/SystemAPI/SystemAPI.uvue
pages/SystemAPI/SystemAPI.uvue
+18
-2
pages/advance/advance.vue
pages/advance/advance.vue
+12
-1
pages/component/helloView.nvue
pages/component/helloView.nvue
+2
-2
pages/component/helloView.uvue
pages/component/helloView.uvue
+2
-3
pages/index/basicTest.test.js
pages/index/basicTest.test.js
+8
-29
pages/index/basicTest.uvue
pages/index/basicTest.uvue
+4
-155
pages/index/basicTest.vue
pages/index/basicTest.vue
+3
-160
pages/index/index.uvue
pages/index/index.uvue
+23
-11
pages/index/index.vue
pages/index/index.vue
+15
-2
uni_modules/uts-advance/utssdk/app-android/index.uts
uni_modules/uts-advance/utssdk/app-android/index.uts
+2
-3
uni_modules/uts-helloworld/utssdk/index.uts
uni_modules/uts-helloworld/utssdk/index.uts
+20
-1
uni_modules/uts-nativepage/utssdk/app-android/NativeLib.kt
uni_modules/uts-nativepage/utssdk/app-android/NativeLib.kt
+18
-0
uni_modules/uts-nativepage/utssdk/app-android/index.uts
uni_modules/uts-nativepage/utssdk/app-android/index.uts
+62
-2
uni_modules/uts-nativepage/utssdk/app-android/libs/arm64-v8a/libnativelib.so
...ivepage/utssdk/app-android/libs/arm64-v8a/libnativelib.so
+0
-0
uni_modules/uts-nativepage/utssdk/app-android/libs/armeabi-v7a/libnativelib.so
...epage/utssdk/app-android/libs/armeabi-v7a/libnativelib.so
+0
-0
uni_modules/uts-nativepage/utssdk/app-android/libs/x86/libnativelib.so
...ts-nativepage/utssdk/app-android/libs/x86/libnativelib.so
+0
-0
uni_modules/uts-nativepage/utssdk/app-android/libs/x86_64/libnativelib.so
...nativepage/utssdk/app-android/libs/x86_64/libnativelib.so
+0
-0
uni_modules/uts-syntaxcase/utssdk/app-android/kotlinCode.kt
uni_modules/uts-syntaxcase/utssdk/app-android/kotlinCode.kt
+41
-2
uni_modules/uts-syntaxcase/utssdk/app-ios/config.json
uni_modules/uts-syntaxcase/utssdk/app-ios/config.json
+1
-1
uni_modules/uts-syntaxcase/utssdk/index.uts
uni_modules/uts-syntaxcase/utssdk/index.uts
+204
-36
uni_modules/uts-tests/utssdk/Array.uts
uni_modules/uts-tests/utssdk/Array.uts
+0
-3
uni_modules/uts-tests/utssdk/ArrayBuffer.uts
uni_modules/uts-tests/utssdk/ArrayBuffer.uts
+2
-2
uni_modules/uts-tests/utssdk/Date.uts
uni_modules/uts-tests/utssdk/Date.uts
+2
-2
uni_modules/uts-tests/utssdk/Global.uts
uni_modules/uts-tests/utssdk/Global.uts
+5
-1
uni_modules/uts-tests/utssdk/JSON.uts
uni_modules/uts-tests/utssdk/JSON.uts
+62
-5
uni_modules/uts-tests/utssdk/JSON_large.uts
uni_modules/uts-tests/utssdk/JSON_large.uts
+17
-16
uni_modules/uts-tests/utssdk/KeyWord.uts
uni_modules/uts-tests/utssdk/KeyWord.uts
+3
-1
uni_modules/uts-tests/utssdk/Math.uts
uni_modules/uts-tests/utssdk/Math.uts
+14
-6
uni_modules/uts-tests/utssdk/Number.uts
uni_modules/uts-tests/utssdk/Number.uts
+73
-22
uni_modules/uts-tests/utssdk/Operators.uts
uni_modules/uts-tests/utssdk/Operators.uts
+13
-4
uni_modules/uts-tests/utssdk/Promise.uts
uni_modules/uts-tests/utssdk/Promise.uts
+422
-0
uni_modules/uts-tests/utssdk/TextDecoder.uts
uni_modules/uts-tests/utssdk/TextDecoder.uts
+31
-0
uni_modules/uts-tests/utssdk/TextEncoder.uts
uni_modules/uts-tests/utssdk/TextEncoder.uts
+14
-0
uni_modules/uts-tests/utssdk/UTSJSONObject.uts
uni_modules/uts-tests/utssdk/UTSJSONObject.uts
+121
-62
uni_modules/uts-tests/utssdk/console.uts
uni_modules/uts-tests/utssdk/console.uts
+3
-1
uni_modules/uts-tests/utssdk/data.uts
uni_modules/uts-tests/utssdk/data.uts
+6
-0
uni_modules/uts-tests/utssdk/index.uts
uni_modules/uts-tests/utssdk/index.uts
+17
-110
uni_modules/uts-tests/utssdk/tests.uts
uni_modules/uts-tests/utssdk/tests.uts
+20
-1
未找到文件。
changelog.md
浏览文件 @
def25552
## 1.
1.10
## 1.
0.29
*
update 4.
29.2024093009
*
update 4.
36.2024112612-alpha
## 1.
1.9
## 1.
0.28
*
update 4.
28.2024092502
*
update 4.
35.2024112402-alpha
## 1.0.2
3
## 1.0.2
7
*
update 4.
28.2024092105
-alpha
*
update 4.
34.2024112020
-alpha
## 1.0.2
2
## 1.0.2
6
*
update 4.
27.2024091308
-alpha
*
update 4.
33.2024111702
-alpha
## 1.0.2
1
## 1.0.2
5
*
update 4.
26.202408221
3-alpha
*
update 4.
32.202411010
3-alpha
## 1.0.20
## 1.0.24
*
update 4.25.2024081703-alpha
*
update 4.31.2024102414-alpha
## 1.0.19
*
update 4.23.2024070309-alpha
## 1.0.17
## 1.0.17
*
update 4.22.2024062415-alpha
*
update 4.22.2024062415-alpha
...
...
index.html
浏览文件 @
def25552
...
@@ -15,6 +15,6 @@
...
@@ -15,6 +15,6 @@
</head>
</head>
<body>
<body>
<div
id=
"app"
>
<!--app-html-->
</div>
<div
id=
"app"
>
<!--app-html-->
</div>
<script
type=
"module"
src=
"/main
.js
"
></script>
<script
type=
"module"
src=
"/main"
></script>
</body>
</body>
</html>
</html>
nativeResources/android/google-services.json
0 → 100644
浏览文件 @
def25552
demo
\ No newline at end of file
package.json
浏览文件 @
def25552
{
{
"id"
:
"hello-uts"
,
"id"
:
"hello-uts
-alpha
"
,
"name"
:
"hello-uts"
,
"name"
:
"hello-uts
-alpha
"
,
"displayName"
:
"hello-uts"
,
"displayName"
:
"hello-uts
-alpha
"
,
"version"
:
"1.
1.10
"
,
"version"
:
"1.
0.29
"
,
"description"
:
"UTS插件示例项目"
,
"description"
:
"UTS插件示例项目"
,
"repository"
:
"https://gitcode.net/dcloud/hello-uts"
,
"repository"
:
"https://gitcode.net/dcloud/hello-uts"
,
"keywords"
:
[
"keywords"
:
[
...
...
pages.json
浏览文件 @
def25552
...
@@ -164,10 +164,17 @@
...
@@ -164,10 +164,17 @@
"enablePullDownRefresh"
:
false
"enablePullDownRefresh"
:
false
}
}
}
},
//
{
//
"path"
:
"pages/SyntaxCase/defaultValueTest"
,
//
"style"
:
{
//
"navigationBarTitleText"
:
""
,
//
"enablePullDownRefresh"
:
false
//
}
//
},
//
#endif
//
#endif
//
#ifdef
APP
//
#ifdef
APP
,
{
{
"path"
:
"pages/SyntaxCase/utsAndroid"
,
"path"
:
"pages/SyntaxCase/utsAndroid"
,
"style"
:
{
"style"
:
{
...
...
pages/SyntaxCase/MixNativeCode.uvue
浏览文件 @
def25552
...
@@ -5,19 +5,24 @@
...
@@ -5,19 +5,24 @@
// #ifdef APP-ANDROID && UNI-APP-X
// #ifdef APP-ANDROID && UNI-APP-X
<button @tap="callKotlinMethodGetInfoTest">调用kotlin方法</button>
<button @tap="callKotlinMethodGetInfoTest">调用kotlin方法</button>
<button @tap="callJavaMethodGetInfoTest">调用java方法(需自定义基座)</button>
<button @tap="callJavaMethodGetInfoTest">调用java方法(需自定义基座)</button>
<view style="height: 10px;width: 100%;"></view>
<button @tap="kotlinMemListenTest">kotlin监听内存并持续回调UTS</button>
<button @tap="kotlinStopMemListenTest">停止监听</button>
<text>{{memInfo}}</text>
// #endif
// #endif
</view>
</view>
</view>
</view>
</template>
</template>
<script>
<script>
// #ifdef APP-ANDROID && UNI-APP-X
// #ifdef APP-ANDROID && UNI-APP-X
import { callKotlinMethodGetInfo, callJavaMethodGetInfo} from "../../uni_modules/uts-syntaxcase";
import { callKotlinMethodGetInfo, callJavaMethodGetInfo
,callKotlinCallbackUTS,callKotlinStopCallbackUTS
} from "../../uni_modules/uts-syntaxcase";
// #endif
// #endif
export default {
export default {
data() {
data() {
return {
return {
title: 'UTS混编示例',
title: 'UTS混编示例',
memInfo:''
}
}
},
},
...
@@ -36,6 +41,16 @@
...
@@ -36,6 +41,16 @@
title:javaInfo
title:javaInfo
})
})
},
},
kotlinMemListenTest: function () {
callKotlinCallbackUTS(function(ret:string){
this.memInfo = ret
})
},
kotlinStopMemListenTest:function () {
callKotlinStopCallbackUTS()
},
// #endif
// #endif
}
}
...
...
pages/SyntaxCase/MixNativeCode.vue
浏览文件 @
def25552
...
@@ -4,16 +4,21 @@
...
@@ -4,16 +4,21 @@
<view
class=
"uni-btn-v uni-common-mt"
>
<view
class=
"uni-btn-v uni-common-mt"
>
<button
@
tap=
"callKotlinMethodGetInfoTest"
>
调用kotlin方法
</button>
<button
@
tap=
"callKotlinMethodGetInfoTest"
>
调用kotlin方法
</button>
<button
@
tap=
"callJavaMethodGetInfoTest"
>
调用java方法(需自定义基座)
</button>
<button
@
tap=
"callJavaMethodGetInfoTest"
>
调用java方法(需自定义基座)
</button>
<view
style=
"height: 10px;width: 100%;"
></view>
<button
@
tap=
"kotlinMemListenTest"
>
kotlin监听内存并持续回调
</button>
<button
@
tap=
"kotlinStopMemListenTest"
>
停止监听
</button>
<text>
{{
memInfo
}}
</text>
</view>
</view>
</view>
</view>
</
template
>
</
template
>
<
script
>
<
script
>
import
{
callKotlinMethodGetInfo
,
callJavaMethodGetInfo
}
from
"
../../uni_modules/uts-syntaxcase
"
;
import
{
callKotlinMethodGetInfo
,
callJavaMethodGetInfo
,
callKotlinCallbackUTS
,
callKotlinStopCallbackUTS
}
from
"
../../uni_modules/uts-syntaxcase
"
;
export
default
{
export
default
{
data
()
{
data
()
{
return
{
return
{
title
:
'
UTS混编示例
'
,
title
:
'
UTS混编示例
'
,
memInfo
:
''
}
}
},
},
...
@@ -31,6 +36,15 @@
...
@@ -31,6 +36,15 @@
title
:
javaInfo
title
:
javaInfo
})
})
},
},
kotlinMemListenTest
:
function
()
{
callKotlinCallbackUTS
((
ret
)
=>
{
this
.
memInfo
=
ret
})
},
kotlinStopMemListenTest
:
function
()
{
callKotlinStopCallbackUTS
()
},
}
}
}
}
...
...
pages/SyntaxCase/defaultValueTest.vue
0 → 100644
浏览文件 @
def25552
<
template
>
<view
class=
"buttons"
>
<button
@
click=
"testClick"
>
测试全部
</button>
<text>
{{
testRet
}}
</text>
</view>
</
template
>
<
script
setup
>
import
{
Scan
,
Scan1
,
Scan2
,
myClass
}
from
"
@/uni_modules/uts-syntaxcase
"
;
import
{
ref
}
from
'
vue
'
const
myClassInit
=
new
myClass
();
let
testRet
=
ref
(
"
1
"
);
const
testClick
=
function
(){
testRet
.
value
=
"
success
"
// #ifdef APP-ANDROID
if
(
Scan
()
!=
60000
){
testRet
=
"
error1
"
console
.
log
(
"
error1
"
)
}
if
(
Scan
(
100
)
!=
100
){
testRet
=
"
error2
"
console
.
log
(
"
error2
"
)
}
// #endif
if
(
Scan1
()
!=
"
null
"
){
testRet
=
"
error3
"
console
.
log
(
"
error3
"
)
}
if
(
Scan1
(
100
)
!=
100
){
testRet
=
"
error4
"
console
.
log
(
"
error4
"
)
}
if
(
Scan2
()
!=
"
null
"
){
testRet
=
"
error5
"
console
.
log
(
"
error5
"
)
}
if
(
Scan2
(
100
)
!=
100
){
testRet
=
"
error6
"
console
.
log
(
"
error6
"
)
}
if
(
myClassInit
.
to
(
'
123
'
)
!=
"
123
"
){
testRet
=
"
error7
"
console
.
log
(
"
error7
"
)
}
}
</
script
>
<
style
lang=
"scss"
>
.buttons
{
padding
:
20rpx
20rpx
460rpx
;
button
{
margin-bottom
:
20rpx
;
font-size
:
28rpx
;
padding
:
3px
;
}
}
</
style
>
pages/SyntaxCase/index.uvue
浏览文件 @
def25552
...
@@ -52,8 +52,12 @@
...
@@ -52,8 +52,12 @@
<view>测试complete:{{ format(testUtsClassInstanceResult['complete']) }}</view>
<view>测试complete:{{ format(testUtsClassInstanceResult['complete']) }}</view>
<view>测试callback:{{ format(testUtsClassInstanceResult['callback']) }}</view>
<view>测试callback:{{ format(testUtsClassInstanceResult['callback']) }}</view>
<button @click="testUtsClassSetter">点击测试class 示例setter方法</button>
<button @click="testUtsClassSetter">点击测试class 示例setter方法</button>
<view>测试setter:{{ format(testUtsClassSetterResult) }}</view>
<view>测试setter:{{ format(testUtsClassSetterResult) }}</view>
<button @click="testAll">点击测试所有</button>
<view>测试promise返回值:{{ format(testUtsReturnPromiseResult) }}</view>
<button @click="testAll">点击测试所有</button>
<!-- #ifdef APP-IOS -->
<button @click="testPromiseStaticMethod">点击测试promise静态方法</button>
<!-- #endif -->
</view>
</view>
<view style="height: 20px;"></view>
<view style="height: 20px;"></view>
</scroll-view>
</scroll-view>
...
@@ -71,8 +75,14 @@
...
@@ -71,8 +75,14 @@
testAsyncParam3,
testAsyncParam3,
Test,
Test,
request,
request,
SetterTest,
SetterTest,
PromiseReturnDemo,
} from "../../uni_modules/uts-syntaxcase";
} from "../../uni_modules/uts-syntaxcase";
// #endif
// #ifdef APP-IOS
import {
testPromiseStaticMethod
} from "@/uni_modules/uts-syntaxcase"
// #endif
// #endif
let test:Test|null = null
let test:Test|null = null
let id = 0
let id = 0
...
@@ -135,7 +145,8 @@
...
@@ -135,7 +145,8 @@
complete: null,
complete: null,
callback: null
callback: null
},
},
testUtsClassSetterResult: null,
testUtsClassSetterResult: null,
testUtsReturnPromiseResult: null,
}
}
},
},
methods: {
methods: {
...
@@ -161,7 +172,8 @@
...
@@ -161,7 +172,8 @@
this.testUtsClassSyncWithCallback();
this.testUtsClassSyncWithCallback();
this.testUtsClassAsync();
this.testUtsClassAsync();
this.testUtsClassInstance();
this.testUtsClassInstance();
this.testUtsClassSetter();
this.testUtsClassSetter();
this.testUtsReturnPromise();
},
},
testUtsSync() {
testUtsSync() {
this.testUtsSyncResult = false;
this.testUtsSyncResult = false;
...
@@ -441,7 +453,26 @@
...
@@ -441,7 +453,26 @@
} catch (e) {
} catch (e) {
console.error("testUtsClassSetter", e);
console.error("testUtsClassSetter", e);
}
}
},
},
testUtsReturnPromise() {
this.testUtsReturnPromiseResult = false;
try {
let demo = new PromiseReturnDemo();
demo.test1();
demo.test2();
if (demo.recordRet == 2) {
this.testUtsReturnPromiseResult = true;
}
} catch (e) {
console.error("testUtsClassSetter", e);
}
},
// #ifdef APP-IOS
testPromiseStaticMethod() {
testPromiseStaticMethod()
}
// #endif
}
}
}
}
</script>
</script>
\ No newline at end of file
pages/SyntaxCase/index.vue
浏览文件 @
def25552
...
@@ -51,7 +51,8 @@
...
@@ -51,7 +51,8 @@
<view>
测试complete:
{{
format
(
testUtsClassInstanceResult
.
complete
)
}}
</view>
<view>
测试complete:
{{
format
(
testUtsClassInstanceResult
.
complete
)
}}
</view>
<view>
测试callback:
{{
format
(
testUtsClassInstanceResult
.
callback
)
}}
</view>
<view>
测试callback:
{{
format
(
testUtsClassInstanceResult
.
callback
)
}}
</view>
<button
@
click=
"testUtsClassSetter"
>
点击测试class 示例setter方法
</button>
<button
@
click=
"testUtsClassSetter"
>
点击测试class 示例setter方法
</button>
<view>
测试setter:
{{
format
(
testUtsClassSetterResult
)
}}
</view>
<view>
测试setter:
{{
format
(
testUtsClassSetterResult
)
}}
</view>
<view>
测试promise返回值:
{{
format
(
testUtsReturnPromiseResult
)
}}
</view>
<button
@
click=
"testAll"
>
点击测试所有
</button>
<button
@
click=
"testAll"
>
点击测试所有
</button>
</view>
</view>
</
template
>
</
template
>
...
@@ -65,7 +66,8 @@
...
@@ -65,7 +66,8 @@
testAsyncParam3
,
testAsyncParam3
,
Test
,
Test
,
request
,
request
,
SetterTest
,
SetterTest
,
PromiseReturnDemo
,
}
from
"
../../uni_modules/uts-syntaxcase
"
;
}
from
"
../../uni_modules/uts-syntaxcase
"
;
// #endif
// #endif
let
test
let
test
...
@@ -129,7 +131,8 @@
...
@@ -129,7 +131,8 @@
complete
:
null
,
complete
:
null
,
callback
:
null
callback
:
null
},
},
testUtsClassSetterResult
:
null
,
testUtsClassSetterResult
:
null
,
testUtsReturnPromiseResult
:
null
,
}
}
},
},
methods
:
{
methods
:
{
...
@@ -149,7 +152,8 @@
...
@@ -149,7 +152,8 @@
this
.
testUtsClassSyncWithCallback
();
this
.
testUtsClassSyncWithCallback
();
this
.
testUtsClassAsync
();
this
.
testUtsClassAsync
();
this
.
testUtsClassInstance
();
this
.
testUtsClassInstance
();
this
.
testUtsClassSetter
();
this
.
testUtsClassSetter
();
this
.
testUtsReturnPromise
();
},
},
testUtsSync
()
{
testUtsSync
()
{
this
.
testUtsSyncResult
=
false
;
this
.
testUtsSyncResult
=
false
;
...
@@ -422,6 +426,20 @@
...
@@ -422,6 +426,20 @@
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
error
(
"
testUtsClassSetter
"
,
e
);
console
.
error
(
"
testUtsClassSetter
"
,
e
);
}
}
},
testUtsReturnPromise
()
{
this
.
testUtsReturnPromiseResult
=
false
;
try
{
let
demo
=
new
PromiseReturnDemo
();
demo
.
test1
();
demo
.
test2
();
if
(
demo
.
recordRet
==
2
)
{
this
.
testUtsReturnPromiseResult
=
true
;
}
}
catch
(
e
)
{
console
.
error
(
"
testUtsClassSetter
"
,
e
);
}
},
},
}
}
}
}
...
...
pages/SyntaxCase/instanceTest.vue
浏览文件 @
def25552
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
<div>
<div>
{{
ret
}}
{{
ret
}}
<button
@
click=
"instanceCreate"
>
多实例创建测试
</button>
<button
@
click=
"instanceCreate"
>
多实例创建测试
</button>
<button
@
click=
"defaultValueTest"
>
默认值测试
</button>
</div>
</div>
</
template
>
</
template
>
...
@@ -11,7 +12,12 @@
...
@@ -11,7 +12,12 @@
User
User
}
from
'
@/uni_modules/uts-advance
'
}
from
'
@/uni_modules/uts-advance
'
import
{
Scan
,
Scan1
,
Scan2
,
myClass
}
from
"
@/uni_modules/uts-syntaxcase
"
;
export
default
{
export
default
{
data
()
{
data
()
{
...
@@ -21,6 +27,34 @@
...
@@ -21,6 +27,34 @@
},
},
methods
:
{
methods
:
{
defaultValueTest
()
{
const
myClassInit
=
new
myClass
();
// 默认值测试
if
(
Scan
()
!=
60000
){
this
.
ret
=
"
测试失败1
"
}
if
(
Scan
(
100
)
!=
100
){
this
.
ret
=
"
测试失败2
"
}
if
(
Scan1
()
!=
null
){
this
.
ret
=
"
测试失败3
"
}
if
(
Scan1
(
100
)
!=
100
){
this
.
ret
=
"
测试失败4
"
}
let
ret5
=
Scan2
()
if
(
ret5
!=
"
null
"
){
console
.
log
(
ret5
)
this
.
ret
=
"
测试失败5
"
}
if
(
Scan2
(
100
)
!=
100
){
this
.
ret
=
"
测试失败6
"
}
if
(
myClassInit
.
to
(
'
123
'
)
!=
123
){
this
.
ret
=
"
测试失败7
"
}
},
instanceCreate
()
{
instanceCreate
()
{
const
user1
=
new
User
(
"
张三
"
,
20
);
const
user1
=
new
User
(
"
张三
"
,
20
);
...
...
pages/SystemAPI/SystemAPI.uvue
浏览文件 @
def25552
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
</view>
</view>
</template>
</template>
<script lang="ts">
<script lang="ts">
import { gotoDemoActivity,sayHelloFromJar } from "@/uni_modules/uts-nativepage";
import { gotoDemoActivity,sayHelloFromJar
,sayHelloFromSO
} from "@/uni_modules/uts-nativepage";
import { getBatteryInfo, GetBatteryInfoOptions } from "@/uni_modules/uts-getbatteryinfo";
import { getBatteryInfo, GetBatteryInfoOptions } from "@/uni_modules/uts-getbatteryinfo";
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
import {
import {
...
@@ -95,6 +95,9 @@
...
@@ -95,6 +95,9 @@
},{
},{
name: "调用jar中的方法",
name: "调用jar中的方法",
function: "testNativeJar"
function: "testNativeJar"
},{
name: "调用so中的方法",
function: "testNativeSO"
}] as Page[]
}] as Page[]
}
}
] as ListItem[],
] as ListItem[],
...
@@ -127,9 +130,13 @@
...
@@ -127,9 +130,13 @@
break
break
case 'testGotoDemoActivity':
case 'testGotoDemoActivity':
this.testGotoDemoActivity()
this.testGotoDemoActivity()
break
case 'testNativeJar':
case 'testNativeJar':
this.testNativeJar()
this.testNativeJar()
break
break
case 'testNativeSO':
this.testNativeSO()
break
}
}
return
return
}
}
...
@@ -226,7 +233,16 @@
...
@@ -226,7 +233,16 @@
icon: 'none',
icon: 'none',
title: '来自jar中的返回值:' + ret
title: '来自jar中的返回值:' + ret
})
})
},
},
testNativeSO() {
let ret = sayHelloFromSO();
uni.showToast({
icon: 'none',
title: '来自so中的返回值:' + ret
})
},
testGotoDemoActivity() {
testGotoDemoActivity() {
let ret = gotoDemoActivity();
let ret = gotoDemoActivity();
if (!ret) {
if (!ret) {
...
...
pages/advance/advance.vue
浏览文件 @
def25552
...
@@ -116,9 +116,20 @@
...
@@ -116,9 +116,20 @@
},
{
},
{
name
:
"
参数传递示例
"
,
name
:
"
参数传递示例
"
,
url
:
"
SyntaxCase/paramTest
"
url
:
"
SyntaxCase/paramTest
"
},{
},
{
name
:
"
实例测试示例
"
,
name
:
"
实例测试示例
"
,
url
:
"
SyntaxCase/instanceTest
"
url
:
"
SyntaxCase/instanceTest
"
},
// #ifdef UNI-APP-X
{
name
:
"
默认值测试示例
"
,
url
:
"
SyntaxCase/defaultValueTest
"
},
// #endif
{
name
:
"
混编测试示例
"
,
url
:
"
SyntaxCase/MixNativeCode
"
}
}
]
]
},
},
...
...
pages/component/helloView.nvue
浏览文件 @
def25552
<template>
<template>
<div>
<div>
<uts-hello-view buttonText="点击按钮内容" style="width:375px;height: 375px;background-color: aqua;"></uts-hello-view>
<uts-hello-view buttonText="点击按钮内容" style="width:375px;height: 375px;background-color: aqua;"></uts-hello-view>
<uts-hello-container>
<uts-hello-container
style="flex: 1;background-color: red;"
>
<text>文本组件</text>
<text
style="left: 100px;top: 100px;background-color: green;"
>文本组件</text>
<image src="../../static/logo.png" mode="aspectFit"></image>
<image src="../../static/logo.png" mode="aspectFit"></image>
</uts-hello-container>
</uts-hello-container>
</div>
</div>
...
...
pages/component/helloView.uvue
浏览文件 @
def25552
...
@@ -2,8 +2,8 @@
...
@@ -2,8 +2,8 @@
<div>
<div>
<button @tap="doSth">调用组件的方法</button>
<button @tap="doSth">调用组件的方法</button>
<uts-hello-view ref="helloView" buttonText="点击按钮内容" style="width:375px;height: 375px;background-color: aqua;"></uts-hello-view>
<uts-hello-view ref="helloView" buttonText="点击按钮内容" style="width:375px;height: 375px;background-color: aqua;"></uts-hello-view>
<uts-hello-container>
<uts-hello-container
style="flex: 1;background-color: red;"
>
<text>文本组件</text>
<text
style="left: 100px;top: 100px;background-color: green;"
>文本组件</text>
<image src="../../static/logo.png" mode="aspectFit"></image>
<image src="../../static/logo.png" mode="aspectFit"></image>
</uts-hello-container>
</uts-hello-container>
</div>
</div>
...
@@ -14,7 +14,6 @@
...
@@ -14,7 +14,6 @@
export default {
export default {
data() {
data() {
return {
return {
}
}
},
},
methods: {
methods: {
...
...
pages/index/basicTest.test.js
浏览文件 @
def25552
const
ERR_RE
=
/expected:<
(
.*
)
> but was:<
(
.*
)
>/
const
ERR_RE
=
/expected:<
(
.*
)
> but was:<
(
.*
)
>/
let
result
;
let
result
;
const
resultEmptyError
=
'
获取到 result 是空的, 请运行项目进行排查
'
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
await
program
.
reLaunch
(
'
/pages/index/basicTest
'
)
await
program
.
reLaunch
(
'
/pages/index/basicTest
'
)
...
@@ -11,6 +11,9 @@ beforeAll(async () => {
...
@@ -11,6 +11,9 @@ beforeAll(async () => {
})
})
function
getApiFailed
(
describe
,
api
)
{
function
getApiFailed
(
describe
,
api
)
{
if
(
Object
.
keys
(
result
).
length
===
0
){
return
resultEmptyError
}
const
failed
=
result
[
describe
]?.
failed
?.
find
(
item
=>
{
const
failed
=
result
[
describe
]?.
failed
?.
find
(
item
=>
{
return
item
.
split
(
'
:
'
)[
0
]
===
api
return
item
.
split
(
'
:
'
)[
0
]
===
api
})
})
...
@@ -22,7 +25,9 @@ describes.forEach(d => {
...
@@ -22,7 +25,9 @@ describes.forEach(d => {
d
?.
tests
&&
d
.
tests
.
forEach
(
api
=>
{
d
?.
tests
&&
d
.
tests
.
forEach
(
api
=>
{
it
(
api
,
()
=>
{
it
(
api
,
()
=>
{
const
failed
=
getApiFailed
(
d
.
describe
,
api
)
const
failed
=
getApiFailed
(
d
.
describe
,
api
)
if
(
failed
)
{
if
(
failed
==
resultEmptyError
){
expect
(
''
).
toBe
(
resultEmptyError
)
}
else
if
(
failed
)
{
const
parts
=
failed
.
split
(
'
\n
'
)
const
parts
=
failed
.
split
(
'
\n
'
)
const
matches
=
parts
[
1
].
match
(
ERR_RE
)
const
matches
=
parts
[
1
].
match
(
ERR_RE
)
if
(
matches
?.
length
)
{
if
(
matches
?.
length
)
{
...
@@ -41,32 +46,6 @@ if (process.env.UNI_PROJECT_TYPE === '2.0' && process.env.uniTestPlatformInfo.to
...
@@ -41,32 +46,6 @@ if (process.env.UNI_PROJECT_TYPE === '2.0' && process.env.uniTestPlatformInfo.to
it
(
"
jest_testTypeFromAppJs
"
,
async
()
=>
{
it
(
"
jest_testTypeFromAppJs
"
,
async
()
=>
{
const
res
=
await
page
.
callMethod
(
'
jest_testTypeFromAppJs
'
)
const
res
=
await
page
.
callMethod
(
'
jest_testTypeFromAppJs
'
)
expect
(
res
).
toEqual
(
true
)
expect
(
res
).
toEqual
(
true
)
})
})
}
if
(
process
.
env
.
UNI_PROJECT_TYPE
===
'
2.0
'
&&
(
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
().
startsWith
(
'
ios
'
)
||
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
)))
{
describe
(
'
testCallbackKeepAlive
'
,
()
=>
{
it
(
"
jest_testCallbackKeepAlive
"
,
async
()
=>
{
const
res
=
await
page
.
callMethod
(
'
jest_testCallbackKeepAlive
'
)
expect
(
res
).
toEqual
(
true
)
})
it
(
"
jest_testCallbackNonKeepAlive
"
,
async
()
=>
{
const
res
=
await
page
.
callMethod
(
'
jest_testCallbackNonKeepAlive
'
)
expect
(
res
).
toEqual
(
4
)
})
})
})
})
}
}
\ No newline at end of file
if
(
process
.
env
.
UNI_PROJECT_TYPE
===
'
1.0
'
&&
(
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
().
startsWith
(
'
ios
'
)
||
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
)))
{
describe
(
'
testCallbackKeepAlive
'
,
()
=>
{
it
(
"
jest_testCallbackKeepAlive
"
,
async
()
=>
{
const
res
=
await
page
.
callMethod
(
'
jest_testCallbackKeepAlive
'
)
expect
(
res
).
toEqual
(
20
)
})
it
(
"
jest_testCallbackNonKeepAlive
"
,
async
()
=>
{
const
res
=
await
page
.
callMethod
(
'
jest_testCallbackNonKeepAlive
'
)
expect
(
res
).
toEqual
(
4
)
})
})
}
pages/index/basicTest.uvue
浏览文件 @
def25552
...
@@ -22,11 +22,7 @@
...
@@ -22,11 +22,7 @@
<script lang="ts">
<script lang="ts">
import { runTests, Result } from '../../uni_modules/uts-tests'
import { runTests, Result } from '../../uni_modules/uts-tests'
// #ifdef APP-IOS
// #ifdef APP-IOS
import { testTypeFromAppJs, Options } from '@/uni_modules/uts-ios-tests';
import { testTypeFromAppJs, Options } from '@/uni_modules/uts-ios-tests'
// #endif
// #ifdef APP
import { onTest1, testKeepAlive, testKeepAliveOption, createTest, TestKeepAliveClass, TestKeepAliveOption, } from '@/uni_modules/uts-tests'
import { testNonKeepAlive, testNonKeepAliveOption } from '@/uni_modules/uts-tests'
// #endif
// #endif
export default {
export default {
data() {
data() {
...
@@ -34,9 +30,7 @@ export default {
...
@@ -34,9 +30,7 @@ export default {
title: 'UTS基础语法',
title: 'UTS基础语法',
resultArray: [] as Result[],
resultArray: [] as Result[],
result: {} as UTSJSONObject,
result: {} as UTSJSONObject,
names: [] as string[],
names: [] as string[],
keepAliveCount: 0,
nonKeepAliveCount: 0
}
}
},
},
onReady() {
onReady() {
...
@@ -54,158 +48,13 @@ export default {
...
@@ -54,158 +48,13 @@ export default {
for (const key in resultMap) {
for (const key in resultMap) {
this.names.push(key)
this.names.push(key)
this.resultArray.push(resultMap[key] as Result)
this.resultArray.push(resultMap[key] as Result)
}
}
console.log('jest_testCallbackKeepAlive:' + this.jest_testCallbackKeepAlive())
this.jest_testCallbackNonKeepAlive().then(res=>{
console.log('jest_testCallbackNonKeepAlive:' + res)
})
},
},
// #ifdef APP-IOS
// #ifdef APP-IOS
jest_testTypeFromAppJs() {
jest_testTypeFromAppJs() {
return testTypeFromAppJs({
return testTypeFromAppJs({
num: 1
num: 1
} as Options)
} as Options)
},
// #endif
// #ifdef APP
jest_testCallbackKeepAlive(): boolean {
let ret: boolean = true
let count = 0;
onTest1((res) => {
count++;
console.log("onTest1 callback =====> ", res)
})
if (count < 2) {
ret = false
}
count = 0;
testKeepAlive((res) => {
count++;
console.log(res)
})
if (count < 2) {
ret = false
}
count = 0;
testKeepAliveOption({
a: "testKeepAliveOption",
success: (res) => {
count++;
console.log("testKeepAliveOption callback =====> ", res)
}
} as TestKeepAliveOption)
if (count < 2) {
ret = false
}
count = 0;
TestKeepAliveClass.onTestStatic((res) => {
count++;
console.log("onTestStatic callback =====> ", res)
})
if (count < 2) {
ret = false
}
count = 0;
TestKeepAliveClass.testKeepAliveStatic((res) => {
count++;
console.log("testKeepAliveStatic callback =====> ", res)
})
if (count < 2) {
ret = false
}
count = 0;
TestKeepAliveClass.testKeepAliveOptionStatic({
a: "testKeepAliveOption",
success: (res) => {
count++;
console.log("testKeepAliveOptionStatic callback =====> ", res)
}
} as TestKeepAliveOption)
if (count < 2) {
ret = false
}
count = 0;
const obj = new TestKeepAliveClass()
obj.onTest((res) => {
count++;
console.log("TestKeepAliveClass.onTest callback =====> ", res)
})
if (count < 2) {
ret = false
}
count = 0;
obj.testKeepAlive((res) => {
count++;
console.log("TestKeepAliveClass.testKeepAlive callback =====> ", res)
})
if (count < 2) {
ret = false
}
count = 0;
obj.testKeepAliveOption({
a: "testKeepAliveOption",
success: (res) => {
count++;
console.log("TestKeepAliveClass.testKeepAliveOption callback =====> ", res)
}
} as TestKeepAliveOption)
if (count < 2) {
ret = false
}
count = 0;
const testImpl = createTest()
testImpl.test((res) => {
count++;
console.log("TestImpl.test callback =====> ", res)
})
if (count < 2) {
ret = false
}
this.keepAliveCount = count
return ret
},
jest_testCallbackNonKeepAlive(): Promise<number> {
let count = 0
const fn = (res:string) => {
count++;
console.log("testCallbackNonKeepAlive callback =====> ", res)
}
testNonKeepAlive(fn)
testNonKeepAlive(fn)
const options: TestKeepAliveOption = {
a:'a',
success(res:string){
count++;
console.log("testCallbackNonKeepAliveOption callback =====> ", res)
}
}
testNonKeepAliveOption(options)
testNonKeepAliveOption(options)
return new Promise((resolve)=>{
setTimeout(()=>{
this.nonKeepAliveCount = count
resolve(count)
},50)
})
}
}
// #endif
// #endif
},
},
...
...
pages/index/basicTest.vue
浏览文件 @
def25552
...
@@ -20,177 +20,20 @@
...
@@ -20,177 +20,20 @@
import
{
import
{
runTests
runTests
}
from
'
../../uni_modules/uts-tests
'
}
from
'
../../uni_modules/uts-tests
'
import
{
onTest1
,
testKeepAlive
,
testKeepAliveOption
,
createTest
,
TestKeepAliveClass
}
from
'
@/uni_modules/uts-tests
'
import
{
testNonKeepAlive
,
testNonKeepAliveOption
}
from
'
@/uni_modules/uts-tests
'
export
default
{
export
default
{
data
()
{
data
()
{
return
{
return
{
title
:
'
UTS基础语法
'
,
title
:
'
UTS基础语法
'
,
result
:
{},
result
:
{}
keepAliveCount
:
0
,
nonKeepAliveCount
:
0
}
}
},
},
onReady
()
{
onReady
()
{
this
.
test
()
this
.
test
()
},
},
methods
:
{
methods
:
{
async
test
()
{
test
()
{
this
.
result
=
runTests
()
this
.
result
=
runTests
()
console
.
log
(
this
.
result
)
console
.
log
(
this
.
result
)
console
.
log
(
'
jest_testCallbackKeepAlive:
'
+
await
this
.
jest_testCallbackKeepAlive
())
console
.
log
(
'
jest_testCallbackNonKeepAlive:
'
+
await
this
.
jest_testCallbackNonKeepAlive
())
},
jest_testCallbackKeepAlive
()
{
let
ret
=
true
let
count
=
0
;
onTest1
((
res
)
=>
{
count
++
;
console
.
log
(
"
onTest1 callback =====>
"
,
res
)
})
if
(
count
<
2
)
{
ret
=
false
}
// count = 0;
testKeepAlive
((
res
)
=>
{
count
++
;
console
.
log
(
res
)
})
if
(
count
<
2
)
{
ret
=
false
}
// count = 0;
testKeepAliveOption
({
a
:
"
testKeepAliveOption
"
,
success
:
(
res
)
=>
{
count
++
;
console
.
log
(
"
testKeepAliveOption callback =====>
"
,
res
)
}
})
if
(
count
<
2
)
{
ret
=
false
}
// count = 0;
TestKeepAliveClass
.
onTestStatic
((
res
)
=>
{
count
++
;
console
.
log
(
"
onTestStatic callback =====>
"
,
res
)
})
if
(
count
<
2
)
{
ret
=
false
}
// count = 0;
TestKeepAliveClass
.
testKeepAliveStatic
((
res
)
=>
{
count
++
;
console
.
log
(
"
testKeepAliveStatic callback =====>
"
,
res
)
})
if
(
count
<
2
)
{
ret
=
false
}
// count = 0;
TestKeepAliveClass
.
testKeepAliveOptionStatic
({
a
:
"
testKeepAliveOption
"
,
success
:
(
res
)
=>
{
count
++
;
console
.
log
(
"
testKeepAliveOptionStatic callback =====>
"
,
res
)
}
})
if
(
count
<
2
)
{
ret
=
false
}
// count = 0;
const
obj
=
new
TestKeepAliveClass
()
obj
.
onTest
((
res
)
=>
{
count
++
;
console
.
log
(
"
TestKeepAliveClass.onTest callback =====>
"
,
res
)
})
if
(
count
<
2
)
{
ret
=
false
}
// count = 0;
obj
.
testKeepAlive
((
res
)
=>
{
count
++
;
console
.
log
(
"
TestKeepAliveClass.testKeepAlive callback =====>
"
,
res
)
})
if
(
count
<
2
)
{
ret
=
false
}
// count = 0;
obj
.
testKeepAliveOption
({
a
:
"
testKeepAliveOption
"
,
success
:
(
res
)
=>
{
count
++
;
console
.
log
(
"
TestKeepAliveClass.testKeepAliveOption callback =====>
"
,
res
)
}
})
if
(
count
<
2
)
{
ret
=
false
}
// count = 0;
const
testImpl
=
createTest
()
testImpl
.
test
((
res
)
=>
{
count
++
;
console
.
log
(
"
TestImpl.test callback =====>
"
,
res
)
})
if
(
count
<
2
)
{
ret
=
false
}
return
new
Promise
((
resolve
)
=>
{
setTimeout
(()
=>
{
this
.
keepAliveCount
=
count
resolve
(
count
)
},
30
)
})
},
jest_testCallbackNonKeepAlive
()
{
let
ret
=
true
let
count
=
0
// 使用相同的回调函数多次传递调用,确保每次都正常
const
fn
=
(
res
)
=>
{
count
++
;
console
.
log
(
"
testCallbackNonKeepAlive callback =====>
"
,
res
)
}
testNonKeepAlive
(
fn
)
testNonKeepAlive
(
fn
)
if
(
count
<
2
)
{
ret
=
false
}
count
=
0
const
options
=
{
a
:
'
a
'
,
success
(
res
){
count
++
;
console
.
log
(
"
testCallbackNonKeepAliveOption callback =====>
"
,
res
)
}
}
testNonKeepAliveOption
(
options
)
testNonKeepAliveOption
(
options
)
if
(
count
<
2
)
{
ret
=
false
}
return
new
Promise
((
resolve
)
=>
{
setTimeout
(()
=>
{
this
.
nonKeepAliveCount
=
count
resolve
(
count
)
},
30
)
})
}
}
}
}
}
}
...
...
pages/index/index.uvue
浏览文件 @
def25552
...
@@ -6,12 +6,13 @@
...
@@ -6,12 +6,13 @@
<button type="primary" @tap="testDoSthWithCallback">uts异步方法(无参数)</button>
<button type="primary" @tap="testDoSthWithCallback">uts异步方法(无参数)</button>
<button type="primary" @tap="testDoSthWithString">uts异步方法(字符串参数)</button>
<button type="primary" @tap="testDoSthWithString">uts异步方法(字符串参数)</button>
<button type="primary" @tap="testDoSthWithJSON">uts异步方法(json参数)</button>
<button type="primary" @tap="testDoSthWithJSON">uts异步方法(json参数)</button>
<button type="primary" @tap="testBuildinObject">内置对象语法测试</button>
<button type="primary" @tap="testCallback">多次回调示例</button>
<button type="primary" @tap="testBuildinObject">内置对象语法测试</button>
</view>
</view>
</view>
</view>
</template>
</template>
<script>
<script>
import { callWithJSONParam, callWithStringParam, callWithoutParam, JsonParamOptions, inputJSON } from "../../uni_modules/uts-helloworld";
import { callWithJSONParam, callWithStringParam, callWithoutParam, JsonParamOptions, inputJSON
,onCallback
} from "../../uni_modules/uts-helloworld";
export default {
export default {
data() {
data() {
...
@@ -72,15 +73,26 @@
...
@@ -72,15 +73,26 @@
}
}
} as JsonParamOptions);
} as JsonParamOptions);
},
},
/**
testCallback: function () {
* 测试内置对象
*/
onCallback(
testBuildinObject: function() {
function(response){
uni.navigateTo({
uni.showToast({
url: `/pages/index/basicTest`
title:'uts插件uts-helloworld的callWithStringParam方法收到了你输入的字符串:'+response,
})
icon:'none'
}
});
},
);
},
/**
* 测试内置对象
*/
testBuildinObject: function() {
uni.navigateTo({
url: `/pages/index/basicTest`
})
}
}
}
}
}
</script>
</script>
...
...
pages/index/index.vue
浏览文件 @
def25552
...
@@ -6,12 +6,13 @@
...
@@ -6,12 +6,13 @@
<button
type=
"primary"
@
tap=
"testDoSthWithCallback"
>
uts异步方法(无参数)
</button>
<button
type=
"primary"
@
tap=
"testDoSthWithCallback"
>
uts异步方法(无参数)
</button>
<button
type=
"primary"
@
tap=
"testDoSthWithString"
>
uts异步方法(字符串参数)
</button>
<button
type=
"primary"
@
tap=
"testDoSthWithString"
>
uts异步方法(字符串参数)
</button>
<button
type=
"primary"
@
tap=
"testDoSthWithJSON"
>
uts异步方法(json参数)
</button>
<button
type=
"primary"
@
tap=
"testDoSthWithJSON"
>
uts异步方法(json参数)
</button>
<button
type=
"primary"
@
tap=
"testCallback"
>
多次回调示例
</button>
<button
type=
"primary"
@
tap=
"testBuildinObject"
>
内置对象语法测试
</button>
<button
type=
"primary"
@
tap=
"testBuildinObject"
>
内置对象语法测试
</button>
</view>
</view>
</view>
</view>
</
template
>
</
template
>
<
script
>
<
script
>
import
{
callWithJSONParam
,
callWithStringParam
,
callWithoutParam
}
from
"
../../uni_modules/uts-helloworld
"
;
import
{
callWithJSONParam
,
callWithStringParam
,
callWithoutParam
,
onCallback
}
from
"
../../uni_modules/uts-helloworld
"
;
export
default
{
export
default
{
data
()
{
data
()
{
...
@@ -46,7 +47,7 @@
...
@@ -46,7 +47,7 @@
this
.
stringParam
,
this
.
stringParam
,
function
(
response
){
function
(
response
){
uni
.
showToast
({
uni
.
showToast
({
title
:
'
uts插件uts-helloworld的
callWithStringParam方法收到了你输入的字符串
:
'
+
response
,
title
:
'
uts插件uts-helloworld的
onCallback方法
:
'
+
response
,
icon
:
'
none
'
icon
:
'
none
'
});
});
},
},
...
@@ -71,6 +72,18 @@
...
@@ -71,6 +72,18 @@
}
}
});
});
},
},
testCallback
:
function
()
{
onCallback
(
function
(
response
){
uni
.
showToast
({
title
:
'
uts插件uts-helloworld的callWithStringParam方法收到了你输入的字符串:
'
+
response
,
icon
:
'
none
'
});
},
);
},
/**
/**
* 测试内置对象
* 测试内置对象
*/
*/
...
...
uni_modules/uts-advance/utssdk/app-android/index.uts
浏览文件 @
def25552
...
@@ -111,9 +111,8 @@ class AddUIRunnable implements Runnable {
...
@@ -111,9 +111,8 @@ class AddUIRunnable implements Runnable {
textView.setBackgroundColor(Color.RED)
textView.setBackgroundColor(Color.RED)
textView.setTag("helloText")
textView.setTag("helloText")
textView.setGravity(Gravity.CENTER)
textView.setGravity(Gravity.CENTER)
let decorView = UTSAndroid.getUniActivity()!.window.decorView;
let decorView = UTSAndroid.getUniActivity()!.getWindow().getDecorView();
let frameContent = decorView.findViewById<FrameLayout>(android.R.id.content)
let frameContent = decorView.findViewById<FrameLayout>(android.R.id.content)
let layoutParam = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
let layoutParam = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
...
...
uni_modules/uts-helloworld/utssdk/index.uts
浏览文件 @
def25552
...
@@ -42,4 +42,23 @@ export function callWithJSONParam(opts: JsonParamOptions) {
...
@@ -42,4 +42,23 @@ export function callWithJSONParam(opts: JsonParamOptions) {
}
}
/**
* 导出多次回调UTS函数
* @param opts
*/
export function onCallback(callback: (sth:string) => void) {
/**
* 模拟多次回调
*/
let count = 1
let taskId = -1
taskId = setInterval(function() {
callback(`第 ${count} 次回调`)
count++;
console.log("count",count)
if(count > 3){
clearInterval(taskId)
}
}, 500);
}
uni_modules/uts-nativepage/utssdk/app-android/NativeLib.kt
0 → 100644
浏览文件 @
def25552
package
uts.sdk.modules.utsNativepage
class
NativeLib
{
/**
* A native method that is implemented by the 'nativelib' native library,
* which is packaged with this application.
*/
external
fun
stringFromJNI
():
String
companion
object
{
// Used to load the 'nativelib' library on application startup.
init
{
System
.
loadLibrary
(
"nativelib"
)
}
}
}
uni_modules/uts-nativepage/utssdk/app-android/index.uts
浏览文件 @
def25552
...
@@ -19,7 +19,7 @@ import Toast from 'android.widget.Toast';
...
@@ -19,7 +19,7 @@ import Toast from 'android.widget.Toast';
import ShortcutInfoCompat from 'androidx.core.content.pm.ShortcutInfoCompat'
import ShortcutInfoCompat from 'androidx.core.content.pm.ShortcutInfoCompat'
import ShortcutManagerCompat from 'androidx.core.content.pm.ShortcutManagerCompat'
import ShortcutManagerCompat from 'androidx.core.content.pm.ShortcutManagerCompat'
import IconCompat from 'androidx.core.graphics.drawable.IconCompat'
import IconCompat from 'androidx.core.graphics.drawable.IconCompat'
import ActivityLifecycleCallbacks from 'android.app.Application.ActivityLifecycleCallbacks';
import Service from 'android.app.Service';
import Service from 'android.app.Service';
import System from 'java.lang.System';
import System from 'java.lang.System';
...
@@ -61,7 +61,64 @@ export function sayHelloFromJar(): string {
...
@@ -61,7 +61,64 @@ export function sayHelloFromJar(): string {
}
}
/**
* 调用SO动态库中的方法
*/
export function sayHelloFromSO():string {
// 这里的逻辑是为了判断 当前的自定义activity 是否注册了,并以此为条件判断是否是自定义基座
let hasXActivityIntegration = true
try{
let packageManager = UTSAndroid.getUniActivity()!.getPackageManager();
let intent = new Intent(UTSAndroid.getUniActivity(),DemoActivity().javaClass);
let resolveInfo = packageManager.queryIntentActivities(intent,0);
console.log(resolveInfo.size)
if(resolveInfo.size == 0){
hasXActivityIntegration = false;
}
}catch(e:Exception){
console.log(e);
hasXActivityIntegration = false;
}
if(!hasXActivityIntegration){
return "需要在自定义基座运行";
}
let nativeLib = new NativeLib()
return nativeLib.stringFromJNI()
}
class MyLifecycleCallbacks implements ActivityLifecycleCallbacks {
override onActivityCreated(a: Activity, b: Bundle|null):void {
console.log("onActivityCreated",a)
}
override onActivityStarted(a: Activity):void {
console.log("onActivityStarted",a)
}
override onActivityResumed(a: Activity):void {
console.log("onActivityResumed",a)
}
override onActivityPaused(a: Activity):void {
console.log("onActivityPaused",a)
}
override onActivityStopped(a: Activity):void {
console.log("onActivityStopped",a)
}
override onActivitySaveInstanceState(a: Activity, b: Bundle):void {
console.log("onActivitySaveInstanceState",a)
}
override onActivityDestroyed(a: Activity):void {
console.log("onActivityDestroyed",a)
}
}
export class AppHookProxy implements UTSAndroidHookProxy {
export class AppHookProxy implements UTSAndroidHookProxy {
...
@@ -74,6 +131,9 @@ export class AppHookProxy implements UTSAndroidHookProxy {
...
@@ -74,6 +131,9 @@ export class AppHookProxy implements UTSAndroidHookProxy {
//onCreate 初始化三方SDK
//onCreate 初始化三方SDK
Log.d("AppHookProxy", "AppHookProxy--onCreate---isPrivacyAgree")
Log.d("AppHookProxy", "AppHookProxy--onCreate---isPrivacyAgree")
}
}
application.registerActivityLifecycleCallbacks(new MyLifecycleCallbacks());
}
}
}
}
...
@@ -165,7 +225,7 @@ class StartServiceListener implements OnClickListener{
...
@@ -165,7 +225,7 @@ class StartServiceListener implements OnClickListener{
override onClick(v?: View):void{
override onClick(v?: View):void{
var
intent = new Intent(UTSAndroid.getUniActivity(), ForeService().javaClass);
let
intent = new Intent(UTSAndroid.getUniActivity(), ForeService().javaClass);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
UTSAndroid.getAppContext()!.startForegroundService(intent);
UTSAndroid.getAppContext()!.startForegroundService(intent);
}
}
...
...
uni_modules/uts-nativepage/utssdk/app-android/libs/arm64-v8a/libnativelib.so
0 → 100644
浏览文件 @
def25552
文件已添加
uni_modules/uts-nativepage/utssdk/app-android/libs/armeabi-v7a/libnativelib.so
0 → 100644
浏览文件 @
def25552
文件已添加
uni_modules/uts-nativepage/utssdk/app-android/libs/x86/libnativelib.so
0 → 100644
浏览文件 @
def25552
文件已添加
uni_modules/uts-nativepage/utssdk/app-android/libs/x86_64/libnativelib.so
0 → 100644
浏览文件 @
def25552
文件已添加
uni_modules/uts-syntaxcase/utssdk/app-android/kotlinCode.kt
浏览文件 @
def25552
package
uts.sdk.modules.utsSyntaxcase
package
uts.sdk.modules.utsSyntaxcase
import
android.app.ActivityManager
import
android.content.Context.ACTIVITY_SERVICE
import
android.os.Build
import
android.os.Build
import
io.dcloud.uts.UTSAndroid
import
io.dcloud.uts.UTSAndroid
import
io.dcloud.uts.setInterval
import
io.dcloud.uts.clearInterval
import
io.dcloud.uts.console
object
NativeCode
{
object
NativeCode
{
fun
getPhoneInfo
():
String
{
fun
getPhoneInfo
():
String
{
return
"${Build.BOARD}-${Build.USER}"
val
ret
=
"${Build.BOARD}-${Build.USER}"
console
.
log
(
"PhoneInfo"
,
ret
)
return
ret
}
}
fun
finishActivity
(){
fun
finishActivity
(){
...
@@ -17,5 +23,38 @@ object NativeCode {
...
@@ -17,5 +23,38 @@ object NativeCode {
fun
getJavaUser
():
JavaUser
{
fun
getJavaUser
():
JavaUser
{
return
JavaUser
(
"张三"
,
12
)
return
JavaUser
(
"张三"
,
12
)
}
}
/**
* 记录上一次的任务id
*/
private
var
lastTaskId
=
-
1
fun
kotlinCallbackUTS
(
callback
:
(
String
)
->
Unit
){
if
(
lastTaskId
!=
-
1
){
// 避免重复开启
clearInterval
(
lastTaskId
)
}
lastTaskId
=
setInterval
({
val
activityManager
=
UTSAndroid
.
getUniActivity
()
?.
getSystemService
(
ACTIVITY_SERVICE
)
as
ActivityManager
val
memoryInfo
=
ActivityManager
.
MemoryInfo
()
activityManager
.
getMemoryInfo
(
memoryInfo
)
val
availMem
=
memoryInfo
.
availMem
/
1024
/
1024
val
totalMem
=
memoryInfo
.
totalMem
/
1024
/
1024
callback
(
"设备内存:$totalMem MB,可用内存:$availMem MB"
)
},
1000
,
2000
)
}
fun
kotlinStopMemListenTest
(){
if
(
lastTaskId
!=
-
1
){
// 避免重复开启
clearInterval
(
lastTaskId
)
}
}
}
}
\ No newline at end of file
uni_modules/uts-syntaxcase/utssdk/app-ios/config.json
浏览文件 @
def25552
{
{
"deploymentTarget"
:
"1
3
.0"
"deploymentTarget"
:
"1
2
.0"
}
}
\ No newline at end of file
uni_modules/uts-syntaxcase/utssdk/index.uts
浏览文件 @
def25552
import
{
RequestTask
,
SyncOptions
,
AsyncOptions
,
SyntaxResult
,
SyncResult
,
TestOptions
}
from
"./interface.uts"
;
import
{
RequestTask
,
SyncOptions
,
AsyncOptions
,
SyntaxResult
,
SyncResult
,
TestOptions
}
from
"./interface.uts"
;
import
{
log
}
from
"./utils.uts"
;
import
{
log
}
from
"./utils.uts"
;
// #ifdef APP-IOS
import
{
UTSPromiseAggregateError
,
UTSPromiseFulfilledResult
,
UTSPromiseRejectedResult
}
from
"DCloudUTSFoundation"
;
// #endif
/**
/**
* 导出一个属性
* 导出一个属性
...
@@ -51,18 +54,12 @@ export function testSyncWithCallback(opts : AsyncOptions) : SyntaxResult {
...
@@ -51,18 +54,12 @@ export function testSyncWithCallback(opts : AsyncOptions) : SyntaxResult {
async
function
testAwaitPromise
(
res
:
SyntaxResult
)
:
Promise
<
SyntaxResult
>
{
async
function
testAwaitPromise
(
res
:
SyntaxResult
)
:
Promise
<
SyntaxResult
>
{
// #ifdef APP-ANDROID
return
await
new
Promise
(
function
(
resolve
:
(
res
:
SyntaxResult
)
=>
void
)
{
return
await
new
Promise
(
function
(
resolve
:
(
res
:
SyntaxResult
)
=>
void
)
{
setTimeout
(()
=>
{
resolve
(
res
)
resolve
(
res
)
setTimeout
(()
=>
{
},
2000
)
resolve
(
res
)
})
},
2000
)
})
// #endif
// #ifndef APP-ANDROID
return
res
// #endif
}
}
/**
/**
* 导出一个异步方法
* 导出一个异步方法
...
@@ -103,7 +100,7 @@ export async function testAsyncParam3(id : number, name : string, opts : AsyncOp
...
@@ -103,7 +100,7 @@ export async function testAsyncParam3(id : number, name : string, opts : AsyncOp
export
class
Test
{
export
class
Test
{
id
:
number
;
id
:
number
;
name
:
string
;
name
:
string
;
static
type
:
string
=
"Test"
;
static
type
:
string
=
"Test"
;
constructor
(
id
:
number
,
options
:
TestOptions
)
{
constructor
(
id
:
number
,
options
:
TestOptions
)
{
...
@@ -125,21 +122,119 @@ export class Test {
...
@@ -125,21 +122,119 @@ export class Test {
const
res
=
await
testAsync
(
opts
);
const
res
=
await
testAsync
(
opts
);
return
res
;
return
res
;
}
}
}
}
export
class
SetterTest
{
// #ifdef APP-IOS
// #ifdef UNI-APP-X
private
_nickName
:
string
=
''
;
export
function
testPromiseStaticMethod
()
{
get
nickName
()
:
string
{
let
p0
=
new
Promise
<
SyntaxResult
|
null
>
((
resolve
,
reject
)
=>
{
console
.
log
(
'get nickName'
);
let
success
=
true
return
this
.
_nickName
;
setTimeout
(()
=>
{
}
if
(
success
)
{
set
nickName
(
value
:
string
)
{
const
res
:
SyntaxResult
=
{
console
.
log
(
'set nickName'
);
name
:
"pomise 0"
,
this
.
_nickName
=
value
;
}
}
resolve
(
res
);
}
else
{
reject
(
new
Error
(
"this is promise 0 reject reasion"
))
}
},
1000
);
});
let
p1
=
new
Promise
<
SyntaxResult
|
null
>
((
resolve
,
reject
)
=>
{
let
success
=
true
setTimeout
(()
=>
{
if
(
success
)
{
resolve
(
null
);
}
else
{
reject
(
new
Error
(
"this is promise 1 reject reasion"
))
}
},
2000
);
});
let
p2
=
new
Promise
<
SyntaxResult
|
null
>
((
resolve
,
reject
)
=>
{
let
success
=
false
setTimeout
(()
=>
{
if
(
success
)
{
resolve
(
null
);
}
else
{
// reject(new Error("this is promise 2 reject reasion"))
reject
(
null
)
}
},
2500
);
});
// test for any
let
pt
=
Promise
.
any
([
p0
,
p1
,
p2
]);
pt
.
then
(
(
res
)
=>
{
console
.
log
(
"promise.any test success"
,
res
)
})
.
catch
(
(
error
:
any
|
null
)
=>
{
if
(
error
instanceof
UTSPromiseAggregateError
)
{
let
err
=
error
as
UTSPromiseAggregateError
console
.
log
(
err
.
name
,
err
.
message
,
err
.
errors
);
}
else
{
console
.
log
(
error
);
}
})
// test for allSettled
Promise
.
allSettled
([
p0
,
p1
,
p2
])
.
then
((
res
)
=>
{
res
.
forEach
((
item
,
index
)
=>
{
if
(
item
instanceof
UTSPromiseFulfilledResult
<
SyntaxResult
|
null
>
)
{
let
item0
=
item
as
UTSPromiseFulfilledResult
console
.
log
(
item0
.
value
,
"UTSPromiseFulfilledResult value"
)
}
else
if
(
item
instanceof
UTSPromiseRejectedResult
<
SyntaxResult
|
null
>
)
{
let
item0
=
item
as
UTSPromiseRejectedResult
console
.
log
(
item0
.
reason
,
"UTSPromiseRejectedResult reason"
)
}
})
})
.
catch
((
error
:
any
|
null
)
=>
{
console
.
log
(
error
,
"rejected test for promise.allSettled"
)
})
// test for all
Promise
.
all
([
p0
,
p1
,
p2
])
.
then
((
res
)
=>
{
console
.
log
(
res
,
res
.
count
)
})
.
catch
(
(
error
:
any
|
null
)
=>
{
console
.
log
(
error
,
"rejected test for promise.all"
)
})
// test for race
Promise
.
race
([
p0
,
p1
,
p2
])
.
then
((
res
)
=>
{
console
.
log
(
res
,
"resolved test for promise.race"
);
})
.
catch
((
error
:
any
|
null
)
=>
{
console
.
log
(
error
,
"catch test for promise.race"
)
})
}
// #endif
// #endif
export
class
SetterTest
{
private
_nickName
:
string
=
''
;
get
nickName
()
:
string
{
console
.
log
(
'get nickName'
);
return
this
.
_nickName
;
}
set
nickName
(
value
:
string
)
{
console
.
log
(
'set nickName'
);
this
.
_nickName
=
value
;
}
}
}
class
RequestTaskImpl
implements
RequestTask
{
class
RequestTaskImpl
implements
RequestTask
{
...
@@ -162,17 +257,34 @@ class RequestTaskImpl implements RequestTask {
...
@@ -162,17 +257,34 @@ class RequestTaskImpl implements RequestTask {
export
function
request
(
url
:
string
)
:
RequestTask
|
null
{
export
function
request
(
url
:
string
)
:
RequestTask
|
null
{
return
new
RequestTaskImpl
(
url
)
return
new
RequestTaskImpl
(
url
)
}
}
// #ifdef APP-ANDROID
// #ifdef UNI-APP-X
// #ifdef APP-ANDROID
export
function
callKotlinMethodGetInfo
():
String
{
export
function
callKotlinMethodGetInfo
():
String
{
return
NativeCode
.
getPhoneInfo
()
return
NativeCode
.
getPhoneInfo
()
}
}
export
function
callJavaMethodGetInfo
():
String
{
export
function
callJavaMethodGetInfo
():
String
{
return
new
JavaUser
(
"jack"
,
12
)
.
name
return
new
JavaUser
(
"jack"
,
12
)
.
name
}
}
export
function
callKotlinCallbackUTS
(
callback
:
(
res
:
string
)
=>
void
)
{
NativeCode
.
kotlinCallbackUTS
(
function
(
res
:
string
){
console
.
log
(
res
)
callback
(
res
)
})
}
export
function
callKotlinStopCallbackUTS
()
{
NativeCode
.
kotlinStopMemListenTest
()
}
// #endif
// #ifdef APP-ANDROID
// #ifdef UNI-APP-X
import
KeyEvent
from
'android.view.KeyEvent'
;
import
KeyEvent
from
'android.view.KeyEvent'
;
import
Configuration
from
'android.content.res.Configuration'
;
import
Configuration
from
'android.content.res.Configuration'
;
...
@@ -316,4 +428,60 @@ export class UTSActivityComponentCallback extends UniActivityComponentCallback {
...
@@ -316,4 +428,60 @@ export class UTSActivityComponentCallback extends UniActivityComponentCallback {
}
}
}
}
// #endif
// #endif
// #endif
// #endif
\ No newline at end of file
export
function
Scan
(
timeMillis
:
Number
=
60000
):
number
{
console
.
log
(
"Scan"
,
timeMillis
)
return
timeMillis
}
export
function
Scan1
(
timeMillis
?:
Number
)
:
string
{
console
.
log
(
"Scan"
,
timeMillis
)
if
(
timeMillis
==
null
){
return
"null"
}
return
timeMillis
!.
toString
()
}
export
function
Scan2
(
timeMillis
?:
Number
|
null
)
:
string
{
console
.
log
(
"Scan"
,
timeMillis
)
if
(
timeMillis
==
null
){
return
"null"
}
return
timeMillis
!.
toString
()
}
export
class
myClass
{
constructor
()
{
}
to
(
name
:
String
)
:
string
{
console
.
log
(
name
);
return
name
}
to1
(
name
?:
String
)
:
string
{
if
(
name
==
null
){
return
"null"
}
console
.
log
(
name
);
return
name
!
}
}
export
class
PromiseReturnDemo
{
recordRet
:
number
=
0
constructor
()
{
}
test1
()
:
Promise
<
boolean
>
{
this
.
recordRet
+=
1
console
.
log
(
'test1'
,
this
.
recordRet
)
return
Promise
.
resolve
(
true
);
}
test2
()
:
void
{
this
.
recordRet
+=
1
console
.
log
(
'test2'
,
this
.
recordRet
)
}
}
uni_modules/uts-tests/utssdk/Array.uts
浏览文件 @
def25552
...
@@ -72,9 +72,6 @@ export function testArray() : Result {
...
@@ -72,9 +72,6 @@ export function testArray() : Result {
console.log(arr[1])//'shoes'
console.log(arr[1])//'shoes'
console.log(arr[1])//'shirts'
console.log(arr[1])//'shirts'
// #END
// #END
expect(arr.length).toEqual(4);
expect(arr[0]).toEqual('shoes');
expect(arr[1]).toEqual('shirts');
// expect(arr[4]).toEqual(null);
// expect(arr[4]).toEqual(null);
const numbers : number[] = [1, 2, 3, 4, 5];
const numbers : number[] = [1, 2, 3, 4, 5];
if (numbers.length > 3) {
if (numbers.length > 3) {
...
...
uni_modules/uts-tests/utssdk/ArrayBuffer.uts
浏览文件 @
def25552
...
@@ -5,8 +5,8 @@ import { TFloat64Array } from './TFloat64Array.uts'
...
@@ -5,8 +5,8 @@ import { TFloat64Array } from './TFloat64Array.uts'
import { TInt8Array } from './TInt8Array.uts'
import { TInt8Array } from './TInt8Array.uts'
import { TInt16Array } from './TInt16Array.uts'
import { TInt16Array } from './TInt16Array.uts'
import { TInt32Array } from './TInt32Array.uts'
import { TInt32Array } from './TInt32Array.uts'
import { TUint8Array } from './TU
i
nt8Array.uts'
import { TUint8Array } from './TU
I
nt8Array.uts'
import { TUint8ClampedArray } from './TU
i
nt8ClampedArray.uts'
import { TUint8ClampedArray } from './TU
I
nt8ClampedArray.uts'
import { TUint16Array } from './TUint16Array.uts'
import { TUint16Array } from './TUint16Array.uts'
import { TUint32Array } from './TUint32Array.uts'
import { TUint32Array } from './TUint32Array.uts'
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
...
...
uni_modules/uts-tests/utssdk/Date.uts
浏览文件 @
def25552
...
@@ -153,8 +153,8 @@ export function testDate() : Result {
...
@@ -153,8 +153,8 @@ export function testDate() : Result {
// #ifdef APP-IOS
// #ifdef APP-IOS
expect(date1.toTimeString()).toEqual("08:00:00 GMT+0800 (中国标准时间)");
//
expect(date1.toTimeString()).toEqual("08:00:00 GMT+0800 (中国标准时间)");
expect(date2.toTimeString()).toEqual("03:24:00 GMT+0800 (中国标准时间)");
//
expect(date2.toTimeString()).toEqual("03:24:00 GMT+0800 (中国标准时间)");
// #endif
// #endif
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
expect(date1.toTimeString()).toEqual("08:00:00 GMT+0800");
expect(date1.toTimeString()).toEqual("08:00:00 GMT+0800");
...
...
uni_modules/uts-tests/utssdk/Global.uts
浏览文件 @
def25552
...
@@ -76,7 +76,8 @@ export function testGlobal() : Result {
...
@@ -76,7 +76,8 @@ export function testGlobal() : Result {
expect(parseInt("922337203685477580700099999999999999999999999999999999999999999999999999999999999999999")).toEqualNumber(9.223372036854776e+86)
expect(parseInt("922337203685477580700099999999999999999999999999999999999999999999999999999999999999999")).toEqualNumber(9.223372036854776e+86)
expect(parseInt("50") / 100).toEqualNumber(0.5);
expect(parseInt("50") / 100).toEqualNumber(0.5);
expect(parseInt("500") / 100).toEqualNumber(5);
expect(parseInt("500") / 100).toEqualNumber(5);
expect(parseInt("3.0")).toEqual(3);
expect(parseInt("3.02")).toEqual(3);
// #END
// #END
})
})
...
@@ -90,6 +91,9 @@ export function testGlobal() : Result {
...
@@ -90,6 +91,9 @@ export function testGlobal() : Result {
expect(parseFloat("3.14some non-digit characters")).toEqual(3.14);
expect(parseFloat("3.14some non-digit characters")).toEqual(3.14);
expect(parseFloat("100") / 50).toEqualNumber(2);
expect(parseFloat("100") / 50).toEqualNumber(2);
expect(parseFloat("105") / 50).toEqual(2.1);
expect(parseFloat("105") / 50).toEqual(2.1);
expect(parseFloat("3.0")).toEqual(3);
expect(parseFloat("3.02").toString()).toEqual("3.02");
// #END
// #END
})
})
...
...
uni_modules/uts-tests/utssdk/JSON.uts
浏览文件 @
def25552
...
@@ -38,9 +38,64 @@ function countOccurrences(str : string, substr : string) : number {
...
@@ -38,9 +38,64 @@ function countOccurrences(str : string, substr : string) : number {
return count;
return count;
}
}
// #ifdef APP-ANDROID
class A1 implements IJSONStringify{
override toJSON():any|null{
let jsonRet = {
'name': "zhangsan",
'age': 12,
}
return jsonRet
}
}
class A2 implements IJSONStringify{
toJSON():any|null{
return 2
}
}
class A3 implements IJSONStringify{
toJSON():any|null{
return "json"
}
}
class A4 implements IJSONStringify{
toJSON():any|null{
return null
}
}
class A5 implements IJSONStringify{
toJSON():any|null{
return new A1()
}
}
class A6 implements IJSONStringify{
toJSON():any|null{
return new A5()
}
}
// #endif
export function testJSON() : Result {
export function testJSON() : Result {
return describe("JSON", () => {
return describe("JSON", () => {
test('custom-stringify', () => {
// #ifdef APP-ANDROID
expect(JSON.stringify(new A1())!.length).toEqual(28)
expect(JSON.stringify(new A2())).toEqual("2")
expect(JSON.stringify(new A3())).toEqual('"json"')
expect(JSON.stringify(new A4())).toEqual('null')
expect(JSON.stringify(new A5())!.length).toEqual(28)
expect(JSON.stringify(new A6())!.length).toEqual(28)
// #endif
})
test('parse', () => {
test('parse', () => {
// #TEST JSON.parse_tip,JSON.parse
// #TEST JSON.parse_tip,JSON.parse
const json = `{"result":true, "count":42}`;
const json = `{"result":true, "count":42}`;
...
@@ -221,21 +276,21 @@ export function testJSON() : Result {
...
@@ -221,21 +276,21 @@ export function testJSON() : Result {
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
let a = JSON.stringify({ "x": 111, "y": "aaa" })
let a = JSON.stringify({ "x": 111, "y": "aaa" })
expect(a).toEqual('{"x":111,"y":"aaa"}');
expect(a).toEqual('{"x":111,"y":"aaa"}');
let a1 = JSON.stringify({ "x": 111, "y": "aaa" }, function (key :
any
, value : any | null) : any | null {
let a1 = JSON.stringify({ "x": 111, "y": "aaa" }, function (key :
string
, value : any | null) : any | null {
if (key == "x") {
if (key == "x") {
return "x"
return "x"
}
}
return value
return value
})
})
expect(a1).toEqual('{"x":"x","y":"aaa"}');
expect(a1).toEqual('{"x":"x","y":"aaa"}');
let a2 = JSON.stringify({ "x": 111, "y": "aaa" }, function (key :
any
, value : any | null) : any | null {
let a2 = JSON.stringify({ "x": 111, "y": "aaa" }, function (key :
string
, value : any | null) : any | null {
if (key == "x") {
if (key == "x") {
return "x"
return "x"
}
}
return value
return value
}, 6)
}, 6)
expect(a2.length).toEqual(36);
expect(a2.length).toEqual(36);
let a3 = JSON.stringify({ "x": 111, "y": "aaa" }, function (key :
any
, value : any | null) : any | null {
let a3 = JSON.stringify({ "x": 111, "y": "aaa" }, function (key :
string
, value : any | null) : any | null {
if (key == "x") {
if (key == "x") {
return "x"
return "x"
}
}
...
@@ -243,7 +298,7 @@ export function testJSON() : Result {
...
@@ -243,7 +298,7 @@ export function testJSON() : Result {
}, 11)
}, 11)
expect(a3.length).toEqual(44);
expect(a3.length).toEqual(44);
let a4 = JSON.stringify({ "x": 111, "y": "aaa" }, function (key :
any
, value : any | null) : any | null {
let a4 = JSON.stringify({ "x": 111, "y": "aaa" }, function (key :
string
, value : any | null) : any | null {
if (key == "x") {
if (key == "x") {
return "x"
return "x"
}
}
...
@@ -264,9 +319,11 @@ export function testJSON() : Result {
...
@@ -264,9 +319,11 @@ export function testJSON() : Result {
expect(a8.length).toEqual(73);
expect(a8.length).toEqual(73);
expect(countOccurrences(a8, "99999")).toEqual(6);
expect(countOccurrences(a8, "99999")).toEqual(6);
// #endif
// #endif
})
})
test('stringify', () => {
test('stringify', () => {
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
...
...
uni_modules/uts-tests/utssdk/JSON_large.uts
浏览文件 @
def25552
...
@@ -22522,22 +22522,23 @@ export function testJSONLarge() : Result {
...
@@ -22522,22 +22522,23 @@ export function testJSONLarge() : Result {
return describe("JSON_large", () => {
return describe("JSON_large", () => {
test('parse', () => {
test('parse', () => {
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
let startTime = System.currentTimeMillis()
let startTime = System.currentTimeMillis()
let listdata = JSON.parseArray<PICKER_ITEM_INFO>(allStr)
let listdata = JSON.parseArray<PICKER_ITEM_INFO>(allStr)
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 < 1800).toEqual(true);
startTime = System.currentTimeMillis()
startTime = System.currentTimeMillis()
let listdata2 = JSON.parse(allStr)
let listdata2 = JSON.parse(allStr)
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 < 1200).toEqual(true);
console.log('不指定类型转换耗时',spendTime,listdata2)
console.log('不指定类型转换耗时',spendTime,listdata2)
// #endif
// #endif
...
...
uni_modules/uts-tests/utssdk/KeyWord.uts
浏览文件 @
def25552
...
@@ -80,9 +80,11 @@ export function testKeyWord() : Result {
...
@@ -80,9 +80,11 @@ export function testKeyWord() : Result {
})
})
test('typeof', () => {
test('typeof', () => {
expect(typeof (null)).toEqual('object')
expect(typeof null).toEqual('object')
let new1 = new User()
let new1 = new User()
expect(typeof (new1)).toEqual('object')
expect(typeof (new1)).toEqual('object')
//expect(typeof null).toEqual('object')
// #ifdef APP-ANDROID || APP-IOS
// #ifdef APP-ANDROID || APP-IOS
expect(typeof (123456.789)).toEqual('Double')
expect(typeof (123456.789)).toEqual('Double')
//expect(typeof(789778979798797987979)).toEqual('number')
//expect(typeof(789778979798797987979)).toEqual('number')
...
...
uni_modules/uts-tests/utssdk/Math.uts
浏览文件 @
def25552
...
@@ -106,6 +106,14 @@ export function testMath() : Result {
...
@@ -106,6 +106,14 @@ export function testMath() : Result {
expect(difference(3, 5)).toEqual(2);
expect(difference(3, 5)).toEqual(2);
expect(difference(5, 3)).toEqual(2);
expect(difference(5, 3)).toEqual(2);
expect(difference(1.23456, 7.89012)).toEqual(6.6555599999999995);
expect(difference(1.23456, 7.89012)).toEqual(6.6555599999999995);
let utsNumber1 = JSON.parse("-160")! as Number
expect(Math.abs(utsNumber1)).toEqual(160);
let utsNumber2 = Math.abs(0) - 0.123456
expect(Math.abs(utsNumber2)).toEqual(0.123456);
})
})
test('acos', () => {
test('acos', () => {
...
@@ -126,7 +134,7 @@ export function testMath() : Result {
...
@@ -126,7 +134,7 @@ export function testMath() : Result {
// 解决精度问题
// 解决精度问题
expect(Math.acos(-1)).toEqual(3.141592653589793);
expect(Math.acos(-1)).toEqual(3.141592653589793);
expect(Math.acos(0)).toEqual(1.5707963267948966);
expect(Math.acos(0)).toEqual(1.5707963267948966);
expect(Math.acos(1)).toEqual(0
.0
);
expect(Math.acos(1)).toEqual(0);
})
})
test('acosh', () => {
test('acosh', () => {
...
@@ -145,7 +153,7 @@ export function testMath() : Result {
...
@@ -145,7 +153,7 @@ export function testMath() : Result {
// expected output: 1.566799236972411
// expected output: 1.566799236972411
// #END
// #END
// 解决精度问题
// 解决精度问题
expect(Math.acosh(1)).toEqual(0
.0
);
expect(Math.acosh(1)).toEqual(0);
expectNumber(Math.acosh(2)).toEqualDouble(1.3169578969248166);
expectNumber(Math.acosh(2)).toEqualDouble(1.3169578969248166);
expectNumber(Math.acosh(2.5)).toEqualDouble(1.566799236972411);
expectNumber(Math.acosh(2.5)).toEqualDouble(1.566799236972411);
})
})
...
@@ -172,7 +180,7 @@ export function testMath() : Result {
...
@@ -172,7 +180,7 @@ export function testMath() : Result {
// 解决精度问题
// 解决精度问题
expect(Math.asin(-1)).toEqual(-1.5707963267948966);
expect(Math.asin(-1)).toEqual(-1.5707963267948966);
// expect(Math.asin(0.5)).toEqual(0.5235987755982989);
// expect(Math.asin(0.5)).toEqual(0.5235987755982989);
expect(Math.asin(0)).toEqual(0
.0
);
expect(Math.asin(0)).toEqual(0);
expect(Math.asin(1)).toEqual(1.5707963267948966);
expect(Math.asin(1)).toEqual(1.5707963267948966);
})
})
...
@@ -197,7 +205,7 @@ export function testMath() : Result {
...
@@ -197,7 +205,7 @@ export function testMath() : Result {
// #END
// #END
// 解决精度问题
// 解决精度问题
expectNumber(Math.asinh(1)).toEqualDouble(0.881373587019543);
expectNumber(Math.asinh(1)).toEqualDouble(0.881373587019543);
expectNumber(Math.asinh(0)).toEqualDouble(0
.0
);
expectNumber(Math.asinh(0)).toEqualDouble(0);
expectNumber(Math.asinh(-1)).toEqualDouble(-0.881373587019543);
expectNumber(Math.asinh(-1)).toEqualDouble(-0.881373587019543);
expectNumber(Math.asinh(2)).toEqualDouble(1.4436354751788103);
expectNumber(Math.asinh(2)).toEqualDouble(1.4436354751788103);
})
})
...
@@ -217,7 +225,7 @@ export function testMath() : Result {
...
@@ -217,7 +225,7 @@ export function testMath() : Result {
// #END
// #END
// 解决精度问题
// 解决精度问题
expect(Math.atan(1)).toEqual(0.7853981633974483);
expect(Math.atan(1)).toEqual(0.7853981633974483);
expect(Math.atan(0)).toEqual(0
.0
);
expect(Math.atan(0)).toEqual(0);
})
})
test('atan2', () => {
test('atan2', () => {
...
@@ -243,7 +251,7 @@ export function testMath() : Result {
...
@@ -243,7 +251,7 @@ export function testMath() : Result {
// expected output: 0
// expected output: 0
// #END
// #END
// 解决精度问题
// 解决精度问题
expect(Math.atanh(0)).toEqual(0
.0
);
expect(Math.atanh(0)).toEqual(0);
// expect(Math.atanh(0.5)).toEqual(0.5493061443340548);
// expect(Math.atanh(0.5)).toEqual(0.5493061443340548);
})
})
...
...
uni_modules/uts-tests/utssdk/Number.uts
浏览文件 @
def25552
...
@@ -76,12 +76,12 @@ export function testNumber() : Result {
...
@@ -76,12 +76,12 @@ export function testNumber() : Result {
expect(UTSNumber.isFinite(Double.POSITIVE_INFINITY)).toEqual(false);
expect(UTSNumber.isFinite(Double.POSITIVE_INFINITY)).toEqual(false);
// #endif
// #endif
})
})
test('number-from-json-parse', () => {
test('number-from-json-parse', () => {
type A = {
type A = {
a:
number
a :
number
}
}
let aj = JSON.parse<A>('{"a":1}');
let aj = JSON.parse<A>('{"a":1}');
expect(aj?.a == 1).toEqual(true);
expect(aj?.a == 1).toEqual(true);
...
@@ -89,13 +89,13 @@ export function testNumber() : Result {
...
@@ -89,13 +89,13 @@ 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(numberEquals(aj?.a,1)).toEqual(true);
expect(numberEquals(aj?.a,
1)).toEqual(true);
expect(numberEquals(aj?.a,1 as number)).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)).toEqual(true);
expect(numberEquals(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();
expect(aj?.a == ki).toEqual(true);
expect(aj?.a == ki).toEqual(true);
expect(aj?.a == kd).toEqual(true);
expect(aj?.a == kd).toEqual(true);
expect(aj?.a == kf).toEqual(true);
expect(aj?.a == kf).toEqual(true);
...
@@ -112,7 +112,7 @@ export function testNumber() : Result {
...
@@ -112,7 +112,7 @@ export function testNumber() : Result {
newA.a = 1.1
newA.a = 1.1
expect(aj?.a == newA.a).toEqual(false);
expect(aj?.a == newA.a).toEqual(false);
expect(aj?.a === newA.a).toEqual(false);
expect(aj?.a === newA.a).toEqual(false);
let a10 = JSON.parse("10")
let a10 = JSON.parse("10")
let b10 = JSON.parse("10")
let b10 = JSON.parse("10")
let c10 = JSON.parse("10.0")
let c10 = JSON.parse("10.0")
...
@@ -120,12 +120,12 @@ export function testNumber() : Result {
...
@@ -120,12 +120,12 @@ export function testNumber() : Result {
expect(a10 == c10).toEqual(true);
expect(a10 == c10).toEqual(true);
let aj2 = JSON.parse<A>('{"a":1}');
let aj2 = JSON.parse<A>('{"a":1}');
expect(aj?.a == aj2?.a).toEqual(true);
expect(aj?.a == aj2?.a).toEqual(true);
// #endif
// #endif
})
})
test('isInteger', () => {
test('isInteger', () => {
expect(Number.isInteger(12)).toEqual(true);
expect(Number.isInteger(12)).toEqual(true);
expect(Number.isInteger(12.01)).toEqual(false);
expect(Number.isInteger(12.01)).toEqual(false);
...
@@ -133,6 +133,49 @@ export function testNumber() : Result {
...
@@ -133,6 +133,49 @@ export function testNumber() : Result {
expect(Number.isInteger(-213123112)).toEqual(true);
expect(Number.isInteger(-213123112)).toEqual(true);
})
})
test('Unary-Operators', () => {
// #ifdef APP-ANDROID
let a = JSON.parse("1") as Number
a++;
expect(a.toString()).toEqual("2");
expect(UTSAndroid.getJavaClass(a).name).toEqual("io.dcloud.uts.UTSNumber");
a--;
expect(a.toString()).toEqual("1");
expect(UTSAndroid.getJavaClass(a).name).toEqual("io.dcloud.uts.UTSNumber");
a /= 0.5;
expect(a.toString()).toEqual("2");
expect(UTSAndroid.getJavaClass(a).name).toEqual("io.dcloud.uts.UTSNumber");
a *= 5;
expect(a.toString()).toEqual("10");
expect(UTSAndroid.getJavaClass(a).name).toEqual("io.dcloud.uts.UTSNumber");
a += -1;
expect(a.toString()).toEqual("9");
expect(UTSAndroid.getJavaClass(a).name).toEqual("io.dcloud.uts.UTSNumber");
a -= -2;
expect(a.toString()).toEqual("11");
expect(UTSAndroid.getJavaClass(a).name).toEqual("io.dcloud.uts.UTSNumber");
let a2 = a % 5
expect(a2.toString()).toEqual("1");
expect(UTSAndroid.getJavaClass(a2).name).toEqual("io.dcloud.uts.UTSNumber");
let b = 12
let c1 = b + a2
expect(c1.toString()).toEqual("13");
expect(UTSAndroid.getJavaClass(c1).name).toEqual("io.dcloud.uts.UTSNumber");
let c2 = a2 + 2
expect(c2.toString()).toEqual("3");
expect(UTSAndroid.getJavaClass(c2).name).toEqual("io.dcloud.uts.UTSNumber");
let c3 = 2 + a2
expect(c3.toString()).toEqual("3");
expect(UTSAndroid.getJavaClass(c3).name).toEqual("io.dcloud.uts.UTSNumber");
// #endif
})
test('isNaN', () => {
test('isNaN', () => {
expect(isNaN(0)).toEqual(false);
expect(isNaN(0)).toEqual(false);
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
...
@@ -171,13 +214,13 @@ export function testNumber() : Result {
...
@@ -171,13 +214,13 @@ export function testNumber() : Result {
expect((123456789987654).toString(16)).toEqual("7048861cc146");
expect((123456789987654).toString(16)).toEqual("7048861cc146");
expect((-0xff).toString(2)).toEqual("-11111111");
expect((-0xff).toString(2)).toEqual("-11111111");
const a = 1e38
const a = 1e38
expect(a.toString(16).substring(0,12)).toEqual("4b3b4ca85a86");
expect(a.toString(16).substring(0,
12)).toEqual("4b3b4ca85a86");
expect(a.toString(16).length).toEqual(32);
expect(a.toString(16).length).toEqual(32);
expect(a.toString(16).substring(23)).toEqual("000000000");
expect(a.toString(16).substring(23)).toEqual("000000000");
expect(a.toString(2).length).toEqual(127);
expect(a.toString(2).length).toEqual(127);
expect(a.toString(2).substring(0,32)).toEqual("10010110011101101001100101010000");
expect(a.toString(2).substring(0,
32)).toEqual("10010110011101101001100101010000");
expect(a.toString(2).substring(100)).toEqual("000000000000000000000000000");
expect(a.toString(2).substring(100)).toEqual("000000000000000000000000000");
const b = 1e22
const b = 1e22
const bStr12 = b.toString(12)
const bStr12 = b.toString(12)
...
@@ -186,9 +229,17 @@ export function testNumber() : Result {
...
@@ -186,9 +229,17 @@ export function testNumber() : Result {
* 浏览器端:27373a86ba1a195400000
* 浏览器端:27373a86ba1a195400000
*/
*/
expect(bStr12.length).toEqual(21);
expect(bStr12.length).toEqual(21);
expect(bStr12.substring(0,14)).toEqual("27373a86ba1a19");
expect(bStr12.substring(0, 14)).toEqual("27373a86ba1a19");
// #ifdef APP-ANDROID
expect(0.6.toString()).toEqual("0.6");
expect(0.6.toString()).toEqual("0.6");
expect((new UTSNumber(2709954670497349.5)).toString()).toEqual("2709954670497349.5");
expect((new UTSNumber(0.00000000000001)).toString()).toEqual("1e-14");
expect((new UTSNumber(0.000001)).toString()).toEqual("0.000001");
expect((new UTSNumber(0.0000001)).toString()).toEqual("1e-7");
expect((new UTSNumber(100000000000000000000.0)).toString()).toEqual("100000000000000000000");
expect((new UTSNumber(1000000000000000000000.0)).toString()).toEqual("1e+21");
// #endif
})
})
test('valueOf', () => {
test('valueOf', () => {
...
...
uni_modules/uts-tests/utssdk/Operators.uts
浏览文件 @
def25552
...
@@ -119,10 +119,19 @@ export function testOperators(): Result {
...
@@ -119,10 +119,19 @@ export function testOperators(): Result {
// web 返回 Infinity
// web 返回 Infinity
// todo 统一处理
// todo 统一处理
// expect(divide(1, 0)).toEqual();
// expect(divide(1, 0)).toEqual();
expect(divide(16788990011, 5)).toEqualNumber(3357798002.2);
expect(divide(16788990011, 5)).toEqualNumber(3357798002.2);
expect(divide(16788990015, 5)).toEqualNumber(3357798003);
expect(divide(16788990015, 5)).toEqualNumber(3357798003);
expectNumber(divide(16788990015, 10088990000)).toEqualDouble(1.6640902622561822);
expectNumber(divide(16788990015, 10088990000)).toEqualDouble(1.6640902622561822);
let utsNum1 = JSON.parse("0.123456")! as Number
let utsNum2 = JSON.parse("0.123456")! as Number
let utsNum3 = utsNum1 / utsNum2
expect(utsNum3).toEqualNumber(1);
let utsNum4 = 0.030864 / utsNum2
expect(utsNum4).toEqualNumber(0.25);
})
})
test('/=', () => {
test('/=', () => {
let a:number = 3;
let a:number = 3;
...
...
uni_modules/uts-tests/utssdk/Promise.uts
0 → 100644
浏览文件 @
def25552
import { describe, test, expect, Result } from './tests.uts'
export function testPromise() : Result {
return describe("Promise", () => {
test('constructor', () => {
// #TEST Promise.Constructor,Promise.Constructor_1
// 常规方式
let p = new Promise<number>((resolve, reject) => {
let success = true;
setTimeout(() => {
if (success) {
resolve(2024)
} else {
let error = new Error("something going wrong")
reject(error)
}
}, 10);
});
p.then((res : number) => {
expect(res).toEqual(2024)
})
// 单个函数
let p1 = new Promise<any | null>((resolve : (value : any | null) => void) => {
setTimeout(function () {
resolve(null)
}, 10);
})
p1.then((res : any | null) => {
expect(res).toEqual(null)
})
// 指定函数类型
let p2 = new Promise((resolve : (value : string) => void, reject : (error : any | null) => void) => {
setTimeout(function () {
reject(null)
}, 10);
})
p2.then()
.catch((error : any | null) => {
expect(error).toEqual(null)
})
// #END
})
test('then', () => {
// #TEST Promise.then,Promise.then_1,Promise.then_2,Promise.then_3,Promise.then_4
let p = new Promise<string>((reslove, reject) => {
setTimeout(function () {
reslove("hello world")
}, 13);
})
p.then(
(res : string) : Promise<string> => {
expect(res).toEqual("hello world")
let p0 = new Promise<string>((reslove, reject) => {
var success = true;
setTimeout(function () {
success = true;
if (success) {
reslove(res + " 2024")
} else {
reject("first then p0 reject message")
}
}, 8);
})
return p0;
},
(err : any | null) : void => {
throw new Error("first then throw error")
}
)
.catch(
(err) : string => {
return "first catch return message"
}
)
.then(
(res) => {
expect(res).toEqual("hello world 2024")
}
)
.catch(
(err) => {
console.log(err, "this is seconded catch")
}
)
.finally(() => {
expect("finally").toEqual("finally")
})
// #END
})
test('catch', () => {
// #TEST Promise.catch,Promise.catch_1,Promise.catch_2,Promise.catch_3,Promise.catch_4
let p = Promise.reject()
p.then()
.catch((res : any | null) => {
expect(res).toEqual(null)
})
// catch 指定返回值
new Promise<string>((resolve, reject) => {
setTimeout(() => {
reject("2024")
}, 12)
})
.then()
.catch((res : any | null) : string => {
expect(res!).toEqual("2024")
return "hello world"
})
.then((res) => {
expect(res).toEqual("hello world")
})
// catch 返回Promise
new Promise<string>((resolve, reject) => {
setTimeout(() => {
reject("2024")
}, 12)
})
.then()
.catch((res : any | null) : Promise<number> => {
expect(res!).toEqual("2024")
let p = new Promise<number>((resolve, reject) => {
resolve(1)
})
return p
})
.then((res) => {
expect(res).toEqual(1)
})
// #END
})
test('finally', () => {
// #TEST Promise.finally
Promise.resolve(2)
.finally(() => {
console.log("finally")
})
.then((res) => {
expect(res).toEqual(2)
})
Promise.reject(3)
.finally(() => {
console.log("finally")
})
.catch((res) => {
expect(res).toEqual(3)
})
Promise.resolve(2)
.finally(() : number => {
console.log("finally")
return 88
})
.then((res) => {
expect(res).toEqual(2)
})
Promise.reject(3).finally(() => {
throw new Error("99")
})
.catch((res) => {
expect((res as Error).message).toEqual("99");
})
console.log("start");
Promise.reject(4).finally(() : Promise<number> => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(20)
}, 1000)
})
})
.catch((res) => {
expect(res).toEqual(4)
})
// #END
})
test('resolve', () => {
// #TEST Promise.resolve,Promise.resolve_1,Promise.resolve_2
// resolve array
Promise.resolve([1, 2, 3])
.then((res) => {
expect(res).toEqual([1, 2, 3])
})
// resolve string
Promise.resolve("成功")
.then((res) => {
expect(res).toEqual("成功");
})
// resolve null
Promise.resolve()
.then((res) => {
// expect(res).toEqual(null);
})
// resolve promise
const original = Promise.resolve(33)
const cast = Promise.resolve(original)
cast.then((res) => {
expect(res).toEqual(33);
})
// 注:此处飘红是编译器误报,实际可以判等
expect(original === cast).toEqual(true)
// #END
})
test('reject', () => {
// #TEST Promise.reject
// reject array
Promise.reject([1, 2, 3])
.catch((err) => {
expect(err).toEqual([1, 2, 3])
})
// reject error
Promise.reject(new Error("this is reject error message"))
.catch((err) => {
expect((err as Error).message).toEqual("this is reject error message");
})
// reject null
Promise.reject()
.catch((err) => {
expect(err).toEqual(null);
})
// reject promise
const original = Promise.reject(33)
const cast = Promise.reject(original)
cast.catch((err) => {
expect((err as Promise<any>) === original).toEqual(true);
})
expect(original === cast).toEqual(false)
// #END
})
test('all', () => {
// #TEST Promise.all
let p0 = new Promise<string>((resolve, reject) => {
setTimeout(function () {
resolve("1");
}, 10);
})
let p1 = new Promise<string>((resolve, reject) => {
setTimeout(function () {
resolve("2");
}, 10);
})
let p2 = new Promise<string>((resolve, reject) => {
setTimeout(function () {
resolve("3");
}, 10);
})
let p3 = new Promise<string>((resolve, reject) => {
setTimeout(function () {
let error = new Error("p3 reject reason")
reject(error);
}, 10);
})
// resolve
Promise.all([p0, p1, p2])
.then((res) => {
expect(res).toEqual(["1", "2", "3"])
})
// reject
Promise.all([p1, p2, p3])
.then()
.catch((error) => {
console.log(error);
expect((error as Error).message).toEqual("p3 reject reason");
})
// #END
})
test('allSettled', () => {
// #TEST Promise.allSettled
let p0 = new Promise<string | null>((resolve, reject) => {
setTimeout(function () {
resolve("1");
}, 10);
})
let p1 = new Promise<string | null>((resolve, reject) => {
setTimeout(function () {
resolve(null);
}, 10);
})
let p2 = new Promise<string | null>((resolve, reject) => {
setTimeout(function () {
reject(null)
}, 10);
})
let p3 = new Promise<string | null>((resolve, reject) => {
setTimeout(function () {
let error = new Error("p3 reject reason")
reject(error);
}, 10);
})
Promise.allSettled([p0, p1, p2, p3])
.then((res) => {
console.log(res);
let statusArr : string[] = []
res.forEach((item, index : number) => {
statusArr.add(item.status)
})
expect(statusArr).toEqual(["fulfilled", "fulfilled", "rejected", "rejected"])
})
// #END
})
test('any', () => {
// #TEST Promise.any
let p0 = new Promise<string | null>((resolve, reject) => {
setTimeout(function () {
resolve("1");
}, 10);
})
let p1 = new Promise<string | null>((resolve, reject) => {
setTimeout(function () {
resolve(null);
}, 15);
})
let p2 = new Promise<string | null>((resolve, reject) => {
setTimeout(function () {
reject(null)
}, 10);
})
let p3 = new Promise<string | null>((resolve, reject) => {
setTimeout(function () {
reject("error");
}, 12);
})
// test for resolve
Promise.any([p0, p1, p2])
.then((res) => {
console.log(res)
expect(res).toEqual("1");
})
// test for reject
Promise.any([p2, p3])
.then()
.catch(
(error : any | null) => {
console.log("test for promise.any error ==> ", error);
// #ifdef APP-IOS
expect((error as UTSPromiseAggregateError).name).toEqual("AggregateError");
expect((error as UTSPromiseAggregateError).message).toEqual("All promises were rejected");
expect((error as UTSPromiseAggregateError).errors).toEqual([null, "error"]);
// #endif
// #ifdef APP-ANDROID
expect((error as UTSPromiseAggregateError).name).toEqual("AggregateError");
expect((error as UTSPromiseAggregateError).message).toEqual("All promises were rejected");
expect((error as UTSPromiseAggregateError).errors).toEqual([null, "error"]);
// #endif
})
// #END
})
test('race', () => {
// #TEST Promise.race
let p0 = new Promise<string | null>((resolve, reject) => {
setTimeout(function () {
resolve("fast");
}, 10);
})
let p1 = new Promise<string | null>((resolve, reject) => {
setTimeout(function () {
resolve("slow");
}, 15);
})
let p2 = new Promise<string | null>((resolve, reject) => {
setTimeout(function () {
reject(null)
}, 12);
})
// test for resolve
Promise.race([p0, p1])
.then((res) => {
console.log("test for race resolve ===> ", res);
expect(res).toEqual("fast");
})
// test for reject
Promise.race([p1, p2])
.then()
.catch((error) => {
console.log("test for race reject ===> ", error);
expect(error).toEqual(null);
})
// #END
})
})
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TextDecoder.uts
0 → 100644
浏览文件 @
def25552
import { describe, test, expect, Result } from './tests.uts'
export function testDecoder() : Result {
return describe("TextDecoder", () => {
test('decoder', () => {
// #TEST TextDecoder.decode
var utf8decoder = new TextDecoder(); // default 'utf-8' or 'utf8'
var u8arr = Uint8Array.of(240, 160, 174, 183);
var i8arr = Int8Array.of(-16, -96, -82, -73);
expect(utf8decoder.decode(u8arr)).toEqual('𠮷')
expect(utf8decoder.decode(i8arr)).toEqual('𠮷')
utf8decoder = new TextDecoder("gbk"); // default 'utf-8' or 'utf8'
expect(utf8decoder.decode(u8arr)).toEqual('馉');
expect(utf8decoder.decode(i8arr)).toEqual('馉')
utf8decoder = new TextDecoder("utf-8");
var arraybuffer = new ArrayBuffer(4)
var dataView = new DataView(arraybuffer)
dataView.setInt8(0, -16)
dataView.setInt8(1, -96)
dataView.setInt8(2, -82)
dataView.setInt8(3, -73)
expect(utf8decoder.decode(dataView)).toEqual('𠮷');
// #END
})
})
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TextEncoder.uts
0 → 100644
浏览文件 @
def25552
import { describe, test, expect, Result } from './tests.uts'
export function testEncoder() : Result {
return describe("TextEncoder", () => {
test('encoder', () => {
// #TEST TextEncoder.encode
const encoder = new TextEncoder()
const int8 = encoder.encode("€");
console.log(int8); // Uint8Array(3) [226, 130, 172]
// #END
expect(int8.toString()).toEqual("226,130,172");
})
})
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/UTSJSONObject.uts
浏览文件 @
def25552
import { describe, test, expect, expectNumber, Result } from './tests.uts'
import { describe, test, expect, expectNumber, Result } from './tests.uts'
import { mockData } from './data.uts'
export function testUTSJSONObject() : Result {
export function testUTSJSONObject() : Result {
return describe("utsjsonobject", () => {
return describe("utsjsonobject", () => {
test('keys', () => {
test('keys', () => {
// #TEST UTSJSONObject.keys
// #TEST UTSJSONObject.keys
let obj = {
let obj = {
name:"zhangsan",
name: "zhangsan",
age:11
age: 11
}
}
expect(UTSJSONObject.keys(obj).length).toEqual(2);
let ret1 = UTSJSONObject.keys(obj).length
// #END
console.log(ret1) //2
// #END
expect(ret1).toEqual(2);
expect(UTSJSONObject.keys(mockData).length).toEqual(2);
})
})
test('toJSONObject', () => {
test('toJSONObject', () => {
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
let result = {}
let result = {}
result["opt"] = "xxxx"
result["opt"] = "xxxx"
let subArray = [] as Array<UTSJSONObject>
let subArray = [] as Array<UTSJSONObject>
let subModel = {}
let subModel = {}
subModel["name"] = "xxx"
subModel["name"] = "xxx"
subModel["type"] = 0
subModel["type"] = 0
subArray.push(subModel)
subArray.push(subModel)
let service = {}
let service = {}
service["name"] = "0xxxb34fb"
service["name"] = "0xxxb34fb"
service["type"] = 0
service["type"] = 0
//这个数据返回为空对象数组
//这个数据返回为空对象数组
service["array"] = subArray
service["array"] = subArray
result["service"] = service
result["service"] = service
expect(result.toJSONObject().toJSONString()).toEqual('{"opt":"xxxx","service":{"array":[{"name":"xxx","type":0}],"name":"0xxxb34fb","type":0}}');
type TestData = {
num:number;
num2:number;
str:string;
}
let data1:TestData = {
num:1,
num2:2.369,
str:'test'
}
let data2 = JSON.parse<UTSJSONObject>(JSON.stringify(data1))
expect(data2!.toJSONString()).toEqual('{"str":"test","num":1.0,"num2":2.369}')
type TestData4 = {
name:string,
data:any,
}
let data4 : TestData4 = {
name:"张三",
data:data1
}
let data5 = {
data4 :data4
}
expect(data5!.toJSONString()).toEqual('{"data4":{"data":{"num":1,"num2":2.369,"str":"test"},"name":"张三"}}')
expect(result.toJSONObject().toJSONString()).toEqual('{"opt":"xxxx","service":{"array":[{"name":"xxx","type":0}],"name":"0xxxb34fb","type":0}}');
type TestData = {
num:number;
num2:number;
str:string;
}
let data1:TestData = {
num:1,
num2:2.369,
str:'test'
}
let data2 = JSON.parse<UTSJSONObject>(JSON.stringify(data1))
expect(data2!.toJSONString()).toEqual('{"str":"test","num":1.0,"num2":2.369}')
class TestData2 implements IJSONStringify{
toJSON():any|null{
return "122"
}
}
let testData2 = TestData2()
let dataClass = UTSAndroid.getJavaClass(data2)
let data3 = {
strA:"stringA",
dataClass:dataClass,
booleanB:false,
testData:testData2
}
expect(data3!.toJSONString()).toEqual('{"testData":"122","strA":"stringA","dataClass":"io.dcloud.uts.UTSJSONObject","booleanB":false}')
type TestData4 = {
name:string,
data:any,
}
let data4 : TestData4 = {
name:"张三",
data:data1
}
let data5 = {
data4 :data4
}
expect(data5!.toJSONString()).toEqual('{"data4":{"data":{"num":1,"num2":2.369,"str":"test"},"name":"张三"}}')
// class TestData6 implements IJsonStringify{
// toJSON():any|null{
// return JSON.parse("22")
// }
// }
// let testData6 = TestData6()
// let data6 = {
// data:testData6,
// array:[1,"22",false],
// name:"data6"
// }
// expect(data6!.toJSONString()).toEqual('{"data":22.0,"array":[1,"22",false],"name":"data6"}')
// console.log(data6.toJSONString())
// #endif
// #endif
})
})
test('assign-notype', () => {
test('assign-notype', () => {
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
// #TEST UTSJSONObject.assign
// #TEST UTSJSONObject.assign
...
@@ -114,6 +154,16 @@ export function testUTSJSONObject() : Result {
...
@@ -114,6 +154,16 @@ export function testUTSJSONObject() : Result {
// #endif
// #endif
})
})
test('get-no-exist-value', () => {
// #ifdef APP-ANDROID
let test = {
qq:[11,22]
}
expect(test.getNumber("qq[2]")).toEqual(null);
expect(test.getNumber("qq[2]",999)).toEqual(999);
// #endif
})
test('setvalue-after-get', () => {
test('setvalue-after-get', () => {
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
// #TEST UTSJSONObject.getJSON,UTSJSONObject.getArray
// #TEST UTSJSONObject.getJSON,UTSJSONObject.getArray
...
@@ -134,8 +184,8 @@ export function testUTSJSONObject() : Result {
...
@@ -134,8 +184,8 @@ export function testUTSJSONObject() : Result {
expect(firstCar!['value']).toEqual(20);
expect(firstCar!['value']).toEqual(20);
// #endif
// #endif
})
})
test('get-speed', () => {
test('get-speed', () => {
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
// #TEST UTSJSONObject.getString
// #TEST UTSJSONObject.getString
...
@@ -151,7 +201,7 @@ export function testUTSJSONObject() : Result {
...
@@ -151,7 +201,7 @@ export function testUTSJSONObject() : Result {
}
}
// #END
// #END
let spendTime = Date.now() - startTime
let spendTime = Date.now() - startTime
expect(spendTime <
3
00).toEqual(true);
expect(spendTime <
8
00).toEqual(true);
// #endif
// #endif
})
})
...
@@ -247,5 +297,14 @@ export function testUTSJSONObject() : Result {
...
@@ -247,5 +297,14 @@ export function testUTSJSONObject() : Result {
// #END
// #END
})
})
test('useless-as', () => {
const obj = {
a: { b: { c: 'c' } }
};
((obj["a"] as UTSJSONObject)["b"] as UTSJSONObject)["c"] = "c1"
expect(obj.getString("a.b.c")).toEqual('c1')
})
})
})
}
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/console.uts
浏览文件 @
def25552
import { describe, test, expect, expectNumber, Result } from './tests.uts'
import { describe, test, expect, expectNumber, Result } from './tests.uts'
function obtainInnerObject(obj:Any | null):UTSJSONObject{
// #ifdef APP-ANDROID
function obtainInnerObject(obj:any | null):UTSJSONObject{
let jsonStr = console.getLogV2(obj).slice(19,-17)
let jsonStr = console.getLogV2(obj).slice(19,-17)
let a = JSON.parseArray(jsonStr)![0]
let a = JSON.parseArray(jsonStr)![0]
return a as UTSJSONObject
return a as UTSJSONObject
}
}
// #endif
export function testConsole() : Result {
export function testConsole() : Result {
return describe("log", () => {
return describe("log", () => {
...
...
uni_modules/uts-tests/utssdk/data.uts
0 → 100644
浏览文件 @
def25552
const mockData = {
username:"lucy",
age:12
}
export {mockData}
uni_modules/uts-tests/utssdk/index.uts
浏览文件 @
def25552
...
@@ -19,9 +19,10 @@ import { testType } from './Type.uts'
...
@@ -19,9 +19,10 @@ import { testType } from './Type.uts'
export { Result } from './tests.uts'
export { Result } from './tests.uts'
import { testArrayBuffer } from './ArrayBuffer.uts'
import { testArrayBuffer } from './ArrayBuffer.uts'
import { testNativeCode } from './NativeCode.uts'
import { testNativeCode } from './NativeCode.uts'
import { testPromise} from "./Promise.uts"
import { testEncoder} from "./TextEncoder.uts"
// Promise、Proxy、Reflect、Weakmap、WeakSet 不支持
import { testDecoder} from "./TextDecoder.uts"
// Proxy、Reflect、Weakmap、WeakSet 不支持
export function runTests() : UTSJSONObject {
export function runTests() : UTSJSONObject {
const ArrayRes = testArray();
const ArrayRes = testArray();
const DateRes = testDate();
const DateRes = testDate();
...
@@ -40,12 +41,17 @@ export function runTests() : UTSJSONObject {
...
@@ -40,12 +41,17 @@ export function runTests() : UTSJSONObject {
const TypeRes = testType();
const TypeRes = testType();
const JSONLargeRes = testJSONLarge();
const JSONLargeRes = testJSONLarge();
const consoleRes = testConsole();
const consoleRes = testConsole();
const UTSJSONObjectRes = testUTSJSONObject();
const UTSJSONObjectRes = testUTSJSONObject();
// #ifdef APP-ANDROID || WEB
// #ifdef APP-ANDROID || WEB
const ArrayBufferRes = testArrayBuffer();
const ArrayBufferRes = testArrayBuffer();
// #endif
// #endif
const NativeCodeRes = testNativeCode();
const NativeCodeRes = testNativeCode();
const PromiseRes = testPromise();
// #ifdef APP-ANDROID || WEB
const TextEncoderRes = testEncoder();
const TextDecoderRes = testDecoder();
// #endif
return {
return {
Array: ArrayRes,
Array: ArrayRes,
Date: DateRes,
Date: DateRes,
...
@@ -66,110 +72,11 @@ export function runTests() : UTSJSONObject {
...
@@ -66,110 +72,11 @@ export function runTests() : UTSJSONObject {
console: consoleRes,
console: consoleRes,
UTSJSONObject: UTSJSONObjectRes,
UTSJSONObject: UTSJSONObjectRes,
// #ifdef APP-ANDROID || WEB
// #ifdef APP-ANDROID || WEB
ArrayBuffer: ArrayBufferRes,
ArrayBuffer: ArrayBufferRes,
TextEncoder: TextEncoderRes,
TextDecoder: TextDecoderRes,
// #endif
// #endif
NativeCode: NativeCodeRes
NativeCode: NativeCodeRes,
Primise: PromiseRes
}
}
}
}
\ No newline at end of file
// #ifdef APP
import { expect } from './tests.uts'
export type TestKeepAliveCallback = (res: string) => void
export function onTest1(callback: TestKeepAliveCallback) {
callback("1")
callback("2")
}
@UTSJS.keepAlive
export function testKeepAlive(callback: TestKeepAliveCallback) {
callback("1")
callback("2")
}
export type TestKeepAliveOption = {
a: string
success: TestKeepAliveCallback | null
}
@UTSJS.keepAlive
export function testKeepAliveOption(option: TestKeepAliveOption) {
console.log(option.a);
option.success?.("1")
option.success?.("2")
}
export class TestKeepAliveClass {
constructor() {
super()
}
onTest(callback: TestKeepAliveCallback) {
callback("1")
callback("2")
}
@UTSJS.keepAlive
testKeepAlive(callback: TestKeepAliveCallback) {
callback("1")
callback("2")
}
@UTSJS.keepAlive
testKeepAliveOption(option: TestKeepAliveOption) {
console.log(option.a);
option.success?.("1")
option.success?.("2")
}
static onTestStatic(callback: TestKeepAliveCallback) {
callback("1")
callback("2")
}
@UTSJS.keepAlive
static testKeepAliveStatic(callback: TestKeepAliveCallback) {
callback("1")
callback("2")
}
@UTSJS.keepAlive
static testKeepAliveOptionStatic(option: TestKeepAliveOption) {
console.log(option.a);
option.success?.("1")
option.success?.("2")
}
}
interface ITest {
test(callback : (msg : string) => void) : void
}
class TestImpl implements ITest {
@UTSJS.keepAlive
test(callback : (msg : string) => void) : void {
callback("1")
callback("2")
}
}
export function createTest() : ITest {
return new TestImpl()
}
export function testNonKeepAlive(callback: (res: string) => void){
setTimeout(()=>{
callback("1")
},10)
}
export function testNonKeepAliveOption(option: TestKeepAliveOption) {
console.log(option.a);
setTimeout(()=>{
option.success?.("1")
},10)
}
// #endif
uni_modules/uts-tests/utssdk/tests.uts
浏览文件 @
def25552
import { Matchers,NumberMatchers } from './Matchers.uts'
import { Matchers,NumberMatchers } from './Matchers.uts'
export const describes = new Map<string, Result>()
export const describes = new Map<string, Result>()
// #ifndef APP-IOS
export class Result implements IJSONStringify {
total = 0
passed: string[] = []
failed: string[] = []
toJSON():any|null{
let jsonRet = {
'total': this.total,
'passed': this.passed,
'failed': this.failed,
}
return jsonRet
}
}
// #endif
// #ifdef APP-IOS
export class Result {
export class Result {
total = 0
total = 0
passed: string[] = []
passed: string[] = []
failed: string[] = []
failed: string[] = []
}
}
// #endif
let result: Result = new Result()
let result: Result = new Result()
...
@@ -24,7 +43,7 @@ export function test(name: string, fn: () => void) {
...
@@ -24,7 +43,7 @@ export function test(name: string, fn: () => void) {
result.passed.push(name)
result.passed.push(name)
// console.log('push....',result.passed.length)
// console.log('push....',result.passed.length)
} catch (e) {
} catch (e) {
result.failed.push(`${name}:\n${
(e as Error)
.message}`)
result.failed.push(`${name}:\n${
e
.message}`)
}
}
result.total++
result.total++
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录