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