-
Notifications
You must be signed in to change notification settings - Fork 85
/
color_rgb_test.go
47 lines (41 loc) · 1.43 KB
/
color_rgb_test.go
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
package color
import (
"testing"
)
func testRgbToC256Color(t *testing.T, name string, c RGBColor, expected uint8) {
t.Log("RGB Color:", c.Sprint(name))
t.Log("256 Color:", c.C256().Sprint(name))
actual := c.C256().Value()
if actual != expected {
t.Errorf("%s not converted correctly: expected %v, actual %v", name, actual, expected)
}
}
func TestRGBStyle_SetOpts(t *testing.T) {
s := NewRGBStyle(RGB(234, 78, 23), RGB(20, 144, 234))
s.Println("rgb style message")
s.SetOpts(Opts{OpItalic, OpBold, OpUnderscore})
s.Println("RGB style message with options")
}
func TestRgbToC256(t *testing.T) {
testRgbToC256Color(t, "white", RGB(255, 255, 255), 15)
testRgbToC256Color(t, "red", RGB(255, 0, 0), 9)
testRgbToC256Color(t, "yellow", RGB(255, 255, 0), 11)
testRgbToC256Color(t, "greenBg", RGB(0, 255, 0, true), 10)
testRgbToC256Color(t, "blueBg", RGB(0, 0, 255, true), 12)
testRgbToC256Color(t, "light blue", RGB(57, 187, 226), 74)
}
func TestRgbToC256Background(t *testing.T) {
white := RGB(255, 255, 255)
whiteBg := RGB(255, 255, 255, true)
whiteFg := RGB(255, 255, 255, false)
if white.C256().String() != whiteFg.C256().String() {
t.Error("standard color didn't match foreground color")
}
if white.C256().String() == whiteBg.C256().String() {
t.Error("standard color matched background color")
}
prefix := whiteBg.C256().String()[:3]
if prefix != "48;" {
t.Errorf("background color didn't have background prefix: %v", prefix)
}
}