<?php
// test_markdown.php — run: php test_markdown.php
require_once __DIR__ . '/lib/markdown.php';
function assert_eq($label, $got, $expected) {
if ($got !== $expected) {
echo "FAIL: $label\n Expected: $expected\n Got: $got\n";
exit(1);
}
echo "PASS: $label\n";
}
// Headings
assert_eq('h1', parse_markdown("# Title"), '<h1>Title</h1>');
assert_eq('h2', parse_markdown("## Subtitle"), '<h2>Subtitle</h2>');
assert_eq('h3', parse_markdown("### Sub-sub"), '<h3>Sub-sub</h3>');
// Inline formatting
assert_eq('bold', parse_markdown("**bold**"), '<p><strong>bold</strong></p>');
assert_eq('italic', parse_markdown("*italic*"), '<p><em>italic</em></p>');
assert_eq('link', parse_markdown("[text](url)"), '<p><a href="url">text</a></p>');
// Paragraphs
assert_eq('two paragraphs', parse_markdown("First\n\nSecond"), '<p>First</p><p>Second</p>');
// Mixed
assert_eq('heading then paragraph', parse_markdown("# Title\n\nSome text"), '<h1>Title</h1><p>Some text</p>');
// Complex
assert_eq('bold in paragraph', parse_markdown("This is **important** text"), '<p>This is <strong>important</strong> text</p>');
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>');
echo "\nAll markdown tests passed.\n";