diff --git a/uni_modules/uts-tests/utssdk/TextDecoder.uts b/uni_modules/uts-tests/utssdk/TextDecoder.uts new file mode 100644 index 0000000000000000000000000000000000000000..4249e314df7512f1e1e19ed1e6329e8b2d5a4950 --- /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 7528c7d92088dd66ff3eef328afd68e96230e79d..125c0ac16fb941c901a125ca8f9f81ed6e630db0 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