diff options
author | Marcos Casagrande <marcoscvp90@gmail.com> | 2020-06-27 21:57:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-27 15:57:32 -0400 |
commit | f0093a9d8bed7bc10ac06e612a925d0e8d192981 (patch) | |
tree | de290b63f0d713a6b29af31c1018354c49bd7519 /std/node/buffer_test.ts | |
parent | 4302941b06b51233b13cd1f7293a4f38e0ec8073 (diff) |
test(std/node): Add Buffer tests (#6524)
Diffstat (limited to 'std/node/buffer_test.ts')
-rw-r--r-- | std/node/buffer_test.ts | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/std/node/buffer_test.ts b/std/node/buffer_test.ts index 2be7a70bb..8f6d19058 100644 --- a/std/node/buffer_test.ts +++ b/std/node/buffer_test.ts @@ -2,6 +2,18 @@ import { assert, assertEquals, assertThrows } from "../testing/asserts.ts"; import Buffer from "./buffer.ts"; Deno.test({ + name: "Buffer global scope", + fn() { + // deno-lint-ignore ban-ts-comment + // @ts-ignore + assert(window.Buffer === Buffer); + // deno-lint-ignore ban-ts-comment + // @ts-ignore + assert(globalThis.Buffer === Buffer); + }, +}); + +Deno.test({ name: "alloc fails on negative numbers", fn() { assertThrows( @@ -411,13 +423,35 @@ Deno.test({ Deno.test({ name: "isBuffer returns true if the object is a buffer", fn() { - assert(Buffer.isBuffer(Buffer.from("test"))); + assertEquals(Buffer.isBuffer(Buffer.from("test")), true); }, }); Deno.test({ name: "isBuffer returns false if the object is not a buffer", fn() { - assert(!Buffer.isBuffer({ test: 3 })); + assertEquals(Buffer.isBuffer({ test: 3 }), false); + assertEquals(Buffer.isBuffer(new Uint8Array()), false); + }, +}); + +Deno.test({ + name: "Buffer toJSON", + fn() { + assertEquals( + JSON.stringify(Buffer.from("deno")), + '{"type":"Buffer","data":[100,101,110,111]}' + ); + }, +}); + +Deno.test({ + name: "buf.slice does not create a copy", + fn() { + const buf = Buffer.from("ceno"); + // This method is not compatible with the Uint8Array.prototype.slice() + const slice = buf.slice(); + slice[0]++; + assertEquals(slice.toString(), "deno"); }, }); |