mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-27 02:51:44 -08:00
parent
9875de38d9
commit
8ed1c90c28
|
@ -58,10 +58,14 @@ func (p *properties) getColor(property Property, defaultValue string) string {
|
|||
return defaultValue
|
||||
}
|
||||
colorString := parseString(val, defaultValue)
|
||||
_, err := getColorFromName(colorString, false)
|
||||
if err == nil {
|
||||
return colorString
|
||||
}
|
||||
r := regexp.MustCompile(`(?P<color>#[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})`)
|
||||
match := r.FindStringSubmatch(colorString)
|
||||
if match != nil && match[0] != "" {
|
||||
return match[0]
|
||||
values := groupDict(r, colorString)
|
||||
if values != nil && values["color"] != "" {
|
||||
return values["color"]
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ func TestGetString(t *testing.T) {
|
|||
values: values,
|
||||
}
|
||||
value := properties.getString(TextProperty, "err")
|
||||
assert.Equal(t, value, expected)
|
||||
assert.Equal(t, expected, value)
|
||||
}
|
||||
|
||||
func TestGetStringNoEntry(t *testing.T) {
|
||||
|
@ -25,7 +25,7 @@ func TestGetStringNoEntry(t *testing.T) {
|
|||
values: values,
|
||||
}
|
||||
value := properties.getString(TextProperty, expected)
|
||||
assert.Equal(t, value, expected)
|
||||
assert.Equal(t, expected, value)
|
||||
}
|
||||
|
||||
func TestGetStringNoTextEntry(t *testing.T) {
|
||||
|
@ -34,17 +34,27 @@ func TestGetStringNoTextEntry(t *testing.T) {
|
|||
values: values,
|
||||
}
|
||||
value := properties.getString(TextProperty, expected)
|
||||
assert.Equal(t, value, expected)
|
||||
assert.Equal(t, expected, value)
|
||||
}
|
||||
|
||||
func TestGetColor(t *testing.T) {
|
||||
func TestGetHexColor(t *testing.T) {
|
||||
expected := expectedColor
|
||||
values := map[Property]interface{}{UserColor: expected}
|
||||
properties := properties{
|
||||
values: values,
|
||||
}
|
||||
value := properties.getColor(UserColor, "#789123")
|
||||
assert.Equal(t, value, expected)
|
||||
assert.Equal(t, expected, value)
|
||||
}
|
||||
|
||||
func TestGetColor(t *testing.T) {
|
||||
expected := "yellow"
|
||||
values := map[Property]interface{}{UserColor: expected}
|
||||
properties := properties{
|
||||
values: values,
|
||||
}
|
||||
value := properties.getColor(UserColor, "#789123")
|
||||
assert.Equal(t, expected, value)
|
||||
}
|
||||
|
||||
func TestDefaultColorWithInvalidColorCode(t *testing.T) {
|
||||
|
@ -54,7 +64,7 @@ func TestDefaultColorWithInvalidColorCode(t *testing.T) {
|
|||
values: values,
|
||||
}
|
||||
value := properties.getColor(UserColor, expected)
|
||||
assert.Equal(t, value, expected)
|
||||
assert.Equal(t, expected, value)
|
||||
}
|
||||
|
||||
func TestDefaultColorWithUnavailableProperty(t *testing.T) {
|
||||
|
@ -64,7 +74,7 @@ func TestDefaultColorWithUnavailableProperty(t *testing.T) {
|
|||
values: values,
|
||||
}
|
||||
value := properties.getColor(UserColor, expected)
|
||||
assert.Equal(t, value, expected)
|
||||
assert.Equal(t, expected, value)
|
||||
}
|
||||
|
||||
func TestGetBool(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue