-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathcolor_test.go
65 lines (53 loc) · 1.35 KB
/
color_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"image/color"
"testing"
)
func TestRGB(t *testing.T) {
r, g, b := rgb(color.Black)
var want = [3]uint16{0x00, 0x00, 0x00}
var have = [3]uint16{r, g, b}
if !eq(want, have) {
t.Errorf("RGB data mismatch. Want: %v, Have: %v\n", want, have)
}
r, g, b = rgb(color.White)
have = [3]uint16{r, g, b}
want[0], want[1], want[2] = 0xff, 0xff, 0xff
if !eq(want, have) {
t.Errorf("RGB data mismatch. Want: %v, Have: %v\n", want, have)
}
r, g, b = rgb(color.RGBA{0xff, 0x00, 0x00, 0x00})
have = [3]uint16{r, g, b}
want[0], want[1], want[2] = 0xff, 0x00, 0x00
if !eq(want, have) {
t.Errorf("RGB data mismatch. Want: %v, Have: %v\n", want, have)
}
}
func TestTermColor(t *testing.T) {
want := uint16(16 + 1) // Black + default offset
have := termColor(0, 0, 0)
if want != have {
t.Errorf("term color mismatch. Want: %v, Have: %v\n", want, have)
}
want = uint16(231 + 1) // White + default offset
have = termColor(255, 255, 255)
if want != have {
t.Errorf("term color mismatch. Want: %v, Have: %v\n", want, have)
}
want = uint16(196 + 1) // Red + default offset
have = termColor(255, 0, 0)
if want != have {
t.Errorf("term color mismatch. Want: %v, Have: %v\n", want, have)
}
}
func eq(a, b [3]uint16) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if b[i] != v {
return false
}
}
return true
}