|
1 | | -import mdformat |
| 1 | +from pathlib import Path |
| 2 | +import re |
2 | 3 |
|
| 4 | +from markdown_it.utils import read_fixture_file |
| 5 | +import mdformat |
| 6 | +import pytest |
3 | 7 |
|
4 | | -def test_word_wrap(): |
5 | | - input_text = """\ |
6 | | -[^a] |
| 8 | +FIXTURE_PATH = Path(__file__).parent / "fixtures_wrap.md" |
| 9 | +fixtures = read_fixture_file(FIXTURE_PATH) |
7 | 10 |
|
8 | | -[^a]: Ooh no, the first line of this first paragraph is still wrapped too wide |
9 | | - unfortunately. Should fix this. |
10 | 11 |
|
11 | | - But this second paragraph is wrapped exactly as expected. Woohooo, awesome! |
12 | | -""" |
13 | | - expected_output = """\ |
14 | | -[^a] |
| 12 | +def _extract_wrap_length(title): |
| 13 | + if match := re.search(r"wrap at (\d+)", title): |
| 14 | + return int(match.group(1)) |
| 15 | + return 40 |
15 | 16 |
|
16 | | -[^a]: Ooh no, the first line of this first |
17 | | - paragraph is still wrapped too wide |
18 | | - unfortunately. Should fix this. |
19 | 17 |
|
20 | | - But this second paragraph is wrapped |
21 | | - exactly as expected. Woohooo, |
22 | | - awesome! |
23 | | -""" |
24 | | - output = mdformat.text(input_text, options={"wrap": 40}, extensions={"footnote"}) |
25 | | - assert output == expected_output |
| 18 | +@pytest.mark.parametrize( |
| 19 | + "line,title,text,expected", |
| 20 | + fixtures, |
| 21 | + ids=[f[1] for f in fixtures], |
| 22 | +) |
| 23 | +def test_word_wrap(line, title, text, expected): |
| 24 | + wrap_length = _extract_wrap_length(title) |
| 25 | + output = mdformat.text(text, options={"wrap": wrap_length}, extensions={"footnote"}) |
| 26 | + assert output.rstrip() == expected.rstrip(), output |
0 commit comments