-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentry_test.go
82 lines (63 loc) · 1.5 KB
/
entry_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
74
75
76
77
78
79
80
81
82
package retrosort
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestEntryPrefixLong(t *testing.T) {
e := newEntry("a file name.foo", []string{"a file name.foo"})
if d := cmp.Diff("a_file_name_foo", e.prefix(15)); d != "" {
t.Error(d)
}
if d := cmp.Diff("a_file_name_foo", e.prefix(16)); d != "" {
t.Error(d)
}
}
func TestEntryPrefixSingle(t *testing.T) {
es := []entry{
newEntry("123", []string{}),
newEntry(".-#", []string{}),
newEntry(" _%3", []string{}),
}
for _, e := range es {
if d := cmp.Diff("#", e.prefix(1)); d != "" {
t.Error(e, d)
}
}
}
func TestEntryPrefixVarious(t *testing.T) {
e := newEntry("my great(-)file.yes", []string{})
testCases := []struct {
expected string
size int
}{
{"m", 1},
{"my_great", 8},
{"my_great_file", 13},
}
for _, c := range testCases {
if d := cmp.Diff(c.expected, e.prefix(c.size)); d != "" {
t.Error(d)
}
}
}
func TestEntryFileMapSingle(t *testing.T) {
e := newEntry("a", []string{"/path/to/a.file"})
expected := map[string]string{
"/path/to/a.file": "a.file",
}
actual := e.fileMap()
if d := cmp.Diff(expected, actual); d != "" {
t.Error(d)
}
}
func TestEntryFileMapMultiple(t *testing.T) {
e := newEntry("a", []string{"/path/to/a.file", "/other/path/for/a [test].file"})
expected := map[string]string{
"/path/to/a.file": "a/a.file",
"/other/path/for/a [test].file": "a/a [test].file",
}
actual := e.fileMap()
if d := cmp.Diff(expected, actual); d != "" {
t.Error(d)
}
}