markitzero_test.go (view raw)
1package main
2
3import (
4 "testing"
5)
6
7func doonezerotest(t *testing.T, input, output string) {
8 result := markitzero(input)
9 if result != output {
10 t.Errorf("\nexpected:\n%s\noutput:\n%s", output, result)
11 }
12}
13
14func TestBasictest(t *testing.T) {
15 input := `link to https://example.com/ with **bold** text`
16 output := `link to <a class="mention u-url" href="https://example.com/">https://example.com/</a> with <b>bold</b> text`
17 doonezerotest(t, input, output)
18}
19
20func TestLinebreak1(t *testing.T) {
21 input := "hello\n> a quote\na comment"
22 output := "hello<blockquote>a quote</blockquote><p>a comment"
23 doonezerotest(t, input, output)
24}
25
26func TestLinebreak2(t *testing.T) {
27 input := "hello\n\n> a quote\n\na comment"
28 output := "hello<br><blockquote>a quote</blockquote><p>a comment"
29 doonezerotest(t, input, output)
30}
31
32func TestLinebreak3(t *testing.T) {
33 input := "hello\n\n```\nfunc(s string)\n```\n\ndoes it go?"
34 output := "hello<br><pre><code>func(s string)</code></pre><p>does it go?"
35 doonezerotest(t, input, output)
36}
37
38func TestSimplelink(t *testing.T) {
39 input := "This is a [link](https://example.com)."
40 output := `This is a <a class="mention u-url" href="https://example.com">link</a>.`
41 doonezerotest(t, input, output)
42}
43
44func TestSimplelink2(t *testing.T) {
45 input := "See (http://example.com) for examples."
46 output := `See (<a class="mention u-url" href="http://example.com">http://example.com</a>) for examples.`
47 doonezerotest(t, input, output)
48}
49
50func TestWikilink(t *testing.T) {
51 input := "I watched [Hackers](https://en.wikipedia.org/wiki/Hackers_(film))"
52 output := `I watched <a class="mention u-url" href="https://en.wikipedia.org/wiki/Hackers_(film)">Hackers</a>`
53 doonezerotest(t, input, output)
54}