From c427c2df427f477eb1214d8ff3fdfad36e191a6c Mon Sep 17 00:00:00 2001 From: binaryta Date: Mon, 10 Dec 2018 05:38:30 +0900 Subject: Add TooLarge error code for buffers (#1298) In collaboration with @yushimatenjin --- js/buffer_test.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'js/buffer_test.ts') diff --git a/js/buffer_test.ts b/js/buffer_test.ts index 58668de26..2683b3862 100644 --- a/js/buffer_test.ts +++ b/js/buffer_test.ts @@ -1,9 +1,9 @@ import { Buffer, readAll } from "deno"; +import * as deno from "deno"; // This code has been ported almost directly from Go's src/bytes/buffer_test.go // Copyright 2009 The Go Authors. All rights reserved. BSD license. // https://github.com/golang/go/blob/master/LICENSE import { assert, assertEqual, test } from "./test_util.ts"; - // N controls how many iterations of certain checks are performed. const N = 100; let testBytes: Uint8Array | null; @@ -130,6 +130,25 @@ test(async function bufferLargeByteWrites() { check(buf, ""); }); +test(async function bufferTooLargeByteWrites() { + init(); + const tmp = new Uint8Array(72); + const growLen = Number.MAX_VALUE; + const xBytes = repeat("x", 0); + const buf = new Buffer(xBytes.buffer as ArrayBuffer); + const { nread, eof } = await buf.read(tmp); + + let err; + try { + buf.grow(growLen); + } catch (e) { + err = e; + } + + assertEqual(err.kind, deno.ErrorKind.TooLarge); + assertEqual(err.name, "TooLarge"); +}); + test(async function bufferLargeByteReads() { init(); const buf = new Buffer(); -- cgit v1.2.3