diff options
author | 2022-06-29 04:29:01 -0700 | |
---|---|---|
committer | 2022-06-29 04:29:01 -0700 | |
commit | 7d5464adbeee3ac5b9ea0b9004f2a5b99f2f3032 (patch) | |
tree | 0c764a686b839923d90c231cd3d6666f6391a439 /test/bun.js/text-encoder.test.js | |
parent | 95c17852717c0857fcbce37169980ea563082e39 (diff) | |
download | bun-7d5464adbeee3ac5b9ea0b9004f2a5b99f2f3032.tar.gz bun-7d5464adbeee3ac5b9ea0b9004f2a5b99f2f3032.tar.zst bun-7d5464adbeee3ac5b9ea0b9004f2a5b99f2f3032.zip |
[encoder] Fix non-ascii latin1 characters
Diffstat (limited to 'test/bun.js/text-encoder.test.js')
-rw-r--r-- | test/bun.js/text-encoder.test.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/bun.js/text-encoder.test.js b/test/bun.js/text-encoder.test.js index 5687e0222..5f8778bde 100644 --- a/test/bun.js/text-encoder.test.js +++ b/test/bun.js/text-encoder.test.js @@ -69,6 +69,31 @@ describe("TextDecoder", () => { }); describe("TextEncoder", () => { + it("should encode latin1 text with non-ascii latin1 characters", () => { + var text = "H©ell©o Wor©ld!"; + + gcTrace(true); + const encoder = new TextEncoder(); + const encoded = encoder.encode(text); + gcTrace(true); + const into = new Uint8Array(100); + const out = encoder.encodeInto(text, into); + gcTrace(true); + expect(out.read).toBe(text.length); + + expect(encoded instanceof Uint8Array).toBe(true); + const result = [ + 72, 194, 169, 101, 108, 108, 194, 169, 111, 32, 87, 111, 114, 194, 169, + 108, 100, 33, + ]; + for (let i = 0; i < result.length; i++) { + expect(encoded[i]).toBe(result[i]); + expect(into[i]).toBe(result[i]); + } + expect(encoded.length).toBe(result.length); + expect(out.written).toBe(result.length); + }); + it("should encode latin1 text", () => { gcTrace(true); const text = "Hello World!"; @@ -126,6 +151,34 @@ describe("TextEncoder", () => { expect(encoded.length).toBe(getByteLength(text)); }); + it("should encode latin1 rope text with non-ascii latin1 characters", () => { + var text = "H©ell©o"; + text += " "; + text += "Wor©ld!"; + + gcTrace(true); + const encoder = new TextEncoder(); + const encoded = encoder.encode(text); + gcTrace(true); + const into = new Uint8Array(100); + const out = encoder.encodeInto(text, into); + gcTrace(true); + expect(out.read).toBe(text.length); + + expect(encoded instanceof Uint8Array).toBe(true); + const result = [ + 72, 194, 169, 101, 108, 108, 194, 169, 111, 32, 87, 111, 114, 194, 169, + 108, 100, 33, + ]; + + for (let i = 0; i < result.length; i++) { + expect(encoded[i]).toBe(into[i]); + expect(encoded[i]).toBe(result[i]); + } + expect(encoded.length).toBe(result.length); + expect(out.written).toBe(encoded.length); + }); + it("should encode utf-16 text", () => { var text = `❤️ Red Heart ✨ Sparkles |