|
1 | 1 | """Tests for the Slack utilities module.""" |
2 | 2 |
|
3 | | -from bender.slack_utils import SLACK_MSG_LIMIT, split_text |
| 3 | +from bender.slack_utils import SLACK_MSG_LIMIT, md_to_mrkdwn, split_text |
4 | 4 |
|
5 | 5 |
|
6 | 6 | class TestSlackMsgLimit: |
@@ -63,3 +63,40 @@ def test_newline_stripped_between_chunks(self) -> None: |
63 | 63 | result = split_text(text, 6) |
64 | 64 | assert result[0] == "abcde" |
65 | 65 | assert result[1] == "fghij" |
| 66 | + |
| 67 | + |
| 68 | +class TestMdToMrkdwn: |
| 69 | + """Tests for the md_to_mrkdwn function.""" |
| 70 | + |
| 71 | + def test_headers_to_bold(self) -> None: |
| 72 | + """Markdown headers become bold text.""" |
| 73 | + assert md_to_mrkdwn("## Hello") == "*Hello*" |
| 74 | + assert md_to_mrkdwn("### World") == "*World*" |
| 75 | + assert md_to_mrkdwn("# Title") == "*Title*" |
| 76 | + |
| 77 | + def test_bold_double_asterisk(self) -> None: |
| 78 | + """Double asterisks become single asterisks.""" |
| 79 | + assert md_to_mrkdwn("this is **bold** text") == "this is *bold* text" |
| 80 | + |
| 81 | + def test_links(self) -> None: |
| 82 | + """Markdown links become Slack links.""" |
| 83 | + assert md_to_mrkdwn("[click](https://example.com)") == "<https://example.com|click>" |
| 84 | + |
| 85 | + def test_horizontal_rule(self) -> None: |
| 86 | + """Horizontal rules become empty lines.""" |
| 87 | + assert md_to_mrkdwn("above\n---\nbelow") == "above\n\nbelow" |
| 88 | + |
| 89 | + def test_plain_text_unchanged(self) -> None: |
| 90 | + """Plain text passes through unchanged.""" |
| 91 | + assert md_to_mrkdwn("just plain text") == "just plain text" |
| 92 | + |
| 93 | + def test_code_blocks_preserved(self) -> None: |
| 94 | + """Code blocks are not modified.""" |
| 95 | + text = "```\nkubectl get pods\n```" |
| 96 | + assert md_to_mrkdwn(text) == text |
| 97 | + |
| 98 | + def test_combined(self) -> None: |
| 99 | + """Multiple conversions in one message.""" |
| 100 | + md = "## Task\n**Client:** helmcode\n[Link](https://example.com)" |
| 101 | + expected = "*Task*\n*Client:* helmcode\n<https://example.com|Link>" |
| 102 | + assert md_to_mrkdwn(md) == expected |
0 commit comments