mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
c059a3d343
* BREAKING(json): remove `json` from module names * revert * fixes
32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
import { assertEquals, assertRejects } from "@std/assert";
|
|
import type { ConcatenatedJsonParseStream } from "./concatenated_json_parse_stream.ts";
|
|
import type { JsonParseStream } from "./parse_stream.ts";
|
|
|
|
export async function assertValidParse(
|
|
transform: typeof ConcatenatedJsonParseStream | typeof JsonParseStream,
|
|
chunks: string[],
|
|
expect: unknown[],
|
|
) {
|
|
const r = ReadableStream.from(chunks)
|
|
.pipeThrough(new transform());
|
|
const res = await Array.fromAsync(r);
|
|
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,
|
|
) {
|
|
const r = ReadableStream.from(chunks)
|
|
.pipeThrough(new transform());
|
|
await assertRejects(
|
|
async () => await Array.fromAsync(r),
|
|
ErrorClass,
|
|
msgIncludes,
|
|
);
|
|
}
|