zenity/file_util_test.go

41 lines
909 B
Go
Raw Normal View History

2021-06-18 11:16:04 -04:00
package zenity
import (
"os"
"path/filepath"
"testing"
)
func Test_splitDirAndName(t *testing.T) {
2022-12-15 09:29:56 -05:00
t.Parallel()
2021-06-18 11:16:04 -04:00
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"},
{"/", "/", ""},
2023-04-12 08:36:20 -04:00
{"", "", ""},
2021-06-18 11:16:04 -04:00
// 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 {
2023-04-12 06:22:30 -04:00
gotDir, gotName, _ := splitDirAndName(tt.path)
2021-06-18 11:16:04 -04:00
if gotDir != tt.wantDir {
2021-07-07 08:24:46 -04:00
t.Errorf("splitDirAndName[%d].dir = %q; want %q", i, gotDir, tt.wantDir)
2021-06-18 11:16:04 -04:00
}
if gotName != tt.wantName {
2021-07-07 08:24:46 -04:00
t.Errorf("splitDirAndName[%d].name = %q; want %q", i, gotName, tt.wantName)
2021-06-18 11:16:04 -04:00
}
}
}