@@ -21,8 +21,8 @@ const (
2121 TestRepoURL = TestAppURL + TestOrgRepo + "/"
2222)
2323
24- // alphanumLink an HTML link to an alphanumeric-style issue
25- func alphanumIssueLink (baseURL , class , name string ) string {
24+ // externalIssueLink an HTML link to an alphanumeric-style issue
25+ func externalIssueLink (baseURL , class , name string ) string {
2626 return link (util .URLJoin (baseURL , name ), class , name )
2727}
2828
@@ -54,6 +54,13 @@ var alphanumericMetas = map[string]string{
5454 "style" : IssueNameStyleAlphanumeric ,
5555}
5656
57+ var regexpMetas = map [string ]string {
58+ "format" : "https://someurl.com/{user}/{repo}/{index}" ,
59+ "user" : "someUser" ,
60+ "repo" : "someRepo" ,
61+ "style" : IssueNameStyleRegexp ,
62+ }
63+
5764// these values should match the TestOrgRepo const above
5865var localMetas = map [string ]string {
5966 "user" : "gogits" ,
@@ -184,7 +191,7 @@ func TestRender_IssueIndexPattern4(t *testing.T) {
184191 test := func (s , expectedFmt string , names ... string ) {
185192 links := make ([]interface {}, len (names ))
186193 for i , name := range names {
187- links [i ] = alphanumIssueLink ("https://someurl.com/someUser/someRepo/" , "ref-issue ref-external-issue" , name )
194+ links [i ] = externalIssueLink ("https://someurl.com/someUser/someRepo/" , "ref-issue ref-external-issue" , name )
188195 }
189196 expected := fmt .Sprintf (expectedFmt , links ... )
190197 testRenderIssueIndexPattern (t , s , expected , & RenderContext {Metas : alphanumericMetas })
@@ -194,6 +201,43 @@ func TestRender_IssueIndexPattern4(t *testing.T) {
194201 test ("test issue ABCDEFGHIJ-1234567890" , "test issue %s" , "ABCDEFGHIJ-1234567890" )
195202}
196203
204+ func TestRender_IssueIndexPattern5 (t * testing.T ) {
205+ setting .AppURL = TestAppURL
206+
207+ // regexp: render inputs without valid mentions
208+ test := func (s , expectedFmt , pattern string , ids , names []string ) {
209+ metas := regexpMetas
210+ metas ["regexp" ] = pattern
211+ links := make ([]interface {}, len (ids ))
212+ for i , id := range ids {
213+ links [i ] = link (util .URLJoin ("https://someurl.com/someUser/someRepo/" , id ), "ref-issue ref-external-issue" , names [i ])
214+ }
215+
216+ expected := fmt .Sprintf (expectedFmt , links ... )
217+ testRenderIssueIndexPattern (t , s , expected , & RenderContext {Metas : metas })
218+ }
219+
220+ test ("abc ISSUE-123 def" , "abc %s def" ,
221+ "ISSUE-(\\ d+)" ,
222+ []string {"123" },
223+ []string {"ISSUE-123" },
224+ )
225+
226+ test ("abc (ISSUE 123) def" , "abc %s def" ,
227+ "\\ (ISSUE (\\ d+)\\ )" ,
228+ []string {"123" },
229+ []string {"(ISSUE 123)" },
230+ )
231+
232+ test ("abc ISSUE-123 def" , "abc %s def" ,
233+ "(ISSUE-(\\ d+))" ,
234+ []string {"ISSUE-123" },
235+ []string {"ISSUE-123" },
236+ )
237+
238+ testRenderIssueIndexPattern (t , "will not match" , "will not match" , & RenderContext {Metas : regexpMetas })
239+ }
240+
197241func testRenderIssueIndexPattern (t * testing.T , input , expected string , ctx * RenderContext ) {
198242 if ctx .URLPrefix == "" {
199243 ctx .URLPrefix = TestAppURL
@@ -202,7 +246,7 @@ func testRenderIssueIndexPattern(t *testing.T, input, expected string, ctx *Rend
202246 var buf strings.Builder
203247 err := postProcess (ctx , []processor {issueIndexPatternProcessor }, strings .NewReader (input ), & buf )
204248 assert .NoError (t , err )
205- assert .Equal (t , expected , buf .String ())
249+ assert .Equal (t , expected , buf .String (), "input=%q" , input )
206250}
207251
208252func TestRender_AutoLink (t * testing.T ) {
0 commit comments