deno.land / std@0.224.0 / io / limited_reader_test.ts
12345678910111213141516171819202122232425262728293031323334// 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(), "");});
Version Info