-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
80 lines (70 loc) · 2.16 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
package main
import (
"fmt"
"github.com/antchfx/htmlquery"
"github.com/stretchr/testify/assert"
"golang.org/x/net/html"
"strings"
"testing"
)
func TestParsePrediction(t *testing.T) {
containTable := []string{
"Své kolegy můžete něčemu novému naučit. Je možné, že vás o to požádá někdo z nadřízených, nebo přímo vedení firmy.",
"Ve vašem životě mohou nyní hrát velkou roli vaši přátelé",
"nebo přímo vedení firmy.",
"Aktivity vhodné pro dnešní den",
}
d, err := htmlquery.LoadDoc("test/example_response.html")
assert.Nil(t, err)
pred := parsePrediction(d)
for _, s := range containTable {
assert.True(t, strings.Contains(pred, s), fmt.Sprintf("Prediction should contain %q", s))
}
}
func TestNodeHasClass(t *testing.T) {
cases := map[string]struct {
classAttr string
expectedClass string
contains bool
}{
"only class": {classAttr: "lev", expectedClass: "lev", contains: true},
"multiple classes": {classAttr: "kral lev zvirat", expectedClass: "lev", contains: true},
"does not contains": {classAttr: "kral lev zvirat", expectedClass: "pav", contains: false},
"empty class": {classAttr: "", expectedClass: "lev", contains: false},
"all empty": {classAttr: "", expectedClass: "", contains: false},
}
for msg, c := range cases {
n := &html.Node{
Attr: []html.Attribute{
html.Attribute{
Namespace: "",
Key: "class",
Val: c.classAttr,
},
html.Attribute{
Namespace: "",
Key: "data-test",
Val: "kral lev zvirat", // testing attr
},
},
}
assert.Equal(t, c.contains, nodeHasClass(n, c.expectedClass), msg)
}
}
func TestSanitizeSign(t *testing.T) {
cases := map[string]struct {
input string
expected string
}{
"valid sign": {input: "lev", expected: "lev"},
"remove special chars": {input: "šťír", expected: "stir"},
"to lower": {input: "Býk", expected: "byk"},
}
for msg, c := range cases {
assert.Equal(t, c.expected, sanitizeSign(c.input), msg)
}
}
func TestIsSignValid(t *testing.T) {
assert.True(t, isSignValid("byk"))
assert.False(t, isSignValid("dymovnica"))
}