package tins2020 import ( "testing" "github.com/stretchr/testify/assert" "github.com/veandco/go-sdl2/sdl" ) func TestHexColor(t *testing.T) { type test struct { Hex string Success bool Expected sdl.Color } tests := []test{ test{Hex: "#AA3939", Success: true, Expected: sdl.Color{R: 170, G: 57, B: 57, A: 255}}, test{Hex: "AA3939", Success: true, Expected: sdl.Color{R: 170, G: 57, B: 57, A: 255}}, test{Hex: "#AA3939BB", Success: true, Expected: sdl.Color{R: 170, G: 57, B: 57, A: 187}}, test{Hex: "AG3939", Success: false, Expected: sdl.Color{}}, test{Hex: "AA3939A", Success: false, Expected: sdl.Color{}}, test{Hex: "AA39A", Success: false, Expected: sdl.Color{}}, } for _, test := range tests { color, err := HexColor(test.Hex) if test.Success { assert.Nil(t, err) assert.Equal(t, color, test.Expected) } else { assert.NotNil(t, err) } } }