aboutsummaryrefslogtreecommitdiff
path: root/internal/color/color_test.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-27 16:50:41 -0400
committerhistoria <[not public]>2026-06-27 16:50:41 -0400
commit988b006a5bb9edb6465653566e7bdf8175347b8c (patch)
tree3a1fceff2ee80c11b5dafcc49c13ababe021e880 /internal/color/color_test.go
parent1cab9ca20e24742f770a676f84e4ed9f1636f297 (diff)
downloadthehouseoficarus-988b006a5bb9edb6465653566e7bdf8175347b8c.tar.gz
feat: one-way map links, blocked paths on map, map grid startup validation, user colors for maps
Diffstat (limited to 'internal/color/color_test.go')
-rw-r--r--internal/color/color_test.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/internal/color/color_test.go b/internal/color/color_test.go
index c1f5e5b..bffc0d7 100644
--- a/internal/color/color_test.go
+++ b/internal/color/color_test.go
@@ -53,3 +53,67 @@ func TestWrapANSISplitsOnNewlines(t *testing.T) {
t.Errorf("WrapANSI newline handling = %q, want %q", got, want)
}
}
+
+func TestParseHexIndex(t *testing.T) {
+ cases := []struct {
+ in string
+ want int
+ }{
+ {"00", 0},
+ {"0F", 15},
+ {"0f", 15},
+ {"D0", 208},
+ {"FF", 255},
+ {"F", 15},
+ }
+ for _, c := range cases {
+ if got := Parse(c.in).Fg; got != c.want {
+ t.Errorf("Parse(%q).Fg = %d, want %d", c.in, got, c.want)
+ }
+ }
+}
+
+func TestParseHexRejectsInvalid(t *testing.T) {
+ for _, in := range []string{"ZZ", "100", "G1"} {
+ if got := Parse(in).Fg; got != -1 {
+ t.Errorf("Parse(%q).Fg = %d, want -1 (rejected)", in, got)
+ }
+ }
+}
+
+func TestParseHexBgAndGradient(t *testing.T) {
+ s := Parse("D0 bg:00 g:C4,52 bold")
+ if s.Fg != 208 {
+ t.Errorf("Fg = %d, want 208", s.Fg)
+ }
+ if s.Bg != 0 {
+ t.Errorf("Bg = %d, want 0", s.Bg)
+ }
+ if !s.Bold {
+ t.Error("Bold not set")
+ }
+ if len(s.Gradient) != 2 || s.Gradient[0] != 196 || s.Gradient[1] != 82 {
+ t.Errorf("Gradient = %v, want [196 82]", s.Gradient)
+ }
+}
+
+func TestAverage(t *testing.T) {
+ // black (0) and white (15) average to a mid grey.
+ mid := Average(Parse("00"), Parse("0F"))
+ if mid.Fg < 0 {
+ t.Fatalf("expected a foreground, got %d", mid.Fg)
+ }
+ r, g, b := Xterm256ToRGB(mid.Fg)
+ if r > 200 || r < 55 || g > 200 || g < 55 || b > 200 || b < 55 {
+ t.Errorf("midpoint of black/white not grey: rgb=%d,%d,%d (idx %d)", r, g, b, mid.Fg)
+ }
+
+ // one side colorless -> use the other.
+ if got := Average(NoColor(), Parse("D0")); got.Fg != 208 {
+ t.Errorf("Average(none, D0).Fg = %d, want 208", got.Fg)
+ }
+ // both colorless -> NoColor.
+ if got := Average(NoColor(), NoColor()); got.Fg != -1 {
+ t.Errorf("Average(none, none).Fg = %d, want -1", got.Fg)
+ }
+}