Skip to content

Commit ef4823c

Browse files
committed
Added a test case for line-start regexes
1 parent e52c683 commit ef4823c

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

tests/fixtures/regex_with_caret.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
version: 1.0.0
2+
dependencies:
3+
- name: kube-prometheus-stack
4+
version: 1.0.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[tool.bumpversion]
2+
current_version = "1.0.0"
3+
regex = true
4+
5+
[[tool.bumpversion.files]]
6+
filename = "thingy.yaml"
7+
search = "^version: {current_version}"
8+
replace = "version: {new_version}"

tests/test_files.py

+25
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,31 @@ def test_regex_search_with_escaped_chars(tmp_path: Path) -> None:
409409
assert version_path.read_text() == f"## [Release] 1.2.4 {now}"
410410

411411

412+
def test_regex_search_with_caret(tmp_path: Path, fixtures_path: Path) -> None:
413+
"""A search that uses a caret to indicate the beginning of the line works correctly."""
414+
# Arrange
415+
config_path = tmp_path / ".bumpversion.toml"
416+
thingy_path = tmp_path / "thingy.yaml"
417+
shutil.copyfile(fixtures_path / "regex_with_caret.yaml", thingy_path)
418+
shutil.copyfile(fixtures_path / "regex_with_caret_config.toml", config_path)
419+
420+
conf = config.get_configuration(config_file=config_path)
421+
version_config = VersionConfig(conf.parse, conf.serialize, conf.search, conf.replace, conf.parts)
422+
current_version = version_config.parse(conf.current_version)
423+
new_version = current_version.bump("patch", version_config.order)
424+
425+
with inside_dir(tmp_path):
426+
cfg_files = [files.ConfiguredFile(file_cfg, version_config) for file_cfg in conf.files]
427+
428+
# Act
429+
files.modify_files(cfg_files, current_version, new_version, get_context(conf))
430+
431+
# Assert
432+
assert (
433+
thingy_path.read_text() == "version: 1.0.1\ndependencies:\n- name: kube-prometheus-stack\n version: 1.0.0\n"
434+
)
435+
436+
412437
def test_bad_regex_search(tmp_path: Path, caplog) -> None:
413438
"""A search string not meant to be a regex is still found and replaced."""
414439
# Arrange

0 commit comments

Comments
 (0)