-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
file_util_test.go
40 lines (36 loc) · 909 Bytes
/
file_util_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
package zenity
import (
"os"
"path/filepath"
"testing"
)
func Test_splitDirAndName(t *testing.T) {
t.Parallel()
tempDir := os.TempDir()
tests := []struct {
path string
wantDir string
wantName string
}{
// filepath.Split test cases
{"a/b", "a/", "b"},
{"a/b/", "a/b/", ""},
{"a/", "a/", ""},
{"a", "", "a"},
{"/", "/", ""},
{"", "", ""},
// we split differently if we know it's a directory
{tempDir, tempDir, ""},
{filepath.Clean(tempDir), filepath.Clean(tempDir), ""},
{filepath.Join(tempDir, "a"), filepath.Clean(tempDir) + string(filepath.Separator), "a"},
}
for i, tt := range tests {
gotDir, gotName, _ := splitDirAndName(tt.path)
if gotDir != tt.wantDir {
t.Errorf("splitDirAndName[%d].dir = %q; want %q", i, gotDir, tt.wantDir)
}
if gotName != tt.wantName {
t.Errorf("splitDirAndName[%d].name = %q; want %q", i, gotName, tt.wantName)
}
}
}