-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolor_test.go
More file actions
49 lines (44 loc) · 972 Bytes
/
color_test.go
File metadata and controls
49 lines (44 loc) · 972 Bytes
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
package color
import (
"testing"
"github.com/kenshaw/colors"
"github.com/xo/ox"
)
func TestColor(t *testing.T) {
for _, test := range colorTests() {
t.Run(test.s, func(t *testing.T) {
v, err := ox.ColorT.New()
if err != nil {
t.Fatalf("expected no error, got: %v", err)
}
if err := v.Set(test.s); err != nil {
t.Fatalf("expected no error, got: %v", err)
}
val, err := ox.As[*colors.Color](v)
if err != nil {
t.Fatalf("expected no error, got: %v", err)
}
if s := val.AsText(); s != test.exp {
t.Errorf("expected %s, got: %s", test.exp, s)
}
t.Logf("c: %v", val)
})
}
}
type colorTest struct {
s string
exp string
}
func colorTests() []colorTest {
return []colorTest{
{"", "transparent"},
{"red", "red"},
{"BLACK", "black"},
{"rgb(0,255,0)", "lime"},
{"rgba( 0, 255, 0, 255)", "lime"},
{"hex(0,ff,0)", "lime"},
{"hex(0,ff,0,ff)", "lime"},
{"#00ff00", "lime"},
{"#00ff00ff", "lime"},
}
}