-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmodel_test.go
57 lines (51 loc) · 1.15 KB
/
model_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
package mecab
import (
"runtime"
"strings"
"testing"
)
func TestModel(t *testing.T) {
model, err := NewModel(rcfile(map[string]string{
"output-format-type": "wakati",
}))
if err != nil {
t.Errorf("unexpected error: %v", err)
return
}
defer model.Destroy()
mecab, err := model.NewMeCab()
if err != nil {
t.Errorf("unexpected error: %v", err)
return
}
defer mecab.Destroy()
result, err := mecab.Parse("こんにちは世界")
if err != nil {
t.Errorf("unexpected error: %v", err)
return
}
expected := "こんにちは 世界 \n"
if result != expected {
t.Errorf("want `%s`, but `%s`", expected, result)
}
}
func TestNewModel_error(t *testing.T) {
_, err := NewModel(rcfile(map[string]string{
"output-format-type": "unknown format",
}))
if err == nil {
t.Errorf("expected error, but not")
return
}
if !strings.Contains(err.Error(), "unknown format type [unknown format]") {
t.Errorf("want %q error, got %q", "unknown format type [unknown format]", err.Error())
}
}
func TestModelFinalizer(t *testing.T) {
for i := 0; i < 10000; i++ {
NewModel(rcfile(map[string]string{}))
}
runtime.GC()
runtime.GC()
runtime.GC()
}