@ -53,6 +53,12 @@ var alphanumericMetas = map[string]string{
"style" : IssueNameStyleAlphanumeric ,
"style" : IssueNameStyleAlphanumeric ,
}
}
// these values should match the Repo const above
var localMetas = map [ string ] string {
"user" : "gogits" ,
"repo" : "gogs" ,
}
func TestRender_IssueIndexPattern ( t * testing . T ) {
func TestRender_IssueIndexPattern ( t * testing . T ) {
// numeric: render inputs without valid mentions
// numeric: render inputs without valid mentions
test := func ( s string ) {
test := func ( s string ) {
@ -91,7 +97,7 @@ func TestRender_IssueIndexPattern2(t *testing.T) {
links [ i ] = numericIssueLink ( util . URLJoin ( setting . AppSubURL , "issues" ) , index )
links [ i ] = numericIssueLink ( util . URLJoin ( setting . AppSubURL , "issues" ) , index )
}
}
expectedNil := fmt . Sprintf ( expectedFmt , links ... )
expectedNil := fmt . Sprintf ( expectedFmt , links ... )
testRenderIssueIndexPattern ( t , s , expectedNil , nil )
testRenderIssueIndexPattern ( t , s , expectedNil , & postProcessCtx { metas : localMetas } )
for i , index := range indices {
for i , index := range indices {
links [ i ] = numericIssueLink ( "https://someurl.com/someUser/someRepo/" , index )
links [ i ] = numericIssueLink ( "https://someurl.com/someUser/someRepo/" , index )
@ -171,6 +177,7 @@ func testRenderIssueIndexPattern(t *testing.T, input, expected string, ctx *post
if ctx . urlPrefix == "" {
if ctx . urlPrefix == "" {
ctx . urlPrefix = AppSubURL
ctx . urlPrefix = AppSubURL
}
}
res , err := ctx . postProcess ( [ ] byte ( input ) )
res , err := ctx . postProcess ( [ ] byte ( input ) )
assert . NoError ( t , err )
assert . NoError ( t , err )
assert . Equal ( t , expected , string ( res ) )
assert . Equal ( t , expected , string ( res ) )
@ -181,10 +188,10 @@ func TestRender_AutoLink(t *testing.T) {
setting . AppSubURL = AppSubURL
setting . AppSubURL = AppSubURL
test := func ( input , expected string ) {
test := func ( input , expected string ) {
buffer , err := PostProcess ( [ ] byte ( input ) , setting . AppSubURL , nil , false )
buffer , err := PostProcess ( [ ] byte ( input ) , setting . AppSubURL , localMetas , false )
assert . Equal ( t , err , nil )
assert . Equal ( t , err , nil )
assert . Equal ( t , strings . TrimSpace ( expected ) , strings . TrimSpace ( string ( buffer ) ) )
assert . Equal ( t , strings . TrimSpace ( expected ) , strings . TrimSpace ( string ( buffer ) ) )
buffer , err = PostProcess ( [ ] byte ( input ) , setting . AppSubURL , nil , true )
buffer , err = PostProcess ( [ ] byte ( input ) , setting . AppSubURL , localMetas , true )
assert . Equal ( t , err , nil )
assert . Equal ( t , err , nil )
assert . Equal ( t , strings . TrimSpace ( expected ) , strings . TrimSpace ( string ( buffer ) ) )
assert . Equal ( t , strings . TrimSpace ( expected ) , strings . TrimSpace ( string ( buffer ) ) )
}
}
@ -214,6 +221,7 @@ func TestRender_FullIssueURLs(t *testing.T) {
if ctx . urlPrefix == "" {
if ctx . urlPrefix == "" {
ctx . urlPrefix = AppSubURL
ctx . urlPrefix = AppSubURL
}
}
ctx . metas = localMetas
result , err := ctx . postProcess ( [ ] byte ( input ) )
result , err := ctx . postProcess ( [ ] byte ( input ) )
assert . NoError ( t , err )
assert . NoError ( t , err )
assert . Equal ( t , expected , string ( result ) )
assert . Equal ( t , expected , string ( result ) )
@ -221,9 +229,11 @@ func TestRender_FullIssueURLs(t *testing.T) {
test ( "Here is a link https://git.osgeo.org/gogs/postgis/postgis/pulls/6" ,
test ( "Here is a link https://git.osgeo.org/gogs/postgis/postgis/pulls/6" ,
"Here is a link https://git.osgeo.org/gogs/postgis/postgis/pulls/6" )
"Here is a link https://git.osgeo.org/gogs/postgis/postgis/pulls/6" )
test ( "Look here http://localhost:3000/person/repo/issues/4" ,
test ( "Look here http://localhost:3000/person/repo/issues/4" ,
` Look here <a href="http://localhost:3000/person/repo/issues/4">#4</a> ` )
` Look here <a href="http://localhost:3000/person/repo/issues/4">person/repo #4</a> ` )
test ( "http://localhost:3000/person/repo/issues/4#issuecomment-1234" ,
test ( "http://localhost:3000/person/repo/issues/4#issuecomment-1234" ,
` <a href="http://localhost:3000/person/repo/issues/4#issuecomment-1234">#4</a> ` )
` <a href="http://localhost:3000/person/repo/issues/4#issuecomment-1234">person/repo#4</a> ` )
test ( "http://localhost:3000/gogits/gogs/issues/4" ,
` <a href="http://localhost:3000/gogits/gogs/issues/4">#4</a> ` )
}
}
func TestRegExp_issueNumericPattern ( t * testing . T ) {
func TestRegExp_issueNumericPattern ( t * testing . T ) {