std/fmt/colors_test.ts
2024-04-29 11:57:30 +09:00

244 lines
6.3 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "@std/assert";
import * as c from "./colors.ts";
Deno.test("reset()", function () {
assertEquals(c.reset("foo bar"), "foo bar");
});
Deno.test("red() single color", function () {
assertEquals(c.red("foo bar"), "foo bar");
});
Deno.test("bgBlue() double color", function () {
assertEquals(c.bgBlue(c.red("foo bar")), "foo bar");
});
Deno.test("red() replaces close characters", function () {
assertEquals(c.red("Hello"), "Hello");
});
Deno.test("getColorEnabled() handles enabled colors", function () {
assertEquals(c.getColorEnabled(), true);
c.setColorEnabled(false);
assertEquals(c.bgBlue(c.red("foo bar")), "foo bar");
c.setColorEnabled(true);
assertEquals(c.red("foo bar"), "foo bar");
});
Deno.test("bold()", function () {
assertEquals(c.bold("foo bar"), "foo bar");
});
Deno.test("dim()", function () {
assertEquals(c.dim("foo bar"), "foo bar");
});
Deno.test("italic()", function () {
assertEquals(c.italic("foo bar"), "foo bar");
});
Deno.test("underline()", function () {
assertEquals(c.underline("foo bar"), "foo bar");
});
Deno.test("inverse()", function () {
assertEquals(c.inverse("foo bar"), "foo bar");
});
Deno.test("hidden()", function () {
assertEquals(c.hidden("foo bar"), "foo bar");
});
Deno.test("strikethrough()", function () {
assertEquals(c.strikethrough("foo bar"), "foo bar");
});
Deno.test("black()", function () {
assertEquals(c.black("foo bar"), "foo bar");
});
Deno.test("red()", function () {
assertEquals(c.red("foo bar"), "foo bar");
});
Deno.test("green()", function () {
assertEquals(c.green("foo bar"), "foo bar");
});
Deno.test("yellow()", function () {
assertEquals(c.yellow("foo bar"), "foo bar");
});
Deno.test("blue()", function () {
assertEquals(c.blue("foo bar"), "foo bar");
});
Deno.test("magenta()", function () {
assertEquals(c.magenta("foo bar"), "foo bar");
});
Deno.test("cyan()", function () {
assertEquals(c.cyan("foo bar"), "foo bar");
});
Deno.test("white()", function () {
assertEquals(c.white("foo bar"), "foo bar");
});
Deno.test("gray()", function () {
assertEquals(c.gray("foo bar"), "foo bar");
});
Deno.test("brightBlack()", function () {
assertEquals(c.brightBlack("foo bar"), "foo bar");
});
Deno.test("brightRed()", function () {
assertEquals(c.brightRed("foo bar"), "foo bar");
});
Deno.test("brightGreen()", function () {
assertEquals(c.brightGreen("foo bar"), "foo bar");
});
Deno.test("brightYellow()", function () {
assertEquals(c.brightYellow("foo bar"), "foo bar");
});
Deno.test("brightBlue()", function () {
assertEquals(c.brightBlue("foo bar"), "foo bar");
});
Deno.test("brightMagenta()", function () {
assertEquals(c.brightMagenta("foo bar"), "foo bar");
});
Deno.test("brightCyan()", function () {
assertEquals(c.brightCyan("foo bar"), "foo bar");
});
Deno.test("brightWhite()", function () {
assertEquals(c.brightWhite("foo bar"), "foo bar");
});
Deno.test("bgBlack()", function () {
assertEquals(c.bgBlack("foo bar"), "foo bar");
});
Deno.test("bgRed()", function () {
assertEquals(c.bgRed("foo bar"), "foo bar");
});
Deno.test("bgGreen()", function () {
assertEquals(c.bgGreen("foo bar"), "foo bar");
});
Deno.test("bgYellow()", function () {
assertEquals(c.bgYellow("foo bar"), "foo bar");
});
Deno.test("bgBlue()", function () {
assertEquals(c.bgBlue("foo bar"), "foo bar");
});
Deno.test("bgMagenta()", function () {
assertEquals(c.bgMagenta("foo bar"), "foo bar");
});
Deno.test("bgCyan()", function () {
assertEquals(c.bgCyan("foo bar"), "foo bar");
});
Deno.test("bgWhite()", function () {
assertEquals(c.bgWhite("foo bar"), "foo bar");
});
Deno.test("bgBrightBlack()", function () {
assertEquals(c.bgBrightBlack("foo bar"), "foo bar");
});
Deno.test("bgBrightRed()", function () {
assertEquals(c.bgBrightRed("foo bar"), "foo bar");
});
Deno.test("bgBrightGreen()", function () {
assertEquals(c.bgBrightGreen("foo bar"), "foo bar");
});
Deno.test("bgBrightYellow()", function () {
assertEquals(c.bgBrightYellow("foo bar"), "foo bar");
});
Deno.test("bgBrightBlue()", function () {
assertEquals(c.bgBrightBlue("foo bar"), "foo bar");
});
Deno.test("bgBrightMagenta()", function () {
assertEquals(c.bgBrightMagenta("foo bar"), "foo bar");
});
Deno.test("bgBrightCyan()", function () {
assertEquals(c.bgBrightCyan("foo bar"), "foo bar");
});
Deno.test("bgBrightWhite()", function () {
assertEquals(c.bgBrightWhite("foo bar"), "foo bar");
});
Deno.test("rgb8() handles clamp", function () {
assertEquals(c.rgb8("foo bar", -10), "foo bar");
});
Deno.test("rgb8() handles truncate", function () {
assertEquals(c.rgb8("foo bar", 42.5), "foo bar");
});
Deno.test("test rgb8", function () {
assertEquals(c.rgb8("foo bar", 42), "foo bar");
});
Deno.test("bgRgb8()", function () {
assertEquals(c.bgRgb8("foo bar", 42), "foo bar");
});
Deno.test("rgb24()", function () {
assertEquals(
c.rgb24("foo bar", {
r: 41,
g: 42,
b: 43,
}),
"foo bar",
);
});
Deno.test("rgb24() handles number", function () {
assertEquals(c.rgb24("foo bar", 0x070809), "foo bar");
});
Deno.test("bgRgb24()", function () {
assertEquals(
c.bgRgb24("foo bar", {
r: 41,
g: 42,
b: 43,
}),
"foo bar",
);
});
Deno.test("bgRgb24() handles number", function () {
assertEquals(c.bgRgb24("foo bar", 0x070809), "foo bar");
});
// https://github.com/chalk/strip-ansi/blob/2b8c961e75760059699373f9a69101065c3ded3a/test.js#L4-L6
Deno.test("stripAnsiCode()", function () {
assertEquals(
c.stripAnsiCode(
"\u001B[0m\u001B[4m\u001B[42m\u001B[31mfoo\u001B[39m\u001B[49m\u001B[24mfoo\u001B[0m",
),
"foofoo",
);
});