Skip to content

Commit

Permalink
fix: Remove trim
Browse files Browse the repository at this point in the history
  • Loading branch information
attakei committed Mar 21, 2024
1 parent 86e5d79 commit 8e61be9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 44 deletions.
10 changes: 2 additions & 8 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@ pub fn update(base_config: &Config, new_version: &Version) -> Result<()> {
replace: "current_version = \"{{new_version}}\"".to_string(),
});
for f in files {
let search_text = Tera::one_off(&f.search, &ctx, true)
.unwrap()
.trim_start()
.to_string();
let replace_text = Tera::one_off(&f.replace, &ctx, true)
.unwrap()
.trim_start()
.to_string();
let search_text = Tera::one_off(&f.search, &ctx, true).unwrap().to_string();
let replace_text = Tera::one_off(&f.replace, &ctx, true).unwrap().to_string();
let new_text = build_updates(read_to_string(&f.path).unwrap(), search_text, replace_text);
let mut out = File::create(&f.path)?;
let _ = out.write(new_text.as_bytes());
Expand Down
76 changes: 40 additions & 36 deletions tests/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import textwrap
from pathlib import Path

import pytest


def test_not_configured_env(cmd):
"""'update' command requires configuration file.
Expand Down Expand Up @@ -72,51 +74,53 @@ def test_valid_conf__single_line(cmd, tmp_path: Path): # noqa: D103
assert 'current_version = "0.2.0"' in (tmp_path / ".age.toml").read_text()


def test_valid_conf__multi_line(cmd, tmp_path: Path): # noqa: D103
@pytest.mark.parametrize(
"fileconf,before,after",
[
(
textwrap.dedent('''\
[[files]]
path = "data.txt"
search = """
Target
======
"""
replace = """
Target
======
v{{new_version}}
------
"""
'''),
textwrap.dedent("""\
Target
======
"""),
textwrap.dedent("""\
Target
======
v0.2.0
------
"""),
)
],
)
def test_valid_conf__multi_line(cmd, tmp_path: Path, fileconf, before, after): # noqa: D103
conf_text = textwrap.dedent(
'''\
f"""\
current_version = "0.0.0"
[[files]]
path = "data.txt"
search = """
Target
======
"""
replace = """
Target
======
v{{new_version}}
------
{fileconf}
"""
'''
)
(tmp_path / ".age.toml").write_text(conf_text)
data_txt = tmp_path / "data.txt"
before = textwrap.dedent("""\
====
Data
====
Target
======
""")
after = textwrap.dedent("""\
====
Data
====
Target
======
v0.2.0
------
""")
data_txt.write_text(before)

proc = cmd("update", "0.2.0")
print(data_txt.read_text())
# print(data_txt.read_text())
print(proc.stdout)
assert proc.returncode == 0
assert len(data_txt.read_text().split("\n")) == 10
assert data_txt.read_text() == after

0 comments on commit 8e61be9

Please sign in to comment.