summaryrefslogtreecommitdiff
path: root/src/gmi/gemtext_test.go
blob: 23cb97f357e648f4fc09200b3c9d5c640f17881e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package gmi

import (
	"bytes"
	"strconv"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestGemtextToMarkdown(t *testing.T) {

	tests := []struct {
		in, exp string
	}{
		{
			in:  "",
			exp: "",
		},
		{
			in:  "=> foo",
			exp: "[Link](foo)\n",
		},
		{
			in:  "what\n=> foo\n=> bar",
			exp: "what\n[Link](foo)\n[Link](bar)\n",
		},
		{
			in:  "=> foo description is here   ",
			exp: "[description is here](foo)\n",
		},
		{
			in:  "=> img.png",
			exp: "![Image](img.png)\n",
		},
		{
			in:  "=> img.png description is here   ",
			exp: "![description is here](img.png)\n",
		},
	}

	for i, test := range tests {
		t.Run(strconv.Itoa(i), func(t *testing.T) {

			got := new(bytes.Buffer)
			err := GemtextToMarkdown(got, bytes.NewBufferString(test.in))
			assert.NoError(t, err)
			assert.Equal(t, test.exp, got.String())
		})
	}
}