deno.land / std@0.224.0 / streams / buffer_test.ts

buffer_test.ts
View Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals } from "../assert/mod.ts";import { Buffer } from "./buffer.ts";
Deno.test("Buffer handles write and read", async function () { const buf = new Buffer(); const writer = buf.writable.getWriter(); const reader = buf.readable.getReader({ mode: "byob" }); const data = new Uint8Array([4, 21, 45, 19]); await writer.write(data); const read = await reader.read(new Uint8Array(4)); assertEquals(read.value, data);});
Deno.test("Buffer handles read empty", async function () { const buf = new Buffer(); const reader = buf.readable.getReader({ mode: "byob" }); const read = await reader.read(new Uint8Array(5)); assert(read.done); assertEquals(read.value!.byteLength, 0);});
Deno.test("Buffer handles write and get bytes", async function () { const buf = new Buffer(); const writer = buf.writable.getWriter(); const data = new Uint8Array([4, 21, 45, 19]); await writer.write(data); assertEquals(buf.bytes(), data);});
Deno.test("Buffer handles truncate", async function () { const buf = new Buffer(); const writer = buf.writable.getWriter(); await writer.write(new Uint8Array([4, 21, 45, 19])); buf.truncate(3); assertEquals(buf.bytes(), new Uint8Array([4, 21, 45]));});
std

Version Info

Tagged at
6 months ago