From 9665d7d21636b0eb344bc83c104f1796e96809bf Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Mon, 5 Dec 2022 11:19:45 -0800 Subject: Add some more text decoder tests --- test/bun.js/text-decoder.test.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test/bun.js/text-decoder.test.js') diff --git a/test/bun.js/text-decoder.test.js b/test/bun.js/text-decoder.test.js index bc10bf649..c2a00222f 100644 --- a/test/bun.js/text-decoder.test.js +++ b/test/bun.js/text-decoder.test.js @@ -101,3 +101,36 @@ describe("TextDecoder", () => { gcTrace(true); }); }); + +it("truncated sequences", () => { + const assert_equals = (a, b) => expect(a).toBe(b); + + // Truncated sequences + assert_equals(new TextDecoder().decode(new Uint8Array([0xf0])), "\uFFFD"); + assert_equals( + new TextDecoder().decode(new Uint8Array([0xf0, 0x9f])), + "\uFFFD", + ); + assert_equals( + new TextDecoder().decode(new Uint8Array([0xf0, 0x9f, 0x92])), + "\uFFFD", + ); + + // Errors near end-of-queue + assert_equals( + new TextDecoder().decode(new Uint8Array([0xf0, 0x9f, 0x41])), + "\uFFFDA", + ); + assert_equals( + new TextDecoder().decode(new Uint8Array([0xf0, 0x41, 0x42])), + "\uFFFDAB", + ); + assert_equals( + new TextDecoder().decode(new Uint8Array([0xf0, 0x41, 0xf0])), + "\uFFFDA\uFFFD", + ); + assert_equals( + new TextDecoder().decode(new Uint8Array([0xf0, 0x8f, 0x92])), + "\uFFFD\uFFFD\uFFFD", + ); +}); -- cgit v1.2.3