2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-09-13 08:21:52 +00:00
|
|
|
|
refactor(assert,async,bytes,cli,collections,crypto,csv,data-structures,datetime,dotenv,encoding,expect,fmt,front-matter,fs,html,http,ini,internal,io,json,jsonc,log,media-types,msgpack,net,path,semver,streams,testing,text,toml,ulid,url,uuid,webgpu,yaml): import from `@std/assert` (#5199)
* refactor: import from `@std/assert`
* update
2024-06-30 08:30:10 +00:00
|
|
|
import { assertEquals } from "@std/assert";
|
2023-09-13 08:21:52 +00:00
|
|
|
import { toJson } from "./to_json.ts";
|
|
|
|
|
2024-02-27 20:12:47 +00:00
|
|
|
Deno.test("toJson()", async () => {
|
2024-07-23 03:23:35 +00:00
|
|
|
const strings = [
|
|
|
|
"[",
|
|
|
|
"1, 2, 3, 4,",
|
2023-11-10 03:57:52 +00:00
|
|
|
'{ "a": 2,',
|
|
|
|
' "b": 3,',
|
|
|
|
' "c": 4 }',
|
2024-07-23 03:23:35 +00:00
|
|
|
"]",
|
|
|
|
];
|
|
|
|
const expected = [1, 2, 3, 4, {
|
2023-09-13 08:21:52 +00:00
|
|
|
a: 2,
|
|
|
|
b: 3,
|
|
|
|
c: 4,
|
2024-07-23 03:23:35 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
const byteStream = ReadableStream.from(strings)
|
|
|
|
.pipeThrough(new TextEncoderStream());
|
|
|
|
assertEquals(await toJson(byteStream), expected);
|
|
|
|
|
|
|
|
const stringStream = ReadableStream.from(strings);
|
|
|
|
assertEquals(await toJson(stringStream), expected);
|
2023-09-13 08:21:52 +00:00
|
|
|
});
|