|
| 1 | +"""Tests for soft break to hard break conversion.""" |
| 2 | + |
| 3 | +import mdformat |
| 4 | + |
| 5 | + |
| 6 | +class TestSoftBreakConversion: |
| 7 | + """Tests for converting soft breaks to hard breaks (backslash + newline).""" |
| 8 | + |
| 9 | + def test_soft_break_gets_backslash(self): |
| 10 | + """Plain newline within a paragraph should become backslash + newline.""" |
| 11 | + input_text = "Line one\nLine two.\n" |
| 12 | + expected = "Line one\\\nLine two.\n" |
| 13 | + result = mdformat.text(input_text, extensions={"space_control"}) |
| 14 | + assert result == expected |
| 15 | + |
| 16 | + def test_multiple_soft_breaks(self): |
| 17 | + """Multiple soft breaks in a paragraph should all get backslashes.""" |
| 18 | + input_text = "Line one\nLine two\nLine three.\n" |
| 19 | + expected = "Line one\\\nLine two\\\nLine three.\n" |
| 20 | + result = mdformat.text(input_text, extensions={"space_control"}) |
| 21 | + assert result == expected |
| 22 | + |
| 23 | + def test_bold_label_lines(self): |
| 24 | + """AI-generated bold label lines should preserve line breaks.""" |
| 25 | + input_text = "**Date**: January 30\n**Time**: 2:00 PM\n**Location**: Room 101\n" |
| 26 | + expected = "**Date**: January 30\\\n**Time**: 2:00 PM\\\n**Location**: Room 101\n" |
| 27 | + result = mdformat.text(input_text, extensions={"space_control"}) |
| 28 | + assert result == expected |
| 29 | + |
| 30 | + def test_paragraph_break_unaffected(self): |
| 31 | + """Double newline (paragraph break) should not be affected.""" |
| 32 | + input_text = "First paragraph.\n\nSecond paragraph.\n" |
| 33 | + expected = "First paragraph.\n\nSecond paragraph.\n" |
| 34 | + result = mdformat.text(input_text, extensions={"space_control"}) |
| 35 | + assert result == expected |
| 36 | + |
| 37 | + def test_existing_hard_break_preserved(self): |
| 38 | + """Lines already ending with backslash should remain correct.""" |
| 39 | + input_text = "Line one\\\nLine two.\n" |
| 40 | + expected = "Line one\\\nLine two.\n" |
| 41 | + result = mdformat.text(input_text, extensions={"space_control"}) |
| 42 | + assert result == expected |
| 43 | + |
| 44 | + def test_code_block_newlines_unaffected(self): |
| 45 | + """Newlines inside fenced code blocks should not get backslashes.""" |
| 46 | + input_text = "```\nline one\nline two\n```\n" |
| 47 | + expected = "```\nline one\nline two\n```\n" |
| 48 | + result = mdformat.text(input_text, extensions={"space_control"}) |
| 49 | + assert result == expected |
| 50 | + |
| 51 | + def test_single_line_paragraph_unaffected(self): |
| 52 | + """A single-line paragraph should not be modified.""" |
| 53 | + input_text = "Just one line.\n" |
| 54 | + expected = "Just one line.\n" |
| 55 | + result = mdformat.text(input_text, extensions={"space_control"}) |
| 56 | + assert result == expected |
| 57 | + |
| 58 | + def test_soft_break_in_list_item(self): |
| 59 | + """Soft breaks within list items should get backslashes.""" |
| 60 | + input_text = "- Line one\n Line two\n" |
| 61 | + expected = "- Line one\\\n Line two\n" |
| 62 | + result = mdformat.text(input_text, extensions={"space_control"}) |
| 63 | + assert result == expected |
0 commit comments