@ -5,11 +5,13 @@
package highlight
package highlight
import (
import (
"reflect "
"strings "
"testing"
"testing"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"github.com/stretchr/testify/assert"
"gopkg.in/ini.v1"
"gopkg.in/ini.v1"
)
)
@ -20,17 +22,18 @@ func TestFile(t *testing.T) {
numLines int
numLines int
fileName string
fileName string
code string
code string
want [ ] string
want string
} {
} {
{
{
name : ".drone.yml" ,
name : ".drone.yml" ,
numLines : 12 ,
numLines : 12 ,
fileName : ".drone.yml" ,
fileName : ".drone.yml" ,
code : ` kind : pipeline
code : util . Dedent ( `
name : default
kind : pipeline
name : default
steps :
steps :
- name : test
- name : test
image : golang : 1.13
image : golang : 1.13
environment :
environment :
GOPROXY : https : //goproxy.cn
GOPROXY : https : //goproxy.cn
@ -38,34 +41,32 @@ steps:
- go get - u
- go get - u
- go build - v
- go build - v
- go test - v - race - coverprofile = coverage . txt - covermode = atomic
- go test - v - race - coverprofile = coverage . txt - covermode = atomic
` ,
` ) ,
want : [ ] string {
want : util . Dedent ( `
` <span class="line"><span class="cl"><span class="nt">kind</span><span class="p">:</span><span class="w"> </span><span class="l">pipeline</span> ` ,
< span class = "line" > < span class = "cl" > < span class = "nt" > kind < / span > < span class = "p" > : < / span > < span class = "w" > < / span > < span class = "l" > pipeline < / span >
` </span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">default</span> ` ,
< / span > < / span > < span class = "line" > < span class = "cl" > < span class = "w" > < / span > < span class = "nt" > name < / span > < span class = "p" > : < / span > < span class = "w" > < / span > < span class = "l" > default < / span >
` </span></span><span class="line"><span class="cl"> ` ,
< / span > < / span > < span class = "line" > < span class = "cl" >
` </span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">steps</span><span class="p">:</span> ` ,
< / span > < / span > < span class = "line" > < span class = "cl" > < span class = "w" > < / span > < span class = "nt" > steps < / span > < span class = "p" > : < / span >
` </span></span><span class="line"><span class="cl"><span class="w"></span>- <span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">test</span> ` ,
< / span > < / span > < span class = "line" > < span class = "cl" > < span class = "w" > < / span > - < span class = "nt" > name < / span > < span class = "p" > : < / span > < span class = "w" > < / span > < span class = "l" > test < / span >
` </span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l">golang:1.13</span> ` ,
< / span > < / span > < span class = "line" > < span class = "cl" > < span class = "w" > < / span > < span class = "nt" > image < / span > < span class = "p" > : < / span > < span class = "w" > < / span > < span class = "l" > golang : 1.13 < / span >
` </span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">environment</span><span class="p">:</span> ` ,
< / span > < / span > < span class = "line" > < span class = "cl" > < span class = "w" > < / span > < span class = "nt" > environment < / span > < span class = "p" > : < / span >
` </span></span><span class="line"><span class="cl"><span class="w"></span><span class="w"> </span><span class="nt">GOPROXY</span><span class="p">:</span><span class="w"> </span><span class="l">https://goproxy.cn</span> ` ,
< / span > < / span > < span class = "line" > < span class = "cl" > < span class = "w" > < / span > < span class = "w" > < / span > < span class = "nt" > GOPROXY < / span > < span class = "p" > : < / span > < span class = "w" > < / span > < span class = "l" > https : //goproxy.cn</span>
` </span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">commands</span><span class="p">:</span> ` ,
< / span > < / span > < span class = "line" > < span class = "cl" > < span class = "w" > < / span > < span class = "nt" > commands < / span > < span class = "p" > : < / span >
` </span></span><span class="line"><span class="cl"><span class="w"></span><span class="w"> </span>- <span class="l">go get -u</span> ` ,
< / span > < / span > < span class = "line" > < span class = "cl" > < span class = "w" > < / span > < span class = "w" > < / span > - < span class = "l" > go get - u < / span >
` </span></span><span class="line"><span class="cl"><span class="w"> </span>- <span class="l">go build -v</span> ` ,
< / span > < / span > < span class = "line" > < span class = "cl" > < span class = "w" > < / span > - < span class = "l" > go build - v < / span >
` < / span > < / span > < span class = "line" > < span class = "cl" > < span class = "w" > < / span > - < span class = "l" > go test - v - race - coverprofile = coverage . txt - covermode = atomic < / span > < span class = "w" >
< / span > < / span > < span class = "line" > < span class = "cl" > < span class = "w" > < / span > - < span class = "l" > go test - v - race - coverprofile = coverage . txt - covermode = atomic < / span > < / span > < / span >
< / span > < / span > < / span > ` ,
` ) ,
` < span class = "w" >
< / span > ` ,
} ,
} ,
} ,
{
{
name : ".drone.yml - trailing space" ,
name : ".drone.yml - trailing space" ,
numLines : 13 ,
numLines : 13 ,
fileName : ".drone.yml" ,
fileName : ".drone.yml" ,
code : ` kind : pipeline
code : strings . Replace ( util . Dedent ( `
name : default ` + `
kind : pipeline
name : default
steps :
steps :
- name : test
- name : test
image : golang : 1.13
image : golang : 1.13
environment :
environment :
GOPROXY : https : //goproxy.cn
GOPROXY : https : //goproxy.cn
@ -73,30 +74,31 @@ steps:
- go get - u
- go get - u
- go build - v
- go build - v
- go test - v - race - coverprofile = coverage . txt - covermode = atomic
- go test - v - race - coverprofile = coverage . txt - covermode = atomic
` ,
` ) + "\n" , "name: default" , "name: default " , 1 ) ,
want : [ ] string {
want : util . Dedent ( `
` <span class="line"><span class="cl"><span class="nt">kind</span><span class="p">:</span><span class="w"> </span><span class="l">pipeline</span> ` ,
< span class = "line" > < span class = "cl" > < span class = "nt" > kind < / span > < span class = "p" > : < / span > < span class = "w" > < / span > < span class = "l" > pipeline < / span >
` </span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">default </span> ` ,
< / span > < / span > < span class = "line" > < span class = "cl" > < span class = "w" > < / span > < span class = "nt" > name < / span > < span class = "p" > : < / span > < span class = "w" > < / span > < span class = "l" > default < / span >
` </span></span><span class="line"><span class="cl"> ` ,
< / span > < / span > < span class = "line" > < span class = "cl" >
` </span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">steps</span><span class="p">:</span> ` ,
< / span > < / span > < span class = "line" > < span class = "cl" > < span class = "w" > < / span > < span class = "nt" > steps < / span > < span class = "p" > : < / span >
` </span></span><span class="line"><span class="cl"><span class="w"></span>- <span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">test</span> ` ,
< / span > < / span > < span class = "line" > < span class = "cl" > < span class = "w" > < / span > - < span class = "nt" > name < / span > < span class = "p" > : < / span > < span class = "w" > < / span > < span class = "l" > test < / span >
` </span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l">golang:1.13</span> ` ,
< / span > < / span > < span class = "line" > < span class = "cl" > < span class = "w" > < / span > < span class = "nt" > image < / span > < span class = "p" > : < / span > < span class = "w" > < / span > < span class = "l" > golang : 1.13 < / span >
` </span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">environment</span><span class="p">:</span> ` ,
< / span > < / span > < span class = "line" > < span class = "cl" > < span class = "w" > < / span > < span class = "nt" > environment < / span > < span class = "p" > : < / span >
` </span></span><span class="line"><span class="cl"><span class="w"></span><span class="w"> </span><span class="nt">GOPROXY</span><span class="p">:</span><span class="w"> </span><span class="l">https://goproxy.cn</span> ` ,
< / span > < / span > < span class = "line" > < span class = "cl" > < span class = "w" > < / span > < span class = "w" > < / span > < span class = "nt" > GOPROXY < / span > < span class = "p" > : < / span > < span class = "w" > < / span > < span class = "l" > https : //goproxy.cn</span>
` </span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">commands</span><span class="p">:</span> ` ,
< / span > < / span > < span class = "line" > < span class = "cl" > < span class = "w" > < / span > < span class = "nt" > commands < / span > < span class = "p" > : < / span >
` </span></span><span class="line"><span class="cl"><span class="w"></span><span class="w"> </span>- <span class="l">go get -u</span> ` ,
< / span > < / span > < span class = "line" > < span class = "cl" > < span class = "w" > < / span > < span class = "w" > < / span > - < span class = "l" > go get - u < / span >
` </span></span><span class="line"><span class="cl"><span class="w"> </span>- <span class="l">go build -v</span> ` ,
< / span > < / span > < span class = "line" > < span class = "cl" > < span class = "w" > < / span > - < span class = "l" > go build - v < / span >
` </span></span><span class="line"><span class="cl"><span class="w"> </span>- <span class="l">go test -v -race -coverprofile=coverage.txt -covermode=atomic</span> ` ,
< / span > < / span > < span class = "line" > < span class = "cl" > < span class = "w" > < / span > - < span class = "l" > go test - v - race - coverprofile = coverage . txt - covermode = atomic < / span >
` </span></span><span class="line"><span class="cl"><span class="w"> </span></span></span> ` ,
< / span > < / span >
} ,
< span class = "w" >
< / span >
` ) ,
} ,
} ,
}
}
for _ , tt := range tests {
for _ , tt := range tests {
t . Run ( tt . name , func ( t * testing . T ) {
t . Run ( tt . name , func ( t * testing . T ) {
if got := File ( tt . numLines , tt . fileName , "" , [ ] byte ( tt . code ) ) ; ! reflect . DeepEqual ( got , tt . want ) {
got := strings . Join ( File ( tt . numLines , tt . fileName , "" , [ ] byte ( tt . code ) ) , "\n" )
t . Errorf ( "File() = %v, want %v" , got , tt . want )
assert . Equal ( t , tt . want , got )
}
} )
} )
}
}
}
}