2024-01-01 21:11:32 +00:00
|
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2024-04-29 02:57:30 +00:00
|
|
|
|
import { assertEquals } from "@std/assert";
|
2019-08-24 17:38:18 +00:00
|
|
|
|
import * as c from "./colors.ts";
|
2018-12-19 04:30:44 +00:00
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("reset()", function () {
|
2021-02-02 03:13:44 +00:00
|
|
|
|
assertEquals(c.reset("foo bar"), "[0mfoo bar[0m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("red() single color", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.red("foo bar"), "[31mfoo bar[39m");
|
2018-12-19 04:30:44 +00:00
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("bgBlue() double color", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.bgBlue(c.red("foo bar")), "[44m[31mfoo bar[39m[49m");
|
2019-01-15 21:16:52 +00:00
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("red() replaces close characters", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.red("Hel[39mlo"), "[31mHel[31mlo[39m");
|
2019-01-15 21:16:52 +00:00
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("getColorEnabled() handles enabled colors", function () {
|
2019-12-20 20:21:30 +00:00
|
|
|
|
assertEquals(c.getColorEnabled(), true);
|
|
|
|
|
c.setColorEnabled(false);
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.bgBlue(c.red("foo bar")), "foo bar");
|
2019-12-20 20:21:30 +00:00
|
|
|
|
c.setColorEnabled(true);
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.red("foo bar"), "[31mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("bold()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.bold("foo bar"), "[1mfoo bar[22m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("dim()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.dim("foo bar"), "[2mfoo bar[22m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("italic()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.italic("foo bar"), "[3mfoo bar[23m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("underline()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.underline("foo bar"), "[4mfoo bar[24m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("inverse()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.inverse("foo bar"), "[7mfoo bar[27m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("hidden()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.hidden("foo bar"), "[8mfoo bar[28m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("strikethrough()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.strikethrough("foo bar"), "[9mfoo bar[29m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("black()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.black("foo bar"), "[30mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("red()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.red("foo bar"), "[31mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("green()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.green("foo bar"), "[32mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("yellow()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.yellow("foo bar"), "[33mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("blue()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.blue("foo bar"), "[34mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("magenta()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.magenta("foo bar"), "[35mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("cyan()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.cyan("foo bar"), "[36mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("white()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.white("foo bar"), "[37mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("gray()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.gray("foo bar"), "[90mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("brightBlack()", function () {
|
2020-08-29 08:29:41 +00:00
|
|
|
|
assertEquals(c.brightBlack("foo bar"), "[90mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("brightRed()", function () {
|
2020-08-29 08:29:41 +00:00
|
|
|
|
assertEquals(c.brightRed("foo bar"), "[91mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("brightGreen()", function () {
|
2020-08-29 08:29:41 +00:00
|
|
|
|
assertEquals(c.brightGreen("foo bar"), "[92mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("brightYellow()", function () {
|
2020-08-29 08:29:41 +00:00
|
|
|
|
assertEquals(c.brightYellow("foo bar"), "[93mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("brightBlue()", function () {
|
2020-08-29 08:29:41 +00:00
|
|
|
|
assertEquals(c.brightBlue("foo bar"), "[94mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("brightMagenta()", function () {
|
2020-08-29 08:29:41 +00:00
|
|
|
|
assertEquals(c.brightMagenta("foo bar"), "[95mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("brightCyan()", function () {
|
2020-08-29 08:29:41 +00:00
|
|
|
|
assertEquals(c.brightCyan("foo bar"), "[96mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("brightWhite()", function () {
|
2020-08-29 08:29:41 +00:00
|
|
|
|
assertEquals(c.brightWhite("foo bar"), "[97mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("bgBlack()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.bgBlack("foo bar"), "[40mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("bgRed()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.bgRed("foo bar"), "[41mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("bgGreen()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.bgGreen("foo bar"), "[42mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("bgYellow()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.bgYellow("foo bar"), "[43mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("bgBlue()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.bgBlue("foo bar"), "[44mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("bgMagenta()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.bgMagenta("foo bar"), "[45mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("bgCyan()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.bgCyan("foo bar"), "[46mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("bgWhite()", function () {
|
2019-08-22 06:20:47 +00:00
|
|
|
|
assertEquals(c.bgWhite("foo bar"), "[47mfoo bar[49m");
|
2018-12-19 04:30:44 +00:00
|
|
|
|
});
|
2020-05-09 10:29:44 +00:00
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("bgBrightBlack()", function () {
|
2020-08-29 08:29:41 +00:00
|
|
|
|
assertEquals(c.bgBrightBlack("foo bar"), "[100mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("bgBrightRed()", function () {
|
2020-08-29 08:29:41 +00:00
|
|
|
|
assertEquals(c.bgBrightRed("foo bar"), "[101mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("bgBrightGreen()", function () {
|
2020-08-29 08:29:41 +00:00
|
|
|
|
assertEquals(c.bgBrightGreen("foo bar"), "[102mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("bgBrightYellow()", function () {
|
2020-08-29 08:29:41 +00:00
|
|
|
|
assertEquals(c.bgBrightYellow("foo bar"), "[103mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("bgBrightBlue()", function () {
|
2020-08-29 08:29:41 +00:00
|
|
|
|
assertEquals(c.bgBrightBlue("foo bar"), "[104mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("bgBrightMagenta()", function () {
|
2020-08-29 08:29:41 +00:00
|
|
|
|
assertEquals(c.bgBrightMagenta("foo bar"), "[105mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("bgBrightCyan()", function () {
|
2020-08-29 08:29:41 +00:00
|
|
|
|
assertEquals(c.bgBrightCyan("foo bar"), "[106mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("bgBrightWhite()", function () {
|
2020-08-29 08:29:41 +00:00
|
|
|
|
assertEquals(c.bgBrightWhite("foo bar"), "[107mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("rgb8() handles clamp", function () {
|
2020-05-09 10:29:44 +00:00
|
|
|
|
assertEquals(c.rgb8("foo bar", -10), "[38;5;0mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("rgb8() handles truncate", function () {
|
2020-05-09 10:29:44 +00:00
|
|
|
|
assertEquals(c.rgb8("foo bar", 42.5), "[38;5;42mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2022-08-24 01:21:57 +00:00
|
|
|
|
Deno.test("test rgb8", function () {
|
2020-05-09 10:29:44 +00:00
|
|
|
|
assertEquals(c.rgb8("foo bar", 42), "[38;5;42mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("bgRgb8()", function () {
|
2020-05-09 10:29:44 +00:00
|
|
|
|
assertEquals(c.bgRgb8("foo bar", 42), "[48;5;42mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("rgb24()", function () {
|
2020-05-09 10:29:44 +00:00
|
|
|
|
assertEquals(
|
|
|
|
|
c.rgb24("foo bar", {
|
|
|
|
|
r: 41,
|
|
|
|
|
g: 42,
|
|
|
|
|
b: 43,
|
|
|
|
|
}),
|
2020-07-14 19:24:17 +00:00
|
|
|
|
"[38;2;41;42;43mfoo bar[39m",
|
2020-05-09 10:29:44 +00:00
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("rgb24() handles number", function () {
|
2020-05-20 14:29:59 +00:00
|
|
|
|
assertEquals(c.rgb24("foo bar", 0x070809), "[38;2;7;8;9mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("bgRgb24()", function () {
|
2020-05-09 10:29:44 +00:00
|
|
|
|
assertEquals(
|
|
|
|
|
c.bgRgb24("foo bar", {
|
|
|
|
|
r: 41,
|
|
|
|
|
g: 42,
|
|
|
|
|
b: 43,
|
|
|
|
|
}),
|
2020-07-14 19:24:17 +00:00
|
|
|
|
"[48;2;41;42;43mfoo bar[49m",
|
2020-05-09 10:29:44 +00:00
|
|
|
|
);
|
|
|
|
|
});
|
2020-05-20 14:29:59 +00:00
|
|
|
|
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("bgRgb24() handles number", function () {
|
2020-05-20 14:29:59 +00:00
|
|
|
|
assertEquals(c.bgRgb24("foo bar", 0x070809), "[48;2;7;8;9mfoo bar[49m");
|
|
|
|
|
});
|
2022-03-06 11:45:51 +00:00
|
|
|
|
|
|
|
|
|
// https://github.com/chalk/strip-ansi/blob/2b8c961e75760059699373f9a69101065c3ded3a/test.js#L4-L6
|
2023-12-28 02:52:35 +00:00
|
|
|
|
Deno.test("stripAnsiCode()", function () {
|
2022-03-06 11:45:51 +00:00
|
|
|
|
assertEquals(
|
2023-12-06 06:58:42 +00:00
|
|
|
|
c.stripAnsiCode(
|
2022-03-06 11:45:51 +00:00
|
|
|
|
"\u001B[0m\u001B[4m\u001B[42m\u001B[31mfoo\u001B[39m\u001B[49m\u001B[24mfoo\u001B[0m",
|
|
|
|
|
),
|
|
|
|
|
"foofoo",
|
|
|
|
|
);
|
|
|
|
|
});
|