2020-01-02 15:13:47 -05:00
|
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2019-03-06 19:42:24 -05:00
|
|
|
|
import { assertEquals } from "../testing/asserts.ts";
|
2019-08-24 13:38:18 -04:00
|
|
|
|
import * as c from "./colors.ts";
|
2019-03-18 11:08:01 -04:00
|
|
|
|
import "../examples/colors.ts";
|
2018-12-18 23:30:44 -05:00
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("singleColor", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.red("foo bar"), "[31mfoo bar[39m");
|
2018-12-18 23:30:44 -05:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("doubleColor", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.bgBlue(c.red("foo bar")), "[44m[31mfoo bar[39m[49m");
|
2019-01-15 16:16:52 -05:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("replacesCloseCharacters", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.red("Hel[39mlo"), "[31mHel[31mlo[39m");
|
2019-01-15 16:16:52 -05:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("enablingColors", function (): void {
|
2019-12-20 15:21:30 -05:00
|
|
|
|
assertEquals(c.getColorEnabled(), true);
|
|
|
|
|
c.setColorEnabled(false);
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.bgBlue(c.red("foo bar")), "foo bar");
|
2019-12-20 15:21:30 -05:00
|
|
|
|
c.setColorEnabled(true);
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.red("foo bar"), "[31mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testBold", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.bold("foo bar"), "[1mfoo bar[22m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testDim", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.dim("foo bar"), "[2mfoo bar[22m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testItalic", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.italic("foo bar"), "[3mfoo bar[23m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testUnderline", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.underline("foo bar"), "[4mfoo bar[24m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testInverse", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.inverse("foo bar"), "[7mfoo bar[27m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testHidden", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.hidden("foo bar"), "[8mfoo bar[28m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testStrikethrough", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.strikethrough("foo bar"), "[9mfoo bar[29m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testBlack", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.black("foo bar"), "[30mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testRed", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.red("foo bar"), "[31mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testGreen", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.green("foo bar"), "[32mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testYellow", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.yellow("foo bar"), "[33mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testBlue", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.blue("foo bar"), "[34mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testMagenta", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.magenta("foo bar"), "[35mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testCyan", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.cyan("foo bar"), "[36mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testWhite", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.white("foo bar"), "[37mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testGray", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.gray("foo bar"), "[90mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testBgBlack", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.bgBlack("foo bar"), "[40mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testBgRed", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.bgRed("foo bar"), "[41mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testBgGreen", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.bgGreen("foo bar"), "[42mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testBgYellow", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.bgYellow("foo bar"), "[43mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testBgBlue", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.bgBlue("foo bar"), "[44mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testBgMagenta", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.bgMagenta("foo bar"), "[45mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testBgCyan", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.bgCyan("foo bar"), "[46mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
|
Deno.test("testBgWhite", function (): void {
|
2019-08-22 02:20:47 -04:00
|
|
|
|
assertEquals(c.bgWhite("foo bar"), "[47mfoo bar[49m");
|
2018-12-18 23:30:44 -05:00
|
|
|
|
});
|
2020-05-09 06:29:44 -04:00
|
|
|
|
|
|
|
|
|
Deno.test("testClampUsingRgb8", function (): void {
|
|
|
|
|
assertEquals(c.rgb8("foo bar", -10), "[38;5;0mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test("testTruncateUsingRgb8", function (): void {
|
|
|
|
|
assertEquals(c.rgb8("foo bar", 42.5), "[38;5;42mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test("testRgb8", function (): void {
|
|
|
|
|
assertEquals(c.rgb8("foo bar", 42), "[38;5;42mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test("test_bgRgb8", function (): void {
|
|
|
|
|
assertEquals(c.bgRgb8("foo bar", 42), "[48;5;42mfoo bar[49m");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test("test_rgb24", function (): void {
|
|
|
|
|
assertEquals(
|
|
|
|
|
c.rgb24("foo bar", {
|
|
|
|
|
r: 41,
|
|
|
|
|
g: 42,
|
|
|
|
|
b: 43,
|
|
|
|
|
}),
|
2020-07-14 15:24:17 -04:00
|
|
|
|
"[38;2;41;42;43mfoo bar[39m",
|
2020-05-09 06:29:44 -04:00
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2020-05-20 10:29:59 -04:00
|
|
|
|
Deno.test("test_rgb24number", function (): void {
|
|
|
|
|
assertEquals(c.rgb24("foo bar", 0x070809), "[38;2;7;8;9mfoo bar[39m");
|
|
|
|
|
});
|
|
|
|
|
|
2020-05-09 06:29:44 -04:00
|
|
|
|
Deno.test("test_bgRgb24", function (): void {
|
|
|
|
|
assertEquals(
|
|
|
|
|
c.bgRgb24("foo bar", {
|
|
|
|
|
r: 41,
|
|
|
|
|
g: 42,
|
|
|
|
|
b: 43,
|
|
|
|
|
}),
|
2020-07-14 15:24:17 -04:00
|
|
|
|
"[48;2;41;42;43mfoo bar[49m",
|
2020-05-09 06:29:44 -04:00
|
|
|
|
);
|
|
|
|
|
});
|
2020-05-20 10:29:59 -04:00
|
|
|
|
|
|
|
|
|
Deno.test("test_bgRgb24number", function (): void {
|
|
|
|
|
assertEquals(c.bgRgb24("foo bar", 0x070809), "[48;2;7;8;9mfoo bar[49m");
|
|
|
|
|
});
|