mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-21 02:55:37 -08:00
The simple filepath.IsAbs() is not enough on Windows, where the relative path may start with a separator and should then be taken relative to the volume name. So, introduce resolveGitPath() helper function that will do the right thing on both Windows and other systems. As a bonus, it returns paths converted to slashes for ease of use with the rest of the git segment: - Git for Windows uses only slashes. - Slashes do work as a path separator on Windows anyway. - Some tests in git segment still use (and rightfully so) slashes. Add tests for resolveGitPath() on both types of systems and fix TestEnableInWorktree using a system-dependent testing constant as a root path.
43 lines
743 B
Go
43 lines
743 B
Go
//go:build windows
|
|
|
|
package segments
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
const TestRootPath = "C:/"
|
|
|
|
func TestResolveGitPath(t *testing.T) {
|
|
cases := []struct {
|
|
Case string
|
|
Base string
|
|
Path string
|
|
Expected string
|
|
}{
|
|
{
|
|
Case: "relative path",
|
|
Base: "dir\\",
|
|
Path: "sub",
|
|
Expected: "dir/sub",
|
|
},
|
|
{
|
|
Case: "absolute path",
|
|
Base: "C:\\base",
|
|
Path: "C:/absolute/path",
|
|
Expected: "C:/absolute/path",
|
|
},
|
|
{
|
|
Case: "disk-relative path",
|
|
Base: "C:\\base",
|
|
Path: "/absolute/path",
|
|
Expected: "C:/absolute/path",
|
|
},
|
|
}
|
|
for _, tc := range cases {
|
|
assert.Equal(t, tc.Expected, resolveGitPath(tc.Base, tc.Path), tc.Case)
|
|
}
|
|
}
|