-
Notifications
You must be signed in to change notification settings - Fork 0
/
tok_test.go
49 lines (44 loc) · 1.09 KB
/
tok_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
package txt
import (
"testing"
)
func TestTokenize(t *testing.T) {
tests := []string{
"Simple text string",
"a MoRe comPlicated string with odd Spacing ... ",
" $testing str@ing !@#$%^&*()",
}
expected := [][]string{
{"simple", "text", "string"},
{"complicated", "string", "odd", "spacing"},
{"testing", "string"},
}
for index, v := range tests {
tokens := Tokenize(v, SplitNonAlphanumeric, nil, TokenizerStopwords)
for idx, tok := range tokens {
expect := expected[index][idx]
if expect != tok {
t.Fatalf("expected '%v', got '%v' for input '%v'", expect, tok, v)
}
}
}
}
func TestNormalizeColors(t *testing.T) {
tests := []string{
"normalize the color HotPink",
"gold is a color",
}
expected := [][]string{
{"normalize", "color", "#FF69B4"},
{"#FFD700", "color"},
}
for index, v := range tests {
tokens := Tokenize(v, SplitNonAlphanumeric, nil, TokenizerStopwords, TokenizerColors)
for idx, tok := range tokens {
expect := expected[index][idx]
if expect != tok {
t.Fatalf("expected '%v', got '%v' for input '%v'", expect, tok, v)
}
}
}
}