fix: allow 16 colors in override

resolves #161
This commit is contained in:
Jan De Dobbeleer 2020-11-15 14:32:07 +01:00 committed by Jan De Dobbeleer
parent 9875de38d9
commit 8ed1c90c28
2 changed files with 24 additions and 10 deletions

View file

@ -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
}

View file

@ -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) {