aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar jhmaster <32803471+jhmaster2000@users.noreply.github.com> 2023-08-08 03:30:05 -0300
committerGravatar GitHub <noreply@github.com> 2023-08-07 23:30:05 -0700
commit182e600eb79655e85b3f0371bc46fc4de8e70094 (patch)
treeb91231bc9155cc769cc81a7b2f0892c47bd26d2c /test
parentcb873cc0818d02216ac7285c58fe59883220d1a9 (diff)
downloadbun-182e600eb79655e85b3f0371bc46fc4de8e70094.tar.gz
bun-182e600eb79655e85b3f0371bc46fc4de8e70094.tar.zst
bun-182e600eb79655e85b3f0371bc46fc4de8e70094.zip
Fix `Bun.hash` functions (#4054)
* fix `Bun.hash` functions to behave as expected * update Bun.hash tests * properly test the returned hash * include murmur32v2 * update Bun.hash docs * run fmt
Diffstat (limited to 'test')
-rw-r--r--test/js/bun/util/hash.test.js39
1 files changed, 21 insertions, 18 deletions
diff --git a/test/js/bun/util/hash.test.js b/test/js/bun/util/hash.test.js
index 87a5a9ce3..29c683801 100644
--- a/test/js/bun/util/hash.test.js
+++ b/test/js/bun/util/hash.test.js
@@ -1,47 +1,50 @@
-import fs from "fs";
import { it, expect } from "bun:test";
-import path from "path";
import { gcTick } from "harness";
it(`Bun.hash()`, () => {
gcTick();
- Bun.hash("hello world");
- Bun.hash(new TextEncoder().encode("hello world"));
+ expect(Bun.hash("hello world")).toBe(0x668d5e431c3b2573n);
+ expect(Bun.hash(new TextEncoder().encode("hello world"))).toBe(0x668d5e431c3b2573n);
});
it(`Bun.hash.wyhash()`, () => {
- Bun.hash.wyhash("hello world");
+ expect(Bun.hash.wyhash("hello world")).toBe(0x668d5e431c3b2573n);
gcTick();
- Bun.hash.wyhash(new TextEncoder().encode("hello world"));
+ expect(Bun.hash.wyhash(new TextEncoder().encode("hello world"))).toBe(0x668d5e431c3b2573n);
});
it(`Bun.hash.adler32()`, () => {
- Bun.hash.adler32("hello world");
+ expect(Bun.hash.adler32("hello world")).toBe(0x1a0b045d);
gcTick();
- Bun.hash.adler32(new TextEncoder().encode("hello world"));
+ expect(Bun.hash.adler32(new TextEncoder().encode("hello world"))).toBe(0x1a0b045d);
});
it(`Bun.hash.crc32()`, () => {
- Bun.hash.crc32("hello world");
+ expect(Bun.hash.crc32("hello world")).toBe(0x0d4a1185);
gcTick();
- Bun.hash.crc32(new TextEncoder().encode("hello world"));
+ expect(Bun.hash.crc32(new TextEncoder().encode("hello world"))).toBe(0x0d4a1185);
});
it(`Bun.hash.cityHash32()`, () => {
- Bun.hash.cityHash32("hello world");
+ expect(Bun.hash.cityHash32("hello world")).toBe(0x19a7581a);
gcTick();
- Bun.hash.cityHash32(new TextEncoder().encode("hello world"));
+ expect(Bun.hash.cityHash32(new TextEncoder().encode("hello world"))).toBe(0x19a7581a);
gcTick();
});
it(`Bun.hash.cityHash64()`, () => {
- Bun.hash.cityHash64("hello world");
+ expect(Bun.hash.cityHash64("hello world")).toBe(0xc7920bbdbecee42fn);
gcTick();
- Bun.hash.cityHash64(new TextEncoder().encode("hello world"));
+ expect(Bun.hash.cityHash64(new TextEncoder().encode("hello world"))).toBe(0xc7920bbdbecee42fn);
gcTick();
});
it(`Bun.hash.murmur32v3()`, () => {
- Bun.hash.murmur32v3("hello world");
+ expect(Bun.hash.murmur32v3("hello world")).toBe(0x5e928f0f);
gcTick();
- Bun.hash.murmur32v3(new TextEncoder().encode("hello world"));
+ expect(Bun.hash.murmur32v3(new TextEncoder().encode("hello world"))).toBe(0x5e928f0f);
+});
+it(`Bun.hash.murmur32v2()`, () => {
+ expect(Bun.hash.murmur32v2("hello world")).toBe(0x44a81419);
+ gcTick();
+ expect(Bun.hash.murmur32v2(new TextEncoder().encode("hello world"))).toBe(0x44a81419);
});
it(`Bun.hash.murmur64v2()`, () => {
- Bun.hash.murmur64v2("hello world");
+ expect(Bun.hash.murmur64v2("hello world")).toBe(0xd3ba2368a832afcen);
gcTick();
- Bun.hash.murmur64v2(new TextEncoder().encode("hello world"));
+ expect(Bun.hash.murmur64v2(new TextEncoder().encode("hello world"))).toBe(0xd3ba2368a832afcen);
});