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

Function TestTryDirMatch

scanner/filegraph_test.go:342–394  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

340}
341
342func TestTryDirMatch(t *testing.T) {
343 files := []FileInfo{
344 {Path: filepath.Join("MyApp", "Models", "User.cs")},
345 {Path: filepath.Join("MyApp", "Models", "Product.cs")},
346 {Path: filepath.Join("MyApp", "Services", "UserService.cs")},
347 }
348 idx := buildFileIndex(files, "")
349
350 t.Run("matches directory with multiple files", func(t *testing.T) {
351 got := tryDirMatch(filepath.Join("MyApp", "Models"), idx)
352 sort.Strings(got)
353 want := []string{
354 filepath.Join("MyApp", "Models", "Product.cs"),
355 filepath.Join("MyApp", "Models", "User.cs"),
356 }
357 if !reflect.DeepEqual(got, want) {
358 t.Errorf("tryDirMatch = %v, want %v", got, want)
359 }
360 })
361
362 t.Run("matches directory with single file", func(t *testing.T) {
363 got := tryDirMatch(filepath.Join("MyApp", "Services"), idx)
364 want := []string{filepath.Join("MyApp", "Services", "UserService.cs")}
365 if !reflect.DeepEqual(got, want) {
366 t.Errorf("tryDirMatch = %v, want %v", got, want)
367 }
368 })
369
370 t.Run("suffix match strips namespace prefix", func(t *testing.T) {
371 // Files are in Models/ but namespace is ProjectName/Models
372 files2 := []FileInfo{
373 {Path: filepath.Join("Models", "User.cs")},
374 {Path: filepath.Join("Models", "Product.cs")},
375 }
376 idx2 := buildFileIndex(files2, "")
377 got := tryDirMatch(filepath.Join("ProjectName", "Models"), idx2)
378 sort.Strings(got)
379 want := []string{
380 filepath.Join("Models", "Product.cs"),
381 filepath.Join("Models", "User.cs"),
382 }
383 if !reflect.DeepEqual(got, want) {
384 t.Errorf("tryDirMatch suffix = %v, want %v", got, want)
385 }
386 })
387
388 t.Run("no match for missing directory", func(t *testing.T) {
389 got := tryDirMatch(filepath.Join("MyApp", "Missing"), idx)
390 if got != nil {
391 t.Errorf("expected nil, got %v", got)
392 }
393 })
394}
395
396func TestFuzzyResolveCsharpNamespace(t *testing.T) {
397 userCS := filepath.Join("MyApp", "Models", "User.cs")

Callers

nothing calls this directly

Calls 2

buildFileIndexFunction · 0.85
tryDirMatchFunction · 0.85

Tested by

no test coverage detected