Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement readString #607

Merged
merged 4 commits into from
Sep 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion io/bufio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ export class BufReader implements Reader {
* For simple uses, a Scanner may be more convenient.
*/
async readString(_delim: string): Promise<string | Deno.EOF> {
dsseng marked this conversation as resolved.
Show resolved Hide resolved
throw new Error("Not implemented");
const buffer = await this.readSlice(_delim.charCodeAt(0));
return new TextDecoder().decode(buffer);
}

/** `readLine()` is a low-level line-reading primitive. Most callers should
Expand Down
9 changes: 9 additions & 0 deletions io/bufio_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ test(async function bufioBufferFull(): Promise<void> {
assertEquals(actual, "world!");
});

test(async function bufioReadString(): Promise<void> {
const string = "And now, hello, world!";
const buf = new BufReader(stringsReader(string), MIN_READ_BUFFER_SIZE);

const line = assertNotEOF(await buf.readString(","));
assertEquals(line, "And now,");
assertEquals(line.length, 8);
});

const testInput = encoder.encode(
"012\n345\n678\n9ab\ncde\nfgh\nijk\nlmn\nopq\nrst\nuvw\nxy"
);
Expand Down