-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_test.go
More file actions
139 lines (135 loc) · 2.73 KB
/
main_test.go
File metadata and controls
139 lines (135 loc) · 2.73 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestTrimPath(t *testing.T) {
tests := []struct {
name string
path string
curDir string
vimDir string
homeDir string
expected string
}{
{
name: "simple",
path: "file.txt",
expected: "file.txt",
},
{
name: "two",
path: "/dir/file.txt",
expected: "/dir/file.txt",
},
{
name: "simple vim dir",
path: "/dir/file.txt",
vimDir: "/dir/",
expected: "file.txt",
},
{
name: "skip vim dir",
path: "/dir/file.txt",
vimDir: "",
expected: "/dir/file.txt",
},
{
name: "not vim dir",
path: "/other/file.txt",
vimDir: "/dir/",
expected: "/other/file.txt",
},
{
name: "inner vim dir",
path: "/other/dir/file.txt",
vimDir: "/dir/",
expected: "/other/dir/file.txt",
},
{
name: "simple home dir",
path: "/dir/home/file.txt",
homeDir: "/dir/home",
expected: "~/file.txt",
},
{
name: "skip home dir",
path: "/dir/home/file.txt",
homeDir: "",
expected: "/dir/home/file.txt",
},
{
name: "not home dir",
path: "/dir/other/file.txt",
homeDir: "/dir/home",
expected: "/dir/other/file.txt",
},
{
name: "inner home dir",
path: "/other/dir/home/file.txt",
homeDir: "/dir/home",
expected: "/other/dir/home/file.txt",
},
{
name: "dot slash",
path: "./file.txt",
expected: "file.txt",
},
{
name: "inner dot slash",
path: "/dir/./file.txt",
expected: "/dir/file.txt",
},
{
name: "double dot slash",
path: "/dir/../file.txt",
expected: "/dir/../file.txt",
},
{
name: "prepend current dir",
path: "file.txt",
curDir: "/dir/",
expected: "/dir/file.txt",
},
{
name: "skip prepend current dir",
path: "/dir/file.txt",
curDir: "/dir/",
expected: "/dir/file.txt",
},
{
name: "already absolute path",
path: "/other/file.txt",
curDir: "/dir/",
expected: "/other/file.txt",
},
{
name: "prepend current and trim home dir",
path: "file.txt",
curDir: "/home/dir/",
homeDir: "/home",
expected: "~/dir/file.txt",
},
{
name: "prepend current and trim vim dir",
path: "file.txt",
curDir: "/vim/dir/",
vimDir: "/vim/",
expected: "dir/file.txt",
},
{
name: "all dirs used",
path: "file.txt",
curDir: "/home/dir/",
vimDir: "/home/dir/",
homeDir: "/home",
expected: "file.txt",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := trimPath(tt.path, tt.curDir, tt.vimDir, tt.homeDir)
assert.Equal(t, tt.expected, actual)
})
}
}