2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2024-04-29 02:57:30 +00:00
|
|
|
import { assertEquals, assertRejects } from "@std/assert";
|
2023-03-13 05:56:53 +00:00
|
|
|
import type { ConcatenatedJsonParseStream } from "./concatenated_json_parse_stream.ts";
|
2024-07-02 01:57:00 +00:00
|
|
|
import type { JsonParseStream } from "./parse_stream.ts";
|
2023-03-13 05:56:53 +00:00
|
|
|
|
|
|
|
export async function assertValidParse(
|
|
|
|
transform: typeof ConcatenatedJsonParseStream | typeof JsonParseStream,
|
|
|
|
chunks: string[],
|
|
|
|
expect: unknown[],
|
|
|
|
) {
|
2023-11-10 19:00:28 +00:00
|
|
|
const r = ReadableStream.from(chunks)
|
2024-06-21 04:20:36 +00:00
|
|
|
.pipeThrough(new transform());
|
2023-11-10 19:00:28 +00:00
|
|
|
const res = await Array.fromAsync(r);
|
2023-03-13 05:56:53 +00:00
|
|
|
assertEquals(res, expect);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function assertInvalidParse(
|
|
|
|
transform: typeof ConcatenatedJsonParseStream | typeof JsonParseStream,
|
|
|
|
chunks: string[],
|
|
|
|
// deno-lint-ignore no-explicit-any
|
|
|
|
ErrorClass: new (...args: any[]) => Error,
|
|
|
|
msgIncludes: string | undefined,
|
|
|
|
) {
|
2023-11-10 19:00:28 +00:00
|
|
|
const r = ReadableStream.from(chunks)
|
2024-06-21 04:20:36 +00:00
|
|
|
.pipeThrough(new transform());
|
2023-03-13 05:56:53 +00:00
|
|
|
await assertRejects(
|
2023-11-10 19:00:28 +00:00
|
|
|
async () => await Array.fromAsync(r),
|
2023-03-13 05:56:53 +00:00
|
|
|
ErrorClass,
|
|
|
|
msgIncludes,
|
|
|
|
);
|
|
|
|
}
|