// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package markup_test
import (
"context"
"html/template"
"strings"
"testing"
"gitea.dev/modules/htmlutil"
"gitea.dev/modules/markup"
"gitea.dev/modules/markup/markdown"
testModule "gitea.dev/modules/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestRender_IssueList(t *testing.T) {
defer testModule.MockVariableValue(&markup.RenderBehaviorForTesting.DisableAdditionalAttributes, true)()
markup.Init(&markup.RenderHelperFuncs{
RenderRepoIssueIconTitle: func(ctx context.Context, opts markup.RenderIssueIconTitleOptions) (template.HTML, error) {
return htmlutil.HTMLFormat("
issue #%d
", opts.IssueIndex), nil
},
})
test := func(input, expected string) {
rctx := markup.NewTestRenderContext(markup.TestAppURL, map[string]string{
"user": "test-user", "repo": "test-repo",
"markupAllowShortIssuePattern": "true",
"footnoteContextId": "12345",
})
out, err := markdown.RenderString(rctx, input)
require.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
for _, tc := range []struct {
name, input, expected string
}{
{
"NormalIssueRef", "#12345",
`#12345
`,
},
{"ListIssueRef", "* #12345", ``},
{"ListIssueRefNormal", "* foo #12345 bar", ``},
{"ListTodoIssueRef", "* [ ] #12345", ``},
{
"IssueFootnote", "foo[^1][^2]\n\n[^1]: bar\n[^2]: baz",
`foo1 2
`,
},
} {
t.Run(tc.name, func(_t *testing.T) {
test(tc.input, tc.expected)
})
}
}