summaryrefslogtreecommitdiff
path: root/internal/ui/theme_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-08 22:25:36 +0300
committerPaul Buetow <paul@buetow.org>2026-04-08 22:25:36 +0300
commit38b276bb3d5be12a63d9bab3fe927803e2c4315c (patch)
treee8820c3508b5b9350a90d05508f3317c9dec0a3e /internal/ui/theme_test.go
parenta2335b65b2ccf7e6ffc440ca3d61dd6bec9e9163 (diff)
Fix task f random theme contrast
Diffstat (limited to 'internal/ui/theme_test.go')
-rw-r--r--internal/ui/theme_test.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/internal/ui/theme_test.go b/internal/ui/theme_test.go
new file mode 100644
index 0000000..5fa6955
--- /dev/null
+++ b/internal/ui/theme_test.go
@@ -0,0 +1,35 @@
+package ui
+
+import (
+ "strconv"
+ "testing"
+)
+
+func TestContrastColorUsesHighContrastForeground(t *testing.T) {
+ for bg := 0; bg < 256; bg++ {
+ fg := contrastColor(strconv.Itoa(bg))
+ if fg != "0" && fg != "15" {
+ t.Fatalf("contrastColor(%d) = %q, want black or white foreground", bg, fg)
+ }
+
+ r, g, b := xtermRGB(bg)
+ var ratio float64
+ if fg == "0" {
+ ratio = contrastRatio(r, g, b, 0, 0, 0)
+ } else {
+ ratio = contrastRatio(r, g, b, 255, 255, 255)
+ }
+ if ratio < 4.5 {
+ t.Fatalf("contrastColor(%d) = %q with contrast ratio %.2f, want >= 4.5", bg, fg, ratio)
+ }
+ }
+}
+
+func TestContrastColorFallsBackForInvalidInput(t *testing.T) {
+ tests := []string{"not-a-color", "-1", "256"}
+ for _, input := range tests {
+ if got := contrastColor(input); got != "15" {
+ t.Fatalf("contrastColor(%q) = %q, want 15", input, got)
+ }
+ }
+}