mirror of
https://github.com/6543/go-hexcolor
synced 2024-12-18 15:54:17 +00:00
add test
This commit is contained in:
parent
fe41f076df
commit
7185dc6b49
2
go.mod
2
go.mod
@ -1,3 +1,5 @@
|
|||||||
module github.com/6543/go-hexcolor
|
module github.com/6543/go-hexcolor
|
||||||
|
|
||||||
go 1.15
|
go 1.15
|
||||||
|
|
||||||
|
require github.com/stretchr/testify v1.6.1
|
||||||
|
10
go.sum
Normal file
10
go.sum
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||||
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
32
hexcolor_test.go
Normal file
32
hexcolor_test.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package go_hexcolor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewHexColor(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
color string
|
||||||
|
hex string
|
||||||
|
err bool
|
||||||
|
}{
|
||||||
|
{"#dd22cc", "dd22cc", false},
|
||||||
|
{"#adf", "aaddff", false},
|
||||||
|
{"15d", "1155dd", false},
|
||||||
|
{"a5i", "", true},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
hc, err := NewHexColor(tc.color)
|
||||||
|
if tc.err && err == nil {
|
||||||
|
t.Fatalf("expected error for color: %q", tc.color)
|
||||||
|
} else if !tc.err && err != nil {
|
||||||
|
t.Fatalf("error for color %q: %s", tc.color, err)
|
||||||
|
}
|
||||||
|
if assert.NotNil(t, hc) {
|
||||||
|
assert.EqualValues(t, tc.hex, hc.hex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user