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 href="https://example.com/">https://example.com/</a> with <b>bold</b> text`
17 doonezerotest(t, input, output)
18}
19
20func TestMultibold(t *testing.T) {
21 input := `**in** out **in**`
22 output := `<b>in</b> out <b>in</b>`
23 doonezerotest(t, input, output)
24}
25
26func TestLinebreak1(t *testing.T) {
27 input := "hello\n> a quote\na comment"
28 output := "hello<blockquote>a quote</blockquote><p>a comment"
29 doonezerotest(t, input, output)
30}
31
32func TestLinebreak2(t *testing.T) {
33 input := "hello\n\n> a quote\n\na comment"
34 output := "hello<br><blockquote>a quote</blockquote><p>a comment"
35 doonezerotest(t, input, output)
36}
37
38func TestLinebreak3(t *testing.T) {
39 input := "hello\n\n```\nfunc(s string)\n```\n\ndoes it go?"
40 output := "hello<br><pre><code>func(s string)</code></pre><p>does it go?"
41 doonezerotest(t, input, output)
42}
43
44func TestCodeStyles(t *testing.T) {
45 input := "hello\n\n```go\nfunc(s string)\n```\n\ndoes it go?"
46 output := "hello<br><pre><code><span class=kw>func</span><span class=op>(</span>s <span class=tp>string</span><span class=op>)</span></code></pre><p>does it go?"
47 doonezerotest(t, input, output)
48}
49
50func TestSimplelink(t *testing.T) {
51 input := "This is a [link](https://example.com)."
52 output := `This is a <a href="https://example.com">link</a>.`
53 doonezerotest(t, input, output)
54}
55
56func TestSimplelink2(t *testing.T) {
57 input := "See (http://example.com) for examples."
58 output := `See (<a href="http://example.com">http://example.com</a>) for examples.`
59 doonezerotest(t, input, output)
60}
61
62func TestWikilink(t *testing.T) {
63 input := "I watched [Hackers](https://en.wikipedia.org/wiki/Hackers_(film))"
64 output := `I watched <a href="https://en.wikipedia.org/wiki/Hackers_(film)">Hackers</a>`
65 doonezerotest(t, input, output)
66}
67
68func TestQuotedlink(t *testing.T) {
69 input := `quoted "https://example.com/link" here`
70 output := `quoted "<a href="https://example.com/link">https://example.com/link</a>" here`
71 doonezerotest(t, input, output)
72}
73
74func TestLinkinQuote(t *testing.T) {
75 input := `> a quote and https://example.com/link`
76 output := `<blockquote>a quote and <a href="https://example.com/link">https://example.com/link</a></blockquote><p>`
77 doonezerotest(t, input, output)
78}
79
80func TestBoldLink(t *testing.T) {
81 input := `**b https://example.com/link b**`
82 output := `<b>b <a href="https://example.com/link">https://example.com/link</a> b</b>`
83 doonezerotest(t, input, output)
84}
85
86func TestHonklink(t *testing.T) {
87 input := `https://en.wikipedia.org/wiki/Honk!`
88 output := `<a href="https://en.wikipedia.org/wiki/Honk!">https://en.wikipedia.org/wiki/Honk!</a>`
89 doonezerotest(t, input, output)
90}
91
92func TestImagelink(t *testing.T) {
93 input := `an image <img alt="caption" src="https://example.com/wherever"> and linked [<img src="there">](example.com)`
94 output := `an image <img alt="caption" src="https://example.com/wherever"> and linked <a href="example.com"><img src="there"></a>`
95 doonezerotest(t, input, output)
96}