mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-27 11:01:00 -08:00
fix: agnoster_short with <1 depth
This commit is contained in:
parent
c6a7a9958a
commit
7ff4954766
|
@ -135,6 +135,9 @@ func (pt *path) getAgnosterShortPath() string {
|
||||||
root := pt.rootLocation()
|
root := pt.rootLocation()
|
||||||
base := base(pt.env.getcwd(), pt.env)
|
base := base(pt.env.getcwd(), pt.env)
|
||||||
pathDepth := pt.pathDepth(pt.getShortPath())
|
pathDepth := pt.pathDepth(pt.getShortPath())
|
||||||
|
if pathDepth <= 0 {
|
||||||
|
return root
|
||||||
|
}
|
||||||
if pathDepth == 1 {
|
if pathDepth == 1 {
|
||||||
return fmt.Sprintf("%s%s%s", root, folderSeparator, base)
|
return fmt.Sprintf("%s%s%s", root, folderSeparator, base)
|
||||||
}
|
}
|
||||||
|
|
|
@ -448,6 +448,60 @@ func TestGetAgnosterShortPathInsideHomeOneLevel(t *testing.T) {
|
||||||
assert.Equal(t, "~ > projects", got)
|
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) {
|
func TestGetFolderPath(t *testing.T) {
|
||||||
pwd := "/usr/home/projects"
|
pwd := "/usr/home/projects"
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
|
|
Loading…
Reference in a new issue