forked from stripe/stripe-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
markdownterm_test.go
73 lines (57 loc) · 2.03 KB
/
markdownterm_test.go
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
64
65
66
67
68
69
70
71
72
73
package ansi
import (
"os"
"testing"
"github.com/russross/blackfriday"
"github.com/stretchr/testify/require"
)
func render(s string, useAnsi bool) string {
flags := 0
if useAnsi {
flags |= MDTERM_USE_ANSI
}
r := MarkdownTermRenderer(flags)
return string(blackfriday.Markdown([]byte(s), r, blackfriday.EXTENSION_STRIKETHROUGH))
}
func TestMain(m *testing.M) {
ForceColors = true
code := m.Run()
ForceColors = false
os.Exit(code)
}
func TestMarkdownTermRenderer(t *testing.T) {
r := MarkdownTermRenderer(MDTERM_USE_ANSI)
require.Equal(t, MDTERM_USE_ANSI, r.GetFlags())
}
func TestMarkdownTerm_Header(t *testing.T) {
require.Equal(t, "Foo\n", render("# Foo\n", true))
require.Equal(t, "Foo\n", render("# Foo\n", false))
require.Equal(t, "", render("", true))
require.Equal(t, "", render("", false))
}
func TestMarkdownTerm_Paragraph(t *testing.T) {
require.Equal(t, "\nFoo.\n\nBar.\n", render("Foo.\n\nBar.", true))
require.Equal(t, "\nFoo.\n\nBar.\n", render("Foo.\n\nBar.", false))
require.Equal(t, "", render("", true))
require.Equal(t, "", render("", false))
}
func TestMarkdownTerm_DoubleEmphasis(t *testing.T) {
require.Equal(t, "\n\x1b[1mfoo\x1b[0m\n", render("**foo**", true))
require.Equal(t, "\nfoo\n", render("**foo**", false))
}
func TestMarkdownTerm_Emphasis(t *testing.T) {
require.Equal(t, "\n\x1b[3mfoo\x1b[0m\n", render("*foo*", true))
require.Equal(t, "\nfoo\n", render("*foo*", false))
}
func TestMarkdownTerm_Link(t *testing.T) {
require.Equal(t, "\nfoo [https://example.com/foo]\n", render("[foo](https://example.com/foo)", true))
require.Equal(t, "\nfoo [https://example.com/foo]\n", render("[foo](https://example.com/foo)", false))
}
func TestMarkdownTerm_TripleEmphasis(t *testing.T) {
require.Equal(t, "\n\x1b[1m\x1b[3mfoo\x1b[0m\x1b[0m\n", render("***foo***", true))
require.Equal(t, "\nfoo\n", render("***foo***", false))
}
func TestMarkdownTerm_StrikeThrough(t *testing.T) {
require.Equal(t, "\n\x1b[9mfoo\x1b[0m\n", render("~~foo~~", true))
require.Equal(t, "\nfoo\n", render("~~foo~~", false))
}