diff options
author | 2023-06-27 00:35:48 +0200 | |
---|---|---|
committer | 2023-06-26 15:35:48 -0700 | |
commit | 16598555f137112a3df2da5d8f2ee8edb496484f (patch) | |
tree | ad389ba4b312e82e4fcdd867e4d013d5a0d20fbb /test/js/node/crypto/node-crypto.test.js | |
parent | a732999da578ca92a1d9e633036225a32e77529d (diff) | |
download | bun-16598555f137112a3df2da5d8f2ee8edb496484f.tar.gz bun-16598555f137112a3df2da5d8f2ee8edb496484f.tar.zst bun-16598555f137112a3df2da5d8f2ee8edb496484f.zip |
`.randomInt()` support (#3357)
* Add initial .randomInt() fallback
* Add basic .randomInt() test
* Attempt creating a native implementation
* Switch to JSC.wrapWithHasContainer
* Switch to .jsNumberFromUint64(), it seems like using just .jsNumber() causes the number to overflow in some cases
* Regenerate out folder after rebasing
Diffstat (limited to 'test/js/node/crypto/node-crypto.test.js')
-rw-r--r-- | test/js/node/crypto/node-crypto.test.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/js/node/crypto/node-crypto.test.js b/test/js/node/crypto/node-crypto.test.js index 9e0e7f396..5a68540cf 100644 --- a/test/js/node/crypto/node-crypto.test.js +++ b/test/js/node/crypto/node-crypto.test.js @@ -8,6 +8,27 @@ it("crypto.randomBytes should return a Buffer", () => { expect(Buffer.isBuffer(crypto.randomBytes(1))).toBe(true); }); +it("crypto.randomInt should return a number", () => { + const result = crypto.randomInt(0, 10); + expect(typeof result).toBe("number"); + expect(result).toBeGreaterThanOrEqual(0); + expect(result).toBeLessThanOrEqual(10); +}); + +it("crypto.randomInt with no arguments", () => { + const result = crypto.randomInt(); + expect(typeof result).toBe("number"); + expect(result).toBeGreaterThanOrEqual(0); + expect(result).toBeLessThanOrEqual(Number.MAX_SAFE_INTEGER); +}); + +it("crypto.randomInt with one argument", () => { + const result = crypto.randomInt(100); + expect(typeof result).toBe("number"); + expect(result).toBeGreaterThanOrEqual(0); + expect(result).toBeLessThanOrEqual(100); +}); + // https://github.com/oven-sh/bun/issues/1839 describe("createHash", () => { it("update & digest", () => { |