|
|
|
@ -21,12 +21,11 @@ import (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
AppURL = "http://localhost:3000/"
|
|
|
|
|
Repo = "gogits/gogs"
|
|
|
|
|
AppSubURL = AppURL + Repo + "/"
|
|
|
|
|
AppURL = "http://localhost:3000/"
|
|
|
|
|
FullURL = AppURL + "gogits/gogs/"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// these values should match the Repo const above
|
|
|
|
|
// these values should match the const above
|
|
|
|
|
var localMetas = map[string]string{
|
|
|
|
|
"user": "gogits",
|
|
|
|
|
"repo": "gogs",
|
|
|
|
@ -48,13 +47,12 @@ func TestMain(m *testing.M) {
|
|
|
|
|
|
|
|
|
|
func TestRender_StandardLinks(t *testing.T) {
|
|
|
|
|
setting.AppURL = AppURL
|
|
|
|
|
setting.AppSubURL = AppSubURL
|
|
|
|
|
|
|
|
|
|
test := func(input, expected, expectedWiki string) {
|
|
|
|
|
buffer, err := markdown.RenderString(&markup.RenderContext{
|
|
|
|
|
Ctx: git.DefaultContext,
|
|
|
|
|
Links: markup.Links{
|
|
|
|
|
Base: setting.AppSubURL,
|
|
|
|
|
Base: FullURL,
|
|
|
|
|
},
|
|
|
|
|
}, input)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
@ -63,7 +61,7 @@ func TestRender_StandardLinks(t *testing.T) {
|
|
|
|
|
buffer, err = markdown.RenderString(&markup.RenderContext{
|
|
|
|
|
Ctx: git.DefaultContext,
|
|
|
|
|
Links: markup.Links{
|
|
|
|
|
Base: setting.AppSubURL,
|
|
|
|
|
Base: FullURL,
|
|
|
|
|
},
|
|
|
|
|
IsWiki: true,
|
|
|
|
|
}, input)
|
|
|
|
@ -74,8 +72,8 @@ func TestRender_StandardLinks(t *testing.T) {
|
|
|
|
|
googleRendered := `<p><a href="https://google.com/" rel="nofollow">https://google.com/</a></p>`
|
|
|
|
|
test("<https://google.com/>", googleRendered, googleRendered)
|
|
|
|
|
|
|
|
|
|
lnk := util.URLJoin(AppSubURL, "WikiPage")
|
|
|
|
|
lnkWiki := util.URLJoin(AppSubURL, "wiki", "WikiPage")
|
|
|
|
|
lnk := util.URLJoin(FullURL, "WikiPage")
|
|
|
|
|
lnkWiki := util.URLJoin(FullURL, "wiki", "WikiPage")
|
|
|
|
|
test("[WikiPage](WikiPage)",
|
|
|
|
|
`<p><a href="`+lnk+`" rel="nofollow">WikiPage</a></p>`,
|
|
|
|
|
`<p><a href="`+lnkWiki+`" rel="nofollow">WikiPage</a></p>`)
|
|
|
|
@ -83,13 +81,12 @@ func TestRender_StandardLinks(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
func TestRender_Images(t *testing.T) {
|
|
|
|
|
setting.AppURL = AppURL
|
|
|
|
|
setting.AppSubURL = AppSubURL
|
|
|
|
|
|
|
|
|
|
test := func(input, expected string) {
|
|
|
|
|
buffer, err := markdown.RenderString(&markup.RenderContext{
|
|
|
|
|
Ctx: git.DefaultContext,
|
|
|
|
|
Links: markup.Links{
|
|
|
|
|
Base: setting.AppSubURL,
|
|
|
|
|
Base: FullURL,
|
|
|
|
|
},
|
|
|
|
|
}, input)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
@ -99,7 +96,7 @@ func TestRender_Images(t *testing.T) {
|
|
|
|
|
url := "../../.images/src/02/train.jpg"
|
|
|
|
|
title := "Train"
|
|
|
|
|
href := "https://gitea.io"
|
|
|
|
|
result := util.URLJoin(AppSubURL, url)
|
|
|
|
|
result := util.URLJoin(FullURL, url)
|
|
|
|
|
// hint: With Markdown v2.5.2, there is a new syntax: [link](URL){:target="_blank"} , but we do not support it now
|
|
|
|
|
|
|
|
|
|
test(
|
|
|
|
@ -289,15 +286,14 @@ This PR has been generated by [Renovate Bot](https://github.com/renovatebot/reno
|
|
|
|
|
|
|
|
|
|
func TestTotal_RenderWiki(t *testing.T) {
|
|
|
|
|
setting.AppURL = AppURL
|
|
|
|
|
setting.AppSubURL = AppSubURL
|
|
|
|
|
|
|
|
|
|
answers := testAnswers(util.URLJoin(AppSubURL, "wiki"), util.URLJoin(AppSubURL, "wiki", "raw"))
|
|
|
|
|
answers := testAnswers(util.URLJoin(FullURL, "wiki"), util.URLJoin(FullURL, "wiki", "raw"))
|
|
|
|
|
|
|
|
|
|
for i := 0; i < len(sameCases); i++ {
|
|
|
|
|
line, err := markdown.RenderString(&markup.RenderContext{
|
|
|
|
|
Ctx: git.DefaultContext,
|
|
|
|
|
Links: markup.Links{
|
|
|
|
|
Base: setting.AppSubURL,
|
|
|
|
|
Base: FullURL,
|
|
|
|
|
},
|
|
|
|
|
Metas: localMetas,
|
|
|
|
|
IsWiki: true,
|
|
|
|
@ -310,12 +306,12 @@ func TestTotal_RenderWiki(t *testing.T) {
|
|
|
|
|
// Guard wiki sidebar: special syntax
|
|
|
|
|
`[[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]`,
|
|
|
|
|
// rendered
|
|
|
|
|
`<p><a href="` + AppSubURL + `wiki/Guardfile-DSL---Configuring-Guard" rel="nofollow">Guardfile-DSL / Configuring-Guard</a></p>
|
|
|
|
|
`<p><a href="` + FullURL + `wiki/Guardfile-DSL---Configuring-Guard" rel="nofollow">Guardfile-DSL / Configuring-Guard</a></p>
|
|
|
|
|
`,
|
|
|
|
|
// special syntax
|
|
|
|
|
`[[Name|Link]]`,
|
|
|
|
|
// rendered
|
|
|
|
|
`<p><a href="` + AppSubURL + `wiki/Link" rel="nofollow">Name</a></p>
|
|
|
|
|
`<p><a href="` + FullURL + `wiki/Link" rel="nofollow">Name</a></p>
|
|
|
|
|
`,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -323,7 +319,7 @@ func TestTotal_RenderWiki(t *testing.T) {
|
|
|
|
|
line, err := markdown.RenderString(&markup.RenderContext{
|
|
|
|
|
Ctx: git.DefaultContext,
|
|
|
|
|
Links: markup.Links{
|
|
|
|
|
Base: setting.AppSubURL,
|
|
|
|
|
Base: FullURL,
|
|
|
|
|
},
|
|
|
|
|
IsWiki: true,
|
|
|
|
|
}, testCases[i])
|
|
|
|
@ -334,15 +330,14 @@ func TestTotal_RenderWiki(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
func TestTotal_RenderString(t *testing.T) {
|
|
|
|
|
setting.AppURL = AppURL
|
|
|
|
|
setting.AppSubURL = AppSubURL
|
|
|
|
|
|
|
|
|
|
answers := testAnswers(util.URLJoin(AppSubURL, "src", "master"), util.URLJoin(AppSubURL, "media", "master"))
|
|
|
|
|
answers := testAnswers(util.URLJoin(FullURL, "src", "master"), util.URLJoin(FullURL, "media", "master"))
|
|
|
|
|
|
|
|
|
|
for i := 0; i < len(sameCases); i++ {
|
|
|
|
|
line, err := markdown.RenderString(&markup.RenderContext{
|
|
|
|
|
Ctx: git.DefaultContext,
|
|
|
|
|
Links: markup.Links{
|
|
|
|
|
Base: AppSubURL,
|
|
|
|
|
Base: FullURL,
|
|
|
|
|
BranchPath: "master",
|
|
|
|
|
},
|
|
|
|
|
Metas: localMetas,
|
|
|
|
@ -357,7 +352,7 @@ func TestTotal_RenderString(t *testing.T) {
|
|
|
|
|
line, err := markdown.RenderString(&markup.RenderContext{
|
|
|
|
|
Ctx: git.DefaultContext,
|
|
|
|
|
Links: markup.Links{
|
|
|
|
|
Base: AppSubURL,
|
|
|
|
|
Base: FullURL,
|
|
|
|
|
},
|
|
|
|
|
}, testCases[i])
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|