2019-10-06 21:01:23 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2019-10-09 20:03:16 +02:00
|
|
|
func doonezerotest(t *testing.T, input, output string) {
|
2019-10-06 21:01:23 +02:00
|
|
|
result := markitzero(input)
|
|
|
|
if result != output {
|
|
|
|
t.Errorf("\nexpected:\n%s\noutput:\n%s", output, result)
|
|
|
|
}
|
|
|
|
}
|
2019-10-06 21:14:18 +02:00
|
|
|
|
2019-10-09 20:03:16 +02:00
|
|
|
func TestBasictest(t *testing.T) {
|
2019-10-06 21:14:18 +02:00
|
|
|
input := `link to https://example.com/ with **bold** text`
|
2019-10-28 21:05:18 +01:00
|
|
|
output := `link to <a href="https://example.com/">https://example.com/</a> with <b>bold</b> text`
|
2019-10-09 20:03:16 +02:00
|
|
|
doonezerotest(t, input, output)
|
2019-10-06 21:14:18 +02:00
|
|
|
}
|
|
|
|
|
2019-10-25 06:27:00 +02:00
|
|
|
func TestMultibold(t *testing.T) {
|
|
|
|
input := `**in** out **in**`
|
|
|
|
output := `<b>in</b> out <b>in</b>`
|
|
|
|
doonezerotest(t, input, output)
|
|
|
|
}
|
|
|
|
|
2019-10-09 20:03:16 +02:00
|
|
|
func TestLinebreak1(t *testing.T) {
|
2019-10-06 21:14:18 +02:00
|
|
|
input := "hello\n> a quote\na comment"
|
|
|
|
output := "hello<blockquote>a quote</blockquote><p>a comment"
|
2019-10-09 20:03:16 +02:00
|
|
|
doonezerotest(t, input, output)
|
2019-10-06 21:14:18 +02:00
|
|
|
}
|
|
|
|
|
2019-10-09 20:03:16 +02:00
|
|
|
func TestLinebreak2(t *testing.T) {
|
2019-10-06 21:14:18 +02:00
|
|
|
input := "hello\n\n> a quote\n\na comment"
|
|
|
|
output := "hello<br><blockquote>a quote</blockquote><p>a comment"
|
2019-10-09 20:03:16 +02:00
|
|
|
doonezerotest(t, input, output)
|
2019-10-06 21:14:18 +02:00
|
|
|
}
|
|
|
|
|
2019-10-09 20:03:16 +02:00
|
|
|
func TestLinebreak3(t *testing.T) {
|
2019-10-06 21:14:18 +02:00
|
|
|
input := "hello\n\n```\nfunc(s string)\n```\n\ndoes it go?"
|
|
|
|
output := "hello<br><pre><code>func(s string)</code></pre><p>does it go?"
|
2019-10-09 20:03:16 +02:00
|
|
|
doonezerotest(t, input, output)
|
2019-10-06 21:14:18 +02:00
|
|
|
}
|
|
|
|
|
2019-10-20 23:18:48 +02:00
|
|
|
func TestCodeStyles(t *testing.T) {
|
|
|
|
input := "hello\n\n```go\nfunc(s string)\n```\n\ndoes it go?"
|
|
|
|
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?"
|
|
|
|
doonezerotest(t, input, output)
|
|
|
|
}
|
|
|
|
|
2019-10-09 20:03:16 +02:00
|
|
|
func TestSimplelink(t *testing.T) {
|
|
|
|
input := "This is a [link](https://example.com)."
|
2019-10-28 21:05:18 +01:00
|
|
|
output := `This is a <a href="https://example.com">link</a>.`
|
2019-10-09 20:03:16 +02:00
|
|
|
doonezerotest(t, input, output)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSimplelink2(t *testing.T) {
|
|
|
|
input := "See (http://example.com) for examples."
|
2019-10-28 21:05:18 +01:00
|
|
|
output := `See (<a href="http://example.com">http://example.com</a>) for examples.`
|
2019-10-09 20:03:16 +02:00
|
|
|
doonezerotest(t, input, output)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWikilink(t *testing.T) {
|
|
|
|
input := "I watched [Hackers](https://en.wikipedia.org/wiki/Hackers_(film))"
|
2019-10-28 21:05:18 +01:00
|
|
|
output := `I watched <a href="https://en.wikipedia.org/wiki/Hackers_(film)">Hackers</a>`
|
2019-10-09 20:03:16 +02:00
|
|
|
doonezerotest(t, input, output)
|
2019-10-06 21:14:18 +02:00
|
|
|
}
|
2019-10-22 05:43:15 +02:00
|
|
|
|
|
|
|
func TestQuotedlink(t *testing.T) {
|
|
|
|
input := `quoted "https://example.com/link" here`
|
2019-10-28 21:05:18 +01:00
|
|
|
output := `quoted "<a href="https://example.com/link">https://example.com/link</a>" here`
|
2019-10-22 05:43:15 +02:00
|
|
|
doonezerotest(t, input, output)
|
|
|
|
}
|
|
|
|
|
2019-10-25 05:38:36 +02:00
|
|
|
func TestLinkinQuote(t *testing.T) {
|
|
|
|
input := `> a quote and https://example.com/link`
|
2019-10-28 21:05:18 +01:00
|
|
|
output := `<blockquote>a quote and <a href="https://example.com/link">https://example.com/link</a></blockquote><p>`
|
2019-10-25 05:38:36 +02:00
|
|
|
doonezerotest(t, input, output)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBoldLink(t *testing.T) {
|
|
|
|
input := `**b https://example.com/link b**`
|
2019-10-28 21:05:18 +01:00
|
|
|
output := `<b>b <a href="https://example.com/link">https://example.com/link</a> b</b>`
|
2019-10-25 05:38:36 +02:00
|
|
|
doonezerotest(t, input, output)
|
|
|
|
}
|
|
|
|
|
2019-10-22 05:43:15 +02:00
|
|
|
func TestHonklink(t *testing.T) {
|
|
|
|
input := `https://en.wikipedia.org/wiki/Honk!`
|
2019-10-28 21:05:18 +01:00
|
|
|
output := `<a href="https://en.wikipedia.org/wiki/Honk!">https://en.wikipedia.org/wiki/Honk!</a>`
|
2019-10-22 05:43:15 +02:00
|
|
|
doonezerotest(t, input, output)
|
|
|
|
}
|
|
|
|
|
2019-10-22 06:16:28 +02:00
|
|
|
func TestImagelink(t *testing.T) {
|
|
|
|
input := `an image <img alt="caption" src="https://example.com/wherever"> and linked [<img src="there">](example.com)`
|
2019-10-28 21:05:18 +01:00
|
|
|
output := `an image <img alt="caption" src="https://example.com/wherever"> and linked <a href="example.com"><img src="there"></a>`
|
2019-10-22 06:16:28 +02:00
|
|
|
doonezerotest(t, input, output)
|
|
|
|
}
|
2019-11-12 20:45:39 +01:00
|
|
|
|
|
|
|
func TestLists(t *testing.T) {
|
|
|
|
input := `hello
|
|
|
|
+ a list
|
|
|
|
+ the list
|
|
|
|
|
|
|
|
para
|
|
|
|
|
|
|
|
- singleton`
|
|
|
|
output := `hello<ul><li>a list<li>the list</ul><p>para<ul><li>singleton</ul><p>`
|
|
|
|
doonezerotest(t, input, output)
|
|
|
|
}
|