-
Notifications
You must be signed in to change notification settings - Fork 6
/
go-webcolors_test.go
146 lines (128 loc) · 3.69 KB
/
go-webcolors_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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package webcolors
import "testing"
func TestNormalizeHex(t *testing.T) {
Value := NormalizeHex("#0099CC")
if Value != "#0099cc" {
t.Error("Expected #0099cc, got", Value)
}
}
func TestNormalizeIntegerTriplet(t *testing.T) {
Value := NormalizeIntegerTriplet([]int{270, -20, 128})
Expected := []int{255, 0, 128}
for i := range Value {
if Value[i] != Expected[i] {
t.Error("Expected", Expected[i], " got", Value[i])
}
}
}
func TestNormalizeIntegerRGB(t *testing.T) {
Value := NormalizeIntegerRGB(270)
if Value != 255 {
t.Error("Expected 255, got", Value)
}
}
func TestNormalizePercentTriplet(t *testing.T) {
Value := NormalizePercentTriplet([]string{"-10%", "250%", "500%"})
Expected := []string{"0%", "100%", "100%"}
for i := range Value {
if Value[i] != Expected[i] {
t.Error("Expected", Expected[i], " got", Value[i])
}
}
}
func TestNormalizePercentRGB(t *testing.T) {
Value := NormalizePercentRGB("-5%")
if Value != "0%" {
t.Error("Expected 0%, got", Value)
}
}
func TestNamesToHex(t *testing.T) {
Value := NamesToHex("white", "css3")
if Value != "#ffffff" {
t.Error("Expected white, got", Value)
}
}
func TestNameToRGB(t *testing.T) {
Value := NameToRGB("navy", "css3")
Expected := []int{0, 0, 128}
for i := range Value {
if Value[i] != Expected[i] {
t.Error("Expected", Expected[i], " got", Value[i])
}
}
}
func TestNameToRGBPercent(t *testing.T) {
Value := NameToRGBPercent("navy", "css3")
Expected := []string{"0%", "0%", "50%"}
for i := range Value {
if Value[i] != Expected[i] {
t.Error("Expected", Expected[i], " got", Value[i])
}
}
}
func TestHexToName(t *testing.T) {
Value := HexToName("#daa520", "css3")
if Value != "goldenrod" {
t.Error("Expected goldenrod, got", Value)
}
}
func TestHexToRGB(t *testing.T) {
Value := HexToRGB("#000080")
Expected := []int{0, 0, 128}
for i := range Value {
if Value[i] != Expected[i] {
t.Error("Expected", Expected[i], " got", Value[i])
}
}
}
func TestHexToRGBPercent(t *testing.T) {
Value := HexToRGBPercent("#000080")
Expected := []string{"0%", "0%", "50%"}
for i := range Value {
if Value[i] != Expected[i] {
t.Error("Expected", Expected[i], " got", Value[i])
}
}
}
func TestRGBToName(t *testing.T) {
Value := RGBToName([]int{0, 0, 128}, "css3")
if Value != "navy" {
t.Error("Expected navy, got", Value)
}
}
func TestRGBToHex(t *testing.T) {
Value := RGBToHex([]int{0, 0, 128})
if Value != "#000080" {
t.Error("Expected #000080, got", Value)
}
}
func TestRGBToRGBPercent(t *testing.T) {
Value := RGBToRGBPercent([]int{218, 165, 32})
Expected := []string{"85.49%", "64.71%", "12.50%"}
for i := range Value {
if Value[i] != Expected[i] {
t.Error("Expected", Expected[i], " got", Value[i])
}
}
}
func TestRGBPercentToName(t *testing.T) {
Value := RGBPercentToName([]string{"85.49%", "64.71%", "12.5%"}, "css3")
if Value != "goldenrod" {
t.Error("Expected goldenrod, got", Value)
}
}
func TestRGBPercentToHex(t *testing.T) {
Value := RGBPercentToHex([]string{"100%", "100%", "0%"})
if Value != "#ffff00" {
t.Error("Expected #ffff00, got", Value)
}
}
func TestRGBPercentToRGB(t *testing.T) {
Value := RGBPercentToRGB([]string{"0%", "0%", "50%"})
Expected := []int{0, 0, 128}
for i := range Value {
if Value[i] != Expected[i] {
t.Error("Expected", Expected[i], " got", Value[i])
}
}
}