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