aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/text-decoder.test.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-05 11:19:45 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-05 11:37:04 -0800
commit9665d7d21636b0eb344bc83c104f1796e96809bf (patch)
treeb4853884a47a7866b703f0917db31810f0bd1568 /test/bun.js/text-decoder.test.js
parentc1149567884bdafbdf5498abcc4ed7bef50571be (diff)
downloadbun-9665d7d21636b0eb344bc83c104f1796e96809bf.tar.gz
bun-9665d7d21636b0eb344bc83c104f1796e96809bf.tar.zst
bun-9665d7d21636b0eb344bc83c104f1796e96809bf.zip
Add some more text decoder tests
Diffstat (limited to 'test/bun.js/text-decoder.test.js')
-rw-r--r--test/bun.js/text-decoder.test.js33
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",
+ );
+});