2020-02-11 11:24:27 -05:00
|
|
|
const { copy, test } = Deno;
|
2019-03-06 19:42:24 -05:00
|
|
|
import { assertEquals } from "../testing/asserts.ts";
|
2019-02-10 18:49:48 -05:00
|
|
|
import { StringWriter } from "./writers.ts";
|
|
|
|
import { StringReader } from "./readers.ts";
|
|
|
|
import { copyN } from "./ioutil.ts";
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
test("ioStringWriter", async function (): Promise<void> {
|
2019-02-10 18:49:48 -05:00
|
|
|
const w = new StringWriter("base");
|
|
|
|
const r = new StringReader("0123456789");
|
2020-04-26 16:26:02 -04:00
|
|
|
await copyN(r, w, 4);
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(w.toString(), "base0123");
|
2020-04-24 18:09:14 -04:00
|
|
|
await copy(r, w);
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(w.toString(), "base0123456789");
|
2019-02-10 18:49:48 -05:00
|
|
|
});
|
2020-06-12 15:15:29 -04:00
|
|
|
|
|
|
|
test("ioStringWriterSync", function (): void {
|
|
|
|
const encoder = new TextEncoder();
|
|
|
|
const w = new StringWriter("");
|
|
|
|
w.writeSync(encoder.encode("deno"));
|
|
|
|
assertEquals(w.toString(), "deno");
|
|
|
|
w.writeSync(encoder.encode("\nland"));
|
|
|
|
assertEquals(w.toString(), "deno\nland");
|
|
|
|
});
|