-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdict_test.go
62 lines (59 loc) · 1.25 KB
/
dict_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
package rword
import (
"errors"
"os"
"path/filepath"
"reflect"
"strings"
"testing"
)
func TestLoadDictFromFile(t *testing.T) {
testCases := []struct {
name string
file string
err error
expected Dictionary
}{
{
name: "empty dictionary",
file: "testdata/empty_dict",
err: nil,
expected: Dictionary{},
},
{
name: "not existing dictionary",
file: "testdata/abcde",
err: os.ErrNotExist,
expected: Dictionary{},
},
{
name: "valid dictionary",
file: "testdata/valid_dict",
err: nil,
expected: Dictionary{"a", "b", "c"},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
d, err := LoadDictFromFile(tc.file)
if tc.err != nil {
if !errors.Is(err, tc.err) {
t.Errorf("expected err: %v, actual: %v", tc.err, err)
}
return
}
if !reflect.DeepEqual(d, tc.expected) {
t.Errorf("expected dictionary content: %v, actual: %v", tc.expected, d)
}
})
}
}
func TestGetPathToDefaultDict(t *testing.T) {
p := GetPathToDefaultDict()
if !strings.HasSuffix(p, defaultDictFile) {
t.Errorf("get %v, want somethind ends with %v", p, defaultDictFile)
}
if !filepath.IsAbs(p) {
t.Errorf("get %v, want absolute path", p)
}
}