本站源代码
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

72 行
1.3KB

  1. // Copyright 2019 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 mdstripper
  5. import (
  6. "strings"
  7. "testing"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestMarkdownStripper(t *testing.T) {
  11. type testItem struct {
  12. markdown string
  13. expectedText []string
  14. expectedLinks []string
  15. }
  16. list := []testItem{
  17. {
  18. `
  19. ## This is a title
  20. This is [one](link) to paradise.
  21. This **is emphasized**.
  22. This: should coallesce.
  23. ` + "```" + `
  24. This is a code block.
  25. This should not appear in the output at all.
  26. ` + "```" + `
  27. * Bullet 1
  28. * Bullet 2
  29. A HIDDEN ` + "`" + `GHOST` + "`" + ` IN THIS LINE.
  30. `,
  31. []string{
  32. "This is a title",
  33. "This is",
  34. "to paradise.",
  35. "This",
  36. "is emphasized",
  37. ".",
  38. "This: should coallesce.",
  39. "Bullet 1",
  40. "Bullet 2",
  41. "A HIDDEN",
  42. "IN THIS LINE.",
  43. },
  44. []string{
  45. "link",
  46. }},
  47. }
  48. for _, test := range list {
  49. text, links := StripMarkdown([]byte(test.markdown))
  50. rawlines := strings.Split(text, "\n")
  51. lines := make([]string, 0, len(rawlines))
  52. for _, line := range rawlines {
  53. line := strings.TrimSpace(line)
  54. if line != "" {
  55. lines = append(lines, line)
  56. }
  57. }
  58. assert.EqualValues(t, test.expectedText, lines)
  59. assert.EqualValues(t, test.expectedLinks, links)
  60. }
  61. }
上海开阖软件有限公司 沪ICP备12045867号-1