(t *testing.T)
| 43 | } |
| 44 | |
| 45 | func 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 | |
| 89 | func TestTableWriter_EmptyTable(t *testing.T) { |
| 90 | tw := NewTableWriter() |
nothing calls this directly
no test coverage detected