markdown_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. package markdown
  2. import (
  3. "testing"
  4. )
  5. func TestParse(t *testing.T) {
  6. testcases := []struct{ input, want string }{
  7. // Bold
  8. {"Don't **communicate** by sharing memory, share memory by communicating.", "Don't [::b]communicate[::-] by sharing memory, share memory by communicating."},
  9. // Italic
  10. {"*Concurrency* is not parallelism.", "[::i]Concurrency[::-] is not parallelism."},
  11. // Underline
  12. {"Channels __orchestrate__; mutexes __serialize__.", "Channels [::u]orchestrate[::-]; mutexes [::u]serialize[::-]."},
  13. // Strikethrough
  14. {"~~Cgo~~ is not Go.", "[::s]Cgo[::-] is not Go."},
  15. // Codeblock
  16. {"Don't just check `errors`, handle them `gracefully`.", "Don't just check [::r]errors[::-], handle them [::r]gracefully[::-]."},
  17. }
  18. for _, testcase := range testcases {
  19. if got := Parse(testcase.input); got != testcase.want {
  20. t.Errorf("got %s; want %s", got, testcase.want)
  21. }
  22. }
  23. }
  24. func BenchmarkParse(b *testing.B) {
  25. const input = `**Lorem** ipsum dolor sit amet, consectetur adipiscing __elit.__ Nullam ante magna, luctus in ~~molestie non, elementum sit~~ amet tortor. Nunc euismod urna ac massa dictum ultrices. Donec tempor __dignissim__ ullamcorper. Mauris ultricies, risus non malesuada consectetur, *purus leo interdum purus*, nec vestibulum lacus neque non nulla.`
  26. for i := 0; i < b.N; i++ {
  27. _ = Parse(input)
  28. }
  29. }