mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
Add some more text decoder tests
This commit is contained in:
@@ -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",
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user