diff --git a/core/utils/file_test.go b/core/utils/file_test.go index 6e15ff02..faba965c 100644 --- a/core/utils/file_test.go +++ b/core/utils/file_test.go @@ -1,6 +1,7 @@ package utils import ( + "regexp" "testing" "github.com/stretchr/testify/assert" @@ -38,3 +39,41 @@ func TestIsDir(t *testing.T) { wrongRes := IsDir(wrongString) assert.False(t, wrongRes, "Expected non-existing path to return false") } + +func TestIgnoreFileRegexPattern(t *testing.T) { + ignoreRegex, err := regexp.Compile(IgnoreFileRegexPattern) + assert.NoError(t, err, "Regex should compile without error") + + testCases := []struct { + path string + expected bool + desc string + }{ + // Should be ignored (directories) + {".git/", true, ".git directory should be ignored"}, + {".git/config", true, ".git/config should be ignored"}, + {".git/objects/pack", true, ".git subdirectory should be ignored"}, + {"node_modules/", true, "node_modules directory should be ignored"}, + {"node_modules/package/index.js", true, "node_modules file should be ignored"}, + {"src/__pycache__/", true, "__pycache__ directory should be ignored"}, + + // Should be ignored (file extensions) + {"file.tmp", true, ".tmp files should be ignored"}, + {"file.temp", true, ".temp files should be ignored"}, + {"file.log", true, ".log files should be ignored"}, + {"file.swp", true, ".swp files should be ignored"}, + {"file.pyc", true, ".pyc files should be ignored"}, + + // Should NOT be ignored + {"main.py", false, "Python files should not be ignored"}, + {"src/app.js", false, "JavaScript files should not be ignored"}, + {".gitignore", false, ".gitignore file should not be ignored"}, + {".github/workflows/ci.yml", false, ".github directory should not be ignored"}, + {"config.json", false, "JSON files should not be ignored"}, + } + + for _, tc := range testCases { + result := ignoreRegex.MatchString(tc.path) + assert.Equal(t, tc.expected, result, tc.desc) + } +}