返回 DeepSeek-Reasonix
protected_dirs_darwin_test.go
根目录 / internal / tool / builtin / protected_dirs_darwin_test.go
1 //go:build darwin
2
3 package builtin
4
5 import (
6 "os"
7 "path/filepath"
8 "testing"
9 )
10
11 func TestProtectedDirsArePruned(t *testing.T) {
12 home, err := os.UserHomeDir()
13 if err != nil || home == "" {
14 t.Skip("no home dir")
15 }
16 for _, name := range []string{"Music", "Pictures", "Movies", "Library"} {
17 abs := filepath.Join(home, name)
18 if !isProtectedDir(abs) {
19 t.Errorf("isProtectedDir(%q) = false, want true", abs)
20 }
21 if skipWalkDir(home, abs, name) != true {
22 t.Errorf("skipWalkDir did not prune protected %q", abs)
23 }
24 }
25 }
26
27 func TestProtectedMatchIsByAbsPathNotBasename(t *testing.T) {
28 home, err := os.UserHomeDir()
29 if err != nil || home == "" {
30 t.Skip("no home dir")
31 }
32 root := filepath.Join(home, "code", "proj")
33 projMusic := filepath.Join(root, "Music")
34 if isProtectedDir(projMusic) {
35 t.Errorf("a project's own Music dir %q must not be protected", projMusic)
36 }
37 if skipWalkDir(root, projMusic, "Music") {
38 t.Errorf("skipWalkDir wrongly pruned a project dir named Music")
39 }
40 }
41
42 func TestProtectedRootItselfIsNotPruned(t *testing.T) {
43 home, err := os.UserHomeDir()
44 if err != nil || home == "" {
45 t.Skip("no home dir")
46 }
47 music := filepath.Join(home, "Music")
48 if skipWalkDir(music, music, "Music") {
49 t.Error("explicitly targeting ~/Music as the walk root must not be pruned")
50 }
51 }
52
52 lines GO