Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
21c62ed1
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1755
Star
32
Fork
10
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
Hello UTS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
21c62ed1
编写于
3月 22, 2025
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip: 适配鸿蒙app
上级
09d8d390
变更
15
展开全部
隐藏空白更改
内联
并排
Showing
15 changed file
with
564 addition
and
490 deletion
+564
-490
pages.json
pages.json
+2
-2
pages/index/index.uvue
pages/index/index.uvue
+9
-3
uni_modules/uts-tests/utssdk/Array.uts
uni_modules/uts-tests/utssdk/Array.uts
+97
-80
uni_modules/uts-tests/utssdk/Date.uts
uni_modules/uts-tests/utssdk/Date.uts
+74
-74
uni_modules/uts-tests/utssdk/Map.uts
uni_modules/uts-tests/utssdk/Map.uts
+25
-20
uni_modules/uts-tests/utssdk/Matchers.uts
uni_modules/uts-tests/utssdk/Matchers.uts
+4
-1
uni_modules/uts-tests/utssdk/Math.uts
uni_modules/uts-tests/utssdk/Math.uts
+96
-96
uni_modules/uts-tests/utssdk/NativeCode.uts
uni_modules/uts-tests/utssdk/NativeCode.uts
+15
-9
uni_modules/uts-tests/utssdk/Number.uts
uni_modules/uts-tests/utssdk/Number.uts
+33
-23
uni_modules/uts-tests/utssdk/Promise.uts
uni_modules/uts-tests/utssdk/Promise.uts
+11
-11
uni_modules/uts-tests/utssdk/RegExp.uts
uni_modules/uts-tests/utssdk/RegExp.uts
+43
-41
uni_modules/uts-tests/utssdk/Set.uts
uni_modules/uts-tests/utssdk/Set.uts
+10
-10
uni_modules/uts-tests/utssdk/String.uts
uni_modules/uts-tests/utssdk/String.uts
+49
-47
uni_modules/uts-tests/utssdk/app-harmony/arktsCode.ets
uni_modules/uts-tests/utssdk/app-harmony/arktsCode.ets
+9
-0
uni_modules/uts-tests/utssdk/index.uts
uni_modules/uts-tests/utssdk/index.uts
+87
-73
未找到文件。
pages.json
浏览文件 @
21c62ed1
...
...
@@ -15,7 +15,7 @@
"enablePullDownRefresh"
:
false
}
}
//
#ifndef
WEB
||
MP
//
#ifndef
WEB
||
MP
||
APP-HARMONY
,
{
"path"
:
"pages/advance/advance"
,
...
...
@@ -181,7 +181,7 @@
//
},
//
#endif
//
#ifdef
APP
//
#ifdef
APP
-ANDROID
||
APP-IOS
{
"path"
:
"pages/SyntaxCase/utsAndroid"
,
"style"
:
{
...
...
pages/index/index.uvue
浏览文件 @
21c62ed1
...
...
@@ -7,14 +7,18 @@
<button type="primary" @tap="testDoSthWithString">uts异步方法(字符串参数)</button>
<button type="primary" @tap="testDoSthWithJSON">uts异步方法(json参数)</button>
<button type="primary" @tap="testCallback">多次回调示例</button>
<!-- #ifndef APP-HARMONY -->
<button type="primary" @tap="testPluginDepend">uts插件依赖示例</button>
<!-- #endif -->
<button type="primary" @tap="testBuildinObject">内置对象语法测试</button>
</view>
</view>
</template>
<script>
import { callWithJSONParam, callWithStringParam, callWithoutParam, JsonParamOptions, inputJSON ,onCallback} from "../../uni_modules/uts-helloworld";
import { testb } from "@/uni_modules/uts-test-b";
import { callWithJSONParam, callWithStringParam, callWithoutParam, JsonParamOptions, inputJSON ,onCallback} from "../../uni_modules/uts-helloworld";
// #ifndef APP-HARMONY
import { testb } from "@/uni_modules/uts-test-b";
// #endif
export default {
data() {
return {
...
...
@@ -93,12 +97,14 @@
url: `/pages/index/basicTest`
})
},
// #ifndef APP-HARMONY
/**
* 测试插件依赖
*/
testPluginDepend() {
testb()
}
}
// #endif
}
}
...
...
uni_modules/uts-tests/utssdk/Array.uts
浏览文件 @
21c62ed1
此差异已折叠。
点击以展开。
uni_modules/uts-tests/utssdk/Date.uts
浏览文件 @
21c62ed1
...
...
@@ -17,11 +17,11 @@ export function testDate() : Result {
// #TEST Date.now
const start = Date.now()
// this example takes 2 seconds to run
console.log('starting timer...')
//
console.log('starting timer...')
// expected output: starting timer...
setTimeout(() => {
const millis = Date.now() - start
console.log(`seconds elapsed = ${Math.floor(millis / 1000)}`)
//
console.log(`seconds elapsed = ${Math.floor(millis / 1000)}`)
// expected output: seconds elapsed = 2
}, 2000)
// #END
...
...
@@ -37,15 +37,15 @@ export function testDate() : Result {
test('new Date', () => {
// #TEST Date.Constructor
const futureDate = new Date();
console.log(futureDate)//日期和时间
//
console.log(futureDate)//日期和时间
// #END
// #TEST Date.Constructor_1
let date1 = new Date('1992-02-02');
console.log(date1.getTime()) // 696988800000
//
console.log(date1.getTime()) // 696988800000
// #END
// #TEST Date.Constructor_2
let date7 = new Date(2016, 6, 6, 14, 6, 59, 1000)
console.log(date7.getMinutes()) //7
//
console.log(date7.getMinutes()) //7
// #END
expect(date7.getMinutes()).toEqual(7);
...
...
@@ -123,7 +123,7 @@ export function testDate() : Result {
test('valueOf', () => {
// #TEST Date.valueOf
const date1 = new Date('December 17, 1995 03:24:00');
console.log(date1.valueOf())//819141840000
//
console.log(date1.valueOf())//819141840000
// #END
// #ifdef APP-ANDROID
if(java.util.TimeZone.getDefault().rawOffset == 28800000){
...
...
@@ -138,10 +138,10 @@ export function testDate() : Result {
test('parse', () => {
// #TEST Date.parse
const unixTimeZero = Date.parse('01 Jan 1970 00:00:00 GMT');
console.log('Unix time zero:', unixTimeZero); // 0
//
console.log('Unix time zero:', unixTimeZero); // 0
const javaScriptRelease = Date.parse('04 Dec 1995 00:12:00 GMT');
console.log('JavaScript release:', javaScriptRelease); // 818035920000
//
console.log('JavaScript release:', javaScriptRelease); // 818035920000
// #END
expect(unixTimeZero).toEqual(0);
...
...
@@ -152,7 +152,7 @@ export function testDate() : Result {
const date1 = new Date('01 Jan 1970 00:00:00 GMT');
const date2 = new Date('December 17, 1995 03:24:00');
// #ifdef APP-IOS
console.log(date1.toTimeString())//"08:00:00 GMT+0800 (中国标准时间)"
//
console.log(date1.toTimeString())//"08:00:00 GMT+0800 (中国标准时间)"
// #endif
// #ifdef APP-IOS
...
...
@@ -173,7 +173,7 @@ export function testDate() : Result {
// #TEST Date.toString
let event = new Date('1995-12-17T03:24:00');
let ret = event.toString()
console.log(ret)//"Sun Dec 17 1995 03:24:00 GMT+0800"
//
console.log(ret)//"Sun Dec 17 1995 03:24:00 GMT+0800"
// #END
...
...
@@ -188,13 +188,13 @@ export function testDate() : Result {
// #TEST Date.toISOString
event = new Date('1995-12-17T03:24:00');
console.log(event.toISOString())//"1995-12-16T19:24:00.000Z"
//
console.log(event.toISOString())//"1995-12-16T19:24:00.000Z"
// #END
expect(event.toISOString()).toEqual("1995-12-16T19:24:00.000Z");
// #TEST Date.toJSON
event = new Date('1995-12-17T03:24:00');
console.log(event.toJSON()) //"1995-12-16T19:24:00.000Z"
//
console.log(event.toJSON()) //"1995-12-16T19:24:00.000Z"
// #END
expect(event.toJSON()).toEqual("1995-12-16T19:24:00.000Z");
// #TEST Date.toDateString
...
...
@@ -246,22 +246,22 @@ export function testDate() : Result {
const finalMonthBoundaryDate = new Date(2016, 1, 29, 23, 59, 59, 999);
const subsequentMonthBoundaryDate = new Date(2016, 1, 29, 23, 59, 59, 1000);
console.log('Birthday date:', birthday.getDate()); // 19
//
console.log('Birthday date:', birthday.getDate()); // 19
console.log('First millisecond date:', firstMillisecondDate.getDate()); // 6
console.log('Previous millisecond date:', previousMillisecondDate.getDate()); // 5
console.log('Final millisecond date:', finalMillisecondDate.getDate()); // 6
console.log('Subsequent millisecond date:', subsequentMillisecondDate.getDate()); // 7
//
console.log('First millisecond date:', firstMillisecondDate.getDate()); // 6
//
console.log('Previous millisecond date:', previousMillisecondDate.getDate()); // 5
//
console.log('Final millisecond date:', finalMillisecondDate.getDate()); // 6
//
console.log('Subsequent millisecond date:', subsequentMillisecondDate.getDate()); // 7
console.log('First millisecond (month boundary) date:', firstMonthBoundaryDate.getDate()); // 29
console.log('Previous millisecond (month boundary) date:', previousMonthBoundaryDate.getDate()); // 28
console.log('Final millisecond (month boundary) date:', finalMonthBoundaryDate.getDate()); // 29
console.log('Subsequent millisecond (month boundary) date:', subsequentMonthBoundaryDate.getDate()); // 1
//
console.log('First millisecond (month boundary) date:', firstMonthBoundaryDate.getDate()); // 29
//
console.log('Previous millisecond (month boundary) date:', previousMonthBoundaryDate.getDate()); // 28
//
console.log('Final millisecond (month boundary) date:', finalMonthBoundaryDate.getDate()); // 29
//
console.log('Subsequent millisecond (month boundary) date:', subsequentMonthBoundaryDate.getDate()); // 1
// #ifndef WEB
// safari 15不支持此格式的日期字符串
const parsedDate = Date.parse("2024-01-09 22:00:00");
console.log('Parsed date:', parsedDate); // 1704808800000
//
console.log('Parsed date:', parsedDate); // 1704808800000
// #endif
// #END
...
...
@@ -301,17 +301,17 @@ export function testDate() : Result {
const finalWeekBoundaryDay = new Date(2016, 6, 9, 23, 59, 59, 999);
const subsequentWeekBoundaryDay = new Date(2016, 6, 9, 23, 59, 59, 1000);
console.log('Birthday day:', birthday.getDay()); // 2 (Tuesday)
//
console.log('Birthday day:', birthday.getDay()); // 2 (Tuesday)
console.log('First millisecond day:', firstMillisecondDay.getDay()); // 3 (Wednesday)
console.log('Previous millisecond day:', previousMillisecondDay.getDay()); // 2 (Tuesday)
console.log('Final millisecond day:', finalMillisecondDay.getDay()); // 3 (Wednesday)
console.log('Subsequent millisecond day:', subsequentMillisecondDay.getDay()); // 4 (Thursday)
//
console.log('First millisecond day:', firstMillisecondDay.getDay()); // 3 (Wednesday)
//
console.log('Previous millisecond day:', previousMillisecondDay.getDay()); // 2 (Tuesday)
//
console.log('Final millisecond day:', finalMillisecondDay.getDay()); // 3 (Wednesday)
//
console.log('Subsequent millisecond day:', subsequentMillisecondDay.getDay()); // 4 (Thursday)
console.log('First millisecond (week boundary) day:', firstWeekBoundaryDay.getDay()); // 6 (Saturday)
console.log('Previous millisecond (week boundary) day:', previousWeekBoundaryDay.getDay()); // 5 (Friday)
console.log('Final millisecond (week boundary) day:', finalWeekBoundaryDay.getDay()); // 6 (Saturday)
console.log('Subsequent millisecond (week boundary) day:', subsequentWeekBoundaryDay.getDay()); // 0 (Sunday)
//
console.log('First millisecond (week boundary) day:', firstWeekBoundaryDay.getDay()); // 6 (Saturday)
//
console.log('Previous millisecond (week boundary) day:', previousWeekBoundaryDay.getDay()); // 5 (Friday)
//
console.log('Final millisecond (week boundary) day:', finalWeekBoundaryDay.getDay()); // 6 (Saturday)
//
console.log('Subsequent millisecond (week boundary) day:', subsequentWeekBoundaryDay.getDay()); // 0 (Sunday)
// #END
expect(birthday.getDay()).toEqual(2);
...
...
@@ -336,12 +336,12 @@ export function testDate() : Result {
const finalMillisecondYear = new Date(2016, 11, 31, 23, 59, 59, 999);
const subsequentMillisecondYear = new Date(2016, 11, 31, 23, 59, 59, 1000);
console.log('Moon landing year:', moonLanding.getFullYear()); // 1969
//
console.log('Moon landing year:', moonLanding.getFullYear()); // 1969
console.log('First millisecond year:', firstMillisecondYear.getFullYear()); // 2016
console.log('Previous millisecond year:', previousMillisecondYear.getFullYear()); // 2015
console.log('Final millisecond year:', finalMillisecondYear.getFullYear()); // 2016
console.log('Subsequent millisecond year:', subsequentMillisecondYear.getFullYear()); // 2017
//
console.log('First millisecond year:', firstMillisecondYear.getFullYear()); // 2016
//
console.log('Previous millisecond year:', previousMillisecondYear.getFullYear()); // 2015
//
console.log('Final millisecond year:', finalMillisecondYear.getFullYear()); // 2016
//
console.log('Subsequent millisecond year:', subsequentMillisecondYear.getFullYear()); // 2017
// #END
...
...
@@ -356,17 +356,17 @@ export function testDate() : Result {
test('getHours', () => {
// #TEST Date.getHours
const birthday = new Date('March 13, 08 04:20');
console.log('Birthday hours:', birthday.getHours()); // 4
//
console.log('Birthday hours:', birthday.getHours()); // 4
const date1 = new Date(2016, 6, 6, 13);
const date2 = new Date(2016, 6, 6, 13, 0, 0, -1);
const date3 = new Date(2016, 6, 6, 13, 59, 59, 999);
const date4 = new Date(2016, 6, 6, 13, 59, 59, 1000);
console.log('First millisecond hours:', date1.getHours()); // 13
console.log('Previous millisecond hours:', date2.getHours()); // 12
console.log('Final millisecond hours:', date3.getHours()); // 13
console.log('Subsequent millisecond hours:', date4.getHours()); // 14
//
console.log('First millisecond hours:', date1.getHours()); // 13
//
console.log('Previous millisecond hours:', date2.getHours()); // 12
//
console.log('Final millisecond hours:', date3.getHours()); // 13
//
console.log('Subsequent millisecond hours:', date4.getHours()); // 14
// #END
expect(birthday.getHours()).toEqual(4);
...
...
@@ -394,17 +394,17 @@ export function testDate() : Result {
test('getMinutes', () => {
// #TEST Date.getMinutes
const birthday = new Date('March 13, 08 04:20');
console.log('Birthday minutes:', birthday.getMinutes()); // 20
//
console.log('Birthday minutes:', birthday.getMinutes()); // 20
const date1 = new Date(2016, 6, 6, 14, 6);
const date2 = new Date(2016, 6, 6, 14, 6, 0, -1);
const date3 = new Date(2016, 6, 6, 14, 6, 59, 999);
const date4 = new Date(2016, 6, 6, 14, 6, 59, 1000);
console.log('First millisecond minutes:', date1.getMinutes()); // 6
console.log('Previous millisecond minutes:', date2.getMinutes()); // 5
console.log('Final millisecond minutes:', date3.getMinutes()); // 6
console.log('Subsequent millisecond minutes:', date4.getMinutes()); // 7
//
console.log('First millisecond minutes:', date1.getMinutes()); // 6
//
console.log('Previous millisecond minutes:', date2.getMinutes()); // 5
//
console.log('Final millisecond minutes:', date3.getMinutes()); // 6
//
console.log('Subsequent millisecond minutes:', date4.getMinutes()); // 7
// #END
expect(birthday.getMinutes()).toEqual(20);
...
...
@@ -423,12 +423,12 @@ export function testDate() : Result {
const finalMillisecondMonth = new Date(2016, 6, 31, 23, 59, 59, 999);
const subsequentMillisecondMonth = new Date(2016, 6, 31, 23, 59, 59, 1000);
console.log('Moon landing month:', moonLanding.getMonth()); // 6
//
console.log('Moon landing month:', moonLanding.getMonth()); // 6
console.log('First millisecond month:', firstMillisecondMonth.getMonth()); // 6
console.log('Previous millisecond month:', previousMillisecondMonth.getMonth()); // 5
console.log('Final millisecond month:', finalMillisecondMonth.getMonth()); // 6
console.log('Subsequent millisecond month:', subsequentMillisecondMonth.getMonth()); // 7
//
console.log('First millisecond month:', firstMillisecondMonth.getMonth()); // 6
//
console.log('Previous millisecond month:', previousMillisecondMonth.getMonth()); // 5
//
console.log('Final millisecond month:', finalMillisecondMonth.getMonth()); // 6
//
console.log('Subsequent millisecond month:', subsequentMillisecondMonth.getMonth()); // 7
// #END
...
...
@@ -443,17 +443,17 @@ export function testDate() : Result {
test('getSeconds', () => {
// #TEST Date.getSeconds
const moonLanding = new Date('July 20, 69 00:20:18');
console.log('Moon landing seconds:', moonLanding.getSeconds()); // 18
//
console.log('Moon landing seconds:', moonLanding.getSeconds()); // 18
const date1 = new Date(2016, 6, 6, 14, 16, 30);
const date2 = new Date(2016, 6, 6, 14, 16, 30, -1);
const date3 = new Date(2016, 6, 6, 14, 16, 30, 999);
const date4 = new Date(2016, 6, 6, 14, 16, 30, 1000);
console.log('First millisecond seconds:', date1.getSeconds()); // 30
console.log('Previous millisecond seconds:', date2.getSeconds()); // 29
console.log('Final millisecond seconds:', date3.getSeconds()); // 30
console.log('Subsequent millisecond seconds:', date4.getSeconds()); // 31
//
console.log('First millisecond seconds:', date1.getSeconds()); // 30
//
console.log('Previous millisecond seconds:', date2.getSeconds()); // 29
//
console.log('Final millisecond seconds:', date3.getSeconds()); // 30
//
console.log('Subsequent millisecond seconds:', date4.getSeconds()); // 31
// #END
expect(moonLanding.getSeconds()).toEqual(18);
...
...
@@ -466,13 +466,13 @@ export function testDate() : Result {
test('getTime', () => {
// #TEST Date.getTime
const moonLanding = new Date('July 20, 69 20:17:40 GMT+00:00');
console.log(moonLanding.getTime()); // -14182940000
//
console.log(moonLanding.getTime()); // -14182940000
const dateEpoch = new Date(0);
console.log(dateEpoch.getTime()); // 0
//
console.log(dateEpoch.getTime()); // 0
const dateOneMillisecond = new Date(1);
console.log(dateOneMillisecond.getTime()); // 1
//
console.log(dateOneMillisecond.getTime()); // 1
// #END
expect(moonLanding.getTime()).toEqual(-14182940000);
...
...
@@ -483,13 +483,13 @@ export function testDate() : Result {
test('setDate', () => {
// #TEST Date.setDate
const event = new Date('August 19, 1975 23:15:30');
console.log('Original date:', event.getDate()); // 19
//
console.log('Original date:', event.getDate()); // 19
event.setDate(24);
console.log('Updated date (24):', event.getDate()); // 24
//
console.log('Updated date (24):', event.getDate()); // 24
event.setDate(32);
console.log('Updated date (32):', event.getDate()); // 1
//
console.log('Updated date (32):', event.getDate()); // 1
// #END
expect(event.getDate()).toEqual(1);
...
...
@@ -499,7 +499,7 @@ export function testDate() : Result {
// #TEST Date.setFullYear
const event = new Date('August 19, 1975 23:15:30');
event.setFullYear(1969);
console.log('Updated year:', event.getFullYear()); // 1969
//
console.log('Updated year:', event.getFullYear()); // 1969
// #END
expect(event.getFullYear()).toEqual(1969);
...
...
@@ -508,10 +508,10 @@ export function testDate() : Result {
test('setHours', () => {
// #TEST Date.setHours
const event = new Date('August 19, 1975 23:15:30');
console.log('Original hours:', event.getHours()); // 23
//
console.log('Original hours:', event.getHours()); // 23
event.setHours(20);
console.log('Updated hours:', event.getHours()); // 20
//
console.log('Updated hours:', event.getHours()); // 20
// #END
expect(event.getHours()).toEqual(20);
...
...
@@ -520,10 +520,10 @@ export function testDate() : Result {
test('setMilliseconds', () => {
// #TEST Date.setMilliseconds
const event = new Date('August 19, 1975 23:15:30');
console.log('Original milliseconds:', event.getMilliseconds()); // 0
//
console.log('Original milliseconds:', event.getMilliseconds()); // 0
event.setMilliseconds(456);
console.log('Updated milliseconds:', event.getMilliseconds()); // 456
//
console.log('Updated milliseconds:', event.getMilliseconds()); // 456
// #END
...
...
@@ -533,10 +533,10 @@ export function testDate() : Result {
test('setMinutes', () => {
// #TEST Date.setMinutes
const event = new Date('August 19, 1975 23:15:30');
console.log('Original minutes:', event.getMinutes()); // 15
//
console.log('Original minutes:', event.getMinutes()); // 15
event.setMinutes(45);
console.log('Updated minutes:', event.getMinutes()); // 45
//
console.log('Updated minutes:', event.getMinutes()); // 45
// #END
expect(event.getMinutes()).toEqual(45);
...
...
@@ -545,10 +545,10 @@ export function testDate() : Result {
test('setMonth', () => {
// #TEST Date.setMonth
const event = new Date('August 19, 1975 23:15:30');
console.log('Original month:', event.getMonth()); // 7 (August)
//
console.log('Original month:', event.getMonth()); // 7 (August)
event.setMonth(3);
console.log('Updated month:', event.getMonth()); // 3 (April)
//
console.log('Updated month:', event.getMonth()); // 3 (April)
// #END
expect(event.getMonth()).toEqual(3);
...
...
@@ -557,10 +557,10 @@ export function testDate() : Result {
test('setSeconds', () => {
// #TEST Date.setSeconds
const event = new Date('August 19, 1975 23:15:30');
console.log('Original seconds:', event.getSeconds()); // 30
//
console.log('Original seconds:', event.getSeconds()); // 30
event.setSeconds(42);
console.log('Updated seconds:', event.getSeconds()); // 42
//
console.log('Updated seconds:', event.getSeconds()); // 42
// #END
expect(event.getSeconds()).toEqual(42);
...
...
@@ -572,7 +572,7 @@ export function testDate() : Result {
const futureDate = new Date();
futureDate.setTime(launchDate.getTime());
console.log('Future date time:', futureDate.getTime()); // Should match launchDate.getTime()
//
console.log('Future date time:', futureDate.getTime()); // Should match launchDate.getTime()
// #END
expect(futureDate.getTime()).toEqual(launchDate.getTime());
...
...
uni_modules/uts-tests/utssdk/Map.uts
浏览文件 @
21c62ed1
...
...
@@ -8,7 +8,7 @@ export function testMap() : Result {
map1.set('a', 'alpha');
map1.set('b', 'beta');
map1.set('g', 'gamma');
console.log(map1.size);
//
console.log(map1.size);
// expected output: 3
// #END
...
...
@@ -22,7 +22,7 @@ export function testMap() : Result {
map1.set('bar', 'baz');
map1.set("1", 'foo');
map1.clear();
console.log(map1.size);
//
console.log(map1.size);
// expected output: 0
// #END
...
...
@@ -33,10 +33,10 @@ export function testMap() : Result {
const map1 = new Map<string, string>();
map1.set('bar', 'foo');
let ret1 = map1.delete('bar')
console.log(ret1);
//
console.log(ret1);
// expected result: true
// (true indicates successful removal)
console.log(map1.has('bar'));
//
console.log(map1.has('bar'));
// expected result: false
// #END
...
...
@@ -47,22 +47,27 @@ export function testMap() : Result {
// #TEST Map.get
const map1 = new Map<string, string>();
map1.set('bar', 'foo');
console.log(map1.get('bar'));
//
console.log(map1.get('bar'));
// expected output: "foo"
// #END
expect(map1.get('bar')).toEqual("foo");
// js端输出undefined需要抹平差异
// #ifdef APP-HARMONY
expect(map1.get('baz')).toEqual(undefined);
// #endif
// #ifndef APP-HARMONY
expect(map1.get('baz')).toEqual(null);
// #endif
})
test('has', () => {
// #TEST Map.has
const map1 = new Map<string, string>();
map1.set('bar', 'foo');
console.log(map1.has('bar'));
//
console.log(map1.has('bar'));
// expected output: true
console.log(map1.has('baz'));
//
console.log(map1.has('baz'));
// expected output: false
// #END
...
...
@@ -73,10 +78,10 @@ export function testMap() : Result {
// #TEST Map.set
let map1 = new Map<string, string>();
map1.set('bar', 'foo');
console.log(map1.get('bar'));
//
console.log(map1.get('bar'));
// expected output: "foo"
console.log(map1.get('baz'));
//
console.log(map1.get('baz'));
// expected output: null
// #END
...
...
@@ -112,7 +117,7 @@ export function testMap() : Result {
map1 = new Map(); //定义一个map,key为string类型,value也是string类型
map1.set('key1', "abc");
map1.set('key1', "def");
console.log(map1.get('key1')) //返回 def
//
console.log(map1.get('key1')) //返回 def
// #END
})
...
...
@@ -123,8 +128,8 @@ export function testMap() : Result {
map1.set('key2', 'value2');
map1.set('key3', 'value3');
map1.forEach((value : string, key : string, map : Map<string, string>) => {
console.log(key)
console.log(value)
//
console.log(key)
//
console.log(value)
})
// #END
...
...
@@ -176,7 +181,7 @@ export function testMap() : Result {
map.set("name", "zhangsan")
map.set("age", 12)
//Map(2) {"name":"zhangsan","age":12}
console.log(map)
//
console.log(map)
// #END
// #TEST Map.sample_visit
...
...
@@ -185,7 +190,7 @@ export function testMap() : Result {
map1.set("age", 12)
let nameVal = map1.get('name')
//zhangsan
console.log(nameVal)
//
console.log(nameVal)
// #END
// #TEST Map.sample_forEach
...
...
@@ -195,18 +200,18 @@ export function testMap() : Result {
// 遍历函数 1
map2.forEach(function (value : any | null) {
console.log(value)
//
console.log(value)
})
// 遍历函数 2
map2.forEach(function (value : any | null, key : string) {
console.log(key)
console.log(value)
//
console.log(key)
//
console.log(value)
})
// 遍历函数 3
map2.forEach(function (value : any | null, key : string, map : Map<string, any | null>) {
console.log(value)
console.log(key)
console.log(map)
//
console.log(value)
//
console.log(key)
//
console.log(map)
})
// #END
})
...
...
uni_modules/uts-tests/utssdk/Matchers.uts
浏览文件 @
21c62ed1
...
...
@@ -8,9 +8,12 @@ export class Matchers<T> {
if (JSON.stringify(expected) == JSON.stringify(this.actual)) {
return
}
// #ifndef APP-IOS
// #ifndef APP-IOS
|| APP-HARMONY
throw new Error(format(expected, this.actual))
// #endif
// #ifdef APP-HARMONY
throw new Error(format(expected as any, this.actual as any))
// #endif
// #ifdef APP-IOS
NSException(name = NSExceptionName.internalInconsistencyException, reason = format(expected, this.actual)).raise()
// #endif
...
...
uni_modules/uts-tests/utssdk/Math.uts
浏览文件 @
21c62ed1
...
...
@@ -7,7 +7,7 @@ export function testMath() : Result {
function getNapier() : number {
return Math.E
}
console.log(getNapier());
//
console.log(getNapier());
// expected output: 2.718281828459045
// #END
...
...
@@ -18,7 +18,7 @@ export function testMath() : Result {
function getNatLog10() : number {
return Math.LN10;
}
console.log(getNatLog10());
//
console.log(getNatLog10());
// expected output: 2.302585092994046
// #END
...
...
@@ -29,7 +29,7 @@ export function testMath() : Result {
function getNatLog2() : number {
return Math.LN2;
}
console.log(getNatLog2());
//
console.log(getNatLog2());
// expected output: 0.6931471805599453
// #END
expect(getNatLog2()).toEqual(0.6931471805599453);
...
...
@@ -39,7 +39,7 @@ export function testMath() : Result {
function getLog10e() : number {
return Math.LOG10E;
}
console.log(getLog10e());
//
console.log(getLog10e());
// expected output: 0.4342944819032518
// #END
expect(getLog10e()).toEqual(0.4342944819032518);
...
...
@@ -49,7 +49,7 @@ export function testMath() : Result {
function getLog2e() : number {
return Math.LOG2E;
}
console.log(getLog2e());
//
console.log(getLog2e());
// expected output: 1.4426950408889634
// #END
expect(getLog2e()).toEqual(1.4426950408889634);
...
...
@@ -59,7 +59,7 @@ export function testMath() : Result {
function calculateCircumference(radius : number) : number {
return 2 * Math.PI * radius;
}
console.log(calculateCircumference(1));
//
console.log(calculateCircumference(1));
// expected output: 6.283185307179586
// #END
expect(calculateCircumference(1)).toEqual(6.283185307179586);
...
...
@@ -70,7 +70,7 @@ export function testMath() : Result {
function getRoot1_2() : number {
return Math.SQRT1_2;
}
console.log(getRoot1_2());
//
console.log(getRoot1_2());
// expected output: 0.7071067811865476
// #END
expect(getRoot1_2()).toEqual(0.7071067811865476);
...
...
@@ -81,7 +81,7 @@ export function testMath() : Result {
function getRoot2() : number {
return Math.SQRT2;
}
console.log(getRoot2());
//
console.log(getRoot2());
// expected output: 1.4142135623730951
// #END
expect(getRoot2()).toEqual(1.4142135623730951);
...
...
@@ -94,13 +94,13 @@ export function testMath() : Result {
return Math.abs(a - b);
}
console.log(difference(3, 5));
//
console.log(difference(3, 5));
// expected output: 2
console.log(difference(5, 3));
//
console.log(difference(5, 3));
// expected output: 2
console.log(difference(1.23456, 7.89012));
//
console.log(difference(1.23456, 7.89012));
// expected output: 6.6555599999999995
// #END
expect(difference(3, 5)).toEqual(2);
...
...
@@ -118,17 +118,17 @@ export function testMath() : Result {
test('acos', () => {
// #TEST Math.acos
console.log(Math.acos(-1));
//
console.log(Math.acos(-1));
// expected output: 3.141592653589793
// #ifdef APP-ANDROID
console.log(Math.acos(NaN));
//
console.log(Math.acos(NaN));
// #endif
// expected output: NaN
console.log(Math.acos(0));
//
console.log(Math.acos(0));
// expected output: 1.5707963267948966
console.log(Math.acos(1));
//
console.log(Math.acos(1));
// expected output: 0
// #END
// 解决精度问题
...
...
@@ -139,17 +139,17 @@ export function testMath() : Result {
test('acosh', () => {
// #TEST Math.acosh
console.log(Math.acosh(1));
//
console.log(Math.acosh(1));
// expected output: 0
// #ifdef APP-ANDROID
console.log(Math.acosh(NaN));
//
console.log(Math.acosh(NaN));
// #endif
// expected output: NaN
console.log(Math.acosh(2));
//
console.log(Math.acosh(2));
// expected output: 1.3169578969248166
console.log(Math.acosh(2.5));
//
console.log(Math.acosh(2.5));
// expected output: 1.566799236972411
// #END
// 解决精度问题
...
...
@@ -161,20 +161,20 @@ export function testMath() : Result {
test('asin', () => {
// #TEST Math.asin
// #ifdef APP-ANDROID
console.log(Math.asin(NaN));
//
console.log(Math.asin(NaN));
// #endif
// expected output: NaN
console.log(Math.asin(-1));
//
console.log(Math.asin(-1));
// expected output: -1.5707963267948966
console.log(Math.asin(0));
//
console.log(Math.asin(0));
// expected output: 0
// console.log(Math.asin(0.5));
// expected output: 0.5235987755982989
console.log(Math.asin(1));
//
console.log(Math.asin(1));
// expected output: 1.5707963267948966
// #END
// 解决精度问题
...
...
@@ -187,20 +187,20 @@ export function testMath() : Result {
test('asinh', () => {
// #TEST Math.asinh
// #ifdef APP-ANDROID
console.log(Math.asinh(NaN));
//
console.log(Math.asinh(NaN));
// #endif
// expected output: NaN
console.log(Math.asinh(1));
//
console.log(Math.asinh(1));
// expected output: 0.881373587019543
console.log(Math.asinh(0));
//
console.log(Math.asinh(0));
// expected output: 0
console.log(Math.asinh(-1));
//
console.log(Math.asinh(-1));
// expected output: -0.881373587019543
console.log(Math.asinh(2));
//
console.log(Math.asinh(2));
// expected output: 1.4436354751788103
// #END
// 解决精度问题
...
...
@@ -213,14 +213,14 @@ export function testMath() : Result {
test('atan', () => {
// #TEST Math.atan
// #ifdef APP-ANDROID
console.log(Math.atan(NaN));
//
console.log(Math.atan(NaN));
// #endif
// expected output: NaN
console.log(Math.atan(1));
//
console.log(Math.atan(1));
// expected output: 0.7853981633974483
console.log(Math.atan(0));
//
console.log(Math.atan(0));
// expected output: 0
// #END
// 解决精度问题
...
...
@@ -230,10 +230,10 @@ export function testMath() : Result {
test('atan2', () => {
// #TEST Math.atan2
console.log(Math.atan2(90, 15));
//
console.log(Math.atan2(90, 15));
// expected output: 1.4056476493802699
console.log(Math.atan2(15, 90));
//
console.log(Math.atan2(15, 90));
// expected output: 0.16514867741462683
// #END
expect(Math.atan2(90, 15)).toEqual(1.4056476493802699);
...
...
@@ -243,11 +243,11 @@ export function testMath() : Result {
test('atanh', () => {
// #TEST Math.atanh
// #ifdef APP-ANDROID
console.log(Math.atanh(NaN));
//
console.log(Math.atanh(NaN));
// #endif
// expected output: NaN
console.log(Math.atanh(0));
//
console.log(Math.atanh(0));
// expected output: 0
// #END
// 解决精度问题
...
...
@@ -263,26 +263,26 @@ export function testMath() : Result {
})
test('ceil', () => {
// #TEST Math.ceil
console.log(Math.ceil(0.95));
//
console.log(Math.ceil(0.95));
// expected output: 1
// #ifdef APP-ANDROID
console.log(Math.ceil(NaN));
//
console.log(Math.ceil(NaN));
// #endif
// expected output: NaN
console.log(Math.ceil(4));
//
console.log(Math.ceil(4));
// expected output: 4
console.log(Math.ceil(7.004));
//
console.log(Math.ceil(7.004));
// expected output: 8
console.log(Math.ceil(-7.004));
//
console.log(Math.ceil(-7.004));
// expected output: -7
console.log(Math.ceil(37110233000.223));
//
console.log(Math.ceil(37110233000.223));
// expected output: 37110233001
console.log(Math.ceil(-37110233000.223));
//
console.log(Math.ceil(-37110233000.223));
// expected output: -37110233000
// #END
expect(Math.ceil(0.95)).toEqual(1);
...
...
@@ -295,7 +295,7 @@ export function testMath() : Result {
test('clz32', () => {
// #TEST Math.clz32
console.log(Math.clz32(1000));
//
console.log(Math.clz32(1000));
// expected output: 22
// #END
...
...
@@ -307,10 +307,10 @@ export function testMath() : Result {
})
test('cos', () => {
// #TEST Math.cos
console.log(Math.cos(0));
//
console.log(Math.cos(0));
// expected output: 1.0
console.log(Math.cos(1));
//
console.log(Math.cos(1));
// expected output: 0.5403023058681398
// #END
// 解决精度问题
...
...
@@ -320,13 +320,13 @@ export function testMath() : Result {
test('cosh', () => {
// #TEST Math.cosh
console.log(Math.cosh(0));
//
console.log(Math.cosh(0));
// expected output: 1.0
console.log(Math.cosh(1));
//
console.log(Math.cosh(1));
// expected output: 1.5430806348152437
console.log(Math.cosh(-1));
//
console.log(Math.cosh(-1));
// expected output: 1.5430806348152437
// #END
// 解决精度问题
...
...
@@ -337,13 +337,13 @@ export function testMath() : Result {
test('exp', () => {
// #TEST Math.exp
console.log(Math.exp(-1));
//
console.log(Math.exp(-1));
// expected output: 0.36787944117144233
console.log(Math.exp(0));
//
console.log(Math.exp(0));
// expected output: 1.0
console.log(Math.exp(1));
//
console.log(Math.exp(1));
// expected output: 2.718281828459045
// #END
// 解决精度问题
...
...
@@ -354,10 +354,10 @@ export function testMath() : Result {
test('expm1', () => {
// #TEST Math.expm1
console.log(Math.expm1(1));
//
console.log(Math.expm1(1));
// expected output: 1.718281828459045
console.log(Math.expm1(-38));
//
console.log(Math.expm1(-38));
// expected output: -1
// #END
expectNumber(Math.expm1(1)).toEqualDouble(1.718281828459045);
...
...
@@ -366,22 +366,22 @@ export function testMath() : Result {
test('floor', () => {
// #TEST Math.floor
console.log(Math.floor(5.95));
//
console.log(Math.floor(5.95));
// expected output: 5
console.log(Math.floor(5.05));
//
console.log(Math.floor(5.05));
// expected output: 5
console.log(Math.floor(5));
//
console.log(Math.floor(5));
// expected output: 5
console.log(Math.floor(-5.05));
//
console.log(Math.floor(-5.05));
// expected output: -6
console.log(Math.floor(37110233000.223));
//
console.log(Math.floor(37110233000.223));
// expected output: 37110233000
console.log(Math.floor(-37110233000.223));
//
console.log(Math.floor(-37110233000.223));
// expected output: -37110233001
// #END
// 解决精度问题
...
...
@@ -396,14 +396,14 @@ export function testMath() : Result {
test('fround', () => {
// #TEST Math.fround
// #ifdef APP-ANDROID
console.log(Math.fround(NaN));
//
console.log(Math.fround(NaN));
// #endif
// expected output: NaN
console.log(Math.fround(1.5));
//
console.log(Math.fround(1.5));
// expected output: 1.5
console.log(Math.fround(1.337));
//
console.log(Math.fround(1.337));
// expected output: 1.3370000123977661
// #END
// 解决精度问题
...
...
@@ -424,10 +424,10 @@ export function testMath() : Result {
// })
test('log', () => {
// #TEST Math.log
console.log(Math.log(1));
//
console.log(Math.log(1));
// expected output: 0.0
console.log(Math.log(10));
//
console.log(Math.log(10));
// expected output: 2.302585092994046
// #END
// 解决精度问题
...
...
@@ -437,13 +437,13 @@ export function testMath() : Result {
test('log10', () => {
// #TEST Math.log10
console.log(Math.log10(10));
//
console.log(Math.log10(10));
// expected output: 1
console.log(Math.log10(100));
//
console.log(Math.log10(100));
// expected output: 2
console.log(Math.log10(1));
//
console.log(Math.log10(1));
// expected output: 0
// #END
...
...
@@ -454,10 +454,10 @@ export function testMath() : Result {
})
test('log1p', () => {
// #TEST Math.log1p
console.log(Math.log1p(Math.E - 1));
//
console.log(Math.log1p(Math.E - 1));
// expected output: 1.0
console.log(Math.log1p(0));
//
console.log(Math.log1p(0));
// expected output: 0.0
// 解决精度问题
// #END
...
...
@@ -467,13 +467,13 @@ export function testMath() : Result {
test('log2', () => {
// #TEST Math.log2
console.log(Math.log2(2));
//
console.log(Math.log2(2));
// expected output: 1.0
console.log(Math.log2(1024));
//
console.log(Math.log2(1024));
// expected output: 10.0
console.log(Math.log2(1));
//
console.log(Math.log2(1));
// expected output: 0.0
// 解决精度问题
// #END
...
...
@@ -484,10 +484,10 @@ export function testMath() : Result {
test('max', () => {
// #TEST Math.max
console.log(Math.max(1, 3, 2));
//
console.log(Math.max(1, 3, 2));
// expected output: 3
console.log(Math.max(-1, -3, -2));
//
console.log(Math.max(-1, -3, -2));
// expected output: -1
// #END
expect(Math.max(1, 3, 2)).toEqual(3);
...
...
@@ -496,10 +496,10 @@ export function testMath() : Result {
test('min', () => {
// #TEST Math.min
console.log(Math.min(2, 3, 1));
//
console.log(Math.min(2, 3, 1));
// expected output: 1
console.log(Math.min(-2, -3, -1));
//
console.log(Math.min(-2, -3, -1));
// expected output: -3
// #END
expect(Math.min(2, 3, 1)).toEqual(1);
...
...
@@ -508,10 +508,10 @@ export function testMath() : Result {
test('pow', () => {
// #TEST Math.pow
console.log(Math.pow(7, 3));
//
console.log(Math.pow(7, 3));
// expected output: 343
console.log(Math.pow(4, 0.5));
//
console.log(Math.pow(4, 0.5));
// expected output: 2
// #END
expectNumber(Math.pow(7, 3)).toEqualDouble(343);
...
...
@@ -524,7 +524,7 @@ export function testMath() : Result {
return Math.floor(Math.random() * max);
}
console.log(getRandomInt(getRandomInt(1)));
//
console.log(getRandomInt(getRandomInt(1)));
// expected output: 0
// #END
expect(getRandomInt(getRandomInt(1))).toEqual(0);
...
...
@@ -532,13 +532,13 @@ export function testMath() : Result {
test('sign', () => {
// #TEST Math.sign
console.log(Math.sign(3));
//
console.log(Math.sign(3));
// expected output: 1
console.log(Math.sign(-3));
//
console.log(Math.sign(-3));
// expected output: -1
console.log(Math.sign(0));
//
console.log(Math.sign(0));
// expected output: 0
// #END
expect(Math.sign(3)).toEqual(1);
...
...
@@ -547,10 +547,10 @@ export function testMath() : Result {
})
test('sin', () => {
// #TEST Math.sin
console.log(Math.sin(0));
//
console.log(Math.sin(0));
// expected output: 0.0
console.log(Math.sin(1));
//
console.log(Math.sin(1));
// expected output: 0.8414709848078965
// #END
// 解决精度问题
...
...
@@ -560,10 +560,10 @@ export function testMath() : Result {
test('sinh', () => {
// #TEST Math.sinh
console.log(Math.sinh(0));
//
console.log(Math.sinh(0));
// expected output: 0.0
console.log(Math.sinh(1));
//
console.log(Math.sinh(1));
// expected output: 1.1752011936438014
// #END
// 解决精度问题
...
...
@@ -576,13 +576,13 @@ export function testMath() : Result {
function calcHypotenuse(a : number, b : number) : number {
return (Math.sqrt((a * a) + (b * b)));
}
console.log(calcHypotenuse(3, 4));
//
console.log(calcHypotenuse(3, 4));
// expected output: 5.0
console.log(calcHypotenuse(5, 12));
//
console.log(calcHypotenuse(5, 12));
// expected output: 13.0
console.log(calcHypotenuse(0, 0));
//
console.log(calcHypotenuse(0, 0));
// expected output: 0.0
// #END
// 解决精度问题
...
...
@@ -593,7 +593,7 @@ export function testMath() : Result {
test('tan', () => {
// #TEST Math.tan
console.log(Math.tan(0));
//
console.log(Math.tan(0));
// expected output: 0.0
// console.log(Math.tan(1));
...
...
@@ -606,13 +606,13 @@ export function testMath() : Result {
test('tanh', () => {
// #TEST Math.tanh
console.log(Math.tanh(-1));
//
console.log(Math.tanh(-1));
// expected output: -0.7615941559557649
console.log(Math.tanh(0));
//
console.log(Math.tanh(0));
// expected output: 0.0
console.log(Math.tanh(1));
//
console.log(Math.tanh(1));
// expected output: 0.7615941559557649
// #END
// 解决精度问题
...
...
@@ -623,13 +623,13 @@ export function testMath() : Result {
test('trunc', () => {
// #TEST Math.trunc
console.log(Math.trunc(13.37));
//
console.log(Math.trunc(13.37));
// expected output: 13
console.log(Math.trunc(42.84));
//
console.log(Math.trunc(42.84));
// expected output: 42
console.log(Math.trunc(0.123));
//
console.log(Math.trunc(0.123));
// expected output: 0
// #END
// 解决精度问题
...
...
uni_modules/uts-tests/utssdk/NativeCode.uts
浏览文件 @
21c62ed1
import { describe, test, expect, Result } from './tests.uts'
// #ifdef APP-HARMONY
import { NativeCode } from './app-harmony/arktsCode.ets'
// #endif
export function testNativeCode(): Result {
return describe("mix-native-code-work", () => {
test('getStrFromNativeCode', () => {
// #ifdef APP-ANDROID
expect(NativeCode.getNativeStr()).toEqual("android-code");
// #endif
// #ifdef APP-IOS
expect(NativeCode.getNativeStr()).toEqual("iOS-code");
// #endif
})
return describe("mix-native-code-work", () => {
test('getStrFromNativeCode', () => {
// #ifdef APP-ANDROID
expect(NativeCode.getNativeStr()).toEqual("android-code");
// #endif
// #ifdef APP-IOS
expect(NativeCode.getNativeStr()).toEqual("iOS-code");
// #endif
// #ifdef APP-HARMONY
expect(NativeCode.getNativeStr()).toEqual("harmonyos-code");
// #endif
})
})
}
uni_modules/uts-tests/utssdk/Number.uts
浏览文件 @
21c62ed1
...
...
@@ -10,9 +10,9 @@ export function testNumber() : Result {
function financial(x : Number) : String {
return x.toFixed(2);
}
console.log(financial(123.456));
//
console.log(financial(123.456));
// expected output: "123.46"
console.log(financial(0.004));
//
console.log(financial(0.004));
// expected output: "0.00"
// #END
...
...
@@ -24,11 +24,11 @@ export function testNumber() : Result {
let num1 : number = -1.1 / 0.1
let num2 : number = -1.1 / 0.1
let num3 : number = -1.1 / -0.1
console.warn(num1)
console.warn(num2)
console.warn(num3)
//
console.warn(num1)
//
console.warn(num2)
//
console.warn(num3)
let obj = { "id": "3be2c600-894c-4231-aa56-82fd989cc961", "result": { "result": [num1, num2, num3] } }
console.log(JSON.stringify(obj))
//
console.log(JSON.stringify(obj))
...
...
@@ -84,7 +84,12 @@ export function testNumber() : Result {
type A = {
a : number
}
// #ifdef APP-HARMONY
let aj: A = JSON.parse('{"a":1}');
// #endif
// #ifndef APP-HARMONY
let aj = JSON.parse<A>('{"a":1}');
// #endif
expect(aj?.a == 1).toEqual(true);
expect(aj?.a == 1 as number).toEqual(true);
expect(aj?.a == 1.0).toEqual(true);
...
...
@@ -193,7 +198,7 @@ export function testNumber() : Result {
test('toPrecision', () => {
// #TEST Number.toPrecision
console.log(123.456.toPrecision(4))//123.5
//
console.log(123.456.toPrecision(4))//123.5
// #END
expect(123.456.toPrecision(4)).toEqual("123.5");
expect(0.004.toPrecision(4)).toEqual("0.004000");
...
...
@@ -202,7 +207,7 @@ export function testNumber() : Result {
test('toString', () => {
// #TEST Number.toString
console.log((10).toString())//10
//
console.log((10).toString())//10
// #END
expect((10).toString()).toEqual("10");
...
...
@@ -255,7 +260,7 @@ export function testNumber() : Result {
test('valueOf', () => {
// #TEST Number.valueOf
console.log((10).valueOf()) //10
//
console.log((10).valueOf()) //10
// #END
expect((10).valueOf()).toEqual(10);
expect((-10.2).valueOf()).toEqual(-10.2);
...
...
@@ -271,10 +276,10 @@ export function testNumber() : Result {
})
// #endif
test('toInt', () => {
// #ifdef APP
// #ifdef APP
-ANDROID || APP-IOS
// #TEST Number.toInt
let a = 12
console.log(a.toInt());
//
console.log(a.toInt());
// expected output: 12
// Int最大值2147483647,溢出了
...
...
@@ -286,11 +291,11 @@ export function testNumber() : Result {
})
test('toByte', () => {
// #ifdef APP
// #ifdef APP
-ANDROID || APP-IOS
// #TEST Number.toByte
let a = 12
// #ifdef APP-ANDROID
console.log(a.toByte());
//
console.log(a.toByte());
// #endif
// expected output: 12
// #END
...
...
@@ -302,7 +307,7 @@ export function testNumber() : Result {
// #ifdef APP-ANDROID
// #TEST Number.toLong
let a = 12
console.log(a.toLong());
//
console.log(a.toLong());
// expected output: 12
// #END
expect(a.toLong()).toEqual(12);
...
...
@@ -310,11 +315,11 @@ export function testNumber() : Result {
})
test('from', () => {
// #ifdef APP
// #ifdef APP
-ANDROID || APP-IOS
// #TEST Number.from
let a: Int = 12
let b = Number.from(a)
console.log(b);
//
console.log(b);
// expected output: 12
// #END
expect(b).toEqual(12);
...
...
@@ -383,15 +388,15 @@ export function testNumber() : Result {
let num1:any = 1.0
let num2 = 1
console.log(num1 == num2)
//
console.log(num1 == num2)
let num3:any = 112233
let num4 = 112233.0
console.log(num3 == num4)
//
console.log(num3 == num4)
// #ifdef APP-ANDROID
let num5:Any = 112233.0
let num6:Any = 112233
console.log(num5 == num6)
//
console.log(num5 == num6)
// #endif
let u11 = {
...
...
@@ -399,11 +404,16 @@ export function testNumber() : Result {
age:0
}
u11["age2"] = 0.0
// #ifdef APP-HARMONY
let a22: number = u11["age2"]
// #endif
// #ifndef APP-HARMONY
let a22 = u11["age2"]
console.log(a22 == 0)
console.log(a22 == 0.0)
console.log(a22 != 0)
console.log(a22 != 0.0)
// #endif
// console.log(a22 == 0)
// console.log(a22 == 0.0)
// console.log(a22 != 0)
// console.log(a22 != 0.0)
})
...
...
uni_modules/uts-tests/utssdk/Promise.uts
浏览文件 @
21c62ed1
...
...
@@ -85,7 +85,7 @@ export function testPromise() : Result {
)
.catch(
(err) => {
console.log(err, "this is seconded catch")
//
console.log(err, "this is seconded catch")
}
)
.finally(() => {
...
...
@@ -143,7 +143,7 @@ export function testPromise() : Result {
Promise.resolve(2)
.finally(() => {
console.log("finally")
//
console.log("finally")
})
.then((res) => {
expect(res).toEqual(2)
...
...
@@ -151,7 +151,7 @@ export function testPromise() : Result {
Promise.reject(3)
.finally(() => {
console.log("finally")
//
console.log("finally")
})
.catch((res) => {
expect(res).toEqual(3)
...
...
@@ -159,7 +159,7 @@ export function testPromise() : Result {
Promise.resolve(2)
.finally(() : number => {
console.log("finally")
//
console.log("finally")
return 88
})
.then((res) => {
...
...
@@ -173,7 +173,7 @@ export function testPromise() : Result {
expect((res as Error).message).toEqual("99");
})
console.log("start");
//
console.log("start");
Promise.reject(4).finally(() : Promise<number> => {
return new Promise((resolve, reject) => {
setTimeout(() => {
...
...
@@ -285,7 +285,7 @@ export function testPromise() : Result {
Promise.all([p1, p2, p3])
.then()
.catch((error) => {
console.log(error);
//
console.log(error);
expect((error as Error).message).toEqual("p3 reject reason");
})
// #END
...
...
@@ -320,7 +320,7 @@ export function testPromise() : Result {
Promise.allSettled([p0, p1, p2, p3])
.then((res) => {
console.log(res);
//
console.log(res);
let statusArr : string[] = []
res.forEach((item, index : number) => {
statusArr.push(item.status)
...
...
@@ -359,7 +359,7 @@ export function testPromise() : Result {
// test for resolve
Promise.any([p0, p1, p2])
.then((res) => {
console.log(res)
//
console.log(res)
expect(res).toEqual("1");
})
...
...
@@ -368,7 +368,7 @@ export function testPromise() : Result {
.then()
.catch(
(error : any | null) => {
console.log("test for promise.any error ==> ", error);
//
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");
...
...
@@ -407,7 +407,7 @@ export function testPromise() : Result {
// test for resolve
Promise.race([p0, p1])
.then((res) => {
console.log("test for race resolve ===> ", res);
//
console.log("test for race resolve ===> ", res);
expect(res).toEqual("fast");
})
...
...
@@ -415,7 +415,7 @@ export function testPromise() : Result {
Promise.race([p1, p2])
.then()
.catch((error) => {
console.log("test for race reject ===> ", error);
//
console.log("test for race reject ===> ", error);
expect(error).toEqual(null);
})
// #END
...
...
uni_modules/uts-tests/utssdk/RegExp.uts
浏览文件 @
21c62ed1
...
...
@@ -22,11 +22,11 @@ export function testRegExp() : Result {
test("dotAll", () => {
// #TEST RegExp.dotAll
const regex1 = new RegExp('foo', 's');
console.log(regex1.dotAll);
//
console.log(regex1.dotAll);
// expected output: true
const regex2 = new RegExp('bar');
console.log(regex2.dotAll);
//
console.log(regex2.dotAll);
// expected output: false
// #END
expect(regex1.dotAll).toEqual(true);
...
...
@@ -36,15 +36,15 @@ export function testRegExp() : Result {
test("flags", () => {
// #TEST RegExp.flags
const regex1 = new RegExp('foo', 'ig');
console.log(regex1.flags);
//
console.log(regex1.flags);
// expected output: "gi"
const regex2 = new RegExp('bar', 'myu');
console.log(regex2.flags);
//
console.log(regex2.flags);
// expected output: "muy"
const regex3 = new RegExp('bar');
console.log(regex3.flags);
//
console.log(regex3.flags);
// expected output: ""
// #END
expect(regex1.flags).toEqual("gi");
...
...
@@ -55,39 +55,41 @@ export function testRegExp() : Result {
test("global", () => {
// #TEST RegExp.global
const regex1 = new RegExp('foo', 'g');
console.log(regex1.global);
//
console.log(regex1.global);
// expected output: true
const regex2 = new RegExp('bar');
console.log(regex2.global);
//
console.log(regex2.global);
// expected output: false
// #END
expect(regex1.global).toEqual(true);
expect(regex2.global).toEqual(false);
});
// #ifndef APP-HARMONY
test("hasIndices", () => {
// #TEST RegExp.hasIndices
const regex1 = new RegExp('foo', 'd');
console.log(regex1.hasIndices);
//
console.log(regex1.hasIndices);
// expected output: true
const regex2 = new RegExp('bar');
console.log(regex2.hasIndices);
//
console.log(regex2.hasIndices);
// expected output: false
// #END
expect(regex1.hasIndices).toEqual(true);
expect(regex2.hasIndices).toEqual(false);
});
// #endif
test("ignoreCase", () => {
// #TEST RegExp.ignoreCase
const regex1 = new RegExp('foo', 'i');
console.log(regex1.ignoreCase);
//
console.log(regex1.ignoreCase);
// expected output: true
const regex2 = new RegExp('bar');
console.log(regex2.ignoreCase);
//
console.log(regex2.ignoreCase);
// expected output: false
// #END
expect(regex1.ignoreCase).toEqual(true);
...
...
@@ -99,7 +101,7 @@ export function testRegExp() : Result {
const regex1 = RegExp('foo*', 'g');
const str1 = 'table football, foosball';
let array1 : RegExpExecArray = regex1.exec(str1)!;
console.log(array1[0] == 'foo')
//
console.log(array1[0] == 'foo')
expect(array1[0] == 'foo').toEqual(true);
// #endif
})
...
...
@@ -109,25 +111,25 @@ export function testRegExp() : Result {
const str = 'ab ab ab';
const result1 = regex.exec(str)!;
console.log(result1.index);
//
console.log(result1.index);
const ret1 = regex.lastIndex
console.log(ret1);
//
console.log(ret1);
// expected output:
// result1.index: 0
// regex.lastIndex: 2
const result2 = regex.exec(str)!;
console.log(result2.index);
//
console.log(result2.index);
let ret2 = regex.lastIndex
console.log(ret2);
//
console.log(ret2);
// expected output:
// result2.index: 3
// regex.lastIndex: 5
const result3 = regex.exec(str)!;
console.log(result3.index);
//
console.log(result3.index);
let ret3 = regex.lastIndex
console.log(ret3);
//
console.log(ret3);
// expected output:
// result3.index: 6
// regex.lastIndex: 8
...
...
@@ -146,11 +148,11 @@ export function testRegExp() : Result {
test("multiline", () => {
// #TEST RegExp.multiline
const regex1 = new RegExp('foo', 'm');
console.log(regex1.multiline);
//
console.log(regex1.multiline);
// expected output: true
const regex2 = new RegExp('bar');
console.log(regex2.multiline);
//
console.log(regex2.multiline);
// expected output: false
// #END
...
...
@@ -161,19 +163,19 @@ export function testRegExp() : Result {
test("source", () => {
// #TEST RegExp.source
const regex1 = new RegExp('foo', 'ig');
console.log(regex1.source);
//
console.log(regex1.source);
// expected output: "foo"
const regex2 = new RegExp('bar');
console.log(regex2.source);
//
console.log(regex2.source);
// expected output: "bar"
const regex3 = /\w+/gi;
console.log(regex3.source);
//
console.log(regex3.source);
// expected output: "\\w+"
const regex4 = new RegExp('\\d+', 'ig');
console.log(regex4.source);
//
console.log(regex4.source);
// expected output: "\\d+"
// #END
...
...
@@ -189,14 +191,14 @@ export function testRegExp() : Result {
const regex1 = new RegExp('foo', 'y');
regex1.lastIndex = 6;
console.log(regex1.sticky);
//
console.log(regex1.sticky);
// expected output: true
let ret = regex1.test(str1)
console.log(ret);
//
console.log(ret);
// expected output: true
regex1.lastIndex = 0;
console.log(regex1.test(str1));
//
console.log(regex1.test(str1));
// #END
expect(regex1.sticky).toEqual(true);
...
...
@@ -217,20 +219,20 @@ export function testRegExp() : Result {
const regex = new RegExp('foo*');
const globalRegex = new RegExp('foo*', 'g');
console.log(regex.test(str));
// expected output: true
//
console.log(regex.test(str));
//
//
expected output: true
console.log(globalRegex.lastIndex);
// expected output: 0
//
console.log(globalRegex.lastIndex);
//
//
expected output: 0
console.log(globalRegex.test(str));
// expected output: true
//
console.log(globalRegex.test(str));
//
//
expected output: true
console.log(globalRegex.lastIndex);
// expected output: 9
//
console.log(globalRegex.lastIndex);
//
//
expected output: 9
console.log(globalRegex.test(str));
// expected output: false
//
console.log(globalRegex.test(str));
//
//
expected output: false
// #END
...
...
@@ -332,14 +334,14 @@ export function testRegExp() : Result {
test('exec', () => {
const reg = /([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/g
console.log("onLoad",reg)
//
console.log("onLoad",reg)
let str = 'L 97.55,34.55,0-1'
let match:null|RegExpExecArray
str = str.slice(1);
match = reg.exec(str);
let arrayRet = [match]
for (let i = 0; i < 5; i++) {
console.log(match,'--')
//
console.log(match,'--')
match = reg.exec(str);
arrayRet.push(match)
...
...
@@ -356,8 +358,8 @@ export function testRegExp() : Result {
// #TEST RegExp.exec
const pattern1 = new RegExp('hello');
const result1 = pattern1.exec('hello world')!;
console.log(result1[0]) //'hello'
console.log(result1.index) //0
//
console.log(result1[0]) //'hello'
//
console.log(result1.index) //0
// #END
expect(result1[0]).toEqual('hello');
...
...
uni_modules/uts-tests/utssdk/Set.uts
浏览文件 @
21c62ed1
...
...
@@ -12,7 +12,7 @@ export function testSet() : Result {
set1.add('forty two');
set1.add('forty two');
set1.add(object1);
console.log(set1.size);
//
console.log(set1.size);
// expected output: 3
// #END
expect(set1.size).toEqual(3);
...
...
@@ -24,7 +24,7 @@ export function testSet() : Result {
set1.add(42);
set1.add(13);
set1.forEach((item) => {
console.log(item);
//
console.log(item);
// expected output: 42
// expected output: 13
})
...
...
@@ -33,9 +33,9 @@ export function testSet() : Result {
set1.forEach((item) => {
expect(set1.has(item)).toEqual(true);
})
console.log(set1)
//
console.log(set1)
let set2 = set1.add(66);
console.log(set2)
//
console.log(set2)
})
test('clear', () => {
// #TEST Set.clear
...
...
@@ -43,7 +43,7 @@ export function testSet() : Result {
set1.add(1);
set1.add('foo');
set1.clear();
console.log(set1.size);
//
console.log(set1.size);
// expected output: 0
// #END
expect(set1.size).toEqual(0);
...
...
@@ -55,7 +55,7 @@ export function testSet() : Result {
set1.add(20);
set1.delete(10);
console.log(set1.size) //1
//
console.log(set1.size) //1
// #END
expect(set1.size).toEqual(1);
...
...
@@ -63,13 +63,13 @@ export function testSet() : Result {
test('has', () => {
// #TEST Set.has
const set1 = new Set<number>([1, 2, 3, 4, 5]);
console.log(set1.has(1));
//
console.log(set1.has(1));
// expected output: true
console.log(set1.has(5));
//
console.log(set1.has(5));
// expected output: true
console.log(set1.has(6));
//
console.log(set1.has(6));
// expected output: false
// #END
...
...
@@ -81,7 +81,7 @@ export function testSet() : Result {
// #TEST Set.forEach,Set.forEach_1,Set.forEach_2
const set1 = new Set<any>(['foo', 'bar'])
let logSetElements = (value : any) => {
console.log(value);
//
console.log(value);
// expected output: foo
// expected output: bar
}
...
...
uni_modules/uts-tests/utssdk/String.uts
浏览文件 @
21c62ed1
...
...
@@ -7,10 +7,10 @@ export function testString() : Result {
const x = "Mozilla";
const e = "";
console.log("Mozilla is " + `${x.length}` + " code units long");
//
console.log("Mozilla is " + `${x.length}` + " code units long");
/* "Mozilla is 7 code units long" */
console.log("The empty string is has a length of " + `${e.length}`);
//
console.log("The empty string is has a length of " + `${e.length}`);
/* "The e string is has a length of 0" */
// #END
...
...
@@ -33,14 +33,15 @@ export function testString() : Result {
// const str = 'x'.repeat(length);
// expect(str.length).toEqual(11);
})
// #ifndef APP-HARMONY
test('at', () => {
// #TEST String.at
const sentence = 'The quick brown fox jumps over the lazy dog.';
let index = 5;
console.log(`Using an index of ${index} the character returned is ${sentence.at(index)}`);
//
console.log(`Using an index of ${index} the character returned is ${sentence.at(index)}`);
// expected output: "Using an index of 5 the character returned is u"
index = -4;
console.log(`Using an index of ${index} the character returned is ${sentence.at(index)}`);
//
console.log(`Using an index of ${index} the character returned is ${sentence.at(index)}`);
// expected output: "Using an index of -4 the character returned is d"
// #END
...
...
@@ -59,20 +60,21 @@ export function testString() : Result {
const empty = "";
expect(empty.at(0)).toEqual(null);
})
// #endif
test('charAt', () => {
// #TEST String.charAt
const anyString = "Brave new world";
console.log("The character at index 0 is '" + anyString.charAt(0) + "'");
//
console.log("The character at index 0 is '" + anyString.charAt(0) + "'");
// The character at index 0 is 'B'
console.log("The character at index 1 is '" + anyString.charAt(1) + "'");
//
console.log("The character at index 1 is '" + anyString.charAt(1) + "'");
// The character at index 1 is 'r'
console.log("The character at index 2 is '" + anyString.charAt(2) + "'");
//
console.log("The character at index 2 is '" + anyString.charAt(2) + "'");
// The character at index 2 is 'a'
console.log("The character at index 3 is '" + anyString.charAt(3) + "'");
//
console.log("The character at index 3 is '" + anyString.charAt(3) + "'");
// The character at index 3 is 'v'
console.log("The character at index 4 is '" + anyString.charAt(4) + "'");
//
console.log("The character at index 4 is '" + anyString.charAt(4) + "'");
// The character at index 4 is 'e'
console.log("The character at index 999 is '" + anyString.charAt(999) + "'");
//
console.log("The character at index 999 is '" + anyString.charAt(999) + "'");
// The character at index 999 is ''
// #END
...
...
@@ -95,7 +97,7 @@ export function testString() : Result {
// #ifdef APP-ANDROID
// #TEST String.toWellFormed
let ret = "ab\uD800".toWellFormed()
console.log(ret) //"ab\uFFFD"
//
console.log(ret) //"ab\uFFFD"
// #END
expect(ret).toEqual("ab\uFFFD");
...
...
@@ -112,7 +114,7 @@ export function testString() : Result {
// #ifdef APP-ANDROID
// #TEST String.isWellFormed
let ret = "ab\uD800".isWellFormed()
console.log(ret) //false
//
console.log(ret) //false
// #END
expect(ret).toEqual(false);
...
...
@@ -129,7 +131,7 @@ export function testString() : Result {
// #TEST String.charCodeAt
const sentence = 'The quick brown fox jumps over the lazy dog.';
const index = 4;
console.log(`The character code ${sentence.charCodeAt(index)} is equal to ${sentence.charAt(index)}`);
//
console.log(`The character code ${sentence.charCodeAt(index)} is equal to ${sentence.charAt(index)}`);
// expected output: "The character code 113 is equal to q"
// #END
...
...
@@ -145,9 +147,9 @@ export function testString() : Result {
})
test('fromCharCode', () => {
// #TEST String.fromCharCode
console.log(String.fromCharCode(65, 66, 67));
//
console.log(String.fromCharCode(65, 66, 67));
// expected output: "ABC"
console.log(String.fromCharCode(0x12014));
//
console.log(String.fromCharCode(0x12014));
// expected output: "𝌆a𝌇"
// #END
...
...
@@ -159,7 +161,7 @@ export function testString() : Result {
// #TEST String.concat
let hello = 'Hello, '
let ret1 = hello.concat('Kevin', '. Have a nice day.')
console.log(ret1)
//
console.log(ret1)
// Hello, Kevin. Have a nice day.
// #END
...
...
@@ -169,12 +171,12 @@ export function testString() : Result {
test('endsWith', () => {
// #TEST String.endsWith
const str1 = 'Cats are the best!';
console.log(str1.endsWith('best!'));
//
console.log(str1.endsWith('best!'));
// expected output: true
console.log(str1.endsWith('best', 17));
//
console.log(str1.endsWith('best', 17));
// expected output: true
const str2 = 'Is this a question?';
console.log(str2.endsWith('question'));
//
console.log(str2.endsWith('question'));
// expected output: false
// #END
...
...
@@ -188,7 +190,7 @@ export function testString() : Result {
// #TEST String.includes
const sentence = 'The quick brown fox jumps over the lazy dog.';
const word = 'fox';
console.log(sentence.includes(word)) // true
//
console.log(sentence.includes(word)) // true
// #END
expect(sentence.includes(word)).toEqual(true);
...
...
@@ -203,10 +205,10 @@ export function testString() : Result {
const paragraph = 'The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?';
const searchTerm = 'dog';
const indexOfFirst = paragraph.indexOf(searchTerm);
console.log(`The index of the first "${searchTerm}" from the beginning is ${indexOfFirst}`);
//
console.log(`The index of the first "${searchTerm}" from the beginning is ${indexOfFirst}`);
// expected output: "The index of the first "dog" from the beginning is 40"
console.log(`The index of the 2nd "${searchTerm}" is ${paragraph.indexOf(searchTerm, (indexOfFirst + 1))}`);
//
console.log(`The index of the 2nd "${searchTerm}" is ${paragraph.indexOf(searchTerm, (indexOfFirst + 1))}`);
// expected output: "The index of the 2nd "dog" is 52"
// #END
...
...
@@ -226,7 +228,7 @@ export function testString() : Result {
// #TEST String.match
const str = 'The quick brown fox jumps over the lazy dog. It barked.';
const result = str.match(new RegExp('[A-Z]', 'g'));
console.log(result![0])//"T"
//
console.log(result![0])//"T"
// #END
// expect(result!.length).toEqual(2);
expect(result![0]).toEqual("T");
...
...
@@ -263,11 +265,11 @@ export function testString() : Result {
// #TEST String.padEnd
const str1 = 'Breaded Mushrooms';
let ret1= str1.padEnd(25, '.')
console.log(ret1);
//
console.log(ret1);
// expected output: "Breaded Mushrooms........"
const str2 = '200';
let ret2=str2.padEnd(5)
console.log(ret2);
//
console.log(ret2);
// expected output: "200 "
// #END
...
...
@@ -283,7 +285,7 @@ export function testString() : Result {
// #TEST String.padStart
const str1 = '5';
let ret = str1.padStart(2, '0')
console.log(ret);
//
console.log(ret);
// expected output: "05"
// #END
...
...
@@ -315,11 +317,11 @@ export function testString() : Result {
const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';
let ret1 = p.replace('dog', 'monkey')
console.log(ret1);
//
console.log(ret1);
// expected output: "The quick brown fox jumps over the lazy monkey. If the dog reacted, was it really lazy?"
const regex = /Dog/i;
let ret2 = p.replace(regex, 'ferret')
console.log(ret2);
//
console.log(ret2);
// expected output: "The quick brown fox jumps over the lazy ferret. If the dog reacted, was it really lazy?"
// #END
...
...
@@ -340,12 +342,12 @@ export function testString() : Result {
// 不包含捕捉组的示例
let a = "The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?"
let b = a.replace(RegExp("fox"), function (match : string, offset : number, string : string) : string {
console.log("match", match)
console.log("offset", offset)
console.log("string", string)
//
console.log("match", match)
//
console.log("offset", offset)
//
console.log("string", string)
return "cat"
})
console.log("b:", b)
//
console.log("b:", b)
// 包含一个捕获组的示例。注意,目前android仅支持最多五个捕获组
let a1 = "The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?"
...
...
@@ -356,7 +358,7 @@ export function testString() : Result {
console.log("string", string)
return "cat"
})
console.log("b1", b1)
//
console.log("b1", b1)
// #endif
// #END
...
...
@@ -364,7 +366,7 @@ export function testString() : Result {
// const REGEX_FORMAT = /[YMDHhms]o|\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a{1,2}|A{1,2}|m{1,2}|s{1,2}|Z{1,2}|SSS/g
// const formatStr = 'This is a [sample] text with [another] capture group.'
// const nextStr = formatStr.replace(REGEX_FORMAT, (match:string, p1: string|null, offset: number, string: string):string =>{
// console.log('123', p1, match)
//
//
console.log('123', p1, match)
// return p1 ?? match ?? ''
// })
// expect(nextStr).toEqual('This is a sample text with another capture group.');
...
...
@@ -379,9 +381,9 @@ export function testString() : Result {
const paragraph = 'The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?';
const regex = /[^\w\s]/g;
// #ifdef APP-ANDROID
console.log(paragraph.search(regex));
//
console.log(paragraph.search(regex));
// expected output: 43
console.log(paragraph[paragraph.search(regex)]);
//
console.log(paragraph[paragraph.search(regex)]);
// expected output: "."
// #endif
// #END
...
...
@@ -399,9 +401,9 @@ export function testString() : Result {
// #TEST String.slice
const str = 'The quick brown fox jumps over the lazy dog.';
let ret = str.slice(31)
console.log(ret);
//
console.log(ret);
// expected output: "the lazy dog."
console.log(str.slice(4, 19));
//
console.log(str.slice(4, 19));
// expected output: "quick brown fox"
// #END
...
...
@@ -430,10 +432,10 @@ export function testString() : Result {
const str = 'The quick brown fox jumps over the lazy dog.';
const words = str.split(' ');
let ret1 = words[3]
console.log(ret1);
//
console.log(ret1);
// expected output: "fox"
const chars = str.split('');
console.log(chars[8]);
//
console.log(chars[8]);
// expected output: "k"
// #END
...
...
@@ -504,9 +506,9 @@ export function testString() : Result {
// #TEST String.toLowerCase
const str1 = '中文简体 zh-CN || zh-Hans';
const str2 = 'ALPHABET';
console.log('str1'.toLowerCase());
//
console.log('str1'.toLowerCase());
// 中文简体 zh-cn || zh-hans
console.log(str2.toLowerCase());
//
console.log(str2.toLowerCase());
// "alphabet"
// #END
...
...
@@ -517,7 +519,7 @@ export function testString() : Result {
test('toUpperCase', () => {
// #TEST String.toUpperCase
const sentence = 'The quick brown fox jumps over the lazy dog.';
console.log(sentence.toUpperCase());
//
console.log(sentence.toUpperCase());
// expected output: "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG."
// #END
...
...
@@ -526,7 +528,7 @@ export function testString() : Result {
test("lastIndexOf", () => {
// #TEST String.lastIndexOf
console.log('canal'.lastIndexOf('a'))//3
//
console.log('canal'.lastIndexOf('a'))//3
// #END
expect('canal'.lastIndexOf('a')).toEqual(3);
expect('canal'.lastIndexOf('a', 2)).toEqual(1);
...
...
@@ -540,7 +542,7 @@ export function testString() : Result {
// #TEST String.substr
var str1 = "Mozilla";
let ret = str1.substring(0, 3)
console.log(ret)//"Moz"
//
console.log(ret)//"Moz"
// #END
expect(ret).toEqual("Moz");
...
...
@@ -564,7 +566,7 @@ export function testString() : Result {
// #TEST String.trim
let greeting = ' Hello world! ';
let ret = greeting.trim()
console.log(ret) //Hello world!
//
console.log(ret) //Hello world!
// #END
expect(ret).toEqual("Hello world!");
const orig : string = ' foo ';
...
...
@@ -595,7 +597,7 @@ export function testString() : Result {
test("startsWith", () => {
// #TEST String.startsWith
const str = 'hello world';
console.log(str.startsWith('hello'))//true
//
console.log(str.startsWith('hello'))//true
// #END
expect(str.startsWith('hello')).toEqual(true);
...
...
uni_modules/uts-tests/utssdk/app-harmony/arktsCode.ets
0 → 100644
浏览文件 @
21c62ed1
interface INativeCode {
getNativeStr(): string;
}
export const NativeCode = {
getNativeStr: () => {
return "harmonyos-code";
}
} as INativeCode;
\ No newline at end of file
uni_modules/uts-tests/utssdk/index.uts
浏览文件 @
21c62ed1
import { testArray } from './Array.uts'
import { testDate } from './Date.uts'
import { testString } from './String.uts'
import { testError } from './Error.uts'
import { testKeyWord } from './KeyWord.uts'
import { testJSON } from './JSON.uts'
import { testJSONLarge } from './JSON_large.uts'
import { testUTSJSONObject } from './UTSJSONObject.uts'
import { testConsole } from './console.uts'
import { testNumber } from './Number.uts'
import { testMap } from './Map.uts'
import { testSet } from './Set.uts'
import { testOperators } from './Operators.uts'
import { testMath } from './Math.uts'
import { testRegExp } from './RegExp.uts'
import { testForLoop } from './ForLoop.uts'
import { testGlobal } from './Global.uts'
import { testType } from './Type.uts'
export { Result } from './tests.uts'
import { testArrayBuffer } from './ArrayBuffer.uts'
import { testNativeCode } from './NativeCode.uts'
import { testPromise} from "./Promise.uts"
import { testEncoder} from "./TextEncoder.uts"
import { testDecoder} from "./TextDecoder.uts"
import { testArray } from './Array.uts'
import { testDate } from './Date.uts'
import { testString } from './String.uts'
import { testError } from './Error.uts'
import { testKeyWord } from './KeyWord.uts'
// #ifndef APP-HARMONY
import { testJSON } from './JSON.uts'
import { testJSONLarge } from './JSON_large.uts'
import { testUTSJSONObject } from './UTSJSONObject.uts'
// #endif
import { testConsole } from './console.uts'
import { testNumber } from './Number.uts'
import { testMap } from './Map.uts'
import { testSet } from './Set.uts'
import { testOperators } from './Operators.uts'
import { testMath } from './Math.uts'
import { testRegExp } from './RegExp.uts'
import { testForLoop } from './ForLoop.uts'
import { testGlobal } from './Global.uts'
import { testType } from './Type.uts'
export { Result } from './tests.uts'
import { testNativeCode } from './NativeCode.uts'
import { testEncoder } from "./TextEncoder.uts"
import { testDecoder } from "./TextDecoder.uts"
// #ifndef APP-HARMONY
// 相关测试例有非常多的类型推断错误暂时屏蔽,https://issuereporter.developer.huawei.com/detail/250322170103030/comment
import { testArrayBuffer } from './ArrayBuffer.uts'
// TODO 确认鸿蒙对Promise的catch参数有何要求
import { testPromise } from "./Promise.uts"
// for of、for in在鸿蒙平台支持度欠佳,或许应该借助编译器拉齐?
import { testIterator } from "./iterator.uts"
// #endif
import { testUTSXXX } from "./UTSXXX.uts"
// Proxy、Reflect、Weakmap、WeakSet 不支持
export function runTests() : UTSJSONObject {
const ArrayRes = testArray();
const DateRes = testDate();
const StringRes = testString();
const ErrorRes = testError();
const JsonRes = testJSON();
const NumberRes = testNumber();
const MapRes = testMap();
const SetRes = testSet();
const OperatorsRes = testOperators();
const MathRes = testMath();
const RegExpRes = testRegExp();
const KeyWordRes = testKeyWord();
const ForLoopRes = testForLoop();
const GlobalRes = testGlobal();
const TypeRes = testType();
const JSONLargeRes = testJSONLarge();
const consoleRes = testConsole();
const UTSJSONObjectRes = testUTSJSONObject();
const ArrayBufferRes = testArrayBuffer();
// Proxy、Reflect、Weakmap、WeakSet 不支持
export function runTests(): UTSJSONObject {
const ArrayRes = testArray();
const DateRes = testDate();
const StringRes = testString();
const ErrorRes = testError();
const NumberRes = testNumber();
const MapRes = testMap();
const SetRes = testSet();
const OperatorsRes = testOperators();
const MathRes = testMath();
const RegExpRes = testRegExp();
const KeyWordRes = testKeyWord();
const ForLoopRes = testForLoop();
const GlobalRes = testGlobal();
const TypeRes = testType();
// #ifndef APP-HARMONY
const JsonRes = testJSON();
const JSONLargeRes = testJSONLarge();
const UTSJSONObjectRes = testUTSJSONObject();
// #endif
const consoleRes = testConsole();
const NativeCodeRes = testNativeCode();
const PromiseRes = testPromise();
// #ifdef APP-ANDROID || WEB
const TextEncoderRes = testEncoder();
const TextDecoderRes = testDecoder();
// #endif
// #ifndef APP-HARMONY
const ArrayBufferRes = testArrayBuffer();
const PromiseRes = testPromise();
const IteratorRes = testIterator()
const testUTSXXXRes = testUTSXXX()
return {
Array: ArrayRes,
Date: DateRes,
String: StringRes,
Error: ErrorRes,
Json: JsonRes,
JSONLarge: JSONLargeRes,
Number: NumberRes,
Map: MapRes,
Set: SetRes,
Operators: OperatorsRes,
Math: MathRes,
RegExp: RegExpRes,
KeyWord: KeyWordRes,
ForLoop: ForLoopRes,
Global: GlobalRes,
Type: TypeRes,
console: consoleRes,
UTSJSONObject: UTSJSONObject
Res,
ArrayBuffer: ArrayBufferRes,
// #endif
const testUTSXXXRes = testUTSXXX()
return {
Array: ArrayRes,
Date: DateRes,
String: StringRes,
Error: ErrorRes,
Number: NumberRes,
Map: MapRes,
Set: SetRes,
Operators: OperatorsRes,
Math: MathRes,
RegExp: RegExpRes,
KeyWord: KeyWordRes,
ForLoop: ForLoopRes,
Global: GlobalRes,
Type: TypeRes,
console: consoleRes,
// #ifndef APP-HARMONY
ArrayBuffer: ArrayBuffer
Res,
// #endif
// #ifdef APP-ANDROID || WEB
TextEncoder: TextEncoderRes,
TextDecoder: TextDecoderRes,
// #endif
TextDecoder: TextDecoderRes,
// #endif
NativeCode: NativeCodeRes,
// #ifndef APP-HARMONY
Primise: PromiseRes,
Json: JsonRes,
JSONLarge: JSONLargeRes,
UTSJSONObject: UTSJSONObjectRes,
Iterator: IteratorRes,
UTSXXX:testUTSXXXRes,
}
// #endif
UTSXXX: testUTSXXXRes,
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录