mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
a04a2ed798
* fix(streams): strictly define `toJson()` and `toText()` input * fix
28 lines
636 B
TypeScript
28 lines
636 B
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
import { assertEquals } from "@std/assert";
|
|
import { toJson } from "./to_json.ts";
|
|
|
|
Deno.test("toJson()", async () => {
|
|
const strings = [
|
|
"[",
|
|
"1, 2, 3, 4,",
|
|
'{ "a": 2,',
|
|
' "b": 3,',
|
|
' "c": 4 }',
|
|
"]",
|
|
];
|
|
const expected = [1, 2, 3, 4, {
|
|
a: 2,
|
|
b: 3,
|
|
c: 4,
|
|
}];
|
|
|
|
const byteStream = ReadableStream.from(strings)
|
|
.pipeThrough(new TextEncoderStream());
|
|
assertEquals(await toJson(byteStream), expected);
|
|
|
|
const stringStream = ReadableStream.from(strings);
|
|
assertEquals(await toJson(stringStream), expected);
|
|
});
|