-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
121 lines (105 loc) · 3.11 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const test = require("ava");
const colorCode = require("./index");
test("basic red color", (t) => {
t.is(
colorCode("\x1b[31mHelloWorld\x1b[0m"),
'<span style="color:rgb(222,56,43);">HelloWorld</span>'
);
});
test("basic bright red color", (t) => {
t.is(
colorCode("\x1b[31;1mHelloWorld\x1b[0m"),
'<span style="color:rgb(255,0,0);">HelloWorld</span>'
);
});
test("basic red background color", (t) => {
t.is(
colorCode("\x1b[41mHelloWorld\x1b[0m"),
'<span style="background-color:rgb(222,56,43);">HelloWorld</span>'
);
});
test("basic bright red background color", (t) => {
t.is(
colorCode("\x1b[41;1mHelloWorld\x1b[0m"),
'<span style="background-color:rgb(255,0,0);">HelloWorld</span>'
);
});
test("resets with nothing", (t) => {
t.is(
colorCode("\x1b[31mHelloWorld"),
'<span style="color:rgb(222,56,43);">HelloWorld</span>'
);
});
test("resets with empty reset tag", (t) => {
t.is(
colorCode("\x1b[31mHelloWorld\x1b[m"),
'<span style="color:rgb(222,56,43);">HelloWorld</span>'
);
});
test("resets with one", (t) => {
t.is(
colorCode("\u001b[40m A \u001b[41m B \u001b[42m C \u001b[43m D \u001b[0m"),
'<span style="background-color:rgb(1,1,1);"> A </span><span style="background-color:rgb(222,56,43);"> B </span><span style="background-color:rgb(57,181,74);"> C </span><span style="background-color:rgb(255,199,6);"> D </span>'
);
});
test("only reset color", (t) => {
t.is(
colorCode("\u001b[31mA\u001b[41mB\u001b[39mRed"),
'<span style="color:rgb(222,56,43);">A<span style="background-color:rgb(222,56,43);">B</span></span><span style="background-color:rgb(222,56,43);">Red</span>'
);
});
test("only reset background-color", (t) => {
t.is(
colorCode("\u001b[41mA\u001b[31mB\u001b[49mRed"),
'<span style="background-color:rgb(222,56,43);">A<span style="color:rgb(222,56,43);">B</span></span><span style="color:rgb(222,56,43);">Red</span>'
);
});
test("24-bit colors", (t) => {
t.is(
colorCode("\u001b[38;2;12;34;56mTest"),
'<span style="color:rgb(12,34,56);">Test</span>'
);
});
test("look by id with simple colors", (t) => {
t.is(
colorCode("\u001b[38;5;3mTest"),
'<span style="color:rgb(255,199,6);">Test</span>'
);
});
test("look by id with bright colors", (t) => {
t.is(
colorCode("\u001b[38;5;9mTest"),
'<span style="color:rgb(255,0,0);">Test</span>'
);
});
test("look by id with simple background-colors", (t) => {
t.is(
colorCode("\u001b[48;5;3mTest"),
'<span style="background-color:rgb(255,199,6);">Test</span>'
);
});
test("look by id with bright background-colors", (t) => {
t.is(
colorCode("\u001b[48;5;9mTest"),
'<span style="background-color:rgb(255,0,0);">Test</span>'
);
});
test("return nothing when its a incorrect id type", (t) => {
t.is(colorCode("\u001b[38;3;9mTest"), "Test");
});
test("respects no html options background", (t) => {
t.is(
colorCode("\u001b[48;5;9mTest", {
noHtml: true,
}),
"Test"
);
});
test("respects no html options foreground", (t) => {
t.is(
colorCode("\u001b[38;5;9mTest", {
noHtml: true,
}),
"Test"
);
});