-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) | ||
} | ||
} |