From d0cf394f2ddaf4adf42ad69e929aca989dc0075e Mon Sep 17 00:00:00 2001 From: m0_75226990 Date: Thu, 31 Aug 2023 19:41:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20parseInt=20=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uni_modules/uts-tests/utssdk/Number.uts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/uni_modules/uts-tests/utssdk/Number.uts b/uni_modules/uts-tests/utssdk/Number.uts index 8171732..3bee379 100644 --- a/uni_modules/uts-tests/utssdk/Number.uts +++ b/uni_modules/uts-tests/utssdk/Number.uts @@ -24,7 +24,29 @@ export function testNumber(): Result { }) test('parseInt', () => { - expect(parseInt("123.456")).toEqual(123); + 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); -- GitLab