1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-29 02:29:06 -05:00
denoland-deno/testing/pretty_test.ts

94 lines
2.1 KiB
TypeScript
Raw Normal View History

2019-02-15 11:11:55 -05:00
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
2019-03-06 16:39:50 -05:00
import { test } from "./mod.ts";
2019-02-15 11:11:55 -05:00
import { red, green, white, gray, bold } from "../colors/mod.ts";
import { assertEquals } from "./pretty.ts";
2019-03-06 16:39:50 -05:00
import { assertThrows } from "./asserts.ts";
2019-02-15 11:11:55 -05:00
2019-03-04 19:53:35 -05:00
const createHeader = (): string[] => [
2019-02-15 11:11:55 -05:00
"",
"",
` ${gray(bold("[Diff]"))} ${red(bold("Left"))} / ${green(bold("Right"))}`,
"",
""
];
2019-03-04 19:53:35 -05:00
const added: (s: string) => string = (s: string): string => green(bold(s));
const removed: (s: string) => string = (s: string): string => red(bold(s));
2019-02-15 11:11:55 -05:00
test({
name: "pass case",
fn() {
assertEquals({ a: 10 }, { a: 10 });
assertEquals(true, true);
assertEquals(10, 10);
assertEquals("abc", "abc");
assertEquals({ a: 10, b: { c: "1" } }, { a: 10, b: { c: "1" } });
2019-02-15 11:11:55 -05:00
}
});
test({
name: "failed with number",
fn() {
2019-03-06 16:39:50 -05:00
assertThrows(
() => assertEquals(1, 2),
2019-02-15 11:11:55 -05:00
Error,
[...createHeader(), removed(`- 1`), added(`+ 2`), ""].join("\n")
);
}
});
test({
name: "failed with number vs string",
fn() {
2019-03-06 16:39:50 -05:00
assertThrows(
() => assertEquals(1, "1"),
2019-02-15 11:11:55 -05:00
Error,
[...createHeader(), removed(`- 1`), added(`+ "1"`)].join("\n")
);
}
});
test({
name: "failed with array",
fn() {
2019-03-06 16:39:50 -05:00
assertThrows(
() => assertEquals([1, "2", 3], ["1", "2", 3]),
2019-02-15 11:11:55 -05:00
Error,
[
...createHeader(),
white(" Array ["),
removed(`- 1,`),
added(`+ "1",`),
white(' "2",'),
white(" 3,"),
white(" ]"),
""
].join("\n")
);
}
});
test({
name: "failed with object",
fn() {
2019-03-06 16:39:50 -05:00
assertThrows(
() => assertEquals({ a: 1, b: "2", c: 3 }, { a: 1, b: 2, c: [3] }),
2019-02-15 11:11:55 -05:00
Error,
[
...createHeader(),
white(" Object {"),
white(` "a": 1,`),
added(`+ "b": 2,`),
added(`+ "c": Array [`),
added(`+ 3,`),
added(`+ ],`),
removed(`- "b": "2",`),
removed(`- "c": 3,`),
white(" }"),
""
].join("\n")
);
}
});