summaryrefslogtreecommitdiffstats
path: root/model/utils_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'model/utils_test.go')
-rw-r--r--model/utils_test.go188
1 files changed, 188 insertions, 0 deletions
diff --git a/model/utils_test.go b/model/utils_test.go
index e77ce80fb..94ee55aa9 100644
--- a/model/utils_test.go
+++ b/model/utils_test.go
@@ -137,3 +137,191 @@ func TestParseHashtags(t *testing.T) {
}
}
}
+
+func TestIsValidAlphaNum(t *testing.T) {
+ cases := []struct {
+ Input string
+ Result bool
+ }{
+ {
+ Input: "test",
+ Result: true,
+ },
+ {
+ Input: "test-name",
+ Result: true,
+ },
+ {
+ Input: "test--name",
+ Result: true,
+ },
+ {
+ Input: "test__name",
+ Result: true,
+ },
+ {
+ Input: "-",
+ Result: false,
+ },
+ {
+ Input: "__",
+ Result: false,
+ },
+ {
+ Input: "test-",
+ Result: false,
+ },
+ {
+ Input: "test--",
+ Result: false,
+ },
+ {
+ Input: "test__",
+ Result: false,
+ },
+ {
+ Input: "test:name",
+ Result: false,
+ },
+ }
+
+ for _, tc := range cases {
+ actual := IsValidAlphaNum(tc.Input)
+ if actual != tc.Result {
+ t.Fatalf("case: %v\tshould returned: %#v", tc, tc.Result)
+ }
+ }
+}
+
+func TestIsValidAlphaNumHyphenUnderscore(t *testing.T) {
+ casesWithFormat := []struct {
+ Input string
+ Result bool
+ }{
+ {
+ Input: "test",
+ Result: true,
+ },
+ {
+ Input: "test-name",
+ Result: true,
+ },
+ {
+ Input: "test--name",
+ Result: true,
+ },
+ {
+ Input: "test__name",
+ Result: true,
+ },
+ {
+ Input: "test_name",
+ Result: true,
+ },
+ {
+ Input: "test_-name",
+ Result: true,
+ },
+ {
+ Input: "-",
+ Result: false,
+ },
+ {
+ Input: "__",
+ Result: false,
+ },
+ {
+ Input: "test-",
+ Result: false,
+ },
+ {
+ Input: "test--",
+ Result: false,
+ },
+ {
+ Input: "test__",
+ Result: false,
+ },
+ {
+ Input: "test:name",
+ Result: false,
+ },
+ }
+
+ for _, tc := range casesWithFormat {
+ actual := IsValidAlphaNumHyphenUnderscore(tc.Input, true)
+ if actual != tc.Result {
+ t.Fatalf("case: %v\tshould returned: %#v", tc, tc.Result)
+ }
+ }
+
+ casesWithoutFormat := []struct {
+ Input string
+ Result bool
+ }{
+ {
+ Input: "test",
+ Result: true,
+ },
+ {
+ Input: "test-name",
+ Result: true,
+ },
+ {
+ Input: "test--name",
+ Result: true,
+ },
+ {
+ Input: "test__name",
+ Result: true,
+ },
+ {
+ Input: "test_name",
+ Result: true,
+ },
+ {
+ Input: "test_-name",
+ Result: true,
+ },
+ {
+ Input: "-",
+ Result: true,
+ },
+ {
+ Input: "_",
+ Result: true,
+ },
+ {
+ Input: "test-",
+ Result: true,
+ },
+ {
+ Input: "test--",
+ Result: true,
+ },
+ {
+ Input: "test__",
+ Result: true,
+ },
+ {
+ Input: ".",
+ Result: false,
+ },
+
+ {
+ Input: "test,",
+ Result: false,
+ },
+ {
+ Input: "test:name",
+ Result: false,
+ },
+ }
+
+ for _, tc := range casesWithoutFormat {
+ actual := IsValidAlphaNumHyphenUnderscore(tc.Input, false)
+ if actual != tc.Result {
+ t.Fatalf("case: '%v'\tshould returned: %#v", tc.Input, tc.Result)
+ }
+ }
+}