refactor: update test to read AI comments from fixture files

This commit is contained in:
Paul Gauthier (aider) 2024-12-01 10:04:37 -08:00
parent e885f848a6
commit 7a3fd11b6b

View file

@ -1,36 +1,26 @@
from pathlib import Path
from aider.watch import FileWatcher
def test_ai_comment_pattern():
# Test various AI comment patterns
test_comments = [
# Python style
"# ai do something",
"# AI make this better",
"# ai! urgent change needed",
"# AI! another urgent one",
# JavaScript style
"//ai do something",
"//AI make this better",
"//ai! urgent change needed",
"//AI! another urgent one",
"// ai with space",
"// AI with caps",
"// ai! with bang",
]
# Read fixture files
fixtures_dir = Path(__file__).parent.parent / "fixtures"
# Non-AI comments that shouldn't match
non_ai_comments = [
"# this is not an ai comment",
"// this is also not an ai comment",
"# aider is not an ai comment",
"// aider is not an ai comment",
]
with open(fixtures_dir / "watch.py") as f:
py_content = f.read()
with open(fixtures_dir / "watch.js") as f:
js_content = f.read()
# Test that all AI comments match
for comment in test_comments:
assert FileWatcher.ai_comment_pattern.search(comment), f"Should match: {comment}"
# Count AI comments in Python fixture
py_matches = 0
for line in py_content.splitlines():
if FileWatcher.ai_comment_pattern.search(line):
py_matches += 1
assert py_matches == 11, f"Expected 11 AI comments in Python fixture, found {py_matches}"
# Test that non-AI comments don't match
for comment in non_ai_comments:
assert not FileWatcher.ai_comment_pattern.search(comment), f"Should not match: {comment}"
# Count AI comments in JavaScript fixture
js_matches = 0
for line in js_content.splitlines():
if FileWatcher.ai_comment_pattern.search(line):
js_matches += 1
assert js_matches == 11, f"Expected 11 AI comments in JavaScript fixture, found {js_matches}"