@@ -21,8 +21,8 @@ const (
21
21
TestRepoURL = TestAppURL + TestOrgRepo + "/"
22
22
)
23
23
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 {
26
26
return link (util .URLJoin (baseURL , name ), class , name )
27
27
}
28
28
@@ -54,6 +54,13 @@ var alphanumericMetas = map[string]string{
54
54
"style" : IssueNameStyleAlphanumeric ,
55
55
}
56
56
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
+
57
64
// these values should match the TestOrgRepo const above
58
65
var localMetas = map [string ]string {
59
66
"user" : "gogits" ,
@@ -184,7 +191,7 @@ func TestRender_IssueIndexPattern4(t *testing.T) {
184
191
test := func (s , expectedFmt string , names ... string ) {
185
192
links := make ([]interface {}, len (names ))
186
193
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 )
188
195
}
189
196
expected := fmt .Sprintf (expectedFmt , links ... )
190
197
testRenderIssueIndexPattern (t , s , expected , & RenderContext {Metas : alphanumericMetas })
@@ -194,6 +201,43 @@ func TestRender_IssueIndexPattern4(t *testing.T) {
194
201
test ("test issue ABCDEFGHIJ-1234567890" , "test issue %s" , "ABCDEFGHIJ-1234567890" )
195
202
}
196
203
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
+
197
241
func testRenderIssueIndexPattern (t * testing.T , input , expected string , ctx * RenderContext ) {
198
242
if ctx .URLPrefix == "" {
199
243
ctx .URLPrefix = TestAppURL
@@ -202,7 +246,7 @@ func testRenderIssueIndexPattern(t *testing.T, input, expected string, ctx *Rend
202
246
var buf strings.Builder
203
247
err := postProcess (ctx , []processor {issueIndexPatternProcessor }, strings .NewReader (input ), & buf )
204
248
assert .NoError (t , err )
205
- assert .Equal (t , expected , buf .String ())
249
+ assert .Equal (t , expected , buf .String (), "input=%q" , input )
206
250
}
207
251
208
252
func TestRender_AutoLink (t * testing.T ) {
0 commit comments