提交 3ab9e700 编写于 作者: 杜庆泉's avatar 杜庆泉

Merge branch 'dev' into alpha

...@@ -67,29 +67,14 @@ ...@@ -67,29 +67,14 @@
}) })
}, },
gotoLottie: function () { gotoLottie: function () {
// if (checkHasLottieIntegration()) { uni.showToast({
// uni.navigateTo({ title:'暂时不支持uni-appx'
// url: '/pages/SDKIntegration/Lottie/index' })
// })
// } else {
// uni.showToast({
// icon: 'none',
// title: '需要在自定义基座中运行'
// })
// }
}, },
gotoTencentLocation: function () { gotoTencentLocation: function () {
// let ret = checkHasIntegration(); uni.showToast({
// if (!ret) { title:'暂时不支持uni-appx'
// uni.showToast({ })
// icon: 'none',
// title: '需要在自定义基座中运行'
// })
// } else {
// uni.navigateTo({
// url: '/pages/SDKIntegration/TencentLocation/TencentLocation'
// })
// }
}, },
gotoTencentMap: function () { gotoTencentMap: function () {
uni.navigateTo({ uni.navigateTo({
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
], ],
"repository": "", "repository": "",
"engines": { "engines": {
"HBuilderX": "^3.6.8" "HBuilderX": "^3.94"
}, },
"dcloudext": { "dcloudext": {
"type": "uts", "type": "uts",
......
...@@ -19,17 +19,17 @@ ...@@ -19,17 +19,17 @@
this.comp = com this.comp = com
} }
override onAnimationStart(animation: Animator | null) {} override onAnimationStart(animation: Animator) {}
override onAnimationEnd(animation: Animator | null, isReverse: Boolean) { override onAnimationEnd(animation: Animator, isReverse: Boolean) {
this.comp.$emit("bindended") this.comp.$emit("bindended")
} }
override onAnimationEnd(animation: Animator | null) {} override onAnimationEnd(animation: Animator) {}
override onAnimationCancel(animation: Animator | null) {} override onAnimationCancel(animation: Animator) {}
override onAnimationRepeat(animation: Animator | null) {} override onAnimationRepeat(animation: Animator) {}
} }
//原生提供以下属性或方法的实现 //原生提供以下属性或方法的实现
......
...@@ -63,9 +63,16 @@ export function privacyStateTest(callback : (ret : boolean, desc : string) => vo ...@@ -63,9 +63,16 @@ export function privacyStateTest(callback : (ret : boolean, desc : string) => vo
* UTSAndroid.getAppTempPath 测试示例 * UTSAndroid.getAppTempPath 测试示例
*/ */
export function getAppTempPathTest() : boolean { export function getAppTempPathTest() : boolean {
console.log(UTSAndroid.getAppTempPath())
// 1.0 的路径
if (UTSAndroid.getAppTempPath()!.contains("data/io.dcloud.HBuilder/apps/HBuilder/temp")) { if (UTSAndroid.getAppTempPath()!.contains("data/io.dcloud.HBuilder/apps/HBuilder/temp")) {
return true return true
} }
// 2.0的路径
if (UTSAndroid.getAppTempPath()!.contains("cache/temp")) {
return true
}
return false return false
} }
...@@ -74,19 +81,22 @@ export function getAppTempPathTest() : boolean { ...@@ -74,19 +81,22 @@ export function getAppTempPathTest() : boolean {
*/ */
export function typeofClickTest() : boolean { export function typeofClickTest() : boolean {
if (UTSAndroid.typeof('hello wrold') != 'string') {
if ((typeof 'hello wrold') != 'string') {
return false return false
} }
if (UTSAndroid.typeof(3.1415926) != 'number') {
if ((typeof 3.1415) != 'Double') {
return false return false
} }
if (UTSAndroid.typeof(false) != 'boolean') {
if ((typeof false) != 'boolean') {
return false return false
} }
if (UTSAndroid.typeof(true) != 'boolean') { if ((typeof true) != 'boolean') {
return false return false
} }
if (UTSAndroid.typeof(new Date()) != 'object') { if ((typeof new Date()) != 'object') {
return false return false
} }
...@@ -258,13 +268,24 @@ export function unRegLifecycle() { ...@@ -258,13 +268,24 @@ export function unRegLifecycle() {
*/ */
export function arrayPermissionFlowTest(callback : (ret : boolean, desc : string) => void) { export function arrayPermissionFlowTest(callback : (ret : boolean, desc : string) => void) {
if("io.dcloud.uniappx" != UTSAndroid.getAppContext()?.packageName && "io.dcloud.HBuilder" != UTSAndroid.getAppContext()?.packageName){
/**
* 说明是自定义基座,不支持权限测试
*/
uni.showToast({
title:'自定义基座不支持当前测试'
})
return
}
/** /**
* 同时申请日历和联系人权限 * 同时申请日历和联系人权限
*/ */
let permissionNeed = utsArrayOf("android.permission.READ_CALENDAR", "android.permission.WRITE_CALENDAR", "android.permission.READ_CONTACTS", "android.permission.WRITE_CONTACTS", "android.permission.GET_ACCOUNTS") let permissionNeed = utsArrayOf("android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.ACCESS_FINE_LOCATION", "android.permission.READ_PHONE_STATE")
if (UTSAndroid.getSystemPermissionDenied(UTSAndroid.getUniActivity()!, permissionNeed).isEmpty()) { if (UTSAndroid.getSystemPermissionDenied(UTSAndroid.getUniActivity()!, permissionNeed).isEmpty()) {
callback(false, "已具备 日历/联系人权限") callback(false, "已具备请求权限")
return; return;
} }
...@@ -299,23 +320,23 @@ export function getDeviceInfoTest():string { ...@@ -299,23 +320,23 @@ export function getDeviceInfoTest():string {
let info = '' let info = ''
info += 'isUniMp: '+UTSAndroid.isUniMp() + "\n "; info += 'isUniMp: '+UTSAndroid.isUniMp() + "\n ";
info += 'getAppDarkMode: '+UTSAndroid.getAppDarkMode() + "\n "; info += 'getAppDarkMode: '+UTSAndroid.getAppDarkMode() + "\n ";
info += 'getLanguageInfo: '+UTSAndroid.getLanguageInfo(UTSAndroid.getAppContext()!!) + "\n "; info += 'getLanguageInfo: '+ JSON.stringify(UTSAndroid.getLanguageInfo(UTSAndroid.getAppContext()!!)) + "\n ";
info += 'getWebViewInfo: '+UTSAndroid.getWebViewInfo(UTSAndroid.getAppContext()!!) + "\n "; info += 'getWebViewInfo: '+ JSON.stringify(UTSAndroid.getWebViewInfo(UTSAndroid.getAppContext()!!)) + "\n ";
info += 'getDeviceID: '+UTSAndroid.getDeviceID(UTSAndroid.getAppContext()!!) + "\n "; info += 'getDeviceID: '+UTSAndroid.getDeviceID(UTSAndroid.getAppContext()!!) + "\n ";
info += 'getOAID: '+UTSAndroid.getOAID() + "\n "; info += 'getOAID: '+UTSAndroid.getOAID() + "\n ";
info += 'getInnerVersion: '+UTSAndroid.getInnerVersion() + "\n "; info += 'getInnerVersion: '+UTSAndroid.getInnerVersion() + "\n ";
info += 'getUniCompileVersion: '+UTSAndroid.getUniCompileVersion() + "\n "; info += 'getUniCompileVersion: '+UTSAndroid.getUniCompileVersion() + "\n ";
info += 'getUniRuntimeVersion: '+UTSAndroid.getUniRuntimeVersion() + "\n "; info += 'getUniRuntimeVersion: '+UTSAndroid.getUniRuntimeVersion() + "\n ";
info += 'getAppId: '+UTSAndroid.getAppId() + "\n "; info += 'getAppId: '+UTSAndroid.getAppId() + "\n ";
info += 'getAppVersion: '+UTSAndroid.getAppVersion() + "\n "; info += 'getAppVersion: '+JSON.stringify(UTSAndroid.getAppVersion()) + "\n ";
info += 'getAppName: '+UTSAndroid.getAppName() + "\n "; info += 'getAppName: '+UTSAndroid.getAppName() + "\n ";
info += 'getOsTheme: '+UTSAndroid.getOsTheme() + "\n "; info += 'getOsTheme: '+UTSAndroid.getOsTheme() + "\n ";
info += 'getScreenInfo: '+UTSAndroid.getScreenInfo() + "\n "; info += 'getScreenInfo: '+JSON.stringify(UTSAndroid.getScreenInfo()) + "\n ";
info += 'getStatusBarHeight: '+UTSAndroid.getStatusBarHeight() + "\n "; info += 'getStatusBarHeight: '+UTSAndroid.getStatusBarHeight() + "\n ";
info += 'isTitleNViewShow: '+UTSAndroid.isTitleNViewShow() + "\n "; info += 'isTitleNViewShow: '+UTSAndroid.isTitleNViewShow() + "\n ";
info += 'isTabBarShow: '+UTSAndroid.isTabBarShow() + "\n "; info += 'isTabBarShow: '+UTSAndroid.isTabBarShow() + "\n ";
info += 'getWindowHeight: '+UTSAndroid.getWindowHeight() + "\n "; info += 'getWindowHeight: '+UTSAndroid.getWindowHeight() + "\n ";
info += 'getSafeAreaInsets: '+UTSAndroid.getSafeAreaInsets() + "\n "; info += 'getSafeAreaInsets: '+JSON.stringify(UTSAndroid.getSafeAreaInsets()) + "\n ";
info += 'isUniAppX: '+UTSAndroid.isUniAppX() + "\n "; info += 'isUniAppX: '+UTSAndroid.isUniAppX() + "\n ";
return info return info
...@@ -367,10 +388,18 @@ export function convert2AbsFullPathTest() : boolean { ...@@ -367,10 +388,18 @@ export function convert2AbsFullPathTest() : boolean {
return false; return false;
} }
if("io.dcloud.uniappx" == UTSAndroid.getAppContext()?.packageName || "io.dcloud.HBuilder" == UTSAndroid.getAppContext()?.packageName){
/**
* 只有标准基座,校验这个选项
*/
if (!resourcePath.contains("Android/data/io.dcloud")) { if (!resourcePath.contains("Android/data/io.dcloud")) {
console.log("路径转换结果错误") console.log("路径转换结果错误")
return false; return false;
} }
}
let sdcardPath = UTSAndroid.convert2AbsFullPath(resourcePath) let sdcardPath = UTSAndroid.convert2AbsFullPath(resourcePath)
console.log(sdcardPath) console.log(sdcardPath)
...@@ -390,18 +419,26 @@ export function convert2AbsFullPathTest() : boolean { ...@@ -390,18 +419,26 @@ export function convert2AbsFullPathTest() : boolean {
*/ */
export function singlePermissionFlowTest(callback : (ret : boolean, desc : string) => void) { export function singlePermissionFlowTest(callback : (ret : boolean, desc : string) => void) {
let permissionNeed = utsArrayOf("android.permission.RECORD_AUDIO") if("io.dcloud.uniappx" != UTSAndroid.getAppContext()?.packageName && "io.dcloud.HBuilder" != UTSAndroid.getAppContext()?.packageName){
/**
* 说明是自定义基座,不支持权限测试
*/
uni.showToast({
title:'自定义基座不支持当前测试'
})
return
}
let permissionNeed = utsArrayOf("android.permission.READ_PHONE_STATE")
if (UTSAndroid.getSystemPermissionDenied(UTSAndroid.getUniActivity()!, permissionNeed).isEmpty()) { if (UTSAndroid.getSystemPermissionDenied(UTSAndroid.getUniActivity()!, permissionNeed).isEmpty()) {
callback(false, "预期当前不具备 录音的权限") callback(false, "已具备权限")
return; return;
} }
UTSAndroid.requestSystemPermission(UTSAndroid.getUniActivity()!, permissionNeed, function (allRight : boolean, _grantedList : string[]) { UTSAndroid.requestSystemPermission(UTSAndroid.getUniActivity()!, permissionNeed, function (allRight : boolean, _grantedList : string[]) {
if (allRight) { if (allRight) {
// 交给目前的location 引擎,真实执行
// 测试权限api 返回值 // 测试权限api 返回值
if (!UTSAndroid.getSystemPermissionDenied(UTSAndroid.getUniActivity()!, permissionNeed).isEmpty()) { if (!UTSAndroid.getSystemPermissionDenied(UTSAndroid.getUniActivity()!, permissionNeed).isEmpty()) {
// 预期当前基座具备了读写日历的权限
callback(false, "权限请求完成,getSystemPermissionDenied 失败") callback(false, "权限请求完成,getSystemPermissionDenied 失败")
return; return;
} }
......
import { describe, test, expect, Result } from './tests.uts'
export function testGlobal(): Result {
return describe("Global", () => {
test('parseInt', () => {
expect(parseInt("123.456")).toEqual(123);
expect(parseInt("123")).toEqual(123);
expect(parseInt("123", 10)).toEqual(123);
expect(parseInt(" 123", 10)).toEqual(123);
expect(parseInt("077")).toEqual(77);
expect(parseInt("1.9")).toEqual(1);
expect(parseInt("ff", 16)).toEqual(255);
expect(parseInt("0xFF", 0)).toEqual(255);
expect(parseInt("0xFF", 16)).toEqual(255);
expect(parseInt("0xFF")).toEqual(255);
expect(parseInt("0xFF", 10)).toEqual(0);
expect(parseInt("0xF", 16)).toEqual(15);
expect(parseInt("F", 16)).toEqual(15);
expect(parseInt("021", 8)).toEqual(17);
expect(parseInt("015", 10)).toEqual(15);
expect(parseInt("15,123", 10)).toEqual(15);
expect(parseInt("FXX123.99", 16)).toEqual(15);
expect(parseInt("1111", 2)).toEqual(15);
expect(parseInt("15 * 3", 10)).toEqual(15);
expect(parseInt("15e2", 10)).toEqual(15);
expect(parseInt("15px", 10)).toEqual(15);
expect(parseInt("12", 13)).toEqual(15);
expect(parseInt("17", 8)).toEqual(15);
expect(isNaN(parseInt("a"))).toEqual(true)
expect(parseInt("a", 16)).toEqual(10)
expect(isNaN(parseInt("345", 2))).toEqual(true)
expect(isNaN(parseInt("hello"))).toEqual(true)
expect(parseInt("6.022e23")).toEqual(6)
expect(parseInt("9223372036854775807")).toEqual(9.223372036854778e+18)
expect(parseInt("9223372036854775807000")).toEqual(9.223372036854777e+21)
expect(parseInt("922337203685477580700099999999999999999999999999999999999999999999999999999999999999999")).toEqual(9.223372036854776e+86)
expect(parseInt("50") / 100).toEqualNumber(0.5);
expect(parseInt("500") / 100).toEqualNumber(5);
})
test('parseFloat', () => {
expect(parseFloat("11.20")).toEqual(11.2);
expect(parseFloat("3.14")).toEqual(3.14);
expect(parseFloat(" 3.14 ")).toEqual(3.14);
expect(parseFloat("314e-2")).toEqual(3.14);
expect(parseFloat("0.0314E+2")).toEqual(3.14);
expect(parseFloat("3.14some non-digit characters")).toEqual(3.14);
expect(parseFloat("100") / 50).toEqualNumber(2);
expect(parseFloat("105") / 50).toEqual(2.1);
})
test('encodeURI', () => {
expect(encodeURI("你好")).toEqual('%E4%BD%A0%E5%A5%BD')
expect(encodeURI("你好+22")).toEqual('%E4%BD%A0%E5%A5%BD+22')
expect(encodeURI("你;/=好+22")).toEqual('%E4%BD%A0;/=%E5%A5%BD+22')
expect(encodeURI("https://demo.dcloud.net.cn/mock/最新/12")).toEqual('https://demo.dcloud.net.cn/mock/%E6%9C%80%E6%96%B0/12')
})
test('decodeURI', () => {
expect(decodeURI('%E4%BD%A0%E5%A5%BD')).toEqual('你好')
expect(decodeURI("%E4%BD%A0%E5%A5%BD+22")).toEqual('你好+22')
expect(decodeURI("%E4%BD%A0;/=%E5%A5%BD+22")).toEqual('你;/=好+22')
expect(decodeURI("https://demo.dcloud.net.cn/mock/%E6%9C%80%E6%96%B0/12")).toEqual('https://demo.dcloud.net.cn/mock/最新/12')
})
test('encodeURIComponent', () => {
expect(encodeURIComponent("你好")).toEqual('%E4%BD%A0%E5%A5%BD')
expect(encodeURIComponent("你好+22")).toEqual('%E4%BD%A0%E5%A5%BD%2B22')
expect(encodeURIComponent("你;/=好+22")).toEqual('%E4%BD%A0%3B%2F%3D%E5%A5%BD%2B22')
expect(encodeURIComponent("https://demo.dcloud.net.cn/mock/最新/12")).toEqual('https%3A%2F%2Fdemo.dcloud.net.cn%2Fmock%2F%E6%9C%80%E6%96%B0%2F12')
})
test('decodeURIComponent', () => {
expect(decodeURIComponent('%E4%BD%A0%E5%A5%BD')).toEqual('你好')
expect(decodeURIComponent('%E4%BD%A0%E5%A5%BD%2B22')).toEqual('你好+22')
expect(decodeURIComponent('%E4%BD%A0%3B%2F%3D%E5%A5%BD%2B22')).toEqual('你;/=好+22')
expect(decodeURIComponent("https://demo.dcloud.net.cn/mock/%E6%9C%80%E6%96%B0/12")).toEqual('https://demo.dcloud.net.cn/mock/最新/12')
})
})
}
...@@ -5,37 +5,67 @@ class User{ ...@@ -5,37 +5,67 @@ class User{
age:number = 0 age:number = 0
} }
export function testKeyWord(): Result { const passcode = "secret passcode";
return describe("KeyWord", () => { class Parent {
private _name: string = ""; // private是私有的,外部不能访问
get name(): string { // 读取name会触发此拦截器
console.log("start to get parent.name");
return this._name;
}
set name(newName: string) { // 给name赋值会触发此拦截器
console.log("start to set parent.name");
if (passcode == "secret passcode") { // 校验是否有权修改name的值,这里的条件可以修改以方便测试
this._name = newName;
} else {
console.log("Error: set parent.name fail");
}
}
// 静态属性和方法
static age: number = 30
static run(): string {
console.log("this is a static method")
return "static method"
}
// readonly
readonly address: string = ""
weight: number = 80
// constructor
constructor(weight: number) {
console.log("开始实例化")
this.weight = weight
}
// 实例方法
eat(): string {
console.log("this is parent")
return "parent instance method"
}
test('encodeURI', () => { }
expect(encodeURI("你好")).toEqual('%E4%BD%A0%E5%A5%BD')
expect(encodeURI("你好+22")).toEqual('%E4%BD%A0%E5%A5%BD+22')
expect(encodeURI("你;/=好+22")).toEqual('%E4%BD%A0;/=%E5%A5%BD+22')
expect(encodeURI("https://demo.dcloud.net.cn/mock/最新/12")).toEqual('https://demo.dcloud.net.cn/mock/%E6%9C%80%E6%96%B0/12')
})
test('decodeURI', () => { class ChildrenTest extends Parent {
expect(decodeURI('%E4%BD%A0%E5%A5%BD')).toEqual('你好')
expect(decodeURI("%E4%BD%A0%E5%A5%BD+22")).toEqual('你好+22')
expect(decodeURI("%E4%BD%A0;/=%E5%A5%BD+22")).toEqual('你;/=好+22')
expect(decodeURI("https://demo.dcloud.net.cn/mock/%E6%9C%80%E6%96%B0/12")).toEqual('https://demo.dcloud.net.cn/mock/最新/12')
})
test('encodeURIComponent', () => { // override constructor(weight: number) {
expect(encodeURIComponent("你好")).toEqual('%E4%BD%A0%E5%A5%BD') // super(weight)
expect(encodeURIComponent("你好+22")).toEqual('%E4%BD%A0%E5%A5%BD%2B22') // }
expect(encodeURIComponent("你;/=好+22")).toEqual('%E4%BD%A0%3B%2F%3D%E5%A5%BD%2B22')
expect(encodeURIComponent("https://demo.dcloud.net.cn/mock/最新/12")).toEqual('https%3A%2F%2Fdemo.dcloud.net.cn%2Fmock%2F%E6%9C%80%E6%96%B0%2F12')
})
test('decodeURIComponent', () => { override eat(): string {
expect(decodeURIComponent('%E4%BD%A0%E5%A5%BD')).toEqual('你好') super.eat()
expect(decodeURIComponent('%E4%BD%A0%E5%A5%BD%2B22')).toEqual('你好+22') return "children instance method"
expect(decodeURIComponent('%E4%BD%A0%3B%2F%3D%E5%A5%BD%2B22')).toEqual('你;/=好+22') }
expect(decodeURIComponent("https://demo.dcloud.net.cn/mock/%E6%9C%80%E6%96%B0/12")).toEqual('https://demo.dcloud.net.cn/mock/最新/12')
})
// swift 中不能重写父类的存储属性,只能重写父类的计算的属性(本质上是重写计算属性的get set方法)
// #ifndef APP-IOS
override weight = 8
// #endif
}
export function testKeyWord(): Result {
return describe("KeyWord", () => {
test('new', () => { test('new', () => {
let new1 = new User() let new1 = new User()
...@@ -91,6 +121,16 @@ export function testKeyWord(): Result { ...@@ -91,6 +121,16 @@ export function testKeyWord(): Result {
expect(Array.isArray([1,2,3])).toEqual(true) expect(Array.isArray([1,2,3])).toEqual(true)
}) })
test('class', () => {
let p = new Parent(20)
p.name = "tom" // 会打印"start to set person.name"
console.log(p.name); // 先打印"start to get person.name",然后打印"tom"
expect(Parent.age).toEqual(30)
expect(Parent.run()).toEqual("static method")
expect(p.eat()).toEqual("parent instance method")
// let c = new ChildrenTest(0)
// expect(c.eat()).toEqual("children instance method")
})
}) })
} }
...@@ -15,6 +15,17 @@ export class Matchers<T> { ...@@ -15,6 +15,17 @@ export class Matchers<T> {
NSException(name = NSExceptionName.internalInconsistencyException, reason = format(expected, this.actual)).raise() NSException(name = NSExceptionName.internalInconsistencyException, reason = format(expected, this.actual)).raise()
// #endif // #endif
} }
toEqualNumber(expected: T) {
// #ifndef APP-IOS
if (expected == this.actual) {
return
}
// #endif
// #ifdef APP-IOS
this.toEqual(expected)
// #endif
}
} }
/** /**
* 数值对比器 * 数值对比器
......
...@@ -21,40 +21,23 @@ export function testNumber(): Result { ...@@ -21,40 +21,23 @@ export function testNumber(): Result {
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))
})
test('parseInt', () => { expect(123456.789.toFixed(2)).toEqual("123456.79");
expect(parseInt("123.456")).toEqual(123); expect(12345600123.789123.toFixed(2)).toEqual("12345600123.79");
expect(parseInt("123")).toEqual(123); expect((-123456.789).toFixed(5)).toEqual("-123456.78900");
expect(parseInt("123", 10)).toEqual(123); expect(parseFloat("16688995566.369").toFixed(3)).toEqual("16688995566.369");
expect(parseInt(" 123", 10)).toEqual(123); // #ifndef APP-IOS
expect(parseInt("077")).toEqual(77); // android 专有数据类型
expect(parseInt("1.9")).toEqual(1); let a1 = 56
expect(parseInt("ff", 16)).toEqual(255); let a2 = -122
expect(parseInt("0xFF", 0)).toEqual(255); expect(a1.toByte().toFixed(2)).toEqual("56.00");
expect(parseInt("0xFF", 16)).toEqual(255); expect(a2.toByte().toFixed(2)).toEqual("-122.00");
expect(parseInt("0xFF")).toEqual(255);
expect(parseInt("0xFF", 10)).toEqual(0); expect(a1.toShort().toFixed(5)).toEqual("56.00000");
expect(parseInt("0xF", 16)).toEqual(15); expect(a2.toShort().toFixed(5)).toEqual("-122.00000");
expect(parseInt("F", 16)).toEqual(15);
expect(parseInt("021", 8)).toEqual(17); // #endif
expect(parseInt("015", 10)).toEqual(15);
expect(parseInt("15,123", 10)).toEqual(15);
expect(parseInt("FXX123.99", 16)).toEqual(15);
expect(parseInt("1111", 2)).toEqual(15);
expect(parseInt("15 * 3", 10)).toEqual(15);
expect(parseInt("15e2", 10)).toEqual(15);
expect(parseInt("15px", 10)).toEqual(15);
expect(parseInt("12", 13)).toEqual(15);
expect(parseInt("17", 8)).toEqual(15);
})
test('parseFloat', () => {
expect(parseFloat("11.20")).toEqual(11.2);
expect(parseFloat("3.14")).toEqual(3.14);
expect(parseFloat(" 3.14 ")).toEqual(3.14);
expect(parseFloat("314e-2")).toEqual(3.14);
expect(parseFloat("0.0314E+2")).toEqual(3.14);
expect(parseFloat("3.14some non-digit characters")).toEqual(3.14);
}) })
test('isFinite', () => { test('isFinite', () => {
......
...@@ -47,6 +47,9 @@ export function testOperators(): Result { ...@@ -47,6 +47,9 @@ export function testOperators(): Result {
const a: number = 5; // 00000000000000000000000000000101 const a: number = 5; // 00000000000000000000000000000101
const b: number = 3; // 00000000000000000000000000000011 const b: number = 3; // 00000000000000000000000000000011
expect(a & b).toEqual(1); // 00000000000000000000000000000001 expect(a & b).toEqual(1); // 00000000000000000000000000000001
//expect(16677889900 & 10).toEqual(8);
//expect(888999555666 & 23.567).toEqual(18);
}) })
test('&=', () => { test('&=', () => {
let a = 5; // 00000000000000000000000000000101 let a = 5; // 00000000000000000000000000000101
...@@ -58,11 +61,14 @@ export function testOperators(): Result { ...@@ -58,11 +61,14 @@ export function testOperators(): Result {
const b: number = -3; // 11111111111111111111111111111101 const b: number = -3; // 11111111111111111111111111111101
expect(~a).toEqual(-6); // 11111111111111111111111111111010 expect(~a).toEqual(-6); // 11111111111111111111111111111010
expect(~b).toEqual(2); // 00000000000000000000000000000010 expect(~b).toEqual(2); // 00000000000000000000000000000010
}) })
test('|', () => { test('|', () => {
const a: number = 5; // 00000000000000000000000000000101 const a: number = 5; // 00000000000000000000000000000101
const b: number = 3; // 00000000000000000000000000000011 const b: number = 3; // 00000000000000000000000000000011
expect(a | b).toEqual(7); // 00000000000000000000000000000111 expect(a | b).toEqual(7); // 00000000000000000000000000000111
//expect(16677889901 | 10).toEqual(-501979281);
//expect(888999555661 | 23.567).toEqual(-58674593);
}) })
test('|=', () => { test('|=', () => {
let a = 5; // 00000000000000000000000000000101 let a = 5; // 00000000000000000000000000000101
...@@ -73,6 +79,8 @@ export function testOperators(): Result { ...@@ -73,6 +79,8 @@ export function testOperators(): Result {
const a: number = 5; // 00000000000000000000000000000101 const a: number = 5; // 00000000000000000000000000000101
const b: number = 3; // 00000000000000000000000000000011 const b: number = 3; // 00000000000000000000000000000011
expect(a ^ b).toEqual(6); // 00000000000000000000000000000110 expect(a ^ b).toEqual(6); // 00000000000000000000000000000110
//expect(16677889902 ^ 10).toEqual(-501979292);
//expect(888999555662 ^ 23.567).toEqual(-58674599);
}) })
test('^=', () => { test('^=', () => {
let a = 5; // 00000000000000000000000000000101 let a = 5; // 00000000000000000000000000000101
...@@ -91,25 +99,30 @@ export function testOperators(): Result { ...@@ -91,25 +99,30 @@ export function testOperators(): Result {
function divide (a: number, b: number): number { function divide (a: number, b: number): number {
return a / b return a / b
} }
expect(divide(10, 5)).toEqual(2);
expect(divide(-10, -5)).toEqual(2); expect(divide(10, 5)).toEqualNumber(2);
expect(divide(10, -5)).toEqual(-2); expect(divide(-10, -5)).toEqualNumber(2);
expect(divide(-10, 5)).toEqual(-2); expect(divide(10, -5)).toEqualNumber(-2);
expect(divide(0.1, 0.3)).toEqual(0.33333333333333337); expect(divide(-10, 5)).toEqualNumber(-2);
expect(divide(0.3, 0.1)).toEqual(2.9999999999999996); expect(divide(0.1, 0.3)).toEqualNumber(0.33333333333333337);
expect(divide(0.3, 0.1)).toEqualNumber(2.9999999999999996);
expectNumber(divide(1.5, 0.5)).toEqualDouble(3); expectNumber(divide(1.5, 0.5)).toEqualDouble(3);
expect(divide(3, 2)).toEqual(1.5); expect(divide(3, 2)).toEqualNumber(1.5);
// 暂不支持字面量 // 暂不支持字面量
// expect(3 / 2).toEqual(1.5); // expect(3 / 2).toEqual(1.5);
expect(divide(10, 3)).toEqual(3.3333333333333335); expect(divide(10, 3)).toEqualNumber(3.3333333333333335);
expect(divide(3, 10)).toEqual(0.3); expect(divide(3, 10)).toEqualNumber(0.3);
expect(divide(1, 3)).toEqual(0.3333333333333333); expect(divide(1, 3)).toEqualNumber(0.3333333333333333);
expect(divide(1000000, 2000000)).toEqual(0.5); expect(divide(1000000, 2000000)).toEqualNumber(0.5);
// kotlin java.lang.ArithmeticException: divide by zero // kotlin java.lang.ArithmeticException: divide by zero
// swift 返回 inf // swift 返回 inf
// web 返回 Infinity // web 返回 Infinity
// todo 统一处理 // todo 统一处理
// expect(divide(1, 0)).toEqual(); // expect(divide(1, 0)).toEqual();
expect(divide(16788990011, 5)).toEqualNumber(3357798002.2);
expect(divide(16788990015, 5)).toEqualNumber(3357798003);
expectNumber(divide(16788990015, 10088990000)).toEqualDouble(1.6640902622561822);
}) })
test('/=', () => { test('/=', () => {
let a:Number = 3; let a:Number = 3;
...@@ -251,6 +264,8 @@ export function testOperators(): Result { ...@@ -251,6 +264,8 @@ export function testOperators(): Result {
const c: number = -5; // 11111111111111111111111111111011 const c: number = -5; // 11111111111111111111111111111011
expect(a >> b).toEqual(1); // 00000000000000000000000000000001 expect(a >> b).toEqual(1); // 00000000000000000000000000000001
expect(c >> b).toEqual(-2); // 11111111111111111111111111111110 expect(c >> b).toEqual(-2); // 11111111111111111111111111111110
//expect(16677889900 >> 10).toEqual(-490215);
//expect(888999555666 >> 23.567).toEqual(-7);
}) })
test('>>=', () => { test('>>=', () => {
let a = 5; // 00000000000000000000000000000101 let a = 5; // 00000000000000000000000000000101
......
...@@ -206,6 +206,10 @@ export function testString(): Result { ...@@ -206,6 +206,10 @@ export function testString(): Result {
expect(str6).toEqual("The morning is upon us."); expect(str6).toEqual("The morning is upon us.");
expect("".slice()).toEqual(""); expect("".slice()).toEqual("");
expect("abcdefg".slice(-1)).toEqual("g");
expect("abcdefg".slice(-1,-2)).toEqual("");
}) })
test('split', () => { test('split', () => {
const str = 'The quick brown fox jumps over the lazy dog.'; const str = 'The quick brown fox jumps over the lazy dog.';
......
...@@ -11,6 +11,7 @@ import { testOperators } from './Operators.uts' ...@@ -11,6 +11,7 @@ import { testOperators } from './Operators.uts'
import { testMath } from './Math.uts' import { testMath } from './Math.uts'
import { testRegExp } from './RegExp.uts' import { testRegExp } from './RegExp.uts'
import { testForLoop } from './ForLoop.uts' import { testForLoop } from './ForLoop.uts'
import { testGlobal } from './Global.uts'
export { Result } from './tests.uts' export { Result } from './tests.uts'
// Promise、Proxy、Reflect、Weakmap、WeakSet 不支持 // Promise、Proxy、Reflect、Weakmap、WeakSet 不支持
...@@ -28,6 +29,7 @@ export function runTests() : UTSJSONObject { ...@@ -28,6 +29,7 @@ export function runTests() : UTSJSONObject {
const RegExpRes = testRegExp(); const RegExpRes = testRegExp();
const KeyWordRes = testKeyWord(); const KeyWordRes = testKeyWord();
const ForLoopRes = testForLoop(); const ForLoopRes = testForLoop();
const GlobalRes = testGlobal();
return { return {
Array: ArrayRes, Array: ArrayRes,
...@@ -43,5 +45,6 @@ export function runTests() : UTSJSONObject { ...@@ -43,5 +45,6 @@ export function runTests() : UTSJSONObject {
RegExp: RegExpRes, RegExp: RegExpRes,
KeyWord: KeyWordRes, KeyWord: KeyWordRes,
ForLoop: ForLoopRes, ForLoop: ForLoopRes,
Global: GlobalRes,
} }
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册