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

Function TestTableWriter_BasicAlignment

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

Source from the content-addressed store, hash-verified

7)
8
9func TestTableWriter_BasicAlignment(t *testing.T) {
10 tw := NewTableWriter()
11 tw.AddHeader([]string{"ID", "TITLE", "STATUS"})
12 tw.AddSeparator()
13 tw.AddRow(
14 []string{"001", "Short", "pending"},
15 []string{"001", "Short", "pending"},
16 )
17 tw.AddRow(
18 []string{"002", "A much longer title", "in-progress"},
19 []string{"002", "A much longer title", "in-progress"},
20 )
21
22 var buf bytes.Buffer
23 tw.Flush(&buf)
24
25 lines := strings.Split(strings.TrimRight(buf.String(), "\n"), "\n")
26 if len(lines) != 4 {
27 t.Fatalf("expected 4 lines, got %d", len(lines))
28 }
29
30 // All lines should have the same visible width (trimmed trailing space aside)
31 // Check that separator dashes match column widths
32 sepCols := strings.Split(lines[1], " ")
33 if len(sepCols) != 3 {
34 t.Fatalf("expected 3 separator columns, got %d", len(sepCols))
35 }
36
37 // Separator for TITLE column should be at least as wide as "A much longer title"
38 titleSep := sepCols[1]
39 if len(titleSep) < len("A much longer title") {
40 t.Errorf("title separator %q (%d) shorter than longest value (%d)",
41 titleSep, len(titleSep), len("A much longer title"))
42 }
43}
44
45func TestTableWriter_ColorAlignment(t *testing.T) {
46 tw := NewTableWriter()

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected