mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
662f27ce84
Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
68 lines
1.2 KiB
TypeScript
68 lines
1.2 KiB
TypeScript
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
|
import { green, red, stripColor } from "../fmt/colors.ts";
|
|
import { assertEquals, assertThrows } from "./asserts.ts";
|
|
import { format } from "./_format.ts";
|
|
|
|
Deno.test("assert diff formatting (strings)", () => {
|
|
assertThrows(
|
|
() => {
|
|
assertEquals([..."abcd"].join("\n"), [..."abxde"].join("\n"));
|
|
},
|
|
Error,
|
|
`
|
|
a\\n
|
|
b\\n
|
|
${green("+ x")}\\n
|
|
${green("+ d")}\\n
|
|
${green("+ e")}
|
|
${red("- c")}\\n
|
|
${red("- d")}
|
|
`,
|
|
);
|
|
});
|
|
|
|
// Check that the diff formatter overrides some default behaviours of
|
|
// `Deno.inspect()` which are problematic for diffing.
|
|
Deno.test("assert diff formatting", () => {
|
|
// Wraps objects into multiple lines even when they are small. Prints trailing
|
|
// commas.
|
|
assertEquals(
|
|
stripColor(format({ a: 1, b: 2 })),
|
|
`{
|
|
a: 1,
|
|
b: 2,
|
|
}`,
|
|
);
|
|
|
|
// Same for nested small objects.
|
|
assertEquals(
|
|
stripColor(format([{ x: { a: 1, b: 2 }, y: ["a", "b"] }])),
|
|
`[
|
|
{
|
|
x: {
|
|
a: 1,
|
|
b: 2,
|
|
},
|
|
y: [
|
|
"a",
|
|
"b",
|
|
],
|
|
},
|
|
]`,
|
|
);
|
|
|
|
// Grouping is disabled.
|
|
assertEquals(
|
|
stripColor(format(["i", "i", "i", "i", "i", "i", "i"])),
|
|
`[
|
|
"i",
|
|
"i",
|
|
"i",
|
|
"i",
|
|
"i",
|
|
"i",
|
|
"i",
|
|
]`,
|
|
);
|
|
});
|