From 89efe9266f768a4cf78be51d45607ee279997eea Mon Sep 17 00:00:00 2001 From: mahaifeng Date: Mon, 23 Sep 2024 16:42:25 +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 | 7 +++-- 2 files changed, 36 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 7528c7d..125c0ac 100644 --- a/uni_modules/uts-tests/utssdk/index.uts +++ b/uni_modules/uts-tests/utssdk/index.uts @@ -20,7 +20,8 @@ export { Result } from './tests.uts' import { testArrayBuffer } from './ArrayBuffer.uts' import { testNativeCode } from './NativeCode.uts' import { testPromise} from "./Promise.uts" -import { testEncoder} from "./TextEncoder.uts" +import { testEncoder} from "./TextEncoder.uts" +import { testDecoder} from "./TextDecoder.uts" // Proxy、Reflect、Weakmap、WeakSet 不支持 export function runTests() : UTSJSONObject { const ArrayRes = testArray(); @@ -49,6 +50,7 @@ export function runTests() : UTSJSONObject { const PromiseRes = testPromise(); // #ifdef APP-ANDROID || WEB const TextEncoderRes = testEncoder(); + const TextDecoderRes = testDecoder(); // #endif return { Array: ArrayRes, @@ -71,7 +73,8 @@ export function runTests() : UTSJSONObject { UTSJSONObject: UTSJSONObjectRes, // #ifdef APP-ANDROID || WEB ArrayBuffer: ArrayBufferRes, - TextEncoder: TextEncoderRes, + TextEncoder: TextEncoderRes, + TextDecoder: TextDecoderRes, // #endif NativeCode: NativeCodeRes, Primise: PromiseRes -- GitLab