@@ -55,9 +55,12 @@ func link(href, contents string) string {
55
55
return fmt .Sprintf ("<a href=\" %s\" >%s</a>" , href , contents )
56
56
}
57
57
58
- func testRenderIssueIndexPattern (t * testing.T , input , expected string , metas map [string ]string ) {
59
- assert .Equal (t , expected ,
60
- string (RenderIssueIndexPattern ([]byte (input ), AppSubURL , metas )))
58
+ func testRenderIssueIndexPattern (t * testing.T , input , expected string , opts RenderIssueIndexPatternOptions ) {
59
+ if len (opts .URLPrefix ) == 0 {
60
+ opts .URLPrefix = AppSubURL
61
+ }
62
+ actual := string (RenderIssueIndexPattern ([]byte (input ), opts ))
63
+ assert .Equal (t , expected , actual )
61
64
}
62
65
63
66
func TestURLJoin (t * testing.T ) {
@@ -88,8 +91,8 @@ func TestURLJoin(t *testing.T) {
88
91
func TestRender_IssueIndexPattern (t * testing.T ) {
89
92
// numeric: render inputs without valid mentions
90
93
test := func (s string ) {
91
- testRenderIssueIndexPattern (t , s , s , nil )
92
- testRenderIssueIndexPattern (t , s , s , numericMetas )
94
+ testRenderIssueIndexPattern (t , s , s , RenderIssueIndexPatternOptions {} )
95
+ testRenderIssueIndexPattern (t , s , s , RenderIssueIndexPatternOptions { Metas : numericMetas } )
93
96
}
94
97
95
98
// should not render anything when there are no mentions
@@ -123,13 +126,13 @@ func TestRender_IssueIndexPattern2(t *testing.T) {
123
126
links [i ] = numericIssueLink (URLJoin (setting .AppSubURL , "issues" ), index )
124
127
}
125
128
expectedNil := fmt .Sprintf (expectedFmt , links ... )
126
- testRenderIssueIndexPattern (t , s , expectedNil , nil )
129
+ testRenderIssueIndexPattern (t , s , expectedNil , RenderIssueIndexPatternOptions {} )
127
130
128
131
for i , index := range indices {
129
132
links [i ] = numericIssueLink ("https://someurl.com/someUser/someRepo/" , index )
130
133
}
131
134
expectedNum := fmt .Sprintf (expectedFmt , links ... )
132
- testRenderIssueIndexPattern (t , s , expectedNum , numericMetas )
135
+ testRenderIssueIndexPattern (t , s , expectedNum , RenderIssueIndexPatternOptions { Metas : numericMetas } )
133
136
}
134
137
135
138
// should render freestanding mentions
@@ -155,7 +158,7 @@ func TestRender_IssueIndexPattern3(t *testing.T) {
155
158
156
159
// alphanumeric: render inputs without valid mentions
157
160
test := func (s string ) {
158
- testRenderIssueIndexPattern (t , s , s , alphanumericMetas )
161
+ testRenderIssueIndexPattern (t , s , s , RenderIssueIndexPatternOptions { Metas : alphanumericMetas } )
159
162
}
160
163
test ("" )
161
164
test ("this is a test" )
@@ -187,13 +190,32 @@ func TestRender_IssueIndexPattern4(t *testing.T) {
187
190
links [i ] = alphanumIssueLink ("https://someurl.com/someUser/someRepo/" , name )
188
191
}
189
192
expected := fmt .Sprintf (expectedFmt , links ... )
190
- testRenderIssueIndexPattern (t , s , expected , alphanumericMetas )
193
+ testRenderIssueIndexPattern (t , s , expected , RenderIssueIndexPatternOptions { Metas : alphanumericMetas } )
191
194
}
192
195
test ("OTT-1234 test" , "%s test" , "OTT-1234" )
193
196
test ("test T-12 issue" , "test %s issue" , "T-12" )
194
197
test ("test issue ABCDEFGHIJ-1234567890" , "test issue %s" , "ABCDEFGHIJ-1234567890" )
195
198
}
196
199
200
+ func TestRenderIssueIndexPatternWithDefaultURL (t * testing.T ) {
201
+ setting .AppURL = AppURL
202
+ setting .AppSubURL = AppSubURL
203
+
204
+ test := func (input string , expected string ) {
205
+ testRenderIssueIndexPattern (t , input , expected , RenderIssueIndexPatternOptions {
206
+ DefaultURL : AppURL ,
207
+ })
208
+ }
209
+ test ("hello #123 world" ,
210
+ fmt .Sprintf (`<a rel="nofollow" href="%s">hello</a> ` , AppURL )+
211
+ fmt .Sprintf (`<a href="%sissues/123">#123</a> ` , AppSubURL )+
212
+ fmt .Sprintf (`<a rel="nofollow" href="%s">world</a>` , AppURL ))
213
+ test ("hello (#123) world" ,
214
+ fmt .Sprintf (`<a rel="nofollow" href="%s">hello </a>` , AppURL )+
215
+ fmt .Sprintf (`(<a href="%sissues/123">#123</a>)` , AppSubURL )+
216
+ fmt .Sprintf (`<a rel="nofollow" href="%s"> world</a>` , AppURL ))
217
+ }
218
+
197
219
func TestRender_AutoLink (t * testing.T ) {
198
220
setting .AppURL = AppURL
199
221
setting .AppSubURL = AppSubURL
0 commit comments