aboutsummaryrefslogtreecommitdiff
path: root/html2md_test.go
blob: c8e65075f45313a7c7f91432c015d96b6add2872 (plain) (blame)
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
52
53
54
55
56
57
58
59
60
61
62
63
package main_test

import (
	"os"
	"strings"
	"testing"
)

const (
	cmdTest = "./html2md"
	dirTest = "."

	boldText   = "<strong>Bold Text</strong>"
	boldEscape = "<strong>option src_ip</strong>"
)

type testCase struct {
	name, out, in string
	args          []string
}

func TestExec(t *testing.T) {
	testData := []testCase{
		{
			"BoldText", "**Bold Text**", boldText, []string{"-i"},
		},
		{
			"BoldText-delimiter", "__Bold Text__", boldText,
			[]string{"-i", "--opt-strong-delimiter", "__"},
		},
		{
			"BoldEscape", "**option src\\_ip**", boldEscape, []string{"-i"},
		},
		{
			"BoldEscapeOff", "**option src_ip**", boldEscape,
			[]string{"-i", "--opt-escape-mode", "disabled"},
		},
		{
			"Checkbox", "- [x] Checked!\n- [ ] Check Me!",
			"<ul><li><input type=checkbox checked>Checked!</li><li><input type=checkbox>Check Me!</li></ul>",
			[]string{"-i", "-G"},
		},
		{
			"PluginStrikethrough", "Only ~~blue ones~~ ~~left~~",
			"Only <del>blue ones</del> <s> left</s>",
			[]string{"-i", "--plugin-strikethrough"},
		},
		// {
		// 	"", "", "", []string{"-i"},
		// },
	}

	os.Chdir(dirTest)

	t.Logf("\n\n== Testing options and plugins\n\n")

	for _, tc := range testData {
		r := strings.TrimSpace(testIt(t, tc.name, tc.in, tc.args...))
		if tc.out != r {
			t.Errorf(`expected "%s" but got "%s" instead`, tc.out, r)
		}
	}
}