smart_puncts_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package md_test
  2. import (
  3. "testing"
  4. "github.com/google/go-cmp/cmp"
  5. . "src.elv.sh/pkg/md"
  6. )
  7. var smartPunctsTestCases = []testCase{
  8. {
  9. Name: "Simple smart punctuations",
  10. Markdown: `a -- b --- c...`,
  11. HTML: dedent(`
  12. <p>a – b –- c…</p>
  13. `),
  14. },
  15. {
  16. Name: "Smart quotes",
  17. Markdown: `It's "foo" and 'bar'.`,
  18. HTML: dedent(`
  19. <p>It’s “foo” and ‘bar’.</p>
  20. `),
  21. },
  22. {
  23. Name: "Link and image title",
  24. Markdown: dedent(`
  25. [link text](a.html "--")
  26. ![img alt](a.png "--")
  27. `),
  28. HTML: dedent(`
  29. <p><a href="a.html" title="–">link text</a>
  30. <img src="a.png" alt="img alt" title="–" /></p>
  31. `),
  32. },
  33. {
  34. Name: "Link alt",
  35. Markdown: `![img -- alt](a.png)`,
  36. HTML: dedent(`
  37. <p><img src="a.png" alt="img – alt" /></p>
  38. `),
  39. },
  40. {
  41. Name: "Code span is unchanged",
  42. Markdown: "`a -- b`",
  43. HTML: dedent(`
  44. <p><code>a -- b</code></p>
  45. `),
  46. },
  47. {
  48. Name: "Non-inline content is unchanged",
  49. Markdown: dedent(`
  50. ~~~
  51. a -- b
  52. ~~~
  53. `),
  54. HTML: dedent(`
  55. <pre><code>a -- b
  56. </code></pre>
  57. `),
  58. },
  59. }
  60. func TestSmartPuncts(t *testing.T) {
  61. for _, tc := range smartPunctsTestCases {
  62. t.Run(tc.Name, func(t *testing.T) {
  63. var htmlCodec HTMLCodec
  64. Render(tc.Markdown, SmartPunctsCodec{&htmlCodec})
  65. got := htmlCodec.String()
  66. if diff := cmp.Diff(tc.HTML, got); diff != "" {
  67. t.Errorf("input:\n%s\ndiff (-want +got):\n%s",
  68. hr+"\n"+tc.Markdown+hr, diff)
  69. }
  70. })
  71. }
  72. }