diff options
author | 2023-07-20 17:50:54 -0400 | |
---|---|---|
committer | 2023-07-20 14:50:54 -0700 | |
commit | c383c6cd810a80c6080096bbad737f9fa17f2e7b (patch) | |
tree | 21bb087d724facae5dba31666ead3abd03528a53 /test/js/web/encoding/text-decoder.test.js | |
parent | 68b4a64569039f39c7bb661570bf65b80028cf92 (diff) | |
download | bun-c383c6cd810a80c6080096bbad737f9fa17f2e7b.tar.gz bun-c383c6cd810a80c6080096bbad737f9fa17f2e7b.tar.zst bun-c383c6cd810a80c6080096bbad737f9fa17f2e7b.zip |
Pass constructor arguments to TextDecoder (#3692)
* Make TextDecoder constructor use options parameter
The constructor now actually sets TextDecoder properties using the
options parameter.
* Defer decoder allocation to end of constructor
* Verify types of TextDecoder options
* TextDecoder throw TypeError on failure
* Tidying
Diffstat (limited to 'test/js/web/encoding/text-decoder.test.js')
-rw-r--r-- | test/js/web/encoding/text-decoder.test.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/js/web/encoding/text-decoder.test.js b/test/js/web/encoding/text-decoder.test.js index abd4c2a72..d8038e628 100644 --- a/test/js/web/encoding/text-decoder.test.js +++ b/test/js/web/encoding/text-decoder.test.js @@ -225,6 +225,25 @@ describe("TextDecoder", () => { expect(decoder.decode(bytes.subarray(0, amount.written))).toBe(text); gcTrace(true); }); + + it("should respect fatal when encountering invalid data", () => { + const decoder = new TextDecoder("utf-8", { fatal: true }); + expect(() => { + decoder.decode(new Uint8Array([0xC0])) // Invalid UTF8 + }).toThrow(TypeError); + }); + + it("constructor should set values", () => { + const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: false }); + expect(decoder.fatal).toBe(true); + // expect(decoder.ignoreBOM).toBe(false); // currently the getter for ignoreBOM doesn't work and always returns undefined + }); + + it("should throw on invalid input", () => { + expect(() => { + const decoder = new TextDecoder("utf-8", { fatal: 10, ignoreBOM: {} }); + }).toThrow(); + }); }); it("truncated sequences", () => { |