fix: agnoster_short with <1 depth

This commit is contained in:
TravisTX 2020-12-24 09:00:10 -07:00 committed by Jan De Dobbeleer
parent c6a7a9958a
commit 7ff4954766
2 changed files with 57 additions and 0 deletions

View file

@ -135,6 +135,9 @@ func (pt *path) getAgnosterShortPath() string {
root := pt.rootLocation()
base := base(pt.env.getcwd(), pt.env)
pathDepth := pt.pathDepth(pt.getShortPath())
if pathDepth <= 0 {
return root
}
if pathDepth == 1 {
return fmt.Sprintf("%s%s%s", root, folderSeparator, base)
}

View file

@ -448,6 +448,60 @@ func TestGetAgnosterShortPathInsideHomeOneLevel(t *testing.T) {
assert.Equal(t, "~ > projects", got)
}
func TestGetAgnosterShortPathZeroLevelsWindows(t *testing.T) {
pwd := "C:"
env := new(MockedEnvironment)
env.On("getPathSeperator", nil).Return("\\")
env.On("homeDir", nil).Return(homeBillWindows)
env.On("getcwd", nil).Return(pwd)
path := &path{
env: env,
props: &properties{
values: map[Property]interface{}{
FolderSeparatorIcon: " > ",
},
},
}
got := path.getAgnosterShortPath()
assert.Equal(t, "C:", got)
}
func TestGetAgnosterShortPathZeroLevelsLinux(t *testing.T) {
pwd := "/"
env := new(MockedEnvironment)
env.On("getPathSeperator", nil).Return("/")
env.On("homeDir", nil).Return(homeBillWindows)
env.On("getcwd", nil).Return(pwd)
path := &path{
env: env,
props: &properties{
values: map[Property]interface{}{
FolderSeparatorIcon: " > ",
},
},
}
got := path.getAgnosterShortPath()
assert.Equal(t, "", got)
}
func TestGetAgnosterShortPathOneLevel(t *testing.T) {
pwd := "/foo"
env := new(MockedEnvironment)
env.On("getPathSeperator", nil).Return("/")
env.On("homeDir", nil).Return(homeBillWindows)
env.On("getcwd", nil).Return(pwd)
path := &path{
env: env,
props: &properties{
values: map[Property]interface{}{
FolderSeparatorIcon: " > ",
},
},
}
got := path.getAgnosterShortPath()
assert.Equal(t, "foo", got)
}
func TestGetFolderPath(t *testing.T) {
pwd := "/usr/home/projects"
env := new(MockedEnvironment)