summaryrefslogtreecommitdiffstats
path: root/pkg/theme/theme_test.go
blob: 3112894087957723c62470247786efaa1ec5093f (plain)
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
package theme

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestGetHexColorValues(t *testing.T) {
	scenarios := []struct {
		name     string
		hexColor string
		rgb      []int32
		valid    bool
	}{
		{
			name:     "valid uppercase hex color",
			hexColor: "#00FF00",
			rgb:      []int32{0, 255, 0},
			valid:    true,
		},
		{
			name:     "valid lowercase hex color",
			hexColor: "#00ff00",
			rgb:      []int32{0, 255, 0},
			valid:    true,
		},
		{
			name:     "valid short hex color",
			hexColor: "#0bf",
			rgb:      []int32{0, 187, 255},
			valid:    true,
		},
		{
			name:     "invalid hex value",
			hexColor: "#zz00ff",
			valid:    false,
		},
		{
			name:     "invalid length hex color",
			hexColor: "#",
			valid:    false,
		},
		{
			name:     "invalid length hex color",
			hexColor: "#aaaaaaaaaaa",
			valid:    false,
		},
	}

	for _, s := range scenarios {
		s := s
		t.Run(s.name, func(t *testing.T) {
			r, g, b, valid := getHexColorValues(s.hexColor)
			assert.EqualValues(t, s.valid, valid, s.hexColor)
			if valid {
				assert.EqualValues(t, s.rgb[0], r, s.hexColor)
				assert.EqualValues(t, s.rgb[1], g, s.hexColor)
				assert.EqualValues(t, s.rgb[2], b, s.hexColor)
			}
		})
	}
}