1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-23 15:16:54 -05:00
denoland-deno/std/io/readers_test.ts
Ryan Dahl 12c6b2395b
Move encode, decode helpers to /std/encoding/utf8.ts, delete /std/strings/ (#4565)
also removes std/encoding/mod.ts and std/archive/mod.ts which are useless.
2020-04-01 15:23:39 -04:00

38 lines
1.2 KiB
TypeScript

const { copy, test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import { MultiReader, StringReader } from "./readers.ts";
import { StringWriter } from "./writers.ts";
import { copyN } from "./ioutil.ts";
import { decode } from "../encoding/utf8.ts";
test(async function ioStringReader(): Promise<void> {
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, Deno.EOF);
});
test(async function ioStringReader(): Promise<void> {
const r = new StringReader("abcdef");
const buf = new Uint8Array(3);
const res1 = await r.read(buf);
assertEquals(res1, 3);
assertEquals(decode(buf), "abc");
const res2 = await r.read(buf);
assertEquals(res2, 3);
assertEquals(decode(buf), "def");
const res3 = await r.read(buf);
assertEquals(res3, Deno.EOF);
assertEquals(decode(buf), "def");
});
test(async function ioMultiReader(): Promise<void> {
const r = new MultiReader(new StringReader("abc"), new StringReader("def"));
const w = new StringWriter();
const n = await copyN(w, r, 4);
assertEquals(n, 4);
assertEquals(w.toString(), "abcd");
await copy(w, r);
assertEquals(w.toString(), "abcdef");
});