@@ -88,3 +88,79 @@ func TestNormalizePath(t *testing.T) {
8888 t .Errorf ("expected = %v, got = %v" , expectedOutput , result )
8989 }
9090}
91+
92+ func TestShouldIgnoreDirectory (t * testing.T ) {
93+ tests := []struct {
94+ name string
95+ path string
96+ expected bool
97+ }{
98+ {
99+ name : "empty directory name" ,
100+ path : "" ,
101+ expected : false ,
102+ },
103+ // Direct directory names
104+ {
105+ name : "direct node_modules" ,
106+ path : "node_modules" ,
107+ expected : true ,
108+ },
109+ {
110+ name : "direct .git" ,
111+ path : ".git" ,
112+ expected : true ,
113+ },
114+ // Nested paths with ignored directories
115+ {
116+ name : "nested node_modules" ,
117+ path : "plugins/foo/node_modules" ,
118+ expected : true ,
119+ },
120+ {
121+ name : "nested .git in worktree" ,
122+ path : "worktree-a/.git" ,
123+ expected : true ,
124+ },
125+ {
126+ name : "deeply nested node_modules" ,
127+ path : "project/src/components/node_modules" ,
128+ expected : true ,
129+ },
130+ {
131+ name : "node_modules in path with backslashes" ,
132+ path : filepath .Join ("project" , "src" , "node_modules" ),
133+ expected : true ,
134+ },
135+ // Non-ignored directories
136+ {
137+ name : "regular directory" ,
138+ path : "src" ,
139+ expected : false ,
140+ },
141+ {
142+ name : "nested regular directory" ,
143+ path : "plugins/foo" ,
144+ expected : false ,
145+ },
146+ {
147+ name : "directory containing node_modules in name" ,
148+ path : "my_node_modules_backup" ,
149+ expected : false ,
150+ },
151+ {
152+ name : "directory containing .git in name" ,
153+ path : "my.github" ,
154+ expected : false ,
155+ },
156+ }
157+
158+ for _ , tt := range tests {
159+ t .Run (tt .name , func (t * testing.T ) {
160+ result := ShouldIgnoreDirectory (tt .path )
161+ if result != tt .expected {
162+ t .Errorf ("ShouldIgnoreDirectory(%q) = %v, expected %v" , tt .path , result , tt .expected )
163+ }
164+ })
165+ }
166+ }
0 commit comments