summaryrefslogtreecommitdiff
path: root/std/io/bufio_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'std/io/bufio_test.ts')
-rw-r--r--std/io/bufio_test.ts35
1 files changed, 35 insertions, 0 deletions
diff --git a/std/io/bufio_test.ts b/std/io/bufio_test.ts
index c1b1b856b..ef1fcc11e 100644
--- a/std/io/bufio_test.ts
+++ b/std/io/bufio_test.ts
@@ -14,6 +14,7 @@ import {
import {
BufReader,
BufWriter,
+ BufWriterSync,
BufferFullError,
PartialReadError,
readStringDelim,
@@ -353,6 +354,40 @@ Deno.test(async function bufioWriter(): Promise<void> {
}
});
+Deno.test(function bufioWriterSync(): void {
+ const data = new Uint8Array(8192);
+
+ for (let i = 0; i < data.byteLength; i++) {
+ // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
+ data[i] = charCode(" ") + (i % (charCode("~") - charCode(" ")));
+ }
+
+ const w = new Buffer();
+ for (const nwrite of bufsizes) {
+ for (const 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 BufWriterSync(w, bs);
+
+ const context = `nwrite=${nwrite} bufsize=${bs}`;
+ const n = buf.writeSync(data.subarray(0, nwrite));
+ assertEquals(n, nwrite, context);
+
+ buf.flush();
+
+ const written = w.bytes();
+ assertEquals(written.byteLength, nwrite);
+
+ for (let l = 0; l < written.byteLength; l++) {
+ assertEquals(written[l], data[l]);
+ }
+ }
+ }
+});
+
Deno.test(async function bufReaderReadFull(): Promise<void> {
const enc = new TextEncoder();
const dec = new TextDecoder();