aboutsummaryrefslogtreecommitdiff
path: root/test/js/node/buffer.test.js
diff options
context:
space:
mode:
authorGravatar dave caruso <me@paperdave.net> 2023-09-07 04:58:44 -0700
committerGravatar GitHub <noreply@github.com> 2023-09-07 04:58:44 -0700
commit57a06745a48093c25d0f4729ccea41a918d6427d (patch)
treeac2568d5c98918d6364d2a9667c164cd3f3b3867 /test/js/node/buffer.test.js
parent4360ec83b4146e15344b304573795f084f86a7c2 (diff)
downloadbun-57a06745a48093c25d0f4729ccea41a918d6427d.tar.gz
bun-57a06745a48093c25d0f4729ccea41a918d6427d.tar.zst
bun-57a06745a48093c25d0f4729ccea41a918d6427d.zip
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 <dylan.conway567@gmail.com>
Diffstat (limited to 'test/js/node/buffer.test.js')
-rw-r--r--test/js/node/buffer.test.js26
1 files changed, 17 insertions, 9 deletions
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");