2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2022-12-05 06:51:08 +00:00
|
|
|
|
2024-04-29 02:57:30 +00:00
|
|
|
import { assertEquals } from "@std/assert";
|
2022-12-05 06:51:08 +00:00
|
|
|
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);
|
|
|
|
});
|