Skip to content

Commit

Permalink
test: Add hex color test
Browse files Browse the repository at this point in the history
Signed-off-by: AlexNg <contact@ngjx.org>
  • Loading branch information
caffeine-addictt committed Aug 30, 2024
1 parent 1462733 commit 2a3e57e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions cmd/utils/types/color_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package types_test

import (
"testing"

"github.com/caffeine-addictt/template/cmd/utils/types"
)

func TestHexColors(t *testing.T) {
tt := []struct {
in string
rule string
errors bool
}{
{"#d", "hex too short", true},
{"#ddd", "hex valid", false},
{"#ffffff", "hex valid", false},
{"#fff", "hex valid", false},
{"#fffaaas", "hex too long", true},
{"#ff", "hex too short", true},
{"#ae24d2", "hex valid", false},
{"sdwa2fw", "invalid letters", true},
}

for _, tc := range tt {
t.Run(tc.in, func(t *testing.T) {
c := types.HexColor(tc.in)

err := c.UnmarshalJSON([]byte("\"" + tc.in + "\""))
if err != nil && !tc.errors {
t.Errorf("%v. expected to error but got %s: %v", tc.rule, c, err)
}
if err == nil && tc.errors {
t.Errorf("%v. expected to not error but got %s: %v", tc.rule, c, err)
}
})
}
}

0 comments on commit 2a3e57e

Please sign in to comment.