From 57a06745a48093c25d0f4729ccea41a918d6427d Mon Sep 17 00:00:00 2001 From: dave caruso Date: Thu, 7 Sep 2023 04:58:44 -0700 Subject: Progress for Next.js (#4468) * L * ipc * asdfghjkl * dfghjk * it works! * types * patches for next.js * sdfghj * wsdfgn,./ * this * yolo * okay loser * asdfghjk * add some more APIs * MESS * sdfghjkl * remove native events from streams * stuff * remove lazy(primordials) test * debugging * okay * less fake extensions object * fix `Buffer.toString()` args logic * fix deserialize * make tests work * add test for `Buffer.toString` args * Update server.zig * remove test * update test * Update spawn-streaming-stdin.test.ts * fix linux build * Update fs.test.ts * cli message improvements * dfshaj * Fix fs.watch bug maybe? * remove --------- Co-authored-by: Dylan Conway --- test/js/node/buffer.test.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'test/js/node/buffer.test.js') diff --git a/test/js/node/buffer.test.js b/test/js/node/buffer.test.js index 4040f5ce2..7c3d16536 100644 --- a/test/js/node/buffer.test.js +++ b/test/js/node/buffer.test.js @@ -499,6 +499,23 @@ it("creating buffers larger than pool size", () => { expect(sb).toBe(s); }); +it("should use args correctly", () => { + const buf1 = Buffer.allocUnsafe(26); + + for (let i = 0; i < 26; i++) { + // 97 is the decimal ASCII value for 'a'. + buf1[i] = i + 97; + } + + expect(buf1.toString("utf8")).toBe("abcdefghijklmnopqrstuvwxyz"); + expect(buf1.toString("utf8", 0, 5)).toBe("abcde"); + + const buf2 = Buffer.from("tést"); + expect(buf2.toString("hex")).toBe("74c3a97374"); + expect(buf2.toString("utf8", 0, 3)).toBe("té"); + expect(buf2.toString(undefined, 0, 3)).toBe("té"); +}); + it("hex toString()", () => { const hexb = Buffer.allocUnsafe(256); for (let i = 0; i < 256; i++) { @@ -2403,15 +2420,6 @@ it("Buffer.toString(encoding, start, end)", () => { expect(buf.toString("utf8", 100, 1)).toStrictEqual(""); }); -it("Buffer.toString(offset, length, encoding)", () => { - const buf = Buffer.from("0123456789", "utf8"); - - expect(buf.toString(3, 6, "utf8")).toStrictEqual("345678"); - expect(buf.toString(3, 100, "utf8")).toStrictEqual("3456789"); - expect(buf.toString(100, 200, "utf8")).toStrictEqual(""); - expect(buf.toString(100, 50, "utf8")).toStrictEqual(""); -}); - it("Buffer.asciiSlice())", () => { const buf = Buffer.from("0123456789", "ascii"); -- cgit v1.2.3