From d5c39959f9911c3469dfb8fd8ae3780a25b06d14 Mon Sep 17 00:00:00 2001 From: duqingquan Date: Tue, 16 Jul 2024 17:42:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20toWellFormed/isWellFormed?= =?UTF-8?q?=20=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/String.uts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/uni_modules/uts-tests/utssdk/String.uts b/uni_modules/uts-tests/utssdk/String.uts index d208e8a..693b7e7 100644 --- a/uni_modules/uts-tests/utssdk/String.uts +++ b/uni_modules/uts-tests/utssdk/String.uts @@ -55,6 +55,26 @@ export function testString(): Result { const empty = ""; expect(empty.charAt(0)).toEqual(""); }) + test('toWellFormed', () => { + expect("ab\uD800".toWellFormed()).toEqual("ab\uFFFD"); + expect("ab\uD800c".toWellFormed()).toEqual("ab\uFFFDc"); + expect("\uDFFFab".toWellFormed()).toEqual("\uFFFDab"); + expect("c\uDFFFab".toWellFormed()).toEqual("c\uFFFDab"); + expect("abc".toWellFormed()).toEqual("abc"); + expect("ab\uD83D\uDE04c".toWellFormed()).toEqual("ab\uD83D\uDE04c"); + expect("ab\uD83D\uDE04c".toWellFormed()).toEqual("ab\uD83D\uDE04c"); + expect("ab\uD83D\uDE04c\uD83D".toWellFormed()).toEqual("ab\uD83D\uDE04c\uFFFD"); + }) + test('isWellFormed', () => { + expect("ab\uD800".isWellFormed()).toEqual(false); + expect("ab\uD800c".isWellFormed()).toEqual(false); + expect("\uDFFFab".isWellFormed()).toEqual(false); + expect("c\uDFFFab".isWellFormed()).toEqual(false); + expect("abc".isWellFormed()).toEqual(true); + expect("ab\uD83D\uDE04c".isWellFormed()).toEqual(true); + expect("ab\uD83D\uDE04c".isWellFormed()).toEqual(true); + expect("ab\uD83D\uDE04c\uD83D".isWellFormed()).toEqual(false); + }) test('charCodeAt', () => { const sentence = 'The quick brown fox jumps over the lazy dog.'; const index = 4; -- GitLab