diff --git a/pages/SDKIntegration/SDKIntegration.uvue b/pages/SDKIntegration/SDKIntegration.uvue index 4f8b5d60cdff33c93de98a3805fbdfd8f4e3c675..480f5b2317de29228c32d442e23a1c1d9ba3a1f6 100644 --- a/pages/SDKIntegration/SDKIntegration.uvue +++ b/pages/SDKIntegration/SDKIntegration.uvue @@ -67,29 +67,14 @@ }) }, gotoLottie: function () { - // if (checkHasLottieIntegration()) { - // uni.navigateTo({ - // url: '/pages/SDKIntegration/Lottie/index' - // }) - // } else { - // uni.showToast({ - // icon: 'none', - // title: '需要在自定义基座中运行' - // }) - // } + uni.showToast({ + title:'暂时不支持uni-appx' + }) }, gotoTencentLocation: function () { - // let ret = checkHasIntegration(); - // if (!ret) { - // uni.showToast({ - // icon: 'none', - // title: '需要在自定义基座中运行' - // }) - // } else { - // uni.navigateTo({ - // url: '/pages/SDKIntegration/TencentLocation/TencentLocation' - // }) - // } + uni.showToast({ + title:'暂时不支持uni-appx' + }) }, gotoTencentMap: function () { uni.navigateTo({ diff --git a/uni_modules/uts-animation-view/package.json b/uni_modules/uts-animation-view/package.json index 75f987980ac1aa4dab9ddd5de616e54dee38f648..96aae113bcd2f20e2815d226b9035e84bbd3a395 100644 --- a/uni_modules/uts-animation-view/package.json +++ b/uni_modules/uts-animation-view/package.json @@ -8,7 +8,7 @@ ], "repository": "", "engines": { - "HBuilderX": "^3.6.8" + "HBuilderX": "^3.94" }, "dcloudext": { "type": "uts", diff --git a/uni_modules/uts-animation-view/utssdk/app-android/index.vue b/uni_modules/uts-animation-view/utssdk/app-android/index.vue index e68dc12b8e69854810a71e3c8709821dd0d6d0c7..a298254b1fa8abde48f0a7edf7ed67dbf2d5f2cf 100644 --- a/uni_modules/uts-animation-view/utssdk/app-android/index.vue +++ b/uni_modules/uts-animation-view/utssdk/app-android/index.vue @@ -19,17 +19,17 @@ 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") } - 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) {} } //原生提供以下属性或方法的实现 diff --git a/uni_modules/uts-platform-api/utssdk/app-android/index.uts b/uni_modules/uts-platform-api/utssdk/app-android/index.uts index ef774bcf9cb7d6c88471c2eaefa63a111c994776..2b5db4b6ea045e0def5fdb06514aa0f831ea45e6 100644 --- a/uni_modules/uts-platform-api/utssdk/app-android/index.uts +++ b/uni_modules/uts-platform-api/utssdk/app-android/index.uts @@ -63,9 +63,16 @@ export function privacyStateTest(callback : (ret : boolean, desc : string) => vo * UTSAndroid.getAppTempPath 测试示例 */ export function getAppTempPathTest() : boolean { + console.log(UTSAndroid.getAppTempPath()) + // 1.0 的路径 if (UTSAndroid.getAppTempPath()!.contains("data/io.dcloud.HBuilder/apps/HBuilder/temp")) { return true } + // 2.0的路径 + if (UTSAndroid.getAppTempPath()!.contains("cache/temp")) { + return true + } + return false } @@ -73,20 +80,23 @@ export function getAppTempPathTest() : boolean { * UTSAndroid.typeof 测试示例 */ export function typeofClickTest() : boolean { + - if (UTSAndroid.typeof('hello wrold') != 'string') { + if ((typeof 'hello wrold') != 'string') { return false } - if (UTSAndroid.typeof(3.1415926) != 'number') { + + if ((typeof 3.1415) != 'Double') { return false } - if (UTSAndroid.typeof(false) != 'boolean') { + + if ((typeof false) != 'boolean') { return false } - if (UTSAndroid.typeof(true) != 'boolean') { + if ((typeof true) != 'boolean') { return false } - if (UTSAndroid.typeof(new Date()) != 'object') { + if ((typeof new Date()) != 'object') { return false } @@ -258,13 +268,24 @@ export function unRegLifecycle() { */ 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()) { - callback(false, "已具备 日历/联系人权限") + callback(false, "已具备请求权限") return; } @@ -299,23 +320,23 @@ export function getDeviceInfoTest():string { let info = '' info += 'isUniMp: '+UTSAndroid.isUniMp() + "\n "; info += 'getAppDarkMode: '+UTSAndroid.getAppDarkMode() + "\n "; - info += 'getLanguageInfo: '+UTSAndroid.getLanguageInfo(UTSAndroid.getAppContext()!!) + "\n "; - info += 'getWebViewInfo: '+UTSAndroid.getWebViewInfo(UTSAndroid.getAppContext()!!) + "\n "; + info += 'getLanguageInfo: '+ JSON.stringify(UTSAndroid.getLanguageInfo(UTSAndroid.getAppContext()!!)) + "\n "; + info += 'getWebViewInfo: '+ JSON.stringify(UTSAndroid.getWebViewInfo(UTSAndroid.getAppContext()!!)) + "\n "; info += 'getDeviceID: '+UTSAndroid.getDeviceID(UTSAndroid.getAppContext()!!) + "\n "; info += 'getOAID: '+UTSAndroid.getOAID() + "\n "; info += 'getInnerVersion: '+UTSAndroid.getInnerVersion() + "\n "; info += 'getUniCompileVersion: '+UTSAndroid.getUniCompileVersion() + "\n "; info += 'getUniRuntimeVersion: '+UTSAndroid.getUniRuntimeVersion() + "\n "; info += 'getAppId: '+UTSAndroid.getAppId() + "\n "; - info += 'getAppVersion: '+UTSAndroid.getAppVersion() + "\n "; + info += 'getAppVersion: '+JSON.stringify(UTSAndroid.getAppVersion()) + "\n "; info += 'getAppName: '+UTSAndroid.getAppName() + "\n "; info += 'getOsTheme: '+UTSAndroid.getOsTheme() + "\n "; - info += 'getScreenInfo: '+UTSAndroid.getScreenInfo() + "\n "; + info += 'getScreenInfo: '+JSON.stringify(UTSAndroid.getScreenInfo()) + "\n "; info += 'getStatusBarHeight: '+UTSAndroid.getStatusBarHeight() + "\n "; info += 'isTitleNViewShow: '+UTSAndroid.isTitleNViewShow() + "\n "; info += 'isTabBarShow: '+UTSAndroid.isTabBarShow() + "\n "; info += 'getWindowHeight: '+UTSAndroid.getWindowHeight() + "\n "; - info += 'getSafeAreaInsets: '+UTSAndroid.getSafeAreaInsets() + "\n "; + info += 'getSafeAreaInsets: '+JSON.stringify(UTSAndroid.getSafeAreaInsets()) + "\n "; info += 'isUniAppX: '+UTSAndroid.isUniAppX() + "\n "; return info @@ -367,10 +388,18 @@ export function convert2AbsFullPathTest() : boolean { return false; } - if (!resourcePath.contains("Android/data/io.dcloud")) { - console.log("路径转换结果错误") - return false; + + if("io.dcloud.uniappx" == UTSAndroid.getAppContext()?.packageName || "io.dcloud.HBuilder" == UTSAndroid.getAppContext()?.packageName){ + /** + * 只有标准基座,校验这个选项 + */ + if (!resourcePath.contains("Android/data/io.dcloud")) { + console.log("路径转换结果错误") + return false; + } } + + let sdcardPath = UTSAndroid.convert2AbsFullPath(resourcePath) console.log(sdcardPath) @@ -389,19 +418,27 @@ export function convert2AbsFullPathTest() : boolean { * 单个权限,申请流程测试 */ export function singlePermissionFlowTest(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.RECORD_AUDIO") + let permissionNeed = utsArrayOf("android.permission.READ_PHONE_STATE") if (UTSAndroid.getSystemPermissionDenied(UTSAndroid.getUniActivity()!, permissionNeed).isEmpty()) { - callback(false, "预期当前不具备 录音的权限") + callback(false, "已具备权限") return; } UTSAndroid.requestSystemPermission(UTSAndroid.getUniActivity()!, permissionNeed, function (allRight : boolean, _grantedList : string[]) { if (allRight) { - // 交给目前的location 引擎,真实执行 // 测试权限api 返回值 if (!UTSAndroid.getSystemPermissionDenied(UTSAndroid.getUniActivity()!, permissionNeed).isEmpty()) { - // 预期当前基座具备了读写日历的权限 callback(false, "权限请求完成,getSystemPermissionDenied 失败") return; } diff --git a/uni_modules/uts-tests/utssdk/Global.uts b/uni_modules/uts-tests/utssdk/Global.uts new file mode 100644 index 0000000000000000000000000000000000000000..92e135e8a511283eb02a0606836c8994a72528e3 --- /dev/null +++ b/uni_modules/uts-tests/utssdk/Global.uts @@ -0,0 +1,84 @@ +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') + }) + + }) +} diff --git a/uni_modules/uts-tests/utssdk/KeyWord.uts b/uni_modules/uts-tests/utssdk/KeyWord.uts index cf46ac1373f37335dc1eeae6a49c71a6e012d0d3..eb552e482c73a5c790dd88fa0dd9f7a682e3b5e2 100644 --- a/uni_modules/uts-tests/utssdk/KeyWord.uts +++ b/uni_modules/uts-tests/utssdk/KeyWord.uts @@ -5,38 +5,68 @@ class User{ age:number = 0 } +const passcode = "secret passcode"; +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" + } + +} + +class ChildrenTest extends Parent { + + // override constructor(weight: number) { + // super(weight) + // } + + override eat(): string { + super.eat() + return "children instance method" + } + + // swift 中不能重写父类的存储属性,只能重写父类的计算的属性(本质上是重写计算属性的get set方法) + // #ifndef APP-IOS + override weight = 8 + // #endif +} + export function testKeyWord(): Result { return describe("KeyWord", () => { - 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') - }) - - test('new', () => { let new1 = new User() // expect(JSON.stringify(new1)).toEqual('{"age":0,"name":""}') @@ -91,6 +121,16 @@ export function testKeyWord(): Result { 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") + }) }) } diff --git a/uni_modules/uts-tests/utssdk/Matchers.uts b/uni_modules/uts-tests/utssdk/Matchers.uts index 4bb39d1aa28ac9898604010761efbe1d4a2329b6..61a24e5173626da882f0f866a0994625df1413cb 100644 --- a/uni_modules/uts-tests/utssdk/Matchers.uts +++ b/uni_modules/uts-tests/utssdk/Matchers.uts @@ -15,6 +15,17 @@ export class Matchers { NSException(name = NSExceptionName.internalInconsistencyException, reason = format(expected, this.actual)).raise() // #endif } + + toEqualNumber(expected: T) { + // #ifndef APP-IOS + if (expected == this.actual) { + return + } + // #endif + // #ifdef APP-IOS + this.toEqual(expected) + // #endif + } } /** * 数值对比器 diff --git a/uni_modules/uts-tests/utssdk/Number.uts b/uni_modules/uts-tests/utssdk/Number.uts index cdbc18a0392e4716f99b1db2ef8df7f6067ee42a..a487b7506c35eef505c9c1eca0e7663471a0bcc5 100644 --- a/uni_modules/uts-tests/utssdk/Number.uts +++ b/uni_modules/uts-tests/utssdk/Number.uts @@ -21,42 +21,25 @@ export function testNumber(): Result { let obj = {"id":"3be2c600-894c-4231-aa56-82fd989cc961","result":{"result":[num1, num2, num3]}} console.log(JSON.stringify(obj)) + + expect(123456.789.toFixed(2)).toEqual("123456.79"); + expect(12345600123.789123.toFixed(2)).toEqual("12345600123.79"); + expect((-123456.789).toFixed(5)).toEqual("-123456.78900"); + expect(parseFloat("16688995566.369").toFixed(3)).toEqual("16688995566.369"); + // #ifndef APP-IOS + // android 专有数据类型 + let a1 = 56 + let a2 = -122 + expect(a1.toByte().toFixed(2)).toEqual("56.00"); + expect(a2.toByte().toFixed(2)).toEqual("-122.00"); + + expect(a1.toShort().toFixed(5)).toEqual("56.00000"); + expect(a2.toShort().toFixed(5)).toEqual("-122.00000"); + + // #endif + }) - 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); - }) - 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', () => { expect(isFinite(1000 / 1)).toEqual(true); expect(isFinite(910)).toEqual(true); diff --git a/uni_modules/uts-tests/utssdk/Operators.uts b/uni_modules/uts-tests/utssdk/Operators.uts index 89b92207d93a0b7314fae3970dd521a98f9c70e8..c279f3729916f792ddbc949bdfcf58c37d135196 100644 --- a/uni_modules/uts-tests/utssdk/Operators.uts +++ b/uni_modules/uts-tests/utssdk/Operators.uts @@ -47,6 +47,9 @@ export function testOperators(): Result { const a: number = 5; // 00000000000000000000000000000101 const b: number = 3; // 00000000000000000000000000000011 expect(a & b).toEqual(1); // 00000000000000000000000000000001 + + //expect(16677889900 & 10).toEqual(8); + //expect(888999555666 & 23.567).toEqual(18); }) test('&=', () => { let a = 5; // 00000000000000000000000000000101 @@ -58,11 +61,14 @@ export function testOperators(): Result { const b: number = -3; // 11111111111111111111111111111101 expect(~a).toEqual(-6); // 11111111111111111111111111111010 expect(~b).toEqual(2); // 00000000000000000000000000000010 + }) test('|', () => { const a: number = 5; // 00000000000000000000000000000101 const b: number = 3; // 00000000000000000000000000000011 expect(a | b).toEqual(7); // 00000000000000000000000000000111 + //expect(16677889901 | 10).toEqual(-501979281); + //expect(888999555661 | 23.567).toEqual(-58674593); }) test('|=', () => { let a = 5; // 00000000000000000000000000000101 @@ -73,6 +79,8 @@ export function testOperators(): Result { const a: number = 5; // 00000000000000000000000000000101 const b: number = 3; // 00000000000000000000000000000011 expect(a ^ b).toEqual(6); // 00000000000000000000000000000110 + //expect(16677889902 ^ 10).toEqual(-501979292); + //expect(888999555662 ^ 23.567).toEqual(-58674599); }) test('^=', () => { let a = 5; // 00000000000000000000000000000101 @@ -91,25 +99,30 @@ export function testOperators(): Result { function divide (a: number, b: number): number { return a / b } - expect(divide(10, 5)).toEqual(2); - expect(divide(-10, -5)).toEqual(2); - expect(divide(10, -5)).toEqual(-2); - expect(divide(-10, 5)).toEqual(-2); - expect(divide(0.1, 0.3)).toEqual(0.33333333333333337); - expect(divide(0.3, 0.1)).toEqual(2.9999999999999996); + + expect(divide(10, 5)).toEqualNumber(2); + expect(divide(-10, -5)).toEqualNumber(2); + expect(divide(10, -5)).toEqualNumber(-2); + expect(divide(-10, 5)).toEqualNumber(-2); + 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); - expect(divide(3, 2)).toEqual(1.5); + expect(divide(3, 2)).toEqualNumber(1.5); // 暂不支持字面量 // expect(3 / 2).toEqual(1.5); - expect(divide(10, 3)).toEqual(3.3333333333333335); - expect(divide(3, 10)).toEqual(0.3); - expect(divide(1, 3)).toEqual(0.3333333333333333); - expect(divide(1000000, 2000000)).toEqual(0.5); + expect(divide(10, 3)).toEqualNumber(3.3333333333333335); + expect(divide(3, 10)).toEqualNumber(0.3); + expect(divide(1, 3)).toEqualNumber(0.3333333333333333); + expect(divide(1000000, 2000000)).toEqualNumber(0.5); // kotlin java.lang.ArithmeticException: divide by zero // swift 返回 inf // web 返回 Infinity // todo 统一处理 // 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('/=', () => { let a:Number = 3; @@ -251,6 +264,8 @@ export function testOperators(): Result { const c: number = -5; // 11111111111111111111111111111011 expect(a >> b).toEqual(1); // 00000000000000000000000000000001 expect(c >> b).toEqual(-2); // 11111111111111111111111111111110 + //expect(16677889900 >> 10).toEqual(-490215); + //expect(888999555666 >> 23.567).toEqual(-7); }) test('>>=', () => { let a = 5; // 00000000000000000000000000000101 diff --git a/uni_modules/uts-tests/utssdk/String.uts b/uni_modules/uts-tests/utssdk/String.uts index e433dd790cf217bb14334716de67bbe67cbf4af9..73112605f74c7d848f926a759e180c6c0bd6235d 100644 --- a/uni_modules/uts-tests/utssdk/String.uts +++ b/uni_modules/uts-tests/utssdk/String.uts @@ -206,6 +206,10 @@ export function testString(): Result { expect(str6).toEqual("The morning is upon us."); expect("".slice()).toEqual(""); + + expect("abcdefg".slice(-1)).toEqual("g"); + expect("abcdefg".slice(-1,-2)).toEqual(""); + }) test('split', () => { const str = 'The quick brown fox jumps over the lazy dog.'; diff --git a/uni_modules/uts-tests/utssdk/index.uts b/uni_modules/uts-tests/utssdk/index.uts index 8ca931bf0c8bd1343a68214af559077a7b15a159..e5faf6287c85a0ce57f48683552993087a8971b0 100644 --- a/uni_modules/uts-tests/utssdk/index.uts +++ b/uni_modules/uts-tests/utssdk/index.uts @@ -10,7 +10,8 @@ import { testSet } from './Set.uts' import { testOperators } from './Operators.uts' import { testMath } from './Math.uts' import { testRegExp } from './RegExp.uts' -import { testForLoop } from './ForLoop.uts' +import { testForLoop } from './ForLoop.uts' +import { testGlobal } from './Global.uts' export { Result } from './tests.uts' // Promise、Proxy、Reflect、Weakmap、WeakSet 不支持 @@ -27,7 +28,8 @@ export function runTests() : UTSJSONObject { const MathRes = testMath(); const RegExpRes = testRegExp(); const KeyWordRes = testKeyWord(); - const ForLoopRes = testForLoop(); + const ForLoopRes = testForLoop(); + const GlobalRes = testGlobal(); return { Array: ArrayRes, @@ -42,6 +44,7 @@ export function runTests() : UTSJSONObject { Math: MathRes, RegExp: RegExpRes, KeyWord: KeyWordRes, - ForLoop: ForLoopRes, + ForLoop: ForLoopRes, + Global: GlobalRes, } } \ No newline at end of file