zenity/file_util_test.go

40 lines
890 B
Go
Raw Permalink 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"},
{"/", "/", ""},
// 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 {
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
}
}
}