summaryrefslogtreecommitdiff
path: root/std/io/readers_test.ts
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-10-09 17:18:08 -0400
committerRyan Dahl <ry@tinyclouds.org>2019-10-09 17:18:08 -0400
commit28293acd9c12a94f5d769706291032e844c7b92b (patch)
tree1fec6a3cd8d7c9e8bc9b1486f5c8438eb906a595 /std/io/readers_test.ts
parent5c6835efd82c298df99ce71c4a36ca23515333a3 (diff)
parent151ce0266eb4de2c8fc600c81c192a5f791b6169 (diff)
Merge branch 'std_modified' into merge_std3
Diffstat (limited to 'std/io/readers_test.ts')
-rw-r--r--std/io/readers_test.ts39
1 files changed, 39 insertions, 0 deletions
diff --git a/std/io/readers_test.ts b/std/io/readers_test.ts
new file mode 100644
index 000000000..474407427
--- /dev/null
+++ b/std/io/readers_test.ts
@@ -0,0 +1,39 @@
+const { copy } = Deno;
+import { test } from "../testing/mod.ts";
+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 "../strings/mod.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");
+});