-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
117 lines (110 loc) · 2.96 KB
/
main_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package main
import (
"reflect"
"testing"
)
func TestSlackMarkdownToGeneral(t *testing.T) {
tests := []struct {
name string
input string
wantOutput string
}{
{
name: "Simple link",
input: "Visit <https://github.com|GitHub>",
wantOutput: "Visit [GitHub](https://github.com)",
},
{
name: "Bold text",
input: "This is *bold* text",
wantOutput: "This is **bold** text",
},
{
name: "Italic text",
input: "This is _italic_ text",
wantOutput: "This is _italic_ text",
},
{
name: "Strikethrough text",
input: "This is ~strikethrough~ text",
wantOutput: "This is ~strikethrough~ text",
},
{
name: "Code block",
input: "Here is `code`",
wantOutput: "Here is `code`",
},
{
name: "Complex text",
input: "This is *complex* <https://github.com|style> for _~*my slack*~_ `message`",
wantOutput: "This is **complex** [style](https://github.com) for _~**my slack**~_ `message`",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := SlackMarkdownToGeneral(tt.input); got != tt.wantOutput {
t.Errorf("SlackMarkdownToGeneral() = %v, want %v", got, tt.wantOutput)
}
})
}
}
func TestMarkdownToHtmlMark(t *testing.T) {
tests := []struct {
name string
input string
wantOutput string
}{
{
name: "Simple markdown",
input: "This is *bold* text",
wantOutput: "This is *bold* text",
},
{
name: "Tilde replacement",
input: "This is ~strikethrough~ text",
wantOutput: "This is ~~strikethrough~~ text",
},
{
name: "Double enter for paragraph",
input: "This is line one\nThis is line two",
wantOutput: "This is line one\n\nThis is line two",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := MarkdownToHtmlMark(tt.input); got != tt.wantOutput {
t.Errorf("MarkdownToHtmlMark() = %v, want %v", got, tt.wantOutput)
}
})
}
}
func TestSplitSentence(t *testing.T) {
tests := []struct {
name string
input string
wantOutput []string
}{
{
name: "Simple sentence",
input: "This is a test",
wantOutput: []string{"This", " ", "is", " ", "a", " ", "test"},
},
{
name: "Sentence with formatting",
input: "This is *bold* and _italic_ text",
wantOutput: []string{"This", " ", "is", " ", "*bold*", " ", "and", " ", "_italic_", " ", "text"},
},
{
name: "Complex sentence",
input: "This is *complex* <https://github.com|style> for _~*my slack*~_ `message`",
wantOutput: []string{"This", " ", "is", " ", "*complex*", " ", "<https://github.com|style>", " ", "for", " ", "_~*my slack*~_", " ", "`message`"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := splitSentence(tt.input); !reflect.DeepEqual(got, tt.wantOutput) {
t.Errorf("splitSentence() = %v, want %v", got, tt.wantOutput)
}
})
}
}