-
Notifications
You must be signed in to change notification settings - Fork 10
/
path_test.go
55 lines (52 loc) · 1.06 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
package postman
import (
"slices"
"testing"
)
func TestSlicePath(t *testing.T) {
tests := map[string]struct {
in string
out []string
}{
"No elements": {
in: "/",
out: []string{},
},
"Does not start with separator": {
in: "A/B",
out: []string{"A", "B"},
},
"Single element": {
in: "/A",
out: []string{"A"},
},
"Multiple elements": {
in: "/A/B",
out: []string{"A", "B"},
},
"Trailing separator": {
in: "/A/B/",
out: []string{"A", "B"},
},
"Double separator": {
in: "/A//B",
out: []string{"A", "B"},
},
"Non alphanumeric chars": {
in: "/A1/B with spaces/.hidden/_/-&",
out: []string{"A1", "B with spaces", ".hidden", "_", "-&"},
},
"Not a filesystem path, dots do not have special treatment": {
in: "../../A/B/",
out: []string{"..", "..", "A", "B"},
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
o := slicePath(test.in)
if !slices.Equal(o, test.out) {
t.Errorf("unexpected output in %s:\n[GOT]\n%+v\n\n[EXPECTED]\n%+v", name, o, test.out)
}
})
}
}