Skip to content

Commit

Permalink
fix(formatter): leave empty lines in descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
fyhertz committed Jan 21, 2022
1 parent 02e1ba9 commit 7313d06
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/ops2deb/formatter.py
Expand Up @@ -28,8 +28,9 @@ def sort_blueprints(blueprints: List[Blueprint]) -> List[Blueprint]:

def format_description(description: str) -> str:
lines: List[str] = []
description = description.strip("\n")
for line in description.split("\n"):
lines.extend(wrap(line, width=79))
lines.extend(wrap(line, width=79) or [""])
return "\n".join(lines)


Expand Down
17 changes: 12 additions & 5 deletions tests/test_formatter.py
@@ -1,6 +1,8 @@
import pytest

from ops2deb.formatter import format_description

description_with_empty_line = """\
description_with_empty_line = """
This thing does the following:
- It does this
Expand All @@ -12,13 +14,18 @@
"""


def test_format_description_should_remove_empty_lines():
def test_format_description_should_only_remove_empty_lines_at_start_or_end():
result = format_description(description_with_empty_line)
assert "" not in result.split("\n")
assert result[0] != "\n"
assert result[-1] != "\n"
assert "\n" in result


def test_format_description_should_be_idempotent():
result = format_description(description_with_empty_line)
@pytest.mark.parametrize(
"description", [description_with_empty_line, description_with_long_line]
)
def test_format_description_should_be_idempotent(description):
result = format_description(description)
assert format_description(result) == result


Expand Down

0 comments on commit 7313d06

Please sign in to comment.