MCPcopy Create free account
hub / github.com/driangle/taskmd / TestTableWriter_ColorAlignment

Function TestTableWriter_ColorAlignment

apps/cli/internal/cli/tablewriter_test.go:45–87  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

43}
44
45func TestTableWriter_ColorAlignment(t *testing.T) {
46 tw := NewTableWriter()
47 tw.AddHeader([]string{"ID", "STATUS"})
48 tw.AddSeparator()
49
50 // Simulate colored values (ANSI codes add invisible bytes)
51 tw.AddRow(
52 []string{"001", "pending"},
53 []string{"\x1b[36m001\x1b[0m", "\x1b[33mpending\x1b[0m"},
54 )
55 tw.AddRow(
56 []string{"002", "in-progress"},
57 []string{"\x1b[36m002\x1b[0m", "\x1b[32min-progress\x1b[0m"},
58 )
59
60 var colorBuf bytes.Buffer
61 tw.Flush(&colorBuf)
62
63 // Build the same table without color for comparison
64 tw2 := NewTableWriter()
65 tw2.AddHeader([]string{"ID", "STATUS"})
66 tw2.AddSeparator()
67 tw2.AddRow([]string{"001", "pending"}, []string{"001", "pending"})
68 tw2.AddRow([]string{"002", "in-progress"}, []string{"002", "in-progress"})
69
70 var plainBuf bytes.Buffer
71 tw2.Flush(&plainBuf)
72
73 colorLines := strings.Split(strings.TrimRight(colorBuf.String(), "\n"), "\n")
74 plainLines := strings.Split(strings.TrimRight(plainBuf.String(), "\n"), "\n")
75
76 if len(colorLines) != len(plainLines) {
77 t.Fatalf("line count mismatch: color=%d, plain=%d", len(colorLines), len(plainLines))
78 }
79
80 // After stripping ANSI, each line should have the same visible content as the plain version
81 for i := range colorLines {
82 stripped := StripANSI(colorLines[i])
83 if stripped != plainLines[i] {
84 t.Errorf("line %d mismatch:\n stripped: %q\n plain: %q", i, stripped, plainLines[i])
85 }
86 }
87}
88
89func TestTableWriter_EmptyTable(t *testing.T) {
90 tw := NewTableWriter()

Callers

nothing calls this directly

Calls 6

AddHeaderMethod · 0.95
AddSeparatorMethod · 0.95
AddRowMethod · 0.95
FlushMethod · 0.95
NewTableWriterFunction · 0.85
StripANSIFunction · 0.85

Tested by

no test coverage detected