-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath_test.go
More file actions
44 lines (38 loc) · 1.07 KB
/
Copy pathpath_test.go
File metadata and controls
44 lines (38 loc) · 1.07 KB
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
package eutil
import (
"path/filepath"
"testing"
)
func TestParseFilePath(t *testing.T) {
tests := []struct {
input string
expectName string
expectExt string
}{
{"test.txt", "test", ".txt"},
{"dir/subdir/data.json", "data", ".json"},
{"/absolute/path/to/main.go", "main", ".go"},
{"no_extension", "no_extension", ""},
{".hiddenfile", ".hiddenfile", ""},
{"./file.with.multiple.dots.tar.gz", "file.with.multiple.dots.tar", ".gz"},
{"./path with space/file name.txt", "file name", ".txt"},
{"中文路径/文件.doc", "文件", ".doc"},
{".", "", ""},
{"/", "", ""},
}
for _, tt := range tests {
dir, filename, ext, err := ParseFilePath(tt.input)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if filename != tt.expectName {
t.Errorf("filename mismatch: got %q, want %q", filename, tt.expectName)
}
if ext != tt.expectExt {
t.Errorf("extension mismatch: got %q, want %q", ext, tt.expectExt)
}
if tt.input != "." && tt.input != "/" && !filepath.IsAbs(dir) {
t.Errorf("dir should be absolute: got %s", dir)
}
}
}