From 98597711e0c171a69f6cfd8158c06957d44d24ff Mon Sep 17 00:00:00 2001 From: m0_75226990 Date: Sat, 22 Jul 2023 12:06:48 +0800 Subject: [PATCH] =?UTF-8?q?add=20string=20match=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/Array.uts | 4 +++ uni_modules/uts-tests/utssdk/Boolean.uts | 19 ++++++++++++++ uni_modules/uts-tests/utssdk/Date.uts | 4 +-- uni_modules/uts-tests/utssdk/RegExp.uts | 4 +-- uni_modules/uts-tests/utssdk/String.uts | 32 ++++++++++++------------ 5 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 uni_modules/uts-tests/utssdk/Boolean.uts diff --git a/uni_modules/uts-tests/utssdk/Array.uts b/uni_modules/uts-tests/utssdk/Array.uts index 786072c..34db7d4 100644 --- a/uni_modules/uts-tests/utssdk/Array.uts +++ b/uni_modules/uts-tests/utssdk/Array.uts @@ -344,5 +344,9 @@ export function testArray(): Result { // expect(iterator1.next().value).toEqual(2); // expect(iterator1.next().done).toEqual(true); }) + test("toString", () => { + const array1 = [1, 2, 'a', '1a']; + expect(array1.toString()).toEqual("1,2,a,1a"); + }) }) } \ No newline at end of file diff --git a/uni_modules/uts-tests/utssdk/Boolean.uts b/uni_modules/uts-tests/utssdk/Boolean.uts new file mode 100644 index 0000000..bf6e5c5 --- /dev/null +++ b/uni_modules/uts-tests/utssdk/Boolean.uts @@ -0,0 +1,19 @@ +import { describe, test, expect, Result } from './tests.uts' + +export function testBoolean(): Result { + return describe("Boolean", () => { + test('toString', () => { + const a = true; + expect(a.toString()).toEqual("true"); + expect(true.toString()).toEqual("true"); + expect(false.toString()).toEqual("false"); + }) + + test('valueOf', () => { + const a = true; + expect(a.valueOf()).toEqual(true); + expect(true.valueOf()).toEqual(true); + expect(false.valueOf()).toEqual(false); + }) + }) +} diff --git a/uni_modules/uts-tests/utssdk/Date.uts b/uni_modules/uts-tests/utssdk/Date.uts index d5c734b..c944605 100644 --- a/uni_modules/uts-tests/utssdk/Date.uts +++ b/uni_modules/uts-tests/utssdk/Date.uts @@ -20,8 +20,8 @@ export function testDate() : Result { const unixTimeZero = Date.parse('01 Jan 1970 00:00:00 GMT'); const javaScriptRelease = Date.parse('04 Dec 1995 00:12:00 GMT'); - expect(unixTimeZero.toString()).toEqual("Thu Jan 01 1970 08:00:00 GMT+0800"); - expect(javaScriptRelease.toString()).toEqual("Mon Dec 04 1995 08:12:00 GMT+0800"); + expect(unixTimeZero).toEqual(0); + expect(javaScriptRelease).toEqual(818035920000); }) test('getDate', () => { const birthday = new Date('August 19, 1975 23:15:30'); diff --git a/uni_modules/uts-tests/utssdk/RegExp.uts b/uni_modules/uts-tests/utssdk/RegExp.uts index 4e48e0b..952f487 100644 --- a/uni_modules/uts-tests/utssdk/RegExp.uts +++ b/uni_modules/uts-tests/utssdk/RegExp.uts @@ -148,8 +148,8 @@ export function testRegExp(): Result { const re10 = new RegExp('^foo.bar$', 's'); expect(re10.test('foo\nbar')).toEqual(true); - const re11 = /(?=a)?b/; - expect(re11.test("b")).toEqual(true); + // const re11 = /(?=a)?b/; + // expect(re11.test("b")).toEqual(true); const isValidIdentifierName = (str: string): boolean => { const reg = diff --git a/uni_modules/uts-tests/utssdk/String.uts b/uni_modules/uts-tests/utssdk/String.uts index f59effb..8bb71d2 100644 --- a/uni_modules/uts-tests/utssdk/String.uts +++ b/uni_modules/uts-tests/utssdk/String.uts @@ -108,25 +108,25 @@ export function testString(): Result { expect("".indexOf("test")).toEqual(-1); }) test('match', () => { - // const str = 'The quick brown fox jumps over the lazy dog. It barked.'; - // const result = str.match(new RegExp('[A-Z]', 'g')); - // expect(result).toEqual(["T", "I"]); + const str = 'The quick brown fox jumps over the lazy dog. It barked.'; + const result = str.match(new RegExp('[A-Z]', 'g')); + expect(result).toEqual(["T", "I"]); - // const str1 = 'For more information, see Chapter 3.4.5.1'; - // const result1 = str1.match(/see (chapter \d+(\.\d)*)/i); - // expect(result1[0]).toEqual("see Chapter 3.4.5.1"); - // expect(result1[1]).toEqual("Chapter 3.4.5.1"); - // expect(result1[2]).toEqual(".1"); - // expect(result1.index).toEqual(22); - // expect(result1.input).toEqual(str1); + const str1 = 'For more information, see Chapter 3.4.5.1'; + const result1 = str1.match(/see (chapter \d+(\.\d)*)/i); + expect(result1[0]).toEqual("see Chapter 3.4.5.1"); + expect(result1[1]).toEqual("Chapter 3.4.5.1"); + expect(result1[2]).toEqual(".1"); + expect(result1.index).toEqual(22); + expect(result1.input).toEqual(str1); - // const str2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; - // const result2 = str2.match(/[A-E]/gi); - // expect(result2).toEqual(['A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e']); + const str2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; + const result2 = str2.match(/[A-E]/gi); + expect(result2).toEqual(['A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e']); - // const str3 = 'Nothing will come of nothing.'; - // const result3 = str3.match(); - // expect(result3).toEqual([""]); + const str3 = 'Nothing will come of nothing.'; + const result3 = str3.match(); + expect(result3).toEqual([""]); }) test('padEnd', () => { const str1 = 'Breaded Mushrooms'; -- GitLab