(t *testing.T)
| 432 | } |
| 433 | |
| 434 | func TestResolvePathAlias(t *testing.T) { |
| 435 | // Build a simple file index |
| 436 | files := []FileInfo{ |
| 437 | {Path: "src/modules/auth/index.ts"}, |
| 438 | {Path: "src/modules/auth/login.ts"}, |
| 439 | {Path: "src/shared/utils/helpers.ts"}, |
| 440 | {Path: "src/utils/index.ts"}, |
| 441 | } |
| 442 | idx := buildFileIndex(files, "") |
| 443 | |
| 444 | pathAliases := map[string][]string{ |
| 445 | "@modules/*": {"src/modules/*"}, |
| 446 | "@shared/*": {"src/shared/*"}, |
| 447 | "@utils": {"src/utils/index"}, |
| 448 | } |
| 449 | |
| 450 | tests := []struct { |
| 451 | name string |
| 452 | imp string |
| 453 | expected string |
| 454 | }{ |
| 455 | {"wildcard alias", "@modules/auth/login", "src/modules/auth/login.ts"}, |
| 456 | {"wildcard with index", "@modules/auth", "src/modules/auth/index.ts"}, |
| 457 | {"nested wildcard", "@shared/utils/helpers", "src/shared/utils/helpers.ts"}, |
| 458 | {"exact alias", "@utils", "src/utils/index.ts"}, |
| 459 | } |
| 460 | |
| 461 | for _, tt := range tests { |
| 462 | t.Run(tt.name, func(t *testing.T) { |
| 463 | result := resolvePathAlias(tt.imp, pathAliases, ".", idx) |
| 464 | if len(result) == 0 { |
| 465 | t.Errorf("Expected to resolve %q, got no results", tt.imp) |
| 466 | return |
| 467 | } |
| 468 | if result[0] != tt.expected { |
| 469 | t.Errorf("Expected %q to resolve to %q, got %q", tt.imp, tt.expected, result[0]) |
| 470 | } |
| 471 | }) |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | func TestResolvePathAliasNoMatch(t *testing.T) { |
| 476 | files := []FileInfo{ |
nothing calls this directly
no test coverage detected