forked from NYANDEV/forgejo
[GITEA] Add footnote testing
- This adds coverage to the most common and the edge cases of what the footnote implementation should be capable of. This was partly done to ensure no hidden surprises when changing the implementation, as markdown rendering is one of the more important features of Forgejo. (cherry picked from commit 16ecdb41705332843921af8d58c1c9a242add95b) (cherry picked from commit 19dc5ef5e5808abe8a5f85d3eaca3317865595ad) (cherry picked from commit d5955efc0a463164c0b3a75b6621974af22ea47f) (cherry picked from commit 2cdaf1083617acbeec558deeb657a1375cbb3904) (cherry picked from commit 251b567794d3437aac614370e4fe2fdf7ad8b917) Conflicts: modules/markup/markdown/markdown_test.go https://codeberg.org/forgejo/forgejo/pulls/2153
This commit is contained in:
parent
cad9184a36
commit
f863f4b005
1 changed files with 198 additions and 0 deletions
|
@ -546,6 +546,204 @@ func TestMathBlock(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestFootnote(t *testing.T) {
|
||||
testcases := []struct {
|
||||
testcase string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
`Citation needed[^0].
|
||||
[^0]: Source`,
|
||||
`<p>Citation needed<sup id="fnref:user-content-0"><a href="#fn:user-content-0" rel="nofollow">1</a></sup>.</p>
|
||||
<div>
|
||||
<hr/>
|
||||
<ol>
|
||||
<li id="fn:user-content-0">
|
||||
<p>Source <a href="#fnref:user-content-0" rel="nofollow">↩︎</a></p>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
`,
|
||||
},
|
||||
{
|
||||
`Citation needed[^0]`,
|
||||
`<p>Citation needed[^0]</p>
|
||||
`,
|
||||
},
|
||||
{
|
||||
`Citation needed[^1], Citation needed twice[^3]
|
||||
[^3]: Source`,
|
||||
`<p>Citation needed[^1], Citation needed twice<sup id="fnref:user-content-3"><a href="#fn:user-content-3" rel="nofollow">1</a></sup></p>
|
||||
<div>
|
||||
<hr/>
|
||||
<ol>
|
||||
<li id="fn:user-content-3">
|
||||
<p>Source <a href="#fnref:user-content-3" rel="nofollow">↩︎</a></p>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
`,
|
||||
},
|
||||
{
|
||||
`Citation needed[^0]
|
||||
[^1]: Source`,
|
||||
`<p>Citation needed[^0]</p>
|
||||
`,
|
||||
},
|
||||
{
|
||||
`Citation needed[^0]
|
||||
[^0]: Source 1
|
||||
[^0]: Source 2`,
|
||||
`<p>Citation needed<sup id="fnref:user-content-0"><a href="#fn:user-content-0" rel="nofollow">1</a></sup></p>
|
||||
<div>
|
||||
<hr/>
|
||||
<ol>
|
||||
<li id="fn:user-content-0">
|
||||
<p>Source 1 <a href="#fnref:user-content-0" rel="nofollow">↩︎</a></p>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
`,
|
||||
},
|
||||
{
|
||||
`Citation needed![^0]
|
||||
[^0]: Source`,
|
||||
`<p>Citation needed<sup id="fnref:user-content-0"><a href="#fn:user-content-0" rel="nofollow">1</a></sup></p>
|
||||
<div>
|
||||
<hr/>
|
||||
<ol>
|
||||
<li id="fn:user-content-0">
|
||||
<p>Source <a href="#fnref:user-content-0" rel="nofollow">↩︎</a></p>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
`,
|
||||
},
|
||||
{
|
||||
`Trigger [^`,
|
||||
`<p>Trigger [^</p>
|
||||
`,
|
||||
},
|
||||
{
|
||||
`Trigger 2 [^0`,
|
||||
`<p>Trigger 2 [^0</p>
|
||||
`,
|
||||
},
|
||||
{
|
||||
`Citation needed[^0]
|
||||
[^0]: Source with citation needed[^1]
|
||||
[^1]: Source`,
|
||||
`<p>Citation needed<sup id="fnref:user-content-0"><a href="#fn:user-content-0" rel="nofollow">1</a></sup></p>
|
||||
<div>
|
||||
<hr/>
|
||||
<ol>
|
||||
<li id="fn:user-content-0">
|
||||
<p>Source with citation needed<sup id="fnref:user-content-1"><a href="#fn:user-content-1" rel="nofollow">2</a></sup> <a href="#fnref:user-content-0" rel="nofollow">↩︎</a></p>
|
||||
</li>
|
||||
<li id="fn:user-content-1">
|
||||
<p>Source <a href="#fnref:user-content-1" rel="nofollow">↩︎</a></p>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
`,
|
||||
},
|
||||
{
|
||||
`Citation needed[^#]
|
||||
[^#]: Source`,
|
||||
`<p>Citation needed<sup id="fnref:user-content-1"><a href="#fn:user-content-1" rel="nofollow">1</a></sup></p>
|
||||
<div>
|
||||
<hr/>
|
||||
<ol>
|
||||
<li id="fn:user-content-1">
|
||||
<p>Source <a href="#fnref:user-content-1" rel="nofollow">↩︎</a></p>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
`,
|
||||
},
|
||||
{
|
||||
`Citation needed[^0]
|
||||
[^0]: Source`,
|
||||
`<p>Citation needed[^0]<br/>
|
||||
[^0]: Source</p>
|
||||
`,
|
||||
},
|
||||
{
|
||||
`[^0]: Source
|
||||
|
||||
Citation needed[^0].`,
|
||||
`<p>Citation needed<sup id="fnref:user-content-0"><a href="#fn:user-content-0" rel="nofollow">1</a></sup>.</p>
|
||||
<div>
|
||||
<hr/>
|
||||
<ol>
|
||||
<li id="fn:user-content-0">
|
||||
<p>Source <a href="#fnref:user-content-0" rel="nofollow">↩︎</a></p>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
`,
|
||||
},
|
||||
{
|
||||
`Citation needed[^]
|
||||
[^]: Source`,
|
||||
`<p>Citation needed[^]<br/>
|
||||
[^]: Source</p>
|
||||
`,
|
||||
},
|
||||
{
|
||||
`Citation needed[^0]
|
||||
[^0] Source`,
|
||||
`<p>Citation needed[^0]<br/>
|
||||
[^0] Source</p>
|
||||
`,
|
||||
},
|
||||
{
|
||||
`Citation needed[^0]
|
||||
[^0 Source`,
|
||||
`<p>Citation needed[^0]<br/>
|
||||
[^0 Source</p>
|
||||
`,
|
||||
},
|
||||
{
|
||||
`Citation needed[^0] [^0]: Source`,
|
||||
`<p>Citation needed[^0] [^0]: Source</p>
|
||||
`,
|
||||
},
|
||||
{
|
||||
`Citation needed[^Source here 0 # 9-3]
|
||||
[^Source here 0 # 9-3]: Source`,
|
||||
`<p>Citation needed<sup id="fnref:user-content-source-here-0-9-3"><a href="#fn:user-content-source-here-0-9-3" rel="nofollow">1</a></sup></p>
|
||||
<div>
|
||||
<hr/>
|
||||
<ol>
|
||||
<li id="fn:user-content-source-here-0-9-3">
|
||||
<p>Source <a href="#fnref:user-content-source-here-0-9-3" rel="nofollow">↩︎</a></p>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
`,
|
||||
},
|
||||
{
|
||||
`Citation needed[^0]
|
||||
[^0]:`,
|
||||
`<p>Citation needed<sup id="fnref:user-content-0"><a href="#fn:user-content-0" rel="nofollow">1</a></sup></p>
|
||||
<div>
|
||||
<hr/>
|
||||
<ol>
|
||||
<li id="fn:user-content-0">
|
||||
<a href="#fnref:user-content-0" rel="nofollow">↩︎</a></li>
|
||||
</ol>
|
||||
</div>
|
||||
`,
|
||||
},
|
||||
}
|
||||
for _, test := range testcases {
|
||||
res, err := markdown.RenderString(&markup.RenderContext{Ctx: git.DefaultContext}, test.testcase)
|
||||
assert.NoError(t, err, "Unexpected error in testcase: %q", test.testcase)
|
||||
assert.Equal(t, test.expected, res, "Unexpected result in testcase %q", test.testcase)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskList(t *testing.T) {
|
||||
testcases := []struct {
|
||||
testcase string
|
||||
|
|
Loading…
Reference in a new issue