(t *testing.T)
| 7 | ) |
| 8 | |
| 9 | func 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 | |
| 45 | func TestTableWriter_ColorAlignment(t *testing.T) { |
| 46 | tw := NewTableWriter() |
nothing calls this directly
no test coverage detected