Skip to content

Commit 3223b97

Browse files
committed
Add negative match for Manifest-Version
1 parent 8597026 commit 3223b97

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

bumpchanges/updatefiles.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
(?P<prefix> # Open `prefix` capture group
1616
\s* # Any whitespace
1717
(?P<vquote>['"]?) # `'`, `"`, or nothing (saved as `vquote` group)
18-
(?:\w+?-?)? # Optional word characters and optional literal `-`
18+
(?: # Open optional unnamed word prefix group
19+
(?!Manifest-) # Negative lookahead to not match Manifest-Version
20+
\w+?-? # Word characters and optional literal `-`
21+
)?
1922
(?:__)? # Optional literal `__`
2023
version # Literal `version`
2124
(?:__)? # Optional literal `__`

tests/test_versionfiles.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@
9494
"""Plugin-Version: 0.6.0""",
9595
"""Plugin-Version: 2.3.4""",
9696
),
97+
(
98+
# Almost but-not-quite Manifest-Version
99+
"""anifest-Version: 0.6.0""",
100+
"""anifest-Version: 2.3.4""",
101+
),
102+
]
103+
104+
105+
# A list of version-like strings that will _not_ be matched.
106+
unmatched_strings = [
107+
# Java JAR manifest version
108+
"Manifest-Version: 1.0",
109+
"manifest-version: 1.0",
97110
]
98111

99112

@@ -107,3 +120,15 @@ def test_version_updates(tmp_path, original, expected):
107120
version_file.write_text(original, encoding="utf-8")
108121
update_file(version, version_file)
109122
assert version_file.read_text(encoding="utf-8") == expected
123+
124+
@pytest.mark.parametrize("unmatched_line", unmatched_strings)
125+
def test_negative_matches(tmp_path, unmatched_line):
126+
"""Confirm that the invalid version paths are _not_ matched."""
127+
version = "2.3.4"
128+
129+
# Test the text alone (no trailing newline
130+
version_file = tmp_path / "version.txt"
131+
version_file.write_text(unmatched_line, encoding="utf-8")
132+
133+
with pytest.raises(ValueError):
134+
update_file(version, version_file)

0 commit comments

Comments
 (0)