Skip to content

Commit

Permalink
Standardize case for palette color names (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed May 19, 2021
1 parent 2072f11 commit 894e9bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gamut.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (g *Palette) AddColors(cc Colors) {
g.colors[c.Color] = append(g.colors[c.Color], c)
}

g.names[c.Name] = c.Color
g.names[strings.ToUpper(c.Name)] = c.Color
}
}

Expand All @@ -71,7 +71,7 @@ func (g Palette) Clamped(cc []color.Color) Colors {

// Color returns the color with a specific name
func (g Palette) Color(name string) (color.Color, bool) {
c, ok := g.names[name]
c, ok := g.names[strings.ToUpper(name)]
return c, ok
}

Expand Down
10 changes: 10 additions & 0 deletions gamut_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ func TestColor(t *testing.T) {
t.Errorf("Expected %s, got %s", exp.Hex(), cc.Hex())
}

// test case insensitivity
c, ok = p1.Color("spray")
if !ok {
t.Errorf("Expected ok to be true")
}

if exp.Hex() != cc.Hex() {
t.Errorf("Expected %s, got %s", exp.Hex(), cc.Hex())
}

_, ok = p1.Color("Foobar red")
if ok {
t.Errorf("Expected ok to be false")
Expand Down

0 comments on commit 894e9bd

Please sign in to comment.