From 3c8a99687bc24df0e7dbbc82f73013bc360547f3 Mon Sep 17 00:00:00 2001 From: duqingquan Date: Wed, 6 Nov 2024 16:23:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E9=83=A8=E5=88=86number=20to?= =?UTF-8?q?String=20=E6=B5=8B=E8=AF=95=E7=A4=BA=E4=BE=8B=EF=BC=8C=E6=9A=82?= =?UTF-8?q?=E6=97=B6=E4=BF=AE=E6=94=B9=E4=B8=BAJSON.stringify?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uni_modules/uts-tests/utssdk/Number.uts | 51 +++++++++++++------------ 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/uni_modules/uts-tests/utssdk/Number.uts b/uni_modules/uts-tests/utssdk/Number.uts index a536ed5..61d9c80 100644 --- a/uni_modules/uts-tests/utssdk/Number.uts +++ b/uni_modules/uts-tests/utssdk/Number.uts @@ -137,40 +137,40 @@ export function testNumber() : Result { // #ifdef APP-ANDROID let a = JSON.parse("1") as Number a++; - expect(a.toString()).toEqual("2"); - expect(UTSAndroid.getJavaClass(a).name).toEqual("java.lang.Integer"); + expect(JSON.stringify(a)).toEqual("2"); + expect(UTSAndroid.getJavaClass(a).name).toEqual("java.lang.Double"); a--; - expect(a.toString()).toEqual("1"); - expect(UTSAndroid.getJavaClass(a).name).toEqual("java.lang.Integer"); + expect(JSON.stringify(a)).toEqual("1"); + expect(UTSAndroid.getJavaClass(a).name).toEqual("java.lang.Double"); a /= 0.5; - expect(a.toString()).toEqual("2"); - expect(UTSAndroid.getJavaClass(a).name).toEqual("java.lang.Integer"); + expect(JSON.stringify(a)).toEqual("2"); + expect(UTSAndroid.getJavaClass(a).name).toEqual("java.lang.Double"); a *= 5; - expect(a.toString()).toEqual("10"); - expect(UTSAndroid.getJavaClass(a).name).toEqual("java.lang.Integer"); + expect(JSON.stringify(a)).toEqual("10"); + expect(UTSAndroid.getJavaClass(a).name).toEqual("java.lang.Double"); a += -1; - expect(a.toString()).toEqual("9"); - expect(UTSAndroid.getJavaClass(a).name).toEqual("java.lang.Integer"); + expect(JSON.stringify(a)).toEqual("9"); + expect(UTSAndroid.getJavaClass(a).name).toEqual("java.lang.Double"); a -= -2; - expect(a.toString()).toEqual("11"); - expect(UTSAndroid.getJavaClass(a).name).toEqual("java.lang.Integer"); + expect(JSON.stringify(a)).toEqual("11"); + expect(UTSAndroid.getJavaClass(a).name).toEqual("java.lang.Double"); let a2 = a % 5 - expect(a2.toString()).toEqual("1"); - expect(UTSAndroid.getJavaClass(a2).name).toEqual("java.lang.Integer"); + expect(JSON.stringify(a2)).toEqual("1"); + expect(UTSAndroid.getJavaClass(a2).name).toEqual("java.lang.Double"); let b = 12 let c1 = b + a2 - expect(c1.toString()).toEqual("13"); - expect(UTSAndroid.getJavaClass(c1).name).toEqual("java.lang.Integer"); + expect(JSON.stringify(c1)).toEqual("13"); + expect(UTSAndroid.getJavaClass(c1).name).toEqual("java.lang.Double"); let c2 = a2 + 2 - expect(c2.toString()).toEqual("3"); - expect(UTSAndroid.getJavaClass(c2).name).toEqual("java.lang.Integer"); + expect(JSON.stringify(c2)).toEqual("3"); + expect(UTSAndroid.getJavaClass(c2).name).toEqual("java.lang.Double"); let c3 = 2 + a2 - expect(c3.toString()).toEqual("3"); - expect(UTSAndroid.getJavaClass(c3).name).toEqual("java.lang.Integer"); + expect(JSON.stringify(c3)).toEqual("3"); + expect(UTSAndroid.getJavaClass(c3).name).toEqual("java.lang.Double"); // #endif @@ -234,11 +234,12 @@ export function testNumber() : Result { // #ifdef APP-ANDROID expect(0.6.toString()).toEqual("0.6"); expect((2709954670497349.5).toString(10)).toEqual("2709954670497349.5"); - expect(((0.00000000000001)).toString()).toEqual("1e-14"); - expect((new UTSNumber(0.000001)).toString()).toEqual("0.000001"); - expect((new UTSNumber(0.0000001)).toString()).toEqual("1e-7"); - expect((new UTSNumber(100000000000000000000.0)).toString()).toEqual("100000000000000000000"); - expect((new UTSNumber(1000000000000000000000.0)).toString()).toEqual("1e+21"); + // todo change JSON.stringify to toString + expect((JSON.stringify(0.00000000000001))).toEqual("1e-14"); + expect((JSON.stringify(0.000001))).toEqual("0.000001"); + expect((JSON.stringify(0.0000001))).toEqual("1e-7"); + expect((JSON.stringify(100000000000000000000.0))).toEqual("100000000000000000000"); + expect((JSON.stringify(1000000000000000000000.0))).toEqual("1e+21"); // #endif }) -- GitLab