From ba999c9ac3edac32848a9746283d0bfc5331ed44 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sat, 30 Apr 2022 23:58:46 -0700 Subject: cleanup --- integration/bunjs-only-snippets/buffer.test.js | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'integration/bunjs-only-snippets/buffer.test.js') diff --git a/integration/bunjs-only-snippets/buffer.test.js b/integration/bunjs-only-snippets/buffer.test.js index d1a5c7ff3..18b31cae8 100644 --- a/integration/bunjs-only-snippets/buffer.test.js +++ b/integration/bunjs-only-snippets/buffer.test.js @@ -88,6 +88,42 @@ it("writeInt", () => { expect(childBuf.readInt32BE(0, false)).toBe(100); }); +it("Buffer.from", () => { + expect(Buffer.from("hello world").toString("utf8")).toBe("hello world"); + expect(Buffer.from("hello world", "ascii").toString("utf8")).toBe( + "hello world" + ); + expect(Buffer.from("hello world", "latin1").toString("utf8")).toBe( + "hello world" + ); + expect(Buffer.from([254]).join(",")).toBe("254"); + expect(Buffer.from(123).join(",")).toBe(Uint8Array.from(123).join(",")); + expect(Buffer.from({ length: 124 }).join(",")).toBe( + Uint8Array.from({ length: 124 }).join(",") + ); + + expect(Buffer.from(new ArrayBuffer(1024), 0, 512).join(",")).toBe( + new Uint8Array(512).join(",") + ); + + expect(Buffer.from(new Buffer(new ArrayBuffer(1024), 0, 512)).join(",")).toBe( + new Uint8Array(512).join(",") + ); +}); + +it("Buffer.copy", () => { + var array1 = new Uint8Array(128); + array1.fill(100); + Buffer.toBuffer(array1); + var array2 = new Uint8Array(128); + array2.fill(200); + Buffer.toBuffer(array2); + var array3 = new Uint8Array(128); + Buffer.toBuffer(array3); + expect(array1.copy(array2)).toBe(128); + expect(array1.join("")).toBe(array2.join("")); +}); + it("read", () => { var buf = new Buffer(1024); var data = new DataView(buf.buffer); -- cgit v1.2.3