2015-09-11 17:37:12 +08:00
|
|
|
|
package local
|
|
|
|
|
|
|
|
|
|
import (
|
2018-11-02 20:12:51 +08:00
|
|
|
|
"runtime"
|
2015-09-11 17:37:12 +08:00
|
|
|
|
"testing"
|
2021-05-28 19:34:29 +08:00
|
|
|
|
|
|
|
|
|
"github.com/rclone/rclone/lib/encoder"
|
2015-09-11 17:37:12 +08:00
|
|
|
|
)
|
|
|
|
|
|
2015-10-16 17:49:00 +08:00
|
|
|
|
// Test Windows character replacements
|
|
|
|
|
var testsWindows = [][2]string{
|
2016-03-01 00:57:23 +08:00
|
|
|
|
{`c:\temp`, `c:\temp`},
|
|
|
|
|
{`\\?\UNC\theserver\dir\file.txt`, `\\?\UNC\theserver\dir\file.txt`},
|
2018-11-02 20:12:51 +08:00
|
|
|
|
{`//?/UNC/theserver/dir\file.txt`, `\\?\UNC\theserver\dir\file.txt`},
|
|
|
|
|
{`c:/temp`, `c:\temp`},
|
2019-10-28 23:41:47 +08:00
|
|
|
|
{`C:/temp/file.txt`, `C:\temp\file.txt`},
|
2018-11-02 20:12:51 +08:00
|
|
|
|
{`c:\!\"#¤%&/()=;:*^?+-`, `c:\!\"#¤%&\()=;:*^?+-`},
|
|
|
|
|
{`c:\<>"|?*:&\<>"|?*:&\<>"|?*:&`, `c:\<>"|?*:&\<>"|?*:&\<>"|?*:&`},
|
2015-10-16 17:49:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestCleanWindows(t *testing.T) {
|
2018-11-02 20:12:51 +08:00
|
|
|
|
if runtime.GOOS != "windows" {
|
|
|
|
|
t.Skipf("windows only")
|
|
|
|
|
}
|
2015-10-16 17:49:00 +08:00
|
|
|
|
for _, test := range testsWindows {
|
2021-05-28 19:34:29 +08:00
|
|
|
|
got := cleanRootPath(test[0], true, encoder.OS)
|
2015-10-16 17:49:00 +08:00
|
|
|
|
expect := test[1]
|
|
|
|
|
if got != expect {
|
|
|
|
|
t.Fatalf("got %q, expected %q", got, expect)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|