diff options
| author | Ryan Dahl <ry@tinyclouds.org> | 2018-11-09 13:25:30 -0500 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2018-11-09 13:25:30 -0500 |
| commit | 5880827f33ab90d4d5f5ac2f9166fddc76614cfa (patch) | |
| tree | 3711290b246caea080593aa8d436c379c3a10e22 /bufio_test.ts | |
| parent | 9b78509ceb975df3dc9d795c7310dcc4c73436a3 (diff) | |
First pass at BufWriter
Original: https://github.com/denoland/deno_std/commit/9329cd76bd67b96fbeab6ef0b02703bd77a9b482
Diffstat (limited to 'bufio_test.ts')
| -rw-r--r-- | bufio_test.ts | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/bufio_test.ts b/bufio_test.ts index 9c89f0216..f3430a755 100644 --- a/bufio_test.ts +++ b/bufio_test.ts @@ -9,7 +9,7 @@ import { assert, assertEqual } from "https://deno.land/x/testing/testing.ts"; -import { BufReader, BufState } from "./bufio.ts"; +import { BufReader, BufState, BufWriter } from "./bufio.ts"; import { Buffer, stringsReader } from "./buffer.ts"; import * as iotest from "./iotest.ts"; import { charCode, copyBytes } from "./util.ts"; @@ -289,3 +289,36 @@ test(async function bufioPeek() { } */ }); + +test(async function bufioWriter() { + const data = new Uint8Array(8192); + + for (let i = 0; i < data.byteLength; i++) { + data[i] = charCode(" ") + i % (charCode("~") - charCode(" ")); + } + + const w = new Buffer(); + for (let nwrite of bufsizes) { + for (let bs of bufsizes) { + // Write nwrite bytes using buffer size bs. + // Check that the right amount makes it out + // and that the data is correct. + + w.reset(); + const buf = new BufWriter(w, bs); + + const context = `nwrite=${nwrite} bufsize=${bs}`; + const n = await buf.write(data.subarray(0, nwrite)); + assertEqual(n, nwrite, context); + + await buf.flush(); + + const written = w.bytes(); + assertEqual(written.byteLength, nwrite); + + for (let l = 0; l < written.byteLength; l++) { + assertEqual(written[l], data[l]); + } + } + } +}); |
