fix: folder style not using folder_separator_icon

This commit is contained in:
TravisTX 2021-01-03 09:21:17 -07:00 committed by Jan De Dobbeleer
parent 9822227a5e
commit 94ae5ed0b4
2 changed files with 38 additions and 22 deletions

View file

@ -115,7 +115,8 @@ func (pt *path) getFullPath() string {
func (pt *path) getFolderPath() string { func (pt *path) getFolderPath() string {
pwd := pt.getPwd() pwd := pt.getPwd()
return base(pwd, pt.env) pwd = base(pwd, pt.env)
return pt.replaceFolderSeparators(pwd)
} }
func (pt *path) getPwd() string { func (pt *path) getPwd() string {

View file

@ -449,6 +449,7 @@ func TestGetAgnosterShortPathOneLevel(t *testing.T) {
assert.Equal(t, "foo", got) assert.Equal(t, "foo", got)
} }
// nolint:dupl // false positive
func TestGetFullPath(t *testing.T) { func TestGetFullPath(t *testing.T) {
cases := []struct { cases := []struct {
UseFolderSeparatorIcon bool UseFolderSeparatorIcon bool
@ -488,30 +489,44 @@ func TestGetFullPath(t *testing.T) {
} }
} }
// nolint:dupl // false positive
func TestGetFolderPath(t *testing.T) { func TestGetFolderPath(t *testing.T) {
pwd := "/usr/home/projects" cases := []struct {
env := new(MockedEnvironment) UseFolderSeparatorIcon bool
env.On("getPathSeperator", nil).Return("/") Pwd string
env.On("homeDir", nil).Return("/usr/home") Expected string
env.On("getcwd", nil).Return(pwd) }{
path := &path{ {UseFolderSeparatorIcon: false, Pwd: "", Expected: "."},
env: env, {UseFolderSeparatorIcon: false, Pwd: "/", Expected: "/"},
} {UseFolderSeparatorIcon: false, Pwd: "/usr/home", Expected: "~"},
got := path.getFolderPath() {UseFolderSeparatorIcon: false, Pwd: "/usr/home/abc", Expected: "abc"},
assert.Equal(t, "projects", got) {UseFolderSeparatorIcon: false, Pwd: "/a/b/c/d", Expected: "d"},
}
func TestGetFolderPathInsideHome(t *testing.T) { {UseFolderSeparatorIcon: true, Pwd: "", Expected: "."},
pwd := "/usr/home" {UseFolderSeparatorIcon: true, Pwd: "/", Expected: "|"},
env := new(MockedEnvironment) {UseFolderSeparatorIcon: true, Pwd: "/usr/home", Expected: "~"},
env.On("getPathSeperator", nil).Return("/") {UseFolderSeparatorIcon: true, Pwd: "/usr/home/abc", Expected: "abc"},
env.On("homeDir", nil).Return("/usr/home") {UseFolderSeparatorIcon: true, Pwd: "/a/b/c/d", Expected: "d"},
env.On("getcwd", nil).Return(pwd) }
path := &path{
env: env, for _, tc := range cases {
env := new(MockedEnvironment)
env.On("getPathSeperator", nil).Return("/")
env.On("homeDir", nil).Return("/usr/home")
env.On("getcwd", nil).Return(tc.Pwd)
props := map[Property]interface{}{}
if tc.UseFolderSeparatorIcon {
props[FolderSeparatorIcon] = "|"
}
path := &path{
env: env,
props: &properties{
values: props,
},
}
got := path.getFolderPath()
assert.Equal(t, tc.Expected, got)
} }
got := path.getFolderPath()
assert.Equal(t, "~", got)
} }
func TestGetFolderPathCustomMappedLocations(t *testing.T) { func TestGetFolderPathCustomMappedLocations(t *testing.T) {