test: Add comprehensive gitignore pattern tests

This commit is contained in:
Paul Gauthier (aider) 2024-12-11 20:43:03 -08:00
parent 26bc981981
commit ad59c4cbf3
2 changed files with 55 additions and 1 deletions

View file

@ -17,7 +17,6 @@ def load_gitignores(gitignore_paths: list[Path]) -> Optional[PathSpec]:
if not gitignore_paths:
return None
# AI: add tests for all of these patterns ai!
patterns = [
".aider*",
".git",

View file

@ -4,6 +4,61 @@ from aider.io import InputOutput
from aider.watch import FileWatcher
def test_gitignore_patterns():
"""Test that gitignore patterns are properly loaded and matched"""
from pathlib import Path
from aider.watch import load_gitignores
# Create a temporary gitignore file with test patterns
tmp_gitignore = Path("test.gitignore")
tmp_gitignore.write_text("custom_pattern\n*.custom")
gitignores = [tmp_gitignore]
spec = load_gitignores(gitignores)
# Test built-in patterns
assert spec.match_file(".aider.conf")
assert spec.match_file(".git/config")
assert spec.match_file("file~") # Emacs/vim backup
assert spec.match_file("file.bak")
assert spec.match_file("file.swp")
assert spec.match_file("file.swo")
assert spec.match_file("#temp#") # Emacs auto-save
assert spec.match_file(".#lock") # Emacs lock
assert spec.match_file("temp.tmp")
assert spec.match_file("temp.temp")
assert spec.match_file("conflict.orig")
assert spec.match_file("script.pyc")
assert spec.match_file("__pycache__/module.pyc")
assert spec.match_file(".DS_Store")
assert spec.match_file("Thumbs.db")
assert spec.match_file(".idea/workspace.xml")
assert spec.match_file(".vscode/settings.json")
assert spec.match_file("project.sublime-workspace")
assert spec.match_file(".project")
assert spec.match_file(".settings/config.json")
assert spec.match_file("workspace.code-workspace")
assert spec.match_file(".env")
assert spec.match_file(".venv/bin/python")
assert spec.match_file("node_modules/package/index.js")
assert spec.match_file("vendor/lib/module.py")
assert spec.match_file("debug.log")
assert spec.match_file(".cache/files")
assert spec.match_file(".pytest_cache/v/cache")
assert spec.match_file("coverage/lcov.info")
# Test custom patterns from gitignore file
assert spec.match_file("custom_pattern")
assert spec.match_file("file.custom")
# Test non-matching patterns
assert not spec.match_file("regular_file.txt")
assert not spec.match_file("src/main.py")
assert not spec.match_file("docs/index.html")
# Cleanup
tmp_gitignore.unlink()
def test_ai_comment_pattern():
# Create minimal IO and Coder instances for testing
class MinimalCoder: