feat(path): respect folder_separator_icon in a colon-trailed root

This commit is contained in:
L. Yeung 2023-05-11 11:03:56 +08:00 committed by Jan De Dobbeleer
parent ddd4ecafc9
commit 4b71c2ba07
2 changed files with 16 additions and 12 deletions

View file

@ -145,7 +145,7 @@ func (pt *Path) setStyle() {
if len(pt.relative) == 0 { if len(pt.relative) == 0 {
pt.Path = pt.root pt.Path = pt.root
if strings.HasSuffix(pt.Path, ":") { if strings.HasSuffix(pt.Path, ":") {
pt.Path += pt.env.PathSeparator() pt.Path += pt.getFolderSeparator()
} }
return return
} }

View file

@ -14,7 +14,7 @@ import (
mock2 "github.com/stretchr/testify/mock" mock2 "github.com/stretchr/testify/mock"
) )
func renderTemplate(env *mock.MockedEnvironment, segmentTemplate string, context interface{}) string { func renderTemplateNoTrimSpace(env *mock.MockedEnvironment, segmentTemplate string, context interface{}) string {
found := false found := false
for _, call := range env.Mock.ExpectedCalls { for _, call := range env.Mock.ExpectedCalls {
if call.Method == "TemplateCache" { if call.Method == "TemplateCache" {
@ -38,7 +38,11 @@ func renderTemplate(env *mock.MockedEnvironment, segmentTemplate string, context
if err != nil { if err != nil {
return err.Error() return err.Error()
} }
return strings.TrimSpace(text) return text
}
func renderTemplate(env *mock.MockedEnvironment, segmentTemplate string, context interface{}) string {
return strings.TrimSpace(renderTemplateNoTrimSpace(env, segmentTemplate, context))
} }
const ( const (
@ -333,7 +337,7 @@ func TestAgnosterPathStyles(t *testing.T) {
}, },
{ {
Style: Letter, Style: Letter,
Expected: "C:\\", Expected: "C: > ",
HomePath: homeDirWindows, HomePath: homeDirWindows,
Pwd: "C:\\", Pwd: "C:\\",
GOOS: platform.WINDOWS, GOOS: platform.WINDOWS,
@ -610,7 +614,7 @@ func TestAgnosterPathStyles(t *testing.T) {
}, },
{ {
Style: AgnosterShort, Style: AgnosterShort,
Expected: "C:/", Expected: "C: | ",
HomePath: homeDir, HomePath: homeDir,
Pwd: "/mnt/c", Pwd: "/mnt/c",
Pswd: "C:", Pswd: "C:",
@ -641,7 +645,7 @@ func TestAgnosterPathStyles(t *testing.T) {
}, },
{ {
Style: AgnosterShort, Style: AgnosterShort,
Expected: "C:\\", Expected: "C: > ",
HomePath: homeDirWindows, HomePath: homeDirWindows,
Pwd: "C:", Pwd: "C:",
GOOS: platform.WINDOWS, GOOS: platform.WINDOWS,
@ -747,7 +751,7 @@ func TestAgnosterPathStyles(t *testing.T) {
} }
path.setPaths() path.setPaths()
path.setStyle() path.setStyle()
got := renderTemplate(env, "{{ .Path }}", path) got := renderTemplateNoTrimSpace(env, "{{ .Path }}", path)
assert.Equal(t, tc.Expected, got) assert.Equal(t, tc.Expected, got)
} }
} }
@ -877,7 +881,7 @@ func TestFullAndFolderPath(t *testing.T) {
} }
path.setPaths() path.setPaths()
path.setStyle() path.setStyle()
got := renderTemplate(env, tc.Template, path) got := renderTemplateNoTrimSpace(env, tc.Template, path)
assert.Equal(t, tc.Expected, got) assert.Equal(t, tc.Expected, got)
} }
} }
@ -932,7 +936,7 @@ func TestFullPathCustomMappedLocations(t *testing.T) {
} }
path.setPaths() path.setPaths()
path.setStyle() path.setStyle()
got := renderTemplate(env, "{{ .Path }}", path) got := renderTemplateNoTrimSpace(env, "{{ .Path }}", path)
assert.Equal(t, tc.Expected, got) assert.Equal(t, tc.Expected, got)
} }
} }
@ -960,7 +964,7 @@ func TestFolderPathCustomMappedLocations(t *testing.T) {
} }
path.setPaths() path.setPaths()
path.setStyle() path.setStyle()
got := renderTemplate(env, "{{ .Path }}", path) got := renderTemplateNoTrimSpace(env, "{{ .Path }}", path)
assert.Equal(t, "#", got) assert.Equal(t, "#", got)
} }
@ -1141,7 +1145,7 @@ func TestAgnosterPath(t *testing.T) {
} }
path.setPaths() path.setPaths()
path.setStyle() path.setStyle()
got := renderTemplate(env, "{{ .Path }}", path) got := renderTemplateNoTrimSpace(env, "{{ .Path }}", path)
assert.Equal(t, tc.Expected, got, tc.Case) assert.Equal(t, tc.Expected, got, tc.Case)
} }
} }
@ -1295,7 +1299,7 @@ func TestAgnosterLeftPath(t *testing.T) {
} }
path.setPaths() path.setPaths()
path.setStyle() path.setStyle()
got := renderTemplate(env, "{{ .Path }}", path) got := renderTemplateNoTrimSpace(env, "{{ .Path }}", path)
assert.Equal(t, tc.Expected, got, tc.Case) assert.Equal(t, tc.Expected, got, tc.Case)
} }
} }