From 41e2c4c8dc6d47b8a821e8773bf1fdfed1c4d1a8 Mon Sep 17 00:00:00 2001 From: duqingquan Date: Thu, 13 Jun 2024 15:34:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85UTSNumber=20=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=B5=8B=E8=AF=95=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uni_modules/uts-tests/utssdk/JSON.uts | 6 ++++++ uni_modules/uts-tests/utssdk/Number.uts | 19 +++++++++++++++++++ uni_modules/uts-tests/utssdk/console.uts | 18 ++++++++++++++++-- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/uni_modules/uts-tests/utssdk/JSON.uts b/uni_modules/uts-tests/utssdk/JSON.uts index 1810ee4..00ebc1e 100644 --- a/uni_modules/uts-tests/utssdk/JSON.uts +++ b/uni_modules/uts-tests/utssdk/JSON.uts @@ -319,6 +319,12 @@ export function testJSON() : Result { a: 1 }.toMap() expect(map.get('a')).toEqual(1) + + const json = `{"result":true, "count":42}`; + const obj = JSON.parse(json) as UTSJSONObject; + let retStr = JSON.stringify(obj) + expect(retStr).toEqual('{"result":true,"count":42}') + }) test('parse Map', () => { diff --git a/uni_modules/uts-tests/utssdk/Number.uts b/uni_modules/uts-tests/utssdk/Number.uts index a9ab25e..29440bb 100644 --- a/uni_modules/uts-tests/utssdk/Number.uts +++ b/uni_modules/uts-tests/utssdk/Number.uts @@ -60,6 +60,25 @@ export function testNumber() : Result { expect(isFinite(910)).toEqual(true); expect(isFinite(0)).toEqual(true); }) + + test('number-from-json-parse', () => { + type A = { + a:number + } + let aj = JSON.parse('{"a":1}'); + expect(aj?.a == 1).toEqual(true); + expect(aj?.a == 1 as number).toEqual(true); + expect(aj?.a == 1.0).toEqual(true); + expect(aj?.a == 1.0 as number).toEqual(true); + let ki:Int = 1; + let kd:Double = 1.0; + let kf:Float = (1.0).toFloat(); + expect(aj?.a == ki).toEqual(true); + expect(aj?.a == kd).toEqual(true); + expect(aj?.a == kf).toEqual(true); + + }) + test('isInteger', () => { expect(Number.isInteger(12)).toEqual(true); expect(Number.isInteger(12.01)).toEqual(false); diff --git a/uni_modules/uts-tests/utssdk/console.uts b/uni_modules/uts-tests/utssdk/console.uts index 3d8c881..787979c 100644 --- a/uni_modules/uts-tests/utssdk/console.uts +++ b/uni_modules/uts-tests/utssdk/console.uts @@ -21,7 +21,21 @@ export function testConsole() : Result { expect(obtainInnerObject(pageInstance).get("className")).toEqual("io.dcloud.uniapp.vue.ComponentInternalInstance"); expect(obtainInnerObject(pageInstance).get("type")).toEqual("object"); // #endif - } - ) + }) + + test('console-number-from-JSON-parse', () => { + // #ifdef APP-ANDROID + + let aj2 = JSON.parse('{"a":1}') as UTSJSONObject; + console.log(aj2!['a']) + + expect(obtainInnerObject(aj2!['a']).get("type")).toEqual("number"); + expect(obtainInnerObject(aj2!['a']).get("subType")).toEqual("number"); + + // #endif + + }) + }) + } \ No newline at end of file -- GitLab