forked from kljensen/snowball
-
Notifications
You must be signed in to change notification settings - Fork 1
/
snowball_test.go
73 lines (68 loc) · 2.37 KB
/
snowball_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 snowball
import (
"regexp"
"testing"
)
func Test_Stem(t *testing.T) {
testCases := []struct {
in string
language string
stemStopWords bool
out string
nilErr bool
}{
{"aberration", "english", true, "aberr", true},
{"abruptness", "english", true, "abrupt", true},
{"absolute", "english", true, "absolut", true},
{"abated", "english", true, "abat", true},
{"acclivity", "english", true, "accliv", true},
{"accumulations", "english", true, "accumul", true},
{"agreement", "english", true, "agreement", true},
{"breed", "english", true, "breed", true},
{"ape", "english", true, "ape", true},
{"skating", "english", true, "skate", true},
{"fluently", "english", true, "fluentli", true},
{"ied", "english", true, "ie", true},
{"ies", "english", true, "ie", true},
// Change stemStopWords
{"above", "english", true, "abov", true},
{"because", "english", false, "because", true},
// Give invalid language
{"because", "klingon", false, "", false},
// Spanish tests, a few
{"lejana", "spanish", true, "lejan", true},
{"preocuparse", "spanish", true, "preocup", true},
{"oposición", "spanish", true, "oposicion", true},
{"prisionero", "spanish", true, "prisioner", true},
{"ridiculización", "spanish", true, "ridiculiz", true},
{"cotidianeidad", "spanish", true, "cotidian", true},
{"portezuela", "spanish", true, "portezuel", true},
{"enriquecerse", "spanish", true, "enriquec", true},
{"campesinos", "spanish", true, "campesin", true},
{"desalojó", "spanish", true, "desaloj", true},
{"anticipadas", "spanish", true, "anticip", true},
{"goyesca", "spanish", true, "goyesc", true},
{"band", "spanish", true, "band", true},
}
for _, testCase := range testCases {
out, err := Stem(testCase.in, testCase.language, testCase.stemStopWords)
nilErr := true
if err != nil {
nilErr = false
}
if out != testCase.out || nilErr != testCase.nilErr {
t.Errorf("Stem(\"%v\", \"%v\", %v) = \"%v, %v\", but expected %v, %v",
testCase.in, testCase.language, testCase.stemStopWords,
out, nilErr, testCase.out, testCase.nilErr,
)
}
}
}
// Test if the VERSION constant is correctly formatted
//
func Test_Version(t *testing.T) {
validVersionRegexp := regexp.MustCompile(`^v\d+\.\d+\.\d+$`)
if validVersionRegexp.MatchString(VERSION) == false {
t.Errorf("Invalid version specified: %v", VERSION)
}
}