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

wip: 适配鸿蒙app

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