aboutsummaryrefslogtreecommitdiff
path: root/internal/color/color_test.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-25 04:46:40 -0400
committerhistoria <[not public]>2026-06-25 04:46:40 -0400
commit2725e2927a1595c7b100d942d1f14146252adeb7 (patch)
treee8bc2292634a2d686c751981ddb3097517cccc6a /internal/color/color_test.go
parent94a06fbbe682701ca4d4bd2a70cd74d8df29c932 (diff)
downloadthehouseoficarus-2725e2927a1595c7b100d942d1f14146252adeb7.tar.gz
feat: who, global chat, removed redundant YAML IDs
Diffstat (limited to 'internal/color/color_test.go')
-rw-r--r--internal/color/color_test.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/internal/color/color_test.go b/internal/color/color_test.go
new file mode 100644
index 0000000..c1f5e5b
--- /dev/null
+++ b/internal/color/color_test.go
@@ -0,0 +1,55 @@
+package color
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestWrapANSIDisabled(t *testing.T) {
+ s := "this is a very long line that would normally be wrapped if enabled"
+ if got := WrapANSI(s, 0); got != s {
+ t.Errorf("WrapANSI(_, 0) = %q, want unchanged", got)
+ }
+}
+
+func TestWrapANSIShortLineUntouched(t *testing.T) {
+ s := " indented menu item"
+ if got := WrapANSI(s, 80); got != s {
+ t.Errorf("short line was modified: got %q, want %q", got, s)
+ }
+}
+
+func TestWrapANSIWrapsLongLine(t *testing.T) {
+ s := "alpha bravo charlie delta echo foxtrot golf hotel india juliet"
+ got := WrapANSI(s, 20)
+ lines := strings.Split(got, "\r\n")
+ if len(lines) < 2 {
+ t.Fatalf("expected multiple lines, got %d: %q", len(lines), got)
+ }
+ for _, l := range lines {
+ if VisibleLen(l) > 20 {
+ t.Errorf("line exceeds width: %q (%d)", l, VisibleLen(l))
+ }
+ }
+ if strings.Join(strings.Fields(got), " ") != s {
+ t.Errorf("words not preserved: %q", got)
+ }
+}
+
+func TestWrapANSIIgnoresColorCodes(t *testing.T) {
+ colored := FgCode("xterm256", 182) + "hello world" + Reset
+ if VisibleLen(colored) > 80 {
+ t.Fatalf("test setup wrong, visible len = %d", VisibleLen(colored))
+ }
+ if got := WrapANSI(colored, 80); got != colored {
+ t.Errorf("colored line within width was wrapped: %q", got)
+ }
+}
+
+func TestWrapANSISplitsOnNewlines(t *testing.T) {
+ got := WrapANSI("first line\nsecond line", 80)
+ want := "first line\r\nsecond line"
+ if got != want {
+ t.Errorf("WrapANSI newline handling = %q, want %q", got, want)
+ }
+}