diff options
-rw-r--r-- | test/bun.js/text-decoder.test.js | 33 |
1 files changed, 33 insertions, 0 deletions
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", + ); +}); |