@@ -208,32 +208,57 @@ func testFixtures(t *testing.T, fixtures []testFixture, context string) {
208
208
}
209
209
210
210
func TestRegExp_mentionPattern (t * testing.T ) {
211
- trueTestCases := []string {
212
- "@Unknwon" ,
213
- "@ANT_123" ,
214
- "@xxx-DiN0-z-A..uru..s-xxx" ,
215
- " @lol " ,
216
- " @Te-st" ,
217
- "(@gitea)" ,
218
- "[@gitea]" ,
211
+ trueTestCases := []struct {
212
+ pat string
213
+ exp string
214
+ }{
215
+ {"@Unknwon" , "@Unknwon" },
216
+ {"@ANT_123" , "@ANT_123" },
217
+ {"@xxx-DiN0-z-A..uru..s-xxx" , "@xxx-DiN0-z-A..uru..s-xxx" },
218
+ {" @lol " , "@lol" },
219
+ {" @Te-st" , "@Te-st" },
220
+ {"(@gitea)" , "@gitea" },
221
+ {"[@gitea]" , "@gitea" },
222
+ {"@gitea! this" , "@gitea" },
223
+ {"@gitea? this" , "@gitea" },
224
+ {"@gitea. this" , "@gitea" },
225
+ {"@gitea, this" , "@gitea" },
226
+ {"@gitea; this" , "@gitea" },
227
+ {"@gitea!\n this" , "@gitea" },
228
+ {"\n @gitea?\n this" , "@gitea" },
229
+ {"\t @gitea.\n this" , "@gitea" },
230
+ {"@gitea,\n this" , "@gitea" },
231
+ {"@gitea;\n this" , "@gitea" },
232
+ {"@gitea!" , "@gitea" },
233
+ {"@gitea?" , "@gitea" },
234
+ {"@gitea." , "@gitea" },
235
+ {"@gitea," , "@gitea" },
236
+ {"@gitea;" , "@gitea" },
219
237
}
220
238
falseTestCases := []string {
221
239
"@ 0" ,
222
240
"@ " ,
223
241
"@" ,
224
242
"" ,
225
243
"ABC" ,
244
+ "@.ABC" ,
226
245
"/home/gitea/@gitea" ,
227
246
"\" @gitea\" " ,
247
+ "@@gitea" ,
248
+ "@gitea!this" ,
249
+ "@gitea?this" ,
250
+ "@gitea,this" ,
251
+ "@gitea;this" ,
228
252
}
229
253
230
254
for _ , testCase := range trueTestCases {
231
- res := mentionPattern .MatchString (testCase )
232
- assert .True (t , res )
255
+ found := mentionPattern .FindStringSubmatch (testCase .pat )
256
+ assert .Len (t , found , 2 )
257
+ assert .Equal (t , testCase .exp , found [1 ])
233
258
}
234
259
for _ , testCase := range falseTestCases {
235
260
res := mentionPattern .MatchString (testCase )
236
- assert .False (t , res )
261
+ assert .False (t , res , "[%s] should be false" , testCase )
237
262
}
238
263
}
239
264
0 commit comments