(t *testing.T)
| 615 | } |
| 616 | |
| 617 | func TestFindFilePathMatch(t *testing.T) { |
| 618 | tasks := []*model.Task{ |
| 619 | {ID: "001", Title: "Task A", FilePath: "cli/001-setup.md"}, |
| 620 | {ID: "002", Title: "Task B", FilePath: "backend/002-api.md"}, |
| 621 | {ID: "003", Title: "Task C", FilePath: "cli/003-shared.md"}, |
| 622 | {ID: "004", Title: "Task D", FilePath: "backend/003-shared.md"}, |
| 623 | } |
| 624 | |
| 625 | // Exact full path match |
| 626 | task, err := findFilePathMatch("cli/001-setup.md", tasks) |
| 627 | if err != nil { |
| 628 | t.Fatalf("unexpected error: %v", err) |
| 629 | } |
| 630 | if task == nil || task.ID != "001" { |
| 631 | t.Error("Expected exact path match to find task 001") |
| 632 | } |
| 633 | |
| 634 | // Filename with extension (unique) |
| 635 | task, err = findFilePathMatch("002-api.md", tasks) |
| 636 | if err != nil { |
| 637 | t.Fatalf("unexpected error: %v", err) |
| 638 | } |
| 639 | if task == nil || task.ID != "002" { |
| 640 | t.Error("Expected filename match to find task 002") |
| 641 | } |
| 642 | |
| 643 | // Filename without extension (unique) |
| 644 | task, err = findFilePathMatch("001-setup", tasks) |
| 645 | if err != nil { |
| 646 | t.Fatalf("unexpected error: %v", err) |
| 647 | } |
| 648 | if task == nil || task.ID != "001" { |
| 649 | t.Error("Expected filename without extension to find task 001") |
| 650 | } |
| 651 | |
| 652 | // Ambiguous filename |
| 653 | task, err = findFilePathMatch("003-shared.md", tasks) |
| 654 | if err == nil { |
| 655 | t.Fatal("Expected error for ambiguous filename") |
| 656 | } |
| 657 | if !strings.Contains(err.Error(), "ambiguous") { |
| 658 | t.Errorf("Expected 'ambiguous' error, got: %v", err) |
| 659 | } |
| 660 | if task != nil { |
| 661 | t.Error("Expected nil task for ambiguous match") |
| 662 | } |
| 663 | |
| 664 | // No match |
| 665 | task, err = findFilePathMatch("nonexistent.md", tasks) |
| 666 | if err != nil { |
| 667 | t.Fatalf("unexpected error: %v", err) |
| 668 | } |
| 669 | if task != nil { |
| 670 | t.Error("Expected nil for no match") |
| 671 | } |
| 672 | |
| 673 | // Exact path takes priority over ambiguous filename |
| 674 | task, err = findFilePathMatch("cli/003-shared.md", tasks) |
nothing calls this directly
no test coverage detected