Skip to content

Commit

Permalink
Add tests for denoland#6543
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosc90 committed Jun 28, 2020
1 parent 2da0840 commit ae54595
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions cli/tests/unit/buffer_test.ts
Expand Up @@ -12,6 +12,7 @@ import {
} from "./test_util.ts";

// N controls how many iterations of certain checks are performed.
const MAX_SIZE = 2 ** 32 - 2;
const N = 100;
let testBytes: Uint8Array | null;
let testString: string | null;
Expand Down Expand Up @@ -167,6 +168,43 @@ unitTest(async function bufferTooLargeByteWrites(): Promise<void> {
);
});

unitTest(function bufferGrowWriteMaxBuffer(): void {
const bufSize = 16 * 1024;
const capacities = [MAX_SIZE, MAX_SIZE - 1, MAX_SIZE - 512];
for (const capacity of capacities) {
let written = 0;
const buf = new Deno.Buffer();
const writes = Math.floor(capacity / bufSize);
for (let i = 0; i < writes; i++)
written += buf.writeSync(repeat("x", bufSize));

console.log(written, capacity, capacity - written);
if (written < capacity) {
written += buf.writeSync(repeat("x", capacity - written));
}

assertEquals(written, capacity);
}
});

unitTest(function bufferGrowReadSyncCloseToMaxBuffer(): void {
const capacities = [MAX_SIZE, MAX_SIZE - 1, MAX_SIZE - 512];
for (const capacity of capacities) {
const reader = new Deno.Buffer(new ArrayBuffer(capacity));
const buf = new Deno.Buffer();
buf.readFromSync(reader);
}
});

unitTest(async function bufferGrowReadCloseToMaxBuffer(): Promise<void> {
const capacities = [MAX_SIZE, MAX_SIZE - 1, MAX_SIZE - 512];
for (const capacity of capacities) {
const reader = new Deno.Buffer(new ArrayBuffer(capacity));
const buf = new Deno.Buffer();
await buf.readFrom(reader);
}
});

unitTest(async function bufferLargeByteReads(): Promise<void> {
init();
assert(testBytes);
Expand Down

0 comments on commit ae54595

Please sign in to comment.