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

orgmode_test.go 1.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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>\n<a href=\"https://google.com/\" title=\"https://google.com/\">https://google.com/</a>\n</p>"
  23. test("[[https://google.com/]]", googleRendered)
  24. lnk := util.URLJoin(AppSubURL, "WikiPage")
  25. test("[[WikiPage][WikiPage]]",
  26. "<p>\n<a href=\""+lnk+"\" title=\"WikiPage\">WikiPage</a>\n</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. result := util.URLJoin(AppSubURL, url)
  37. test("[[file:"+url+"]]",
  38. "<p>\n<img src=\""+result+"\" alt=\""+result+"\" title=\""+result+"\" />\n</p>")
  39. }