Fix and refactor markdown rendering (#32522)
This commit is contained in:
parent
e546480d0a
commit
5eebe1dc5f
27 changed files with 289 additions and 278 deletions
|
@ -40,17 +40,19 @@ func link(href, class, contents string) string {
|
|||
}
|
||||
|
||||
var numericMetas = map[string]string{
|
||||
"format": "https://someurl.com/{user}/{repo}/{index}",
|
||||
"user": "someUser",
|
||||
"repo": "someRepo",
|
||||
"style": IssueNameStyleNumeric,
|
||||
"format": "https://someurl.com/{user}/{repo}/{index}",
|
||||
"user": "someUser",
|
||||
"repo": "someRepo",
|
||||
"style": IssueNameStyleNumeric,
|
||||
"markupAllowShortIssuePattern": "true",
|
||||
}
|
||||
|
||||
var alphanumericMetas = map[string]string{
|
||||
"format": "https://someurl.com/{user}/{repo}/{index}",
|
||||
"user": "someUser",
|
||||
"repo": "someRepo",
|
||||
"style": IssueNameStyleAlphanumeric,
|
||||
"format": "https://someurl.com/{user}/{repo}/{index}",
|
||||
"user": "someUser",
|
||||
"repo": "someRepo",
|
||||
"style": IssueNameStyleAlphanumeric,
|
||||
"markupAllowShortIssuePattern": "true",
|
||||
}
|
||||
|
||||
var regexpMetas = map[string]string{
|
||||
|
@ -62,8 +64,15 @@ var regexpMetas = map[string]string{
|
|||
|
||||
// these values should match the TestOrgRepo const above
|
||||
var localMetas = map[string]string{
|
||||
"user": "test-owner",
|
||||
"repo": "test-repo",
|
||||
"user": "test-owner",
|
||||
"repo": "test-repo",
|
||||
"markupAllowShortIssuePattern": "true",
|
||||
}
|
||||
|
||||
var localWikiMetas = map[string]string{
|
||||
"user": "test-owner",
|
||||
"repo": "test-repo",
|
||||
"markupContentMode": "wiki",
|
||||
}
|
||||
|
||||
func TestRender_IssueIndexPattern(t *testing.T) {
|
||||
|
@ -124,9 +133,8 @@ func TestRender_IssueIndexPattern2(t *testing.T) {
|
|||
}
|
||||
expectedNil := fmt.Sprintf(expectedFmt, links...)
|
||||
testRenderIssueIndexPattern(t, s, expectedNil, &RenderContext{
|
||||
Ctx: git.DefaultContext,
|
||||
Metas: localMetas,
|
||||
ContentMode: RenderContentAsComment,
|
||||
Ctx: git.DefaultContext,
|
||||
Metas: localMetas,
|
||||
})
|
||||
|
||||
class := "ref-issue"
|
||||
|
@ -139,9 +147,8 @@ func TestRender_IssueIndexPattern2(t *testing.T) {
|
|||
}
|
||||
expectedNum := fmt.Sprintf(expectedFmt, links...)
|
||||
testRenderIssueIndexPattern(t, s, expectedNum, &RenderContext{
|
||||
Ctx: git.DefaultContext,
|
||||
Metas: numericMetas,
|
||||
ContentMode: RenderContentAsComment,
|
||||
Ctx: git.DefaultContext,
|
||||
Metas: numericMetas,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -262,7 +269,7 @@ func TestRender_IssueIndexPattern5(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestRender_IssueIndexPattern_Document(t *testing.T) {
|
||||
func TestRender_IssueIndexPattern_NoShortPattern(t *testing.T) {
|
||||
setting.AppURL = TestAppURL
|
||||
metas := map[string]string{
|
||||
"format": "https://someurl.com/{user}/{repo}/{index}",
|
||||
|
@ -285,6 +292,22 @@ func TestRender_IssueIndexPattern_Document(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestRender_RenderIssueTitle(t *testing.T) {
|
||||
setting.AppURL = TestAppURL
|
||||
metas := map[string]string{
|
||||
"format": "https://someurl.com/{user}/{repo}/{index}",
|
||||
"user": "someUser",
|
||||
"repo": "someRepo",
|
||||
"style": IssueNameStyleNumeric,
|
||||
}
|
||||
actual, err := RenderIssueTitle(&RenderContext{
|
||||
Ctx: git.DefaultContext,
|
||||
Metas: metas,
|
||||
}, "#1")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "#1", actual)
|
||||
}
|
||||
|
||||
func testRenderIssueIndexPattern(t *testing.T, input, expected string, ctx *RenderContext) {
|
||||
ctx.Links.AbsolutePrefix = true
|
||||
if ctx.Links.Base == "" {
|
||||
|
@ -318,8 +341,7 @@ func TestRender_AutoLink(t *testing.T) {
|
|||
Links: Links{
|
||||
Base: TestRepoURL,
|
||||
},
|
||||
Metas: localMetas,
|
||||
ContentMode: RenderContentAsWiki,
|
||||
Metas: localWikiMetas,
|
||||
}, strings.NewReader(input), &buffer)
|
||||
assert.Equal(t, err, nil)
|
||||
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer.String()))
|
||||
|
@ -391,10 +413,10 @@ func TestRegExp_sha1CurrentPattern(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, testCase := range trueTestCases {
|
||||
assert.True(t, hashCurrentPattern.MatchString(testCase))
|
||||
assert.True(t, globalVars().hashCurrentPattern.MatchString(testCase))
|
||||
}
|
||||
for _, testCase := range falseTestCases {
|
||||
assert.False(t, hashCurrentPattern.MatchString(testCase))
|
||||
assert.False(t, globalVars().hashCurrentPattern.MatchString(testCase))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -474,9 +496,9 @@ func TestRegExp_shortLinkPattern(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, testCase := range trueTestCases {
|
||||
assert.True(t, shortLinkPattern.MatchString(testCase))
|
||||
assert.True(t, globalVars().shortLinkPattern.MatchString(testCase))
|
||||
}
|
||||
for _, testCase := range falseTestCases {
|
||||
assert.False(t, shortLinkPattern.MatchString(testCase))
|
||||
assert.False(t, globalVars().shortLinkPattern.MatchString(testCase))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue