From f3a4d30509d221922dc243f71209c1502c6d656f Mon Sep 17 00:00:00 2001 From: mahaifeng Date: Fri, 11 Oct 2024 15:11:21 +0800 Subject: [PATCH] =?UTF-8?q?[textdecoder]=E6=B7=BB=E5=8A=A0textdecoder?= =?UTF-8?q?=E6=B5=8B=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/TextDecoder.uts | 31 ++++++++++++++++++++ uni_modules/uts-tests/utssdk/index.uts | 6 ++-- 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 uni_modules/uts-tests/utssdk/TextDecoder.uts diff --git a/uni_modules/uts-tests/utssdk/TextDecoder.uts b/uni_modules/uts-tests/utssdk/TextDecoder.uts new file mode 100644 index 0000000..4249e31 --- /dev/null +++ b/uni_modules/uts-tests/utssdk/TextDecoder.uts @@ -0,0 +1,31 @@ +import { describe, test, expect, Result } from './tests.uts' + +export function testDecoder() : Result { + return describe("TextDecoder", () => { + test('decoder', () => { + // #TEST TextDecoder.decode + var utf8decoder = new TextDecoder(); // default 'utf-8' or 'utf8' + + var u8arr = Uint8Array.of(240, 160, 174, 183); + var i8arr = Int8Array.of(-16, -96, -82, -73); + + expect(utf8decoder.decode(u8arr)).toEqual('𠮷') + expect(utf8decoder.decode(i8arr)).toEqual('𠮷') + + utf8decoder = new TextDecoder("gbk"); // default 'utf-8' or 'utf8' + expect(utf8decoder.decode(u8arr)).toEqual('馉'); + expect(utf8decoder.decode(i8arr)).toEqual('馉') + + utf8decoder = new TextDecoder("utf-8"); + var arraybuffer = new ArrayBuffer(4) + var dataView = new DataView(arraybuffer) + dataView.setInt8(0, -16) + dataView.setInt8(1, -96) + dataView.setInt8(2, -82) + dataView.setInt8(3, -73) + expect(utf8decoder.decode(dataView)).toEqual('𠮷'); + + // #END + }) + }) +} \ No newline at end of file diff --git a/uni_modules/uts-tests/utssdk/index.uts b/uni_modules/uts-tests/utssdk/index.uts index ccf4605..893ed23 100644 --- a/uni_modules/uts-tests/utssdk/index.uts +++ b/uni_modules/uts-tests/utssdk/index.uts @@ -20,7 +20,7 @@ export { Result } from './tests.uts' import { testArrayBuffer } from './ArrayBuffer.uts' import { testNativeCode } from './NativeCode.uts' import { testEncoder} from "./TextEncoder.uts" - +import { testDecoder} from "./TextDecoder.uts" // Promise、Proxy、Reflect、Weakmap、WeakSet 不支持 export function runTests() : UTSJSONObject { const ArrayRes = testArray(); @@ -48,6 +48,7 @@ export function runTests() : UTSJSONObject { const NativeCodeRes = testNativeCode(); // #ifdef APP-ANDROID || WEB const TextEncoderRes = testEncoder(); + const TextDecoderRes = testDecoder(); // #endif return { Array: ArrayRes, @@ -70,7 +71,8 @@ export function runTests() : UTSJSONObject { UTSJSONObject: UTSJSONObjectRes, // #ifdef APP-ANDROID || WEB ArrayBuffer: ArrayBufferRes, - TextEncoder: TextEncoderRes, + TextEncoder: TextEncoderRes, + TextDecoder: TextDecoderRes, // #endif NativeCode: NativeCodeRes } -- GitLab