lib/fs: Case insensitive conversion to rel path on windows (fixes #5183) (#5176)

This commit is contained in:
Simon Frei
2018-09-11 22:30:32 +02:00
committed by Jakob Borg
parent 60a6a40175
commit 50ba0fd079
7 changed files with 121 additions and 26 deletions

View File

@@ -490,3 +490,29 @@ func TestNewBasicFilesystem(t *testing.T) {
t.Errorf(`newBasicFilesystem("relative/path").root == %q, expected absolutification`, fs.root)
}
}
func TestRel(t *testing.T) {
testCases := []struct {
root string
abs string
expectedRel string
}{
{"/", "/", ""},
{"/", "/test", "test"},
{"/", "/Test", "Test"},
{"/Test", "/Test/test", "test"},
}
if runtime.GOOS == "windows" {
for i := range testCases {
testCases[i].root = filepath.FromSlash(testCases[i].root)
testCases[i].abs = filepath.FromSlash(testCases[i].abs)
testCases[i].expectedRel = filepath.FromSlash(testCases[i].expectedRel)
}
}
for _, tc := range testCases {
if res := rel(tc.abs, tc.root); res != tc.expectedRel {
t.Errorf(`rel("%v", "%v") == "%v", expected "%v"`, tc.abs, tc.root, res, tc.expectedRel)
}
}
}