diff options
author | Marcos Casagrande <marcoscvp90@gmail.com> | 2020-06-12 21:15:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-12 15:15:29 -0400 |
commit | 26bf56afdaf16634ffbaa23684faf3a44cc10f62 (patch) | |
tree | 25265007d7b09bd4580659ae34d833759df745d2 /std/io/bufio_test.ts | |
parent | 7d41bacfba6a3557066345ecd282f0d83e4a4381 (diff) |
fix(std/io): BufWriter/StringWriter bug (#6247)
Diffstat (limited to 'std/io/bufio_test.ts')
-rw-r--r-- | std/io/bufio_test.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/std/io/bufio_test.ts b/std/io/bufio_test.ts index b03640d52..92119e4db 100644 --- a/std/io/bufio_test.ts +++ b/std/io/bufio_test.ts @@ -18,6 +18,7 @@ import { } from "./bufio.ts"; import * as iotest from "./_iotest.ts"; import { StringReader } from "./readers.ts"; +import { StringWriter } from "./writers.ts"; import { charCode, copyBytes } from "./util.ts"; const encoder = new TextEncoder(); @@ -469,3 +470,33 @@ Deno.test( ); } ); + +Deno.test({ + name: "Reset buffer after flush", + async fn(): Promise<void> { + const stringWriter = new StringWriter(); + const bufWriter = new BufWriter(stringWriter); + const encoder = new TextEncoder(); + await bufWriter.write(encoder.encode("hello\nworld\nhow\nare\nyou?\n\n")); + await bufWriter.flush(); + await bufWriter.write(encoder.encode("foobar\n\n")); + await bufWriter.flush(); + const actual = stringWriter.toString(); + assertEquals(actual, "hello\nworld\nhow\nare\nyou?\n\nfoobar\n\n"); + }, +}); + +Deno.test({ + name: "Reset buffer after flush sync", + fn(): void { + const stringWriter = new StringWriter(); + const bufWriter = new BufWriterSync(stringWriter); + const encoder = new TextEncoder(); + bufWriter.writeSync(encoder.encode("hello\nworld\nhow\nare\nyou?\n\n")); + bufWriter.flush(); + bufWriter.writeSync(encoder.encode("foobar\n\n")); + bufWriter.flush(); + const actual = stringWriter.toString(); + assertEquals(actual, "hello\nworld\nhow\nare\nyou?\n\nfoobar\n\n"); + }, +}); |