deno.land / x / msgpack_javascript@v3.0.0-beta2 / test / decode-max-length.test.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596import assert from "assert";import { encode, decode, decodeAsync } from "../src";import type { DecoderOptions } from "../src";
describe("decode with max${Type}Length specified", () => { async function* createStream<T>(input: T) { yield input; }
context("maxStrLength", () => { const input = encode("foo"); const options = { maxStrLength: 1 } satisfies DecoderOptions;
it("throws errors (synchronous)", () => { assert.throws(() => { decode(input, options); }, /max length exceeded/i); });
it("throws errors (asynchronous)", async () => { await assert.rejects(async () => { await decodeAsync(createStream(input), options); }, /max length exceeded/i); }); });
context("maxBinLength", () => { const input = encode(Uint8Array.from([1, 2, 3])); const options = { maxBinLength: 1 } satisfies DecoderOptions;
it("throws errors (synchronous)", () => { assert.throws(() => { decode(input, options); }, /max length exceeded/i); });
it("throws errors (asynchronous)", async () => { await assert.rejects(async () => { await decodeAsync(createStream(input), options); }, /max length exceeded/i); }); });
context("maxArrayLength", () => { const input = encode([1, 2, 3]); const options = { maxArrayLength: 1 } satisfies DecoderOptions;
it("throws errors (synchronous)", () => { assert.throws(() => { decode(input, options); }, /max length exceeded/i); });
it("throws errors (asynchronous)", async () => { await assert.rejects(async () => { await decodeAsync(createStream(input), options); }, /max length exceeded/i); }); });
context("maxMapLength", () => { const input = encode({ foo: 1, bar: 1, baz: 3 }); const options = { maxMapLength: 1 } satisfies DecoderOptions;
it("throws errors (synchronous)", () => { assert.throws(() => { decode(input, options); }, /max length exceeded/i); });
it("throws errors (asynchronous)", async () => { await assert.rejects(async () => { await decodeAsync(createStream(input), options); }, /max length exceeded/i); }); });
context("maxExtType", () => { const input = encode(new Date()); // timextamp ext requires at least 4 bytes. const options = { maxExtLength: 1 } satisfies DecoderOptions;
it("throws errors (synchronous)", () => { assert.throws(() => { decode(input, options); }, /max length exceeded/i); });
it("throws errors (asynchronous)", async () => { await assert.rejects(async () => { await decodeAsync(createStream(input), options); }, /max length exceeded/i); }); });});
Version Info