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

limited_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
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.import { assertEquals } from "../assert/mod.ts";import { LimitedReader } from "./limited_reader.ts";import { StringWriter } from "./string_writer.ts";import { copy } from "./copy.ts";import { readAll } from "./read_all.ts";import { StringReader } from "./string_reader.ts";
Deno.test("ioLimitedReader", async function () { const decoder = new TextDecoder(); let sr = new StringReader("abc"); let r = new LimitedReader(sr, 2); let buffer = await readAll(r); assertEquals(decoder.decode(buffer), "ab"); assertEquals(decoder.decode(await readAll(sr)), "c"); sr = new StringReader("abc"); r = new LimitedReader(sr, 3); buffer = await readAll(r); assertEquals(decoder.decode(buffer), "abc"); assertEquals((await readAll(r)).length, 0); sr = new StringReader("abc"); r = new LimitedReader(sr, 4); buffer = await readAll(r); assertEquals(decoder.decode(buffer), "abc"); assertEquals((await readAll(r)).length, 0);});
Deno.test("ioLimitedReader", async function () { const rb = new StringReader("abc"); const wb = new StringWriter(); await copy(new LimitedReader(rb, -1), wb); assertEquals(wb.toString(), "");});
std

Version Info

Tagged at
6 months ago