mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
parent
1b0ceaff70
commit
fb83354186
|
@ -121,12 +121,17 @@ func (p *properties) getInt(property Property, defaultValue int) int {
|
|||
return defaultValue
|
||||
}
|
||||
|
||||
intValue, ok := val.(int)
|
||||
if intValue, ok := val.(int); ok {
|
||||
return intValue
|
||||
}
|
||||
|
||||
// json parses a float
|
||||
intValue, ok := val.(float64)
|
||||
if !ok {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
return intValue
|
||||
return int(intValue)
|
||||
}
|
||||
|
||||
func (p *properties) getKeyValueMap(property Property, defaultValue map[string]string) map[string]string {
|
||||
|
|
|
@ -342,7 +342,7 @@ func (g *git) getGitHEADContext(ref string) string {
|
|||
|
||||
func (g *git) truncateBranch(branch string) string {
|
||||
maxLength := g.props.getInt(BranchMaxLength, 0)
|
||||
if maxLength == 0 {
|
||||
if maxLength == 0 || len(branch) < maxLength {
|
||||
return branch
|
||||
}
|
||||
return branch[0:maxLength]
|
||||
|
|
|
@ -778,9 +778,10 @@ func TestTruncateBranch(t *testing.T) {
|
|||
MaxLength interface{}
|
||||
}{
|
||||
{Case: "No limit", Expected: "all-your-base-are-belong-to-us", Branch: "all-your-base-are-belong-to-us"},
|
||||
{Case: "No limit - larger", Expected: "all-your-base", Branch: "all-your-base-are-belong-to-us", MaxLength: 13},
|
||||
{Case: "No limit - smaller", Expected: "all-your-base", Branch: "all-your-base", MaxLength: 13},
|
||||
{Case: "No limit - larger", Expected: "all-your-base", Branch: "all-your-base-are-belong-to-us", MaxLength: 13.0},
|
||||
{Case: "No limit - smaller", Expected: "all-your-base", Branch: "all-your-base", MaxLength: 13.0},
|
||||
{Case: "Invalid setting", Expected: "all-your-base", Branch: "all-your-base", MaxLength: "burp"},
|
||||
{Case: "Lower than limit", Expected: "all-your-base", Branch: "all-your-base", MaxLength: 20.0},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
|
|
Loading…
Reference in a new issue