-
Notifications
You must be signed in to change notification settings - Fork 6
/
snowball_test.go
69 lines (58 loc) · 1.36 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
package snowball
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func TestList(t *testing.T) {
require.Greater(t, len(Languages()), 0, "no langs")
}
func TestListEnglish(t *testing.T) {
found := false
for _, v := range Languages() {
if v == "english" {
found = true
break
}
}
require.True(t, found, "english not found")
}
func TestNew(t *testing.T) {
lang := "english"
stmr, err := New(lang)
require.NoError(t, err, "create english stemmer")
require.Equal(t, lang, stmr.Lang())
}
func TestClose(t *testing.T) {
stmr, err := New("english")
require.NoError(t, err, "create english stemmer")
stmr.Close()
require.Nil(t, stmr.stmr, "didn't free C stemmer")
}
func TestNewNoLang(t *testing.T) {
lang := "klingon"
_, err := New(lang)
require.Error(t, err, "dude, we have a klingon stemmer!")
}
func TestStem(t *testing.T) {
var testCases = []struct {
lang string
word string
stem string
}{
{"english", "running", "run"},
{"german", "käuflich", "kauflich"},
}
for _, tc := range testCases {
name := fmt.Sprintf("%s:%s", tc.lang, tc.word)
t.Run(name, func(t *testing.T) {
stmr, err := New(tc.lang)
require.NoErrorf(t, err, "can't create stemmer")
s := stmr.Stem(tc.word)
require.Equal(t, tc.stem, s)
})
}
}
func TestSnowballVersion(t *testing.T) {
require.Regexp(t, `\d+\.\d+(\.\d+)`, SnowballVersion)
}