Skip to content

Commit 94ae5ed

Browse files
tradiffJanDeDobbeleer
authored andcommitted
fix: folder style not using folder_separator_icon
1 parent 9822227 commit 94ae5ed

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

src/segment_path.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ func (pt *path) getFullPath() string {
115115

116116
func (pt *path) getFolderPath() string {
117117
pwd := pt.getPwd()
118-
return base(pwd, pt.env)
118+
pwd = base(pwd, pt.env)
119+
return pt.replaceFolderSeparators(pwd)
119120
}
120121

121122
func (pt *path) getPwd() string {

src/segment_path_test.go

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ func TestGetAgnosterShortPathOneLevel(t *testing.T) {
449449
assert.Equal(t, "foo", got)
450450
}
451451

452+
// nolint:dupl // false positive
452453
func TestGetFullPath(t *testing.T) {
453454
cases := []struct {
454455
UseFolderSeparatorIcon bool
@@ -488,30 +489,44 @@ func TestGetFullPath(t *testing.T) {
488489
}
489490
}
490491

492+
// nolint:dupl // false positive
491493
func TestGetFolderPath(t *testing.T) {
492-
pwd := "/usr/home/projects"
493-
env := new(MockedEnvironment)
494-
env.On("getPathSeperator", nil).Return("/")
495-
env.On("homeDir", nil).Return("/usr/home")
496-
env.On("getcwd", nil).Return(pwd)
497-
path := &path{
498-
env: env,
494+
cases := []struct {
495+
UseFolderSeparatorIcon bool
496+
Pwd string
497+
Expected string
498+
}{
499+
{UseFolderSeparatorIcon: false, Pwd: "", Expected: "."},
500+
{UseFolderSeparatorIcon: false, Pwd: "/", Expected: "/"},
501+
{UseFolderSeparatorIcon: false, Pwd: "/usr/home", Expected: "~"},
502+
{UseFolderSeparatorIcon: false, Pwd: "/usr/home/abc", Expected: "abc"},
503+
{UseFolderSeparatorIcon: false, Pwd: "/a/b/c/d", Expected: "d"},
504+
505+
{UseFolderSeparatorIcon: true, Pwd: "", Expected: "."},
506+
{UseFolderSeparatorIcon: true, Pwd: "/", Expected: "|"},
507+
{UseFolderSeparatorIcon: true, Pwd: "/usr/home", Expected: "~"},
508+
{UseFolderSeparatorIcon: true, Pwd: "/usr/home/abc", Expected: "abc"},
509+
{UseFolderSeparatorIcon: true, Pwd: "/a/b/c/d", Expected: "d"},
499510
}
500-
got := path.getFolderPath()
501-
assert.Equal(t, "projects", got)
502-
}
503511

504-
func TestGetFolderPathInsideHome(t *testing.T) {
505-
pwd := "/usr/home"
506-
env := new(MockedEnvironment)
507-
env.On("getPathSeperator", nil).Return("/")
508-
env.On("homeDir", nil).Return("/usr/home")
509-
env.On("getcwd", nil).Return(pwd)
510-
path := &path{
511-
env: env,
512+
for _, tc := range cases {
513+
env := new(MockedEnvironment)
514+
env.On("getPathSeperator", nil).Return("/")
515+
env.On("homeDir", nil).Return("/usr/home")
516+
env.On("getcwd", nil).Return(tc.Pwd)
517+
props := map[Property]interface{}{}
518+
if tc.UseFolderSeparatorIcon {
519+
props[FolderSeparatorIcon] = "|"
520+
}
521+
path := &path{
522+
env: env,
523+
props: &properties{
524+
values: props,
525+
},
526+
}
527+
got := path.getFolderPath()
528+
assert.Equal(t, tc.Expected, got)
512529
}
513-
got := path.getFolderPath()
514-
assert.Equal(t, "~", got)
515530
}
516531

517532
func TestGetFolderPathCustomMappedLocations(t *testing.T) {

0 commit comments

Comments
 (0)