fix(path): show separator for root drives

resolves #2954
This commit is contained in:
Jan De Dobbeleer 2022-10-17 12:40:29 +02:00 committed by Jan De Dobbeleer
parent 48d1015c3e
commit 016dc50e72
2 changed files with 7 additions and 4 deletions

View file

@ -127,6 +127,9 @@ func (pt *Path) Init(props properties.Properties, env environment.Environment) {
func (pt *Path) setStyle() {
if len(pt.relative) == 0 {
pt.Path = pt.root
if strings.HasSuffix(pt.Path, ":") {
pt.Path += pt.env.PathSeparator()
}
return
}
switch style := pt.props.GetString(properties.Style, Agnoster); style {

View file

@ -294,7 +294,7 @@ func TestAgnosterPathStyles(t *testing.T) {
},
{
Style: Letter,
Expected: "C:",
Expected: "C:\\",
HomePath: homeDirWindows,
Pwd: "C:\\",
GOOS: environment.WINDOWS,
@ -563,7 +563,7 @@ func TestAgnosterPathStyles(t *testing.T) {
},
{
Style: AgnosterShort,
Expected: "C:",
Expected: "C:/",
HomePath: homeDir,
Pwd: "/mnt/c",
Pswd: "C:",
@ -594,7 +594,7 @@ func TestAgnosterPathStyles(t *testing.T) {
},
{
Style: AgnosterShort,
Expected: "C:",
Expected: "C:\\",
HomePath: homeDirWindows,
Pwd: "C:",
GOOS: environment.WINDOWS,
@ -743,7 +743,7 @@ func TestFullAndFolderPath(t *testing.T) {
{Style: Folder, FolderSeparatorIcon: "|", Pwd: "/a/b/c/d", Expected: "d"},
// for Windows paths
{Style: Folder, FolderSeparatorIcon: "\\", Pwd: "C:\\", Expected: "C:", PathSeparator: "\\", GOOS: environment.WINDOWS},
{Style: Folder, FolderSeparatorIcon: "\\", Pwd: "C:\\", Expected: "C:\\", PathSeparator: "\\", GOOS: environment.WINDOWS},
{Style: Folder, FolderSeparatorIcon: "\\", Pwd: homeDirWindows, Expected: "~", PathSeparator: "\\", GOOS: environment.WINDOWS},
{Style: Full, FolderSeparatorIcon: "\\", Pwd: homeDirWindows, Expected: "~", PathSeparator: "\\", GOOS: environment.WINDOWS},
{Style: Full, FolderSeparatorIcon: "\\", Pwd: homeDirWindows + "\\abc", Expected: "~\\abc", PathSeparator: "\\", GOOS: environment.WINDOWS},