summaryrefslogtreecommitdiffstats
path: root/model/user_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'model/user_test.go')
-rw-r--r--model/user_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/model/user_test.go b/model/user_test.go
index a48c3f2e7..a3b4be091 100644
--- a/model/user_test.go
+++ b/model/user_test.go
@@ -150,3 +150,45 @@ func TestUserGetDisplayName(t *testing.T) {
t.Fatal("Display name should be nickname")
}
}
+
+var usernames = []struct {
+ value string
+ expected bool
+}{
+ {"spin-punch", true},
+ {"Spin-punch", false},
+ {"spin punch-", false},
+ {"spin_punch", true},
+ {"spin", true},
+ {"PUNCH", false},
+ {"spin.punch", true},
+ {"spin'punch", false},
+ {"spin*punch", false},
+ {"all", false},
+}
+
+func TestValidUsername(t *testing.T) {
+ for _, v := range usernames {
+ if IsValidUsername(v.value) != v.expected {
+ t.Errorf("expect %v as %v", v.value, v.expected)
+ }
+ }
+}
+
+func TestCleanUsername(t *testing.T) {
+ if CleanUsername("Spin-punch") != "spin-punch" {
+ t.Fatal("didn't clean name properly")
+ }
+ if CleanUsername("PUNCH") != "punch" {
+ t.Fatal("didn't clean name properly")
+ }
+ if CleanUsername("spin'punch") != "spin-punch" {
+ t.Fatal("didn't clean name properly")
+ }
+ if CleanUsername("spin") != "spin" {
+ t.Fatal("didn't clean name properly")
+ }
+ if len(CleanUsername("all")) != 27 {
+ t.Fatal("didn't clean name properly")
+ }
+}