Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

129 linhas
3.2 KiB

  1. //
  2. // Blackfriday Markdown Processor
  3. // Available at http://github.com/russross/blackfriday
  4. //
  5. // Copyright © 2011 Russ Ross <russ@russross.com>.
  6. // Distributed under the Simplified BSD License.
  7. // See README.md for details.
  8. //
  9. //
  10. // Markdown 1.0.3 reference tests
  11. //
  12. package blackfriday
  13. import (
  14. "io/ioutil"
  15. "path/filepath"
  16. "testing"
  17. )
  18. func runMarkdownReference(input string, flag int) string {
  19. renderer := HtmlRenderer(0, "", "")
  20. return string(Markdown([]byte(input), renderer, flag))
  21. }
  22. func doTestsReference(t *testing.T, files []string, flag int) {
  23. // catch and report panics
  24. var candidate string
  25. defer func() {
  26. if err := recover(); err != nil {
  27. t.Errorf("\npanic while processing [%#v]\n", candidate)
  28. }
  29. }()
  30. for _, basename := range files {
  31. filename := filepath.Join("testdata", basename+".text")
  32. inputBytes, err := ioutil.ReadFile(filename)
  33. if err != nil {
  34. t.Errorf("Couldn't open '%s', error: %v\n", filename, err)
  35. continue
  36. }
  37. input := string(inputBytes)
  38. filename = filepath.Join("testdata", basename+".html")
  39. expectedBytes, err := ioutil.ReadFile(filename)
  40. if err != nil {
  41. t.Errorf("Couldn't open '%s', error: %v\n", filename, err)
  42. continue
  43. }
  44. expected := string(expectedBytes)
  45. // fmt.Fprintf(os.Stderr, "processing %s ...", filename)
  46. actual := string(runMarkdownReference(input, flag))
  47. if actual != expected {
  48. t.Errorf("\n [%#v]\nExpected[%#v]\nActual [%#v]",
  49. basename+".text", expected, actual)
  50. }
  51. // fmt.Fprintf(os.Stderr, " ok\n")
  52. // now test every prefix of every input to check for
  53. // bounds checking
  54. if !testing.Short() {
  55. start, max := 0, len(input)
  56. for end := start + 1; end <= max; end++ {
  57. candidate = input[start:end]
  58. // fmt.Fprintf(os.Stderr, " %s %d:%d/%d\n", filename, start, end, max)
  59. _ = runMarkdownReference(candidate, flag)
  60. }
  61. }
  62. }
  63. }
  64. func TestReference(t *testing.T) {
  65. files := []string{
  66. "Amps and angle encoding",
  67. "Auto links",
  68. "Backslash escapes",
  69. "Blockquotes with code blocks",
  70. "Code Blocks",
  71. "Code Spans",
  72. "Hard-wrapped paragraphs with list-like lines",
  73. "Horizontal rules",
  74. "Inline HTML (Advanced)",
  75. "Inline HTML (Simple)",
  76. "Inline HTML comments",
  77. "Links, inline style",
  78. "Links, reference style",
  79. "Links, shortcut references",
  80. "Literal quotes in titles",
  81. "Markdown Documentation - Basics",
  82. "Markdown Documentation - Syntax",
  83. "Nested blockquotes",
  84. "Ordered and unordered lists",
  85. "Strong and em together",
  86. "Tabs",
  87. "Tidyness",
  88. }
  89. doTestsReference(t, files, 0)
  90. }
  91. func TestReference_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {
  92. files := []string{
  93. "Amps and angle encoding",
  94. "Auto links",
  95. "Backslash escapes",
  96. "Blockquotes with code blocks",
  97. "Code Blocks",
  98. "Code Spans",
  99. "Hard-wrapped paragraphs with list-like lines no empty line before block",
  100. "Horizontal rules",
  101. "Inline HTML (Advanced)",
  102. "Inline HTML (Simple)",
  103. "Inline HTML comments",
  104. "Links, inline style",
  105. "Links, reference style",
  106. "Links, shortcut references",
  107. "Literal quotes in titles",
  108. "Markdown Documentation - Basics",
  109. "Markdown Documentation - Syntax",
  110. "Nested blockquotes",
  111. "Ordered and unordered lists",
  112. "Strong and em together",
  113. "Tabs",
  114. "Tidyness",
  115. }
  116. doTestsReference(t, files, EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK)
  117. }