forked from gookit/goutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfsutil_test.go
43 lines (36 loc) · 1.18 KB
/
fsutil_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
package fsutil_test
import (
"fmt"
"io/fs"
"testing"
"github.com/gookit/goutil/basefn"
"github.com/gookit/goutil/fsutil"
"github.com/gookit/goutil/testutil/assert"
)
func TestMain(m *testing.M) {
fmt.Println("before test ... clean testdata/*.txt files")
err := fsutil.RemoveSub("testdata", func(fPath string, ent fs.DirEntry) bool {
return fsutil.PathMatch("*.txt", ent.Name())
})
basefn.MustOK(err)
m.Run()
}
func TestSplitPath(t *testing.T) {
dir, file := fsutil.SplitPath("/path/to/dir/some.txt")
assert.Eq(t, "/path/to/dir/", dir)
assert.Eq(t, "some.txt", file)
}
func TestToAbsPath(t *testing.T) {
assert.Eq(t, "/path/to/dir/", fsutil.ToAbsPath("/path/to/dir/"))
assert.Neq(t, "~/path/to/dir", fsutil.ToAbsPath("~/path/to/dir"))
assert.NotEmpty(t, fsutil.ToAbsPath(""))
assert.Neq(t, ".", fsutil.ToAbsPath("."))
assert.Neq(t, "..", fsutil.ToAbsPath(".."))
assert.Neq(t, "./", fsutil.ToAbsPath("./"))
assert.Neq(t, "../", fsutil.ToAbsPath("../"))
}
func TestSlashPath(t *testing.T) {
assert.Eq(t, "/path/to/dir", fsutil.SlashPath("/path/to/dir"))
assert.Eq(t, "/path/to/dir", fsutil.UnixPath("/path/to/dir"))
assert.Eq(t, "/path/to/dir", fsutil.UnixPath("\\path\\to\\dir"))
}