mirror of
https://github.com/tiennm99/serena.git
synced 2026-07-14 05:06:41 +00:00
Add test for escaped negation pattern parsing
Test demonstrates the fix for escaped character handling order: - Escaped negation patterns are treated as literals, not negations - Real negation patterns properly override ignore rules
This commit is contained in:
@@ -419,6 +419,38 @@ build/
|
||||
assert "#not-a-comment.txt" in patterns
|
||||
assert "!not-negation.txt" in patterns
|
||||
|
||||
def test_escaped_negation_patterns(self):
|
||||
test_dir = self.repo_path / "test_escaped_negation"
|
||||
test_dir.mkdir()
|
||||
|
||||
gitignore = test_dir / ".gitignore"
|
||||
gitignore.write_text(
|
||||
"""*.log
|
||||
\\!not-negation.log
|
||||
!actual-negation.log
|
||||
"""
|
||||
)
|
||||
|
||||
parser = GitignoreParser(str(test_dir))
|
||||
specs = parser.get_ignore_specs()
|
||||
|
||||
assert len(specs) == 1
|
||||
patterns = specs[0].patterns
|
||||
|
||||
# Key assertions: escaped exclamation becomes literal, real negation preserved
|
||||
assert "!not-negation.log" in patterns # escaped -> literal
|
||||
assert "!actual-negation.log" in patterns # real negation preserved
|
||||
|
||||
# Test the actual behavioral difference between escaped and real negation:
|
||||
# *.log pattern should ignore test.log
|
||||
assert parser.should_ignore("test.log")
|
||||
|
||||
# Escaped negation file should still be ignored by *.log pattern
|
||||
assert parser.should_ignore("!not-negation.log")
|
||||
|
||||
# Actual negation should override the *.log pattern
|
||||
assert not parser.should_ignore("actual-negation.log")
|
||||
|
||||
def test_glob_patterns(self):
|
||||
"""Test various glob patterns work correctly."""
|
||||
test_dir = self.repo_path / "test_glob"
|
||||
|
||||
Reference in New Issue
Block a user