-
Notifications
You must be signed in to change notification settings - Fork 216
/
zc_traverser_local_test.go
50 lines (44 loc) · 1.88 KB
/
zc_traverser_local_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
package cmd
import (
"github.com/stretchr/testify/assert"
"os"
"testing"
)
func TestCleanLocalPath(t *testing.T) {
a := assert.New(t)
testCases := map[string]string{
"/user/foo/bar": "/user/foo/bar", // regular unix path with no change
"/user/foo/bar/": "/user/foo/bar", // regular unix path with extra slash
"/user//foo//bar/": "/user/foo/bar", // regular unix path with double slashes
"./foo/bar": "foo/bar", // relative unix path
"../foo/bar": "../foo/bar", // relative unix path with parent dir
"foo/bar": "foo/bar", // shorthand relative unix path
}
for orig, expected := range testCases {
a.Equal(expected, cleanLocalPath(orig))
}
}
func TestCleanLocalPathForWindows(t *testing.T) {
a := assert.New(t)
// ignore these tests when not running on Windows
// as the path cleaning behavior depends on the platform
if os.PathSeparator != '\\' {
t.Skip("not running since the test applies to Windows only")
}
// Paths on Windows get consolidated to backwards-slash typically.
testCases := map[string]string{
`C:\foo\bar`: `C:\foo\bar`, // regular windows path with no change
`C:\foo\bar\`: `C:\foo\bar`, // regular windows path with extra slash
`.\foo\bar`: `foo\bar`, // relative windows path
`..\foo\bar`: `..\foo\bar`, // relative windows path with parent dir
`foo\bar`: `foo\bar`, // shorthand relative windows path
`\\foo\bar\`: `\\foo\bar`, // network share
`C:\`: `C:\`, // special case, the slash after colon is actually required
`D:`: `D:\`, // special case, the slash after colon is actually required
`c:\`: `c:\`, // special case, the slash after colon is actually required
`c:`: `c:\`, // special case, the slash after colon is actually required
}
for orig, expected := range testCases {
a.Equal(expected, cleanLocalPath(orig))
}
}