Skip to content

Commit f177de4

Browse files
committed
test(color): Name() must be stable for gray/grey aliases
1 parent d3a071c commit f177de4

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

‎color/color_test.go‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,32 @@ func TestColorString(t *testing.T) {
232232
t.Errorf("wrong string for red: %q", s)
233233
}
234234
}
235+
236+
// TestColorNameAliases verifies that colors with more than one W3C name
237+
// (e.g. "gray" and "grey") always report the same name.
238+
func TestColorNameAliases(t *testing.T) {
239+
cases := []struct {
240+
c Color
241+
name string
242+
}{
243+
{Gray, "gray"},
244+
{DarkGray, "darkgray"},
245+
{DarkSlateGray, "darkslategray"},
246+
{DimGray, "dimgray"},
247+
{LightGray, "lightgray"},
248+
{LightSlateGray, "lightslategray"},
249+
{SlateGray, "slategray"},
250+
}
251+
for _, cs := range cases {
252+
t.Run(cs.name, func(t *testing.T) {
253+
for i := 0; i < 200; i++ {
254+
if got := cs.c.Name(); got != cs.name {
255+
t.Fatalf("iteration %d: Name() = %q, want %q", i, got, cs.name)
256+
}
257+
if got := cs.c.String(); got != cs.name {
258+
t.Fatalf("iteration %d: String() = %q, want %q", i, got, cs.name)
259+
}
260+
}
261+
})
262+
}
263+
}

0 commit comments

Comments
 (0)