-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcolor_test.go
More file actions
79 lines (62 loc) · 2.22 KB
/
Copy pathcolor_test.go
File metadata and controls
79 lines (62 loc) · 2.22 KB
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
package devslog
import (
"bytes"
"testing"
)
func Test_Color(t *testing.T) {
h := NewHandler(nil, nil)
testGetColor(t, h)
b := []byte("Hello")
testColorColorString(t, b, h)
testColorColorStringFainted(t, b, h)
testColorColorStringBackground(t, b, h)
testColorUnderlineText(t, b, h)
testColorFaintedText(t, b, h)
}
func testGetColor(t *testing.T, h *developHandler) {
result := h.getColor(Black)
expected := colors[1].fg
if !bytes.Equal(expected, result.fg) {
t.Errorf("\nExpected: %s\nResult: %s\nExpected: %[1]q\nResult: %[2]q", expected, result)
}
result = h.getColor(Color(20))
expected = colors[8].fg
if !bytes.Equal(expected, result.fg) {
t.Errorf("\nExpected: %s\nResult: %s\nExpected: %[1]q\nResult: %[2]q", expected, result)
}
}
func testColorColorString(t *testing.T, b []byte, h *developHandler) {
result := h.colorString(b, fgGreen)
expected := []byte("\x1b[32mHello\x1b[0m")
if !bytes.Equal(expected, result) {
t.Errorf("\nExpected: %s\nResult: %s\nExpected: %[1]q\nResult: %[2]q", expected, result)
}
}
func testColorColorStringFainted(t *testing.T, b []byte, h *developHandler) {
result := h.colorStringFainted(b, fgBlue)
expected := []byte("\x1b[2m\x1b[34mHello\x1b[0m")
if !bytes.Equal(expected, result) {
t.Errorf("\nExpected: %s\nResult: %s\nExpected: %[1]q\nResult: %[2]q", expected, result)
}
}
func testColorColorStringBackground(t *testing.T, b []byte, h *developHandler) {
result := h.colorStringBackgorund(b, fgYellow, bgRed)
expected := []byte("\x1b[41m\x1b[33mHello\x1b[0m")
if !bytes.Equal(expected, result) {
t.Errorf("\nExpected: %s\nResult: %s\nExpected: %[1]q\nResult: %[2]q", expected, result)
}
}
func testColorUnderlineText(t *testing.T, b []byte, h *developHandler) {
result := h.underlineText(b)
expected := []byte("\x1b[4mHello\x1b[0m")
if !bytes.Equal(expected, result) {
t.Errorf("\nExpected: %s\nResult: %s\nExpected: %[1]q\nResult: %[2]q", expected, result)
}
}
func testColorFaintedText(t *testing.T, b []byte, h *developHandler) {
result := h.faintedText(b)
expected := []byte("\x1b[2mHello\x1b[0m")
if !bytes.Equal(expected, result) {
t.Errorf("\nExpected: %s\nResult: %s\nExpected: %[1]q\nResult: %[2]q", expected, result)
}
}