summaryrefslogtreecommitdiff
path: root/std/io/bufio_test.ts
diff options
context:
space:
mode:
authorNayeem Rahman <muhammed.9939@gmail.com>2020-02-18 00:51:13 +0000
committerGitHub <noreply@github.com>2020-02-17 19:51:13 -0500
commit5a3292047c42b8a65d164f127fc57e57046fadf7 (patch)
treea7612e75eb56a25ace057cab9eacafcd266c48d8 /std/io/bufio_test.ts
parent7b9f6e9c456175fd8a6c11049a2f5f723e909d03 (diff)
feat(std/io): Export readDelim(), readStringDelim() and readLines() from bufio.ts (#4019)
Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'std/io/bufio_test.ts')
-rw-r--r--std/io/bufio_test.ts29
1 files changed, 28 insertions, 1 deletions
diff --git a/std/io/bufio_test.ts b/std/io/bufio_test.ts
index 665c25361..4f4bd48b1 100644
--- a/std/io/bufio_test.ts
+++ b/std/io/bufio_test.ts
@@ -15,7 +15,9 @@ import {
BufReader,
BufWriter,
BufferFullError,
- UnexpectedEOFError
+ UnexpectedEOFError,
+ readStringDelim,
+ readLines
} from "./bufio.ts";
import * as iotest from "./iotest.ts";
import { charCode, copyBytes, stringsReader } from "./util.ts";
@@ -381,3 +383,28 @@ Deno.test(async function bufReaderReadFull(): Promise<void> {
}
}
});
+
+Deno.test(async function readStringDelimAndLines(): Promise<void> {
+ const enc = new TextEncoder();
+ const data = new Buffer(
+ enc.encode("Hello World\tHello World 2\tHello World 3")
+ );
+ const chunks_ = [];
+
+ for await (const c of readStringDelim(data, "\t")) {
+ chunks_.push(c);
+ }
+
+ assertEquals(chunks_.length, 3);
+ assertEquals(chunks_, ["Hello World", "Hello World 2", "Hello World 3"]);
+
+ const linesData = new Buffer(enc.encode("0\n1\n2\n3\n4\n5\n6\n7\n8\n9"));
+ const lines_ = [];
+
+ for await (const l of readLines(linesData)) {
+ lines_.push(l);
+ }
+
+ assertEquals(lines_.length, 10);
+ assertEquals(lines_, ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]);
+});