From 4b71c2ba072743a6846124b614f7326612d2b4e9 Mon Sep 17 00:00:00 2001 From: "L. Yeung" Date: Thu, 11 May 2023 11:03:56 +0800 Subject: [PATCH] feat(path): respect `folder_separator_icon` in a colon-trailed root --- src/segments/path.go | 2 +- src/segments/path_test.go | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/segments/path.go b/src/segments/path.go index 64565370..2bc53a1d 100644 --- a/src/segments/path.go +++ b/src/segments/path.go @@ -145,7 +145,7 @@ func (pt *Path) setStyle() { if len(pt.relative) == 0 { pt.Path = pt.root if strings.HasSuffix(pt.Path, ":") { - pt.Path += pt.env.PathSeparator() + pt.Path += pt.getFolderSeparator() } return } diff --git a/src/segments/path_test.go b/src/segments/path_test.go index e5701e55..9fa6fbac 100644 --- a/src/segments/path_test.go +++ b/src/segments/path_test.go @@ -14,7 +14,7 @@ import ( 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 for _, call := range env.Mock.ExpectedCalls { if call.Method == "TemplateCache" { @@ -38,7 +38,11 @@ func renderTemplate(env *mock.MockedEnvironment, segmentTemplate string, context if err != nil { 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 ( @@ -333,7 +337,7 @@ func TestAgnosterPathStyles(t *testing.T) { }, { Style: Letter, - Expected: "C:\\", + Expected: "C: > ", HomePath: homeDirWindows, Pwd: "C:\\", GOOS: platform.WINDOWS, @@ -610,7 +614,7 @@ func TestAgnosterPathStyles(t *testing.T) { }, { Style: AgnosterShort, - Expected: "C:/", + Expected: "C: | ", HomePath: homeDir, Pwd: "/mnt/c", Pswd: "C:", @@ -641,7 +645,7 @@ func TestAgnosterPathStyles(t *testing.T) { }, { Style: AgnosterShort, - Expected: "C:\\", + Expected: "C: > ", HomePath: homeDirWindows, Pwd: "C:", GOOS: platform.WINDOWS, @@ -747,7 +751,7 @@ func TestAgnosterPathStyles(t *testing.T) { } path.setPaths() path.setStyle() - got := renderTemplate(env, "{{ .Path }}", path) + got := renderTemplateNoTrimSpace(env, "{{ .Path }}", path) assert.Equal(t, tc.Expected, got) } } @@ -877,7 +881,7 @@ func TestFullAndFolderPath(t *testing.T) { } path.setPaths() path.setStyle() - got := renderTemplate(env, tc.Template, path) + got := renderTemplateNoTrimSpace(env, tc.Template, path) assert.Equal(t, tc.Expected, got) } } @@ -932,7 +936,7 @@ func TestFullPathCustomMappedLocations(t *testing.T) { } path.setPaths() path.setStyle() - got := renderTemplate(env, "{{ .Path }}", path) + got := renderTemplateNoTrimSpace(env, "{{ .Path }}", path) assert.Equal(t, tc.Expected, got) } } @@ -960,7 +964,7 @@ func TestFolderPathCustomMappedLocations(t *testing.T) { } path.setPaths() path.setStyle() - got := renderTemplate(env, "{{ .Path }}", path) + got := renderTemplateNoTrimSpace(env, "{{ .Path }}", path) assert.Equal(t, "#", got) } @@ -1141,7 +1145,7 @@ func TestAgnosterPath(t *testing.T) { } path.setPaths() path.setStyle() - got := renderTemplate(env, "{{ .Path }}", path) + got := renderTemplateNoTrimSpace(env, "{{ .Path }}", path) assert.Equal(t, tc.Expected, got, tc.Case) } } @@ -1295,7 +1299,7 @@ func TestAgnosterLeftPath(t *testing.T) { } path.setPaths() path.setStyle() - got := renderTemplate(env, "{{ .Path }}", path) + got := renderTemplateNoTrimSpace(env, "{{ .Path }}", path) assert.Equal(t, tc.Expected, got, tc.Case) } }