package main import ( "strings" "testing" ) func doonezerotest(t *testing.T, input, output string) { result := markitzero(input) if result != output { t.Errorf("\nexpected:\n%s\noutput:\n%s", output, result) } } func TestBasictest(t *testing.T) { input := `link to https://example.com/ with **bold** text` output := `link to https://example.com/ with bold text` doonezerotest(t, input, output) } func TestMultibold(t *testing.T) { input := `**in** out **in**` output := `in out in` doonezerotest(t, input, output) } func TestLinebreak1(t *testing.T) { input := "hello\n> a quote\na comment" output := "hello
a quote

a comment" doonezerotest(t, input, output) } func TestLinebreak2(t *testing.T) { input := "hello\n\n> a quote\n\na comment" output := "hello

a quote

a comment" doonezerotest(t, input, output) } func TestLinebreak3(t *testing.T) { input := "hello\n\n```\nfunc(s string)\n```\n\ndoes it go?" output := "hello

func(s string)

does it go?" doonezerotest(t, input, output) } func TestCodeStyles(t *testing.T) { input := "hello\n\n```go\nfunc(s string)\n```\n\ndoes it go?" output := "hello

func(s string)

does it go?" doonezerotest(t, input, output) } func TestSimplelink(t *testing.T) { input := "This is a [link](https://example.com)." output := `This is a link.` doonezerotest(t, input, output) } func TestSimplelink2(t *testing.T) { input := "See (http://example.com) for examples." output := `See (http://example.com) for examples.` doonezerotest(t, input, output) } func TestWikilink(t *testing.T) { input := "I watched [Hackers](https://en.wikipedia.org/wiki/Hackers_(film))" output := `I watched Hackers` doonezerotest(t, input, output) } func TestQuotedlink(t *testing.T) { input := `quoted "https://example.com/link" here` output := `quoted "https://example.com/link" here` doonezerotest(t, input, output) } func TestLinkinQuote(t *testing.T) { input := `> a quote and https://example.com/link` output := `

a quote and https://example.com/link

` doonezerotest(t, input, output) } func TestBoldLink(t *testing.T) { input := `**b https://example.com/link b**` output := `b https://example.com/link b` doonezerotest(t, input, output) } func TestHonklink(t *testing.T) { input := `https://en.wikipedia.org/wiki/Honk!` output := `https://en.wikipedia.org/wiki/Honk!` doonezerotest(t, input, output) } func TestImagelink(t *testing.T) { input := `an image caption and linked [](example.com)` output := `an image caption and linked ` doonezerotest(t, input, output) } func TestLists(t *testing.T) { input := `hello + a list + the list para - singleton` output := `hello

para

` doonezerotest(t, input, output) } func TestTables(t *testing.T) { input := `hello | col1 | col 2 | | row2 | cell4 | para ` output := `hello
col1col 2
row2cell4

para` doonezerotest(t, input, output) } func TestHeaders(t *testing.T) { input := `hello ## fruits Love 'em. Eat 'em. ` output := `hello

fruits

Love 'em. Eat 'em.` doonezerotest(t, input, output) } var benchData, simpleData string func init() { benchData = strings.Repeat("hello there sir. It is a **fine** day for some testing!\n", 100) simpleData = strings.Repeat("just a few words\n", 100) } func BenchmarkModerateSize(b *testing.B) { for n := 0; n < b.N; n++ { markitzero(benchData) } } func BenchmarkSimpleData(b *testing.B) { for n := 0; n < b.N; n++ { markitzero(simpleData) } }