MCPcopy Create free account
hub / github.com/JordanCoin/codemap / TestDepsResolveRelative

Function TestDepsResolveRelative

scanner/deps_test.go:548–580  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

546}
547
548func TestDepsResolveRelative(t *testing.T) {
549 handlerPath := filepath.FromSlash("pkg/api/handler.go")
550 typesPath := filepath.FromSlash("pkg/common/types.go")
551 loggerPath := filepath.FromSlash("pkg/log/logger.go")
552
553 files := []FileInfo{
554 {Path: handlerPath},
555 {Path: typesPath},
556 {Path: loggerPath},
557 }
558 idx := buildFileIndex(files, "")
559
560 tests := []struct {
561 name string
562 imp string
563 fromDir string
564 want []string
565 }{
566 {name: "same directory file", imp: "./handler", fromDir: filepath.FromSlash("pkg/api"), want: []string{handlerPath}},
567 {name: "parent directory file", imp: "../common/types", fromDir: filepath.FromSlash("pkg/api"), want: []string{typesPath}},
568 {name: "two levels up", imp: "../../log/logger", fromDir: filepath.FromSlash("pkg/api/internal"), want: []string{loggerPath}},
569 {name: "missing file", imp: "./missing", fromDir: "pkg/api", want: nil},
570 }
571
572 for _, tt := range tests {
573 t.Run(tt.name, func(t *testing.T) {
574 got := resolveRelative(tt.imp, tt.fromDir, idx)
575 if !reflect.DeepEqual(got, tt.want) {
576 t.Fatalf("resolveRelative(%q, %q): want %v, got %v", tt.imp, tt.fromDir, tt.want, got)
577 }
578 })
579 }
580}
581
582func TestDepsFuzzyResolve(t *testing.T) {
583 goHandler := filepath.FromSlash("pkg/service/handler.go")

Callers

nothing calls this directly

Calls 2

buildFileIndexFunction · 0.85
resolveRelativeFunction · 0.85

Tested by

no test coverage detected