You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.5 KiB

  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package markup
  5. import (
  6. "strings"
  7. "testing"
  8. "code.gitea.io/gitea/modules/setting"
  9. "code.gitea.io/gitea/modules/util"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. const AppURL = "http://localhost:3000/"
  13. const Repo = "gogits/gogs"
  14. const AppSubURL = AppURL + Repo + "/"
  15. func TestRender_StandardLinks(t *testing.T) {
  16. setting.AppURL = AppURL
  17. setting.AppSubURL = AppSubURL
  18. test := func(input, expected string) {
  19. buffer := RenderString(input, setting.AppSubURL, nil, false)
  20. assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
  21. }
  22. googleRendered := `<p><a href="https://google.com/" title="https://google.com/">https://google.com/</a></p>`
  23. test("[[https://google.com/]]", googleRendered)
  24. lnk := util.URLJoin(AppSubURL, "WikiPage")
  25. test("[[WikiPage][WikiPage]]",
  26. `<p><a href="`+lnk+`" title="WikiPage">WikiPage</a></p>`)
  27. }
  28. func TestRender_Images(t *testing.T) {
  29. setting.AppURL = AppURL
  30. setting.AppSubURL = AppSubURL
  31. test := func(input, expected string) {
  32. buffer := RenderString(input, setting.AppSubURL, nil, false)
  33. assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
  34. }
  35. url := "../../.images/src/02/train.jpg"
  36. title := "Train"
  37. result := util.URLJoin(AppSubURL, url)
  38. test(
  39. "[[file:"+url+"]["+title+"]]",
  40. `<p><a href="`+result+`"><img src="`+result+`" alt="`+title+`" title="`+title+`" /></a></p>`)
  41. }