-
Notifications
You must be signed in to change notification settings - Fork 3
/
path_test.go
60 lines (54 loc) · 1.11 KB
/
path_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
package main
import (
"slices"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_endsWithSlash(t *testing.T) {
assert.Equal(t, "", endsWithSlash(""))
assert.Equal(t, "/", endsWithSlash("/"))
assert.Equal(t, "x/", endsWithSlash("x"))
assert.Equal(t, "x/", endsWithSlash("x/"))
assert.Equal(t, "x/y/", endsWithSlash("x/y"))
assert.Equal(t, "x/y/", endsWithSlash("x/y/"))
}
func Test_expandPaths(t *testing.T) {
tests := []struct {
paths []string
want []string
}{
{
paths: []string{""},
want: nil,
},
{
paths: []string{"/"},
want: []string{"/"},
},
{
paths: []string{"a"},
want: []string{"a"},
},
{
paths: []string{"a/b/c", "a/b/d"},
want: []string{"a", "a/b", "a/b/c", "a/b/d"},
},
{
paths: []string{"/a/b"},
want: []string{"/", "/a", "/a/b"},
},
{
paths: []string{"/a/b/"},
want: []string{"/", "/a", "/a/b"},
},
{
paths: []string{"/a/b", "/a/c"},
want: []string{"/", "/a", "/a/b", "/a/c"},
},
}
for _, tc := range tests {
expanded := expandPaths(tc.paths)
slices.Sort(expanded)
assert.Equal(t, tc.want, expanded)
}
}