Skip to content

Commit

Permalink
fix: agnoster_short with <1 depth
Browse files Browse the repository at this point in the history
  • Loading branch information
tradiff authored and JanDeDobbeleer committed Dec 24, 2020
1 parent c6a7a99 commit 7ff4954
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
3 changes: 3 additions & 0 deletions segment_path.go
Expand Up @@ -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)
}
Expand Down
54 changes: 54 additions & 0 deletions segment_path_test.go
Expand Up @@ -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)
Expand Down

0 comments on commit 7ff4954

Please sign in to comment.