v0.1.3 ANSI 16 indices and RGB to 16

This commit is contained in:
lixen committed 2026-10-04 02:50:07 -04:00
1 parent 615e11bc78
commit d6ba8b2105
6 files changed
+75 -8

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
package color
import "testing"
// Each reference shade maps to its own index, so the constants, the table and
// the search agree; the named primaries land on the bright indices like xterm.
func TestRGBTo16MapsReferenceShadesToTheirIndex(t *testing.T) {
for i, c := range ansi16 {
if got := RGBTo16(c); got != uint8(i) {
t.Errorf("shade %d %s: index %d", i, c.Hex(), got)
}
}
for c, want := range map[RGB]uint8{Red: ANSIBrightRed, Black: ANSIBlack, White: ANSIBrightWhite, {170, 0, 0}: ANSIRed} {
if got := RGBTo16(c); got != want {
t.Errorf("%s: index %d, want %d", c.Hex(), got, want)
}
}
}