@@ -208,32 +208,57 @@ func testFixtures(t *testing.T, fixtures []testFixture, context string) {
208208}
209209
210210func 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" },
219237 }
220238 falseTestCases := []string {
221239 "@ 0" ,
222240 "@ " ,
223241 "@" ,
224242 "" ,
225243 "ABC" ,
244+ "@.ABC" ,
226245 "/home/gitea/@gitea" ,
227246 "\" @gitea\" " ,
247+ "@@gitea" ,
248+ "@gitea!this" ,
249+ "@gitea?this" ,
250+ "@gitea,this" ,
251+ "@gitea;this" ,
228252 }
229253
230254 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 ])
233258 }
234259 for _ , testCase := range falseTestCases {
235260 res := mentionPattern .MatchString (testCase )
236- assert .False (t , res )
261+ assert .False (t , res , "[%s] should be false" , testCase )
237262 }
238263}
239264
0 commit comments