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 ccf4605719ac0ca191baf8b1b6a5a1a3a4964b66..893ed23df655f6c53d223ef2f71436b2bb6efd24 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 }