Added tests for HexColor.
This commit is contained in:
parent
d742fba7e9
commit
661a11fecd
33
color_test.go
Normal file
33
color_test.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package zntg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"image/color"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHexColor(t *testing.T) {
|
||||||
|
type test struct {
|
||||||
|
Hex string
|
||||||
|
Success bool
|
||||||
|
Expected color.RGBA
|
||||||
|
}
|
||||||
|
tests := []test{
|
||||||
|
test{Hex: "#AA3939", Success: true, Expected: color.RGBA{R: 170, G: 57, B: 57, A: 255}},
|
||||||
|
test{Hex: "AA3939", Success: true, Expected: color.RGBA{R: 170, G: 57, B: 57, A: 255}},
|
||||||
|
test{Hex: "#AA3939BB", Success: true, Expected: color.RGBA{R: 170, G: 57, B: 57, A: 187}},
|
||||||
|
test{Hex: "AG3939", Success: false, Expected: color.RGBA{}},
|
||||||
|
test{Hex: "AA3939A", Success: false, Expected: color.RGBA{}},
|
||||||
|
test{Hex: "AA39A", Success: false, Expected: color.RGBA{}},
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user