-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount_test.go
180 lines (177 loc) · 3.64 KB
/
account_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package is
import "testing"
// TestNickname tests the Nickname function.
func TestNickname(t *testing.T) {
tests := []struct {
name string
nickname string
strict bool
want bool
}{
// Non-strict mode tests
{
name: "Valid Nickname - Alphanumeric",
nickname: "User123",
strict: false,
want: true,
},
{
name: "Valid Nickname - Underscores",
nickname: "User_123",
strict: false,
want: true,
},
{
name: "Valid Nickname - Unicode Japanese",
nickname: "ユーザー名",
strict: false,
want: true,
},
{
name: "Valid Nickname - Unicode Ukraine",
nickname: "Користувач",
strict: false,
want: true,
},
{
name: "Valid Nickname - Unicode Chinese",
nickname: "用户名",
strict: false,
want: true,
},
{
name: "Invalid Nickname - Contains Emoji",
nickname: "😀User",
strict: false,
want: false,
},
{
name: "Invalid Nickname - Contains Space",
nickname: "User Name",
strict: false,
want: false,
},
{
name: "Invalid Nickname - Special Characters",
nickname: "User!123",
strict: false,
want: false,
},
{
name: "Invalid Nickname - Empty String",
nickname: "",
strict: false,
want: false,
},
{
name: "Invalid Nickname - Too Long",
nickname: "ThisUsernameIsWayTooLong1234567890",
strict: false,
want: false,
},
// Strict mode tests
{
name: "Valid Nickname - Alphanumeric (Strict)",
nickname: "User123",
strict: true,
want: true,
},
{
name: "Valid Nickname - Underscores (Strict)",
nickname: "User_123",
strict: true,
want: true,
},
{
name: "Invalid Nickname - Unicode Japanese (Strict)",
nickname: "ユーザー名",
strict: true,
want: false,
},
{
name: "Invalid Nickname - Unicode Ukraine (Strict)",
nickname: "Користувач",
strict: true,
want: false,
},
{
name: "Invalid Nickname - Unicode Chinese (Strict)",
nickname: "用户名",
strict: true,
want: false,
},
{
name: "Valid Nickname - Alphanumeric (Strict)",
nickname: "UserName",
strict: true,
want: true,
},
{
name: "Invalid Nickname - Contains Space (Strict)",
nickname: "User Name",
strict: true,
want: false,
},
{
name: "Invalid Nickname - Special Characters (Strict)",
nickname: "User-Name",
strict: true,
want: false,
},
{
name: "Invalid Nickname - Contains Dot (Strict)",
nickname: "User.Name",
strict: true,
want: false,
},
{
name: "Invalid Nickname - Contains Emoji (Strict)",
nickname: "User😀",
strict: true,
want: false,
},
{
name: "Invalid Nickname - Empty String (Strict)",
nickname: "",
strict: true,
want: false,
},
{
name: "Invalid Nickname - Too Long (Strict)",
nickname: "ThisUsernameIsWayTooLong1234567890",
strict: true,
want: false,
},
{
name: "Valid Nickname - Trimmed Spaces",
nickname: " User123 ",
strict: false,
want: true,
},
{
name: "Valid Nickname - Trimmed Spaces (Strict)",
nickname: " User123 ",
strict: true,
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var got bool
if tt.strict {
got = Nickname(tt.nickname, true)
} else {
got = Nickname(tt.nickname)
}
if got != tt.want {
t.Errorf(
"Nickname(%q, strict=%v) = %v, want %v",
tt.nickname,
tt.strict,
got,
tt.want,
)
}
})
}
}