(t *testing.T)
| 392 | } |
| 393 | |
| 394 | func TestListCommand_LimitFlag(t *testing.T) { |
| 395 | tasks := []*model.Task{ |
| 396 | {ID: "001", Title: "A", Status: model.StatusPending, Priority: model.PriorityLow, FilePath: "a.md"}, |
| 397 | {ID: "002", Title: "B", Status: model.StatusPending, Priority: model.PriorityHigh, FilePath: "b.md"}, |
| 398 | {ID: "003", Title: "C", Status: model.StatusPending, Priority: model.PriorityCritical, FilePath: "c.md"}, |
| 399 | {ID: "004", Title: "D", Status: model.StatusPending, Priority: model.PriorityMedium, FilePath: "d.md"}, |
| 400 | {ID: "005", Title: "E", Status: model.StatusPending, Priority: model.PriorityLow, FilePath: "e.md"}, |
| 401 | } |
| 402 | |
| 403 | tests := []struct { |
| 404 | name string |
| 405 | limit int |
| 406 | sort string |
| 407 | expectedCount int |
| 408 | firstID string |
| 409 | }{ |
| 410 | {"no limit", 0, "", 5, "001"}, |
| 411 | {"limit less than total", 3, "", 3, "001"}, |
| 412 | {"limit equal to total", 5, "", 5, "001"}, |
| 413 | {"limit greater than total", 10, "", 5, "001"}, |
| 414 | {"limit 1", 1, "", 1, "001"}, |
| 415 | {"limit with sort by priority", 2, "priority", 2, "003"}, |
| 416 | } |
| 417 | |
| 418 | for _, tt := range tests { |
| 419 | t.Run(tt.name, func(t *testing.T) { |
| 420 | resetListFlags() |
| 421 | listLimit = tt.limit |
| 422 | |
| 423 | tasksCopy := make([]*model.Task, len(tasks)) |
| 424 | copy(tasksCopy, tasks) |
| 425 | |
| 426 | if tt.sort != "" { |
| 427 | if err := sortTasks(tasksCopy, tt.sort); err != nil { |
| 428 | t.Fatalf("sortTasks() error: %v", err) |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | if listLimit > 0 && listLimit < len(tasksCopy) { |
| 433 | tasksCopy = tasksCopy[:listLimit] |
| 434 | } |
| 435 | |
| 436 | if len(tasksCopy) != tt.expectedCount { |
| 437 | t.Errorf("got %d tasks, want %d", len(tasksCopy), tt.expectedCount) |
| 438 | } |
| 439 | if tasksCopy[0].ID != tt.firstID { |
| 440 | t.Errorf("first task ID = %s, want %s", tasksCopy[0].ID, tt.firstID) |
| 441 | } |
| 442 | }) |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | func TestListCommand_LimitTableOutput(t *testing.T) { |
| 447 | resetListFlags() |
nothing calls this directly
no test coverage detected