| … | … | @@ -0,0 +1,33 @@ |
| 1 | <?php |
| 2 | // test_markdown.php — run: php test_markdown.php |
| 3 | require_once __DIR__ . '/lib/markdown.php'; |
| 4 | |
| 5 | function assert_eq($label, $got, $expected) { |
| 6 | if ($got !== $expected) { |
| 7 | echo "FAIL: $label\n Expected: $expected\n Got: $got\n"; |
| 8 | exit(1); |
| 9 | } |
| 10 | echo "PASS: $label\n"; |
| 11 | } |
| 12 | |
| 13 | // Headings |
| 14 | assert_eq('h1', parse_markdown("# Title"), '<h1>Title</h1>'); |
| 15 | assert_eq('h2', parse_markdown("## Subtitle"), '<h2>Subtitle</h2>'); |
| 16 | assert_eq('h3', parse_markdown("### Sub-sub"), '<h3>Sub-sub</h3>'); |
| 17 | |
| 18 | // Inline formatting |
| 19 | assert_eq('bold', parse_markdown("**bold**"), '<p><strong>bold</strong></p>'); |
| 20 | assert_eq('italic', parse_markdown("*italic*"), '<p><em>italic</em></p>'); |
| 21 | assert_eq('link', parse_markdown("[text](url)"), '<p><a href="url">text</a></p>'); |
| 22 | |
| 23 | // Paragraphs |
| 24 | assert_eq('two paragraphs', parse_markdown("First\n\nSecond"), '<p>First</p><p>Second</p>'); |
| 25 | |
| 26 | // Mixed |
| 27 | assert_eq('heading then paragraph', parse_markdown("# Title\n\nSome text"), '<h1>Title</h1><p>Some text</p>'); |
| 28 | |
| 29 | // Complex |
| 30 | assert_eq('bold in paragraph', parse_markdown("This is **important** text"), '<p>This is <strong>important</strong> text</p>'); |
| 31 | assert_eq('link in paragraph', parse_markdown("Visit [my site](https://example.com) today"), '<p>Visit <a href="https://example.com">my site</a> today</p>'); |
| 32 | |
| 33 | echo "\nAll markdown tests passed.\n"; |