diff --git a/properties.go b/properties.go index 589a7f87..045b224d 100644 --- a/properties.go +++ b/properties.go @@ -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#[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 } diff --git a/properties_test.go b/properties_test.go index f8eb15a6..e4f2744e 100644 --- a/properties_test.go +++ b/properties_test.go @@ -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) {