docs/test: add tests and documentation for competition-aware patterns and commands

This commit is contained in:
venus
2026-07-17 02:18:55 -05:00
parent 9e91f8ef0f
commit f2b349c42d
5 changed files with 243 additions and 7 deletions

View File

@@ -98,3 +98,40 @@ def test_suggest_patterns_empty_and_whitespace():
with pytest.raises(ValueError, match="Input string cannot be empty or whitespace only."):
suggest_patterns(" ")
def test_suggest_patterns_with_competition_name_braced():
"""
Verifies that when the competition name is matched in a braced flag,
additional general wildcard patterns like '^CTF\\{.*\\}$' are generated.
"""
patterns = suggest_patterns("CTF{easy_flag_123}", comp_name="CTF")
# Check that competition prefix is kept literal in specific/variable patterns
assert "^CTF\\{[a-z]{4}_[a-z]{4}_\\d{3}\\}$" in patterns
assert "^CTF\\{[a-z]+_[a-z]+_\\d+\\}$" in patterns
# Check that braced wildcard options are suggested
assert "^CTF\\{.*\\}$" in patterns
assert "^CTF\\{[A-Za-z0-9_\\-]+\\}$" in patterns
assert "^CTF\\{[a-z0-9_]+\\}$" in patterns
def test_suggest_patterns_with_competition_name_non_braced():
"""
Verifies that when the competition name is matched in a non-braced flag,
suffix wildcards like '^SKY-.*$' or '^SKY.*$' are suggested.
"""
patterns = suggest_patterns("SKY-1111-000", comp_name="SKY")
assert "^SKY-\\d{4}-\\d{3}$" in patterns
assert "^SKY-.*$" in patterns
def test_suggest_patterns_with_competition_name_mismatch():
"""
Verifies that if the competition name is not in the example flag,
it falls back to standard regex suggestion matching.
"""
patterns_mismatch = suggest_patterns("CTF{easy_flag_123}", comp_name="SKY")
patterns_none = suggest_patterns("CTF{easy_flag_123}")
assert patterns_mismatch == patterns_none