forked from levinishka/html2text
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml2text_test.go
More file actions
35 lines (33 loc) · 1.44 KB
/
html2text_test.go
File metadata and controls
35 lines (33 loc) · 1.44 KB
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
package html2text
import "testing"
func TestHTML2Text(t *testing.T) {
type args struct {
htmlString string
}
tests := []struct {
name string
args args
want string
}{
{"0", args{""}, ""},
{"1", args{"<div>"}, ""},
{"2", args{"<p></p>"}, ""},
{"3", args{"<p>text </p>"}, "text \n"},
{"4", args{"<p>some new line <br>here and <br />here also</p>"}, "some new line \nhere and \nhere also\n"},
{"5", args{"<h1>text</h1> <div> <noscript> <p> text inside noscript <p> </noscript> </div>"}, "text\n text inside noscript \n"},
{"6", args{"<h1>header</h1> <script> func some func() {some + code = return 1010} </script> <div> text </div>"}, "header\n text "},
{"7", args{"<p>text1 </p> <p> text2 </p>"}, "text1 \n text2 \n"},
{"8", args{"<div> <div> some text</div> <div> another text </div> </div>"}, " some text another text "},
{"9", args{"<div> <div>some & text</div> <div>another text</div> </div>"}, "some & text another text"},
{"10", args{"<div> <p>some <> text</p> <div>another text</div> </div>"}, "some <> text\nanother text"},
{"11", args{"<ul><li>one</li><li>two</li><li>three</li></ul>"}, "• one\n• two\n• three\n"},
{"12", args{"<ol><li>one</li><li>two</li><li>three</li></ol>"}, "1. one\n2. two\n3. three\n"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := HTML2Text(tt.args.htmlString); got != tt.want {
t.Errorf("HTML2Text() = %v, want %v", got, tt.want)
}
})
}
}