(t *testing.T)
| 288 | } |
| 289 | |
| 290 | func TestListCommand_SeparatorAlignment(t *testing.T) { |
| 291 | resetListFlags() |
| 292 | |
| 293 | tasks := []*model.Task{ |
| 294 | {ID: "001", Title: "A very long task title here", Status: model.StatusInProgress, Priority: model.PriorityHigh, FilePath: "tasks/cli/001.md"}, |
| 295 | {ID: "002", Title: "Short", Status: model.StatusPending, Priority: model.PriorityCritical, FilePath: "tasks/002.md"}, |
| 296 | } |
| 297 | |
| 298 | output := captureListTableOutput(t, tasks, "id,title,status,priority,file") |
| 299 | lines := strings.Split(strings.TrimSpace(output), "\n") |
| 300 | |
| 301 | if len(lines) < 3 { |
| 302 | t.Fatalf("Expected at least 3 lines (header, separator, data), got %d", len(lines)) |
| 303 | } |
| 304 | |
| 305 | // The separator is the second line. With tabwriter, columns are tab-aligned, |
| 306 | // so we check that each separator segment (dashes) is at least as wide as |
| 307 | // its corresponding header. |
| 308 | headerLine := lines[0] |
| 309 | separatorLine := lines[1] |
| 310 | |
| 311 | // tabwriter replaces tabs with spaces, so split on 2+ spaces |
| 312 | headerCols := splitTableColumns(headerLine) |
| 313 | sepCols := splitTableColumns(separatorLine) |
| 314 | |
| 315 | if len(headerCols) != len(sepCols) { |
| 316 | t.Fatalf("Header has %d columns, separator has %d columns", len(headerCols), len(sepCols)) |
| 317 | } |
| 318 | |
| 319 | for i, header := range headerCols { |
| 320 | sep := sepCols[i] |
| 321 | if len(sep) < len(header) { |
| 322 | t.Errorf("Separator column %d (%q, len=%d) is shorter than header (%q, len=%d)", |
| 323 | i, sep, len(sep), header, len(header)) |
| 324 | } |
| 325 | // Separator should be all dashes |
| 326 | if strings.Trim(sep, "-") != "" { |
| 327 | t.Errorf("Separator column %d should be all dashes, got %q", i, sep) |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | // Also verify that "title" separator matches the longest title, not just the header |
| 332 | titleIdx := -1 |
| 333 | for i, h := range headerCols { |
| 334 | if h == "title" { |
| 335 | titleIdx = i |
| 336 | break |
| 337 | } |
| 338 | } |
| 339 | if titleIdx >= 0 { |
| 340 | titleSep := sepCols[titleIdx] |
| 341 | longestTitle := "A very long task title here" |
| 342 | if len(titleSep) < len(longestTitle) { |
| 343 | t.Errorf("Title separator (%d dashes) should be at least as wide as longest title (%d chars)", |
| 344 | len(titleSep), len(longestTitle)) |
| 345 | } |
| 346 | } |
| 347 | } |
nothing calls this directly
no test coverage detected