diff options
Diffstat (limited to 'tests/unit_node/crypto/crypto_misc_test.ts')
-rw-r--r-- | tests/unit_node/crypto/crypto_misc_test.ts | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/unit_node/crypto/crypto_misc_test.ts b/tests/unit_node/crypto/crypto_misc_test.ts index 8132f2e99..47a48b1bf 100644 --- a/tests/unit_node/crypto/crypto_misc_test.ts +++ b/tests/unit_node/crypto/crypto_misc_test.ts @@ -1,6 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. import { randomFillSync, randomUUID } from "node:crypto"; import { assert, assertEquals } from "../../unit/test_util.ts"; +import { assertNotEquals } from "@std/assert"; Deno.test("[node/crypto.getRandomUUID] works the same way as Web Crypto API", () => { assertEquals(randomUUID().length, crypto.randomUUID().length); @@ -16,3 +17,14 @@ Deno.test("[node/crypto.randomFillSync] supported arguments", () => { assert(randomFillSync(buf.buffer)); assert(randomFillSync(new DataView(buf.buffer))); }); + +Deno.test("[node/crypto.randomFillSync] array buffer view", () => { + const buf = new Uint8Array(32); + const view = new Uint8Array(buf.buffer, 8, 16); + + assert(randomFillSync(view)); + assertEquals(view.length, 16); + assertNotEquals(view, new Uint8Array(16)); + assertEquals(buf.subarray(0, 8), new Uint8Array(8)); + assertEquals(buf.subarray(24, 32), new Uint8Array(8)); +}); |