Skip to content

Commit

Permalink
fix: allow 16 colors in override
Browse files Browse the repository at this point in the history
resolves #161
  • Loading branch information
JanDeDobbeleer committed Nov 15, 2020
1 parent 9875de3 commit 53ed65d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
10 changes: 7 additions & 3 deletions properties.go
Expand Up @@ -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
}
Expand Down
24 changes: 17 additions & 7 deletions properties_test.go
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 53ed65d

Please sign in to comment.