~mendelmaleh/dummy

ref: b862a107cb4810e7514eccf69deb3fc5f6f5dc4c dummy/utils_test.go -rw-r--r-- 593 bytes
b862a107Mendel E Document new endpoints 1 year, 4 months ago
                                                                                
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
package dummy

import (
	"image/color"
	"testing"
)

const u8 = ^uint8(0)

func TestHex(t *testing.T) {
	cases := []struct {
		name, hex string
		rgba      color.RGBA
	}{
		{"3 digits", "222", color.RGBA{34, 34, 34, u8}},
		{"3 letters", "fff", color.RGBA{u8, u8, u8, u8}},
		{"# and 3 letters", "#fff", color.RGBA{u8, u8, u8, u8}},

		{"6 digits", "#242933", color.RGBA{36, 41, 51, u8}},
	}

	for _, test := range cases {
		cl, err := Hex(test.hex)
		if err != nil {
			t.Error(err)
		}

		if cl != test.rgba {
			t.Errorf("test %s: expected %v, got %v\n", test.name, test.rgba, cl)
		}
	}
}