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