返回 DeepSeek-Reasonix
matcher_test.go
根目录 / internal / pathidentity / matcher_test.go
1 package pathidentity
2
3 import (
4 "os"
5 "path/filepath"
6 "testing"
7 )
8
9 func TestMatcherResolvesEachDistinctPathOnce(t *testing.T) {
10 base := t.TempDir()
11 dirs := []string{}
12 for _, name := range []string{"a", "b", "c", "d"} {
13 dir := filepath.Join(base, name)
14 if err := os.Mkdir(dir, 0o755); err != nil {
15 t.Fatal(err)
16 }
17 dirs = append(dirs, dir)
18 }
19 alias := filepath.Join(base, "alias")
20 if err := os.Symlink(dirs[2], alias); err != nil {
21 t.Skipf("symlink unavailable: %v", err)
22 }
23 dirs = append(dirs, alias, filepath.Join(base, "missing"))
24 calls := map[string]int{}
25 matcher := NewMatcher(Options{FollowLeaf: true}, func(path string, options Options) (Identity, error) {
26 calls[path]++
27 return Resolve(path, options)
28 })
29 for _, left := range dirs {
30 for _, right := range dirs {
31 got, gotErr := matcher.Same(left, right)
32 want, wantErr := Same(left, right, Options{FollowLeaf: true})
33 if got != want || (gotErr == nil) != (wantErr == nil) {
34 t.Fatalf("Same(%s, %s) = %v, %v; want %v, %v", left, right, got, gotErr, want, wantErr)
35 }
36 }
37 }
38 for path, n := range calls {
39 if n != 1 {
40 t.Errorf("%s resolved %d times in one pass", path, n)
41 }
42 }
43 if len(calls) != len(dirs) {
44 t.Errorf("resolved %d paths, want %d", len(calls), len(dirs))
45 }
46 }
47
47 lines GO