summaryrefslogtreecommitdiffstats
path: root/modules/markup/markdown/markdown_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/markup/markdown/markdown_test.go')
-rw-r--r--modules/markup/markdown/markdown_test.go102
1 files changed, 7 insertions, 95 deletions
diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go
index c19037f629..605094df46 100644
--- a/modules/markup/markdown/markdown_test.go
+++ b/modules/markup/markdown/markdown_test.go
@@ -8,7 +8,6 @@ import (
"strings"
"testing"
- "code.gitea.io/gitea/modules/markup"
. "code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
@@ -41,69 +40,6 @@ func TestRender_StandardLinks(t *testing.T) {
`<p><a href="`+lnkWiki+`" rel="nofollow">WikiPage</a></p>`)
}
-func TestRender_ShortLinks(t *testing.T) {
- setting.AppURL = AppURL
- setting.AppSubURL = AppSubURL
- tree := util.URLJoin(AppSubURL, "src", "master")
-
- test := func(input, expected, expectedWiki string) {
- buffer := RenderString(input, tree, nil)
- assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer)))
- buffer = RenderWiki([]byte(input), setting.AppSubURL, nil)
- assert.Equal(t, strings.TrimSpace(expectedWiki), strings.TrimSpace(string(buffer)))
- }
-
- rawtree := util.URLJoin(AppSubURL, "raw", "master")
- url := util.URLJoin(tree, "Link")
- otherUrl := util.URLJoin(tree, "OtherLink")
- imgurl := util.URLJoin(rawtree, "Link.jpg")
- urlWiki := util.URLJoin(AppSubURL, "wiki", "Link")
- otherUrlWiki := util.URLJoin(AppSubURL, "wiki", "OtherLink")
- imgurlWiki := util.URLJoin(AppSubURL, "wiki", "raw", "Link.jpg")
- favicon := "http://google.com/favicon.ico"
-
- test(
- "[[Link]]",
- `<p><a href="`+url+`" rel="nofollow">Link</a></p>`,
- `<p><a href="`+urlWiki+`" rel="nofollow">Link</a></p>`)
- test(
- "[[Link.jpg]]",
- `<p><a href="`+imgurl+`" rel="nofollow"><img src="`+imgurl+`" alt="Link.jpg" title="Link.jpg"/></a></p>`,
- `<p><a href="`+imgurlWiki+`" rel="nofollow"><img src="`+imgurlWiki+`" alt="Link.jpg" title="Link.jpg"/></a></p>`)
- test(
- "[["+favicon+"]]",
- `<p><a href="`+favicon+`" rel="nofollow"><img src="`+favicon+`" title="favicon.ico"/></a></p>`,
- `<p><a href="`+favicon+`" rel="nofollow"><img src="`+favicon+`" title="favicon.ico"/></a></p>`)
- test(
- "[[Name|Link]]",
- `<p><a href="`+url+`" rel="nofollow">Name</a></p>`,
- `<p><a href="`+urlWiki+`" rel="nofollow">Name</a></p>`)
- test(
- "[[Name|Link.jpg]]",
- `<p><a href="`+imgurl+`" rel="nofollow"><img src="`+imgurl+`" alt="Name" title="Name"/></a></p>`,
- `<p><a href="`+imgurlWiki+`" rel="nofollow"><img src="`+imgurlWiki+`" alt="Name" title="Name"/></a></p>`)
- test(
- "[[Name|Link.jpg|alt=AltName]]",
- `<p><a href="`+imgurl+`" rel="nofollow"><img src="`+imgurl+`" alt="AltName" title="AltName"/></a></p>`,
- `<p><a href="`+imgurlWiki+`" rel="nofollow"><img src="`+imgurlWiki+`" alt="AltName" title="AltName"/></a></p>`)
- test(
- "[[Name|Link.jpg|title=Title]]",
- `<p><a href="`+imgurl+`" rel="nofollow"><img src="`+imgurl+`" alt="Title" title="Title"/></a></p>`,
- `<p><a href="`+imgurlWiki+`" rel="nofollow"><img src="`+imgurlWiki+`" alt="Title" title="Title"/></a></p>`)
- test(
- "[[Name|Link.jpg|alt=AltName|title=Title]]",
- `<p><a href="`+imgurl+`" rel="nofollow"><img src="`+imgurl+`" alt="AltName" title="Title"/></a></p>`,
- `<p><a href="`+imgurlWiki+`" rel="nofollow"><img src="`+imgurlWiki+`" alt="AltName" title="Title"/></a></p>`)
- test(
- "[[Name|Link.jpg|alt=\"AltName\"|title='Title']]",
- `<p><a href="`+imgurl+`" rel="nofollow"><img src="`+imgurl+`" alt="AltName" title="Title"/></a></p>`,
- `<p><a href="`+imgurlWiki+`" rel="nofollow"><img src="`+imgurlWiki+`" alt="AltName" title="Title"/></a></p>`)
- test(
- "[[Link]] [[OtherLink]]",
- `<p><a href="`+url+`" rel="nofollow">Link</a> <a href="`+otherUrl+`" rel="nofollow">OtherLink</a></p>`,
- `<p><a href="`+urlWiki+`" rel="nofollow">Link</a> <a href="`+otherUrlWiki+`" rel="nofollow">OtherLink</a></p>`)
-}
-
func TestMisc_IsMarkdownFile(t *testing.T) {
setting.Markdown.FileExtensions = []string{".md", ".markdown", ".mdown", ".mkd"}
trueTestCases := []string{
@@ -141,35 +77,11 @@ func TestRender_Images(t *testing.T) {
test(
"!["+title+"]("+url+")",
- `<p><a href="`+result+`" rel="nofollow"><img src="`+result+`" alt="`+title+`"></a></p>`)
+ `<p><a href="`+result+`" rel="nofollow"><img src="`+result+`" alt="`+title+`"/></a></p>`)
test(
"[["+title+"|"+url+"]]",
- `<p><a href="`+result+`" rel="nofollow"><img src="`+result+`" alt="`+title+`" title="`+title+`"/></a></p>`)
-}
-
-func TestRegExp_ShortLinkPattern(t *testing.T) {
- trueTestCases := []string{
- "[[stuff]]",
- "[[]]",
- "[[stuff|title=Difficult name with spaces*!]]",
- }
- falseTestCases := []string{
- "test",
- "abcdefg",
- "[[]",
- "[[",
- "[]",
- "]]",
- "abcdefghijklmnopqrstuvwxyz",
- }
-
- for _, testCase := range trueTestCases {
- assert.True(t, markup.ShortLinkPattern.MatchString(testCase))
- }
- for _, testCase := range falseTestCases {
- assert.False(t, markup.ShortLinkPattern.MatchString(testCase))
- }
+ `<p><a href="`+result+`" rel="nofollow"><img src="`+result+`" title="`+title+`" alt="`+title+`"/></a></p>`)
}
func testAnswers(baseURLContent, baseURLImages string) []string {
@@ -185,7 +97,7 @@ func testAnswers(baseURLContent, baseURLImages string) []string {
<ul>
<li>Bezier widget (by <a href="` + AppURL + `r-lyeh" rel="nofollow">@r-lyeh</a>) <a href="http://localhost:3000/ocornut/imgui/issues/786" rel="nofollow">#786</a></li>
-<li>Node graph editors https://github.com/ocornut/imgui/issues/306</li>
+<li>Node graph editors <a href="https://github.com/ocornut/imgui/issues/306" rel="nofollow">https://github.com/ocornut/imgui/issues/306</a></li>
<li><a href="` + baseURLContent + `/memory_editor_example" rel="nofollow">Memory Editor</a></li>
<li><a href="` + baseURLContent + `/plot_var_example" rel="nofollow">Plot var helper</a></li>
</ul>
@@ -201,14 +113,14 @@ func testAnswers(baseURLContent, baseURLImages string) []string {
<table>
<thead>
<tr>
-<th><a href="` + baseURLImages + `/images/icon-install.png" rel="nofollow"><img src="` + baseURLImages + `/images/icon-install.png" alt="images/icon-install.png" title="icon-install.png"/></a></th>
+<th><a href="` + baseURLImages + `/images/icon-install.png" rel="nofollow"><img src="` + baseURLImages + `/images/icon-install.png" title="icon-install.png" alt="images/icon-install.png"/></a></th>
<th><a href="` + baseURLContent + `/Installation" rel="nofollow">Installation</a></th>
</tr>
</thead>
<tbody>
<tr>
-<td><a href="` + baseURLImages + `/images/icon-usage.png" rel="nofollow"><img src="` + baseURLImages + `/images/icon-usage.png" alt="images/icon-usage.png" title="icon-usage.png"/></a></td>
+<td><a href="` + baseURLImages + `/images/icon-usage.png" rel="nofollow"><img src="` + baseURLImages + `/images/icon-usage.png" title="icon-usage.png" alt="images/icon-usage.png"/></a></td>
<td><a href="` + baseURLContent + `/Usage" rel="nofollow">Usage</a></td>
</tr>
</tbody>
@@ -218,9 +130,9 @@ func testAnswers(baseURLContent, baseURLImages string) []string {
<ol>
<li><a href="https://github.com/libgdx/libgdx/wiki/Gradle-on-the-Commandline#packaging-for-the-desktop" rel="nofollow">Package your libGDX application</a>
-<a href="` + baseURLImages + `/images/1.png" rel="nofollow"><img src="` + baseURLImages + `/images/1.png" alt="images/1.png" title="1.png"/></a></li>
+<a href="` + baseURLImages + `/images/1.png" rel="nofollow"><img src="` + baseURLImages + `/images/1.png" title="1.png" alt="images/1.png"/></a></li>
<li>Perform a test run by hitting the Run! button.
-<a href="` + baseURLImages + `/images/2.png" rel="nofollow"><img src="` + baseURLImages + `/images/2.png" alt="images/2.png" title="2.png"/></a></li>
+<a href="` + baseURLImages + `/images/2.png" rel="nofollow"><img src="` + baseURLImages + `/images/2.png" title="2.png" alt="images/2.png"/></a></li>
</ol>
`,
}