-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhexcolor_test.go
67 lines (61 loc) · 1.4 KB
/
hexcolor_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
package hexcolor
import "testing"
func TestParseRGBColor(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
input string
wantErr bool
wantColor RGBColor
}{
{
name: "parsing minimum hexadecimal color should succeed",
input: "#000000",
wantErr: false,
wantColor: RGBColor{0, 0, 0},
},
{
name: "parsing maximum hexadecimal color should succeed",
input: "#ffffff",
wantErr: false,
wantColor: RGBColor{255, 255, 255},
},
{
name: "parsing out of bound color component should fail",
input: "#fffffg",
wantErr: true,
wantColor: RGBColor{},
},
{
name: "omitting leading # character should fail",
input: "ffffff",
wantErr: true,
wantColor: RGBColor{},
},
{
name: "parsing insufficient number of characters should fail",
input: "#fffff",
wantErr: true,
wantColor: RGBColor{},
},
{
name: "empty input should fail",
input: "",
wantErr: true,
wantColor: RGBColor{},
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
gotColor, gotErr := ParseRGBColor(tc.input)
if (gotErr != nil) != tc.wantErr {
t.Errorf("got error %v, want error %v", gotErr, tc.wantErr)
}
if gotColor != tc.wantColor {
t.Errorf("got color %v, want color %v", gotColor, tc.wantColor)
}
})
}
}