gitea源码

html_codepreview_test.go 1.1KB

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2024 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package markup_test
  4. import (
  5. "context"
  6. "html/template"
  7. "strings"
  8. "testing"
  9. "code.gitea.io/gitea/modules/markup"
  10. "code.gitea.io/gitea/modules/markup/markdown"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. func TestRenderCodePreview(t *testing.T) {
  14. markup.Init(&markup.RenderHelperFuncs{
  15. RenderRepoFileCodePreview: func(ctx context.Context, options markup.RenderCodePreviewOptions) (template.HTML, error) {
  16. return "<div>code preview</div>", nil
  17. },
  18. })
  19. test := func(input, expected string) {
  20. buffer, err := markup.RenderString(markup.NewTestRenderContext().WithMarkupType(markdown.MarkupName), input)
  21. assert.NoError(t, err)
  22. assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
  23. }
  24. test("http://localhost:3000/owner/repo/src/commit/0123456789/foo/bar.md#L10-L20", "<p><div>code preview</div></p>")
  25. test("http://other/owner/repo/src/commit/0123456789/foo/bar.md#L10-L20", `<p><a href="http://other/owner/repo/src/commit/0123456789/foo/bar.md#L10-L20" rel="nofollow">http://other/owner/repo/src/commit/0123456789/foo/bar.md#L10-L20</a></p>`)
  26. }