aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/buffer.test.js
diff options
context:
space:
mode:
authorGravatar Zilin Zhu <zhuzilinallen@gmail.com> 2022-08-20 14:13:38 +0800
committerGravatar GitHub <noreply@github.com> 2022-08-19 23:13:38 -0700
commit8cf57eb5828b3db12e23c1eb5a674bc7ff7aae4f (patch)
tree154b9db0b2de8c13434bd48ae71502fef3015365 /test/bun.js/buffer.test.js
parentaa404ded348bcd3ef170914126dd4cf0a535f8aa (diff)
downloadbun-8cf57eb5828b3db12e23c1eb5a674bc7ff7aae4f.tar.gz
bun-8cf57eb5828b3db12e23c1eb5a674bc7ff7aae4f.tar.zst
bun-8cf57eb5828b3db12e23c1eb5a674bc7ff7aae4f.zip
fix buffer.copy (#1113)
Diffstat (limited to 'test/bun.js/buffer.test.js')
-rw-r--r--test/bun.js/buffer.test.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/bun.js/buffer.test.js b/test/bun.js/buffer.test.js
index 87937e65e..a7fa539c0 100644
--- a/test/bun.js/buffer.test.js
+++ b/test/bun.js/buffer.test.js
@@ -209,6 +209,33 @@ it("Buffer.copy", () => {
gc();
expect(array1.copy(array2)).toBe(128);
expect(array1.join("")).toBe(array2.join(""));
+
+ {
+ // Create two `Buffer` instances.
+ const buf1 = Buffer.allocUnsafe(26);
+ const buf2 = Buffer.allocUnsafe(26).fill('!');
+
+ for (let i = 0; i < 26; i++) {
+ // 97 is the decimal ASCII value for 'a'.
+ buf1[i] = i + 97;
+ }
+
+ // Copy `buf1` bytes 16 through 19 into `buf2` starting at byte 8 of `buf2`.
+ buf1.copy(buf2, 8, 16, 20);
+ expect(buf2.toString('ascii', 0, 25)).toBe('!!!!!!!!qrst!!!!!!!!!!!!!');
+ }
+
+ {
+ const buf = Buffer.allocUnsafe(26);
+
+ for (let i = 0; i < 26; i++) {
+ // 97 is the decimal ASCII value for 'a'.
+ buf[i] = i + 97;
+ }
+
+ buf.copy(buf, 0, 4, 10);
+ expect(buf.toString()).toBe('efghijghijklmnopqrstuvwxyz');
+ }
});
export function fillRepeating(dstBuffer, start, end) {