deno.land / std@0.224.0 / io / string_reader_test.ts

string_reader_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
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "../assert/mod.ts";import { StringReader } from "./string_reader.ts";
Deno.test("ioStringReader", async function () { const r = new StringReader("abcdef"); const res0 = await r.read(new Uint8Array(6)); assertEquals(res0, 6); const res1 = await r.read(new Uint8Array(6)); assertEquals(res1, null);});
Deno.test("ioStringReader", async function () { const decoder = new TextDecoder(); const r = new StringReader("abcdef"); const buf = new Uint8Array(3); const res1 = await r.read(buf); assertEquals(res1, 3); assertEquals(decoder.decode(buf), "abc"); const res2 = await r.read(buf); assertEquals(res2, 3); assertEquals(decoder.decode(buf), "def"); const res3 = await r.read(buf); assertEquals(res3, null); assertEquals(decoder.decode(buf), "def");});
Deno.test("testStringReaderEof", async function () { const r = new StringReader("abc"); assertEquals(await r.read(new Uint8Array()), 0); assertEquals(await r.read(new Uint8Array(4)), 3); assertEquals(await r.read(new Uint8Array(1)), null);});
std

Version Info

Tagged at
6 months ago