Skip to content

Commit

Permalink
clarify decodeMulti*() can decode empty inputs
Browse files Browse the repository at this point in the history
amend 32654ee
  • Loading branch information
gfx committed May 1, 2022
1 parent 32654ee commit 2b66bb7
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion test/edge-cases.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// kind of hand-written fuzzing data
// any errors should not break Encoder/Decoder instance states
import assert from "assert";
import { encode, decodeAsync, decode, Encoder, Decoder } from "../src";
import { encode, decodeAsync, decode, Encoder, Decoder, decodeMulti, decodeMultiStream } from "../src";
import { DataViewIndexOutOfBoundsError } from "../src/Decoder";

function testEncoder(encoder: Encoder): void {
Expand Down Expand Up @@ -155,6 +155,10 @@ describe("edge cases", () => {
}, RangeError);
});

it("decodes an empty array with decodeMulti()", () => {
assert.deepStrictEqual([...decodeMulti([])], []);
});

it("throws RangeError (asynchronous)", async () => {
const createStream = async function* () {
yield [];
Expand All @@ -164,5 +168,17 @@ describe("edge cases", () => {
await decodeAsync(createStream());
}, RangeError);
});

it("decodes an empty array with decodeMultiStream()", async () => {
const createStream = async function* () {
yield [];
};

const results = [];
for await (const item of decodeMultiStream(createStream())) {
results.push(item);
}
assert.deepStrictEqual(results, []);
});
});
});

0 comments on commit 2b66bb7

Please sign in to comment.