示例#1
0
func TestPathCleanage(t *testing.T) {

	log.SetFlags(0)

	_, c := initFileSystems()
	defer c.Close()

	cases := [][]string{
		[]string{"", "mntX/", ""},
		[]string{"/", "mntX/", ""},
		[]string{".", "mntX/", ""},
		[]string{"./", "mntX/", ""},
		[]string{"mntX", "mntX/", ""},
		[]string{"mntX/", "mntX/", ""},
		// 5...
		[]string{"file", "mntX/", "file"},
		[]string{"dir/", "mntX/", "dir/"},
		[]string{"./dir1/", "mntX/", "dir1/"},
		[]string{"mntX/dir1", "mntX/", "dir1"},
		[]string{"mntX/dir1/file2", "mntX/dir1/", "file2"},
		// 10
		[]string{"mntY/dir1/file2", "mntX/mntY/dir1/", "file2"},
		[]string{"///mntX/dir1/dir2///dir3/", "mntX/dir1/dir2/", "dir3/"},
		[]string{"mntX/dir1/dir2///file3", "mntX/dir1/dir2/", "file3"},
		[]string{"/dir1/dir2///file3", "mntX/dir1/dir2/", "file3"},
		[]string{"dir1/dir2///dir3/", "mntX/dir1/dir2/", "dir3/"},
		// 15
		[]string{"c:\\dir1\\dir2", "mntX/c:/dir1/", "dir2"},
	}

	fs := memfs.New(
		memfs.Ident("mntX"),
	)
	for i, v := range cases {
		inpt := v[0]
		_ = inpt
		wnt1 := v[1]
		wnt2 := v[2]
		dir, bname := common.UnixPather(v[0], fs.RootDir())
		fullpath := dir + bname

		log.Printf("#%2v %-30q %-24q => %-16q %-12q ", i, inpt, dir, bname, fullpath)

		if wnt1 != dir {
			t.Errorf("dir   #%2v got %-24v - wnt %-16v\n", i, dir, wnt1)
		}
		if wnt2 != bname {
			t.Errorf("bname #%2v got %-24v - wnt %-16v\n", i, bname, wnt2)
		}
		if wnt1+wnt2 != fullpath {
			t.Errorf("fullp #%2v got %-24v - wnt %-16v\n", i, fullpath, wnt1+wnt2)
		}
	}

}
示例#2
0
文件: pathing.go 项目: aarzilli/tools
// name is the *external* path or filename.
func (fs *osFileSys) SplitX(name string) (dir, bname string) {

	// return common.UnixPather(name, fs.RootDir())

	dir, bname = common.UnixPather(name, "")

	name = fs.WinGoofify(path.Join(dir, bname))
	dir, bname = filepath.Split(name)

	return
}
示例#3
0
文件: pathing.go 项目: aarzilli/tools
// name is the *external* path or filename.
func (fs *dsFileSys) SplitX(name string) (dir, bname string) {
	return common.UnixPather(name, fs.RootDir())
}
示例#4
0
文件: pathing.go 项目: aarzilli/tools
// name is the *external* path or filename.
func (fs *memMapFs) SplitX(name string) (dir, bname string) {
	return common.UnixPather(name, fs.RootDir())
}