1package tui
2
3import (
4 "strings"
5 "testing"
6)
7
8func TestRenderMarkdownTableWrapsToWidth(t *testing.T) {
9 in := strings.Join([]string{
10 "| Area | What’s visible | Summary |",
11 "| --- | --- | --- |",
12 "| Overall UI | Dark terminal/TUI-style interface | A screenshot of an AI/coding-agent session, likely inside zut or a similar terminal app. |",
13 "| Main content | Markdown-formatted response | The assistant is describing what was seen in a previous screenshot. |",
14 }, "\n")
15 out := RenderMarkdown(in, Dark, 80)
16 plain := stripANSI(out)
17 lines := strings.Split(plain, "\n")
18 if len(lines) <= 4 {
19 t.Fatalf("expected wrapped table rows, got:\n%s", plain)
20 }
21 for i, line := range lines {
22 if visibleWidth(line) > 80 {
23 t.Fatalf("line %d width %d > 80: %q\n%s", i, visibleWidth(line), line, plain)
24 }
25 }
26 want := pipePositions(lines[0])
27 for i, line := range lines[1:] {
28 if got := pipePositions(line); !equalInts(got, want) {
29 t.Fatalf("line %d pipe columns %v, want %v: %q\n%s", i+1, got, want, line, plain)
30 }
31 }
32}
33
34func TestRenderMarkdownTableAlignsColumns(t *testing.T) {
35 in := strings.Join([]string{
36 "| Tool | Core-Sprache | Runtime/Distribution |",
37 "| --- | --- | --- |",
38 "| Claude Code | TypeScript | Node.js |",
39 "| Codex CLI | Rust | Natives Binary (npm-Wrapper) |",
40 "| OpenCode | TypeScript (+ Go für TUI) | Bun, kompiliertes Binary |",
41 "| zut | Go | Natives Binary |",
42 }, "\n")
43 out := RenderMarkdown(in, Dark, 80)
44 plain := stripANSI(out)
45 lines := strings.Split(plain, "\n")
46 if len(lines) != 6 {
47 t.Fatalf("got %d lines:\n%s", len(lines), plain)
48 }
49 counts := make([]int, len(lines))
50 for i, line := range lines {
51 counts[i] = strings.Count(line, "|")
52 if counts[i] != 4 {
53 t.Fatalf("line %d has %d pipes, want 4: %q\n%s", i, counts[i], line, plain)
54 }
55 }
56 // Every pipe column should line up across all rows.
57 want := pipePositions(lines[0])
58 for i, line := range lines[1:] {
59 if got := pipePositions(line); !equalInts(got, want) {
60 t.Fatalf("line %d pipe columns %v, want %v: %q\n%s", i+1, got, want, line, plain)
61 }
62 }
63}
64
65func pipePositions(s string) []int {
66 var out []int
67 for i, r := range []rune(s) {
68 if r == '|' {
69 out = append(out, i)
70 }
71 }
72 return out
73}
74
75func equalInts(a, b []int) bool {
76 if len(a) != len(b) {
77 return false
78 }
79 for i := range a {
80 if a[i] != b[i] {
81 return false
82 }
83 }
84 return true
85}