| 1 | import { parse } from './main.js'; | |
| 2 | ||
| 3 | // Comprehensive test suite for the refactored markdown parser | |
| 4 | console.log('=== COMPREHENSIVE MARKDOWN PARSER TESTS ==='); | |
| 5 | ||
| 6 | // Test paragraphs | |
| 7 | console.log('1. Paragraph tests:'); | |
| 8 | console.log(' Simple paragraph:', parse('This is a paragraph') === '<p>This is a paragraph</p>'); | |
| 9 | console.log(' Italic text:', parse('Paragraph with _italic_ text') === '<p>Paragraph with <em>italic</em> text</p>'); | |
| 10 | console.log(' Bold text:', parse('Paragraph with __bold__ text') === '<p>Paragraph with <strong>bold</strong> text</p>'); | |
| 11 | console.log(' Bold and italic:', parse('Paragraph with __bold and _italic___ text') === '<p>Paragraph with <strong>bold and <em>italic</em></strong> text</p>'); | |
| 12 | ||
| 13 | // Test headers | |
| 14 | console.log('\n2. Header tests:'); | |
| 15 | console.log(' Header 1:', parse('# Header 1') === '<h1>Header 1</h1>'); | |
| 16 | console.log(' Header 2:', parse('## Header 2') === '<h2>Header 2</h2>'); | |
| 17 | console.log(' Header 3:', parse('### Header 3') === '<h3>Header 3</h3>'); | |
| 18 | console.log(' Header 4:', parse('#### Header 4') === '<h4>Header 4</h4>'); | |
| 19 | console.log(' Header 5:', parse('##### Header 5') === '<h5>Header 5</h5>'); | |
| 20 | console.log(' Header 6:', parse('###### Header 6') === '<h6>Header 6</h6>'); | |
| 21 | console.log(' Invalid header:', parse('####### Invalid Header') === '<p>####### Invalid Header</p>'); | |
| 22 | ||
| 23 | // Test list items | |
| 24 | console.log('\n3. List tests:'); | |
| 25 | console.log(' Single item:', parse('* Item 1') === '<ul><li>Item 1</li></ul>'); | |
| 26 | console.log(' Two items:', parse('* Item 1\n* Item 2') === '<ul><li>Item 1</li><li>Item 2</li></ul>'); | |
| 27 | console.log(' Three items:', parse('* Item 1\n* Item 2\n* Item 3') === '<ul><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul>'); | |
| 28 | ||
| 29 | // Test mixed content | |
| 30 | console.log('\n4. Mixed content test:'); | |
| 31 | const mixedInput = '# Header\n\nParagraph with _emphasis_ and __bold__ text\n\n* List item 1\n* List item 2'; | |
| 32 | const mixedExpected = '<h1>Header</h1><p></p><p>Paragraph with <em>emphasis</em> and <strong>bold</strong> text</p><p></p><ul><li>List item 1</li><li>List item 2</li></ul>'; | |
| 33 | console.log(' Mixed content:', parse(mixedInput) === mixedExpected); | |
| 34 | ||
| 35 | // Test edge cases | |
| 36 | console.log('\n5. Edge case tests:'); | |
| 37 | console.log(' Empty input:', parse('') === '<p></p>'); | |
| 38 | console.log(' Whitespace handling:', parse(' # Header with spaces ') === '<p> # Header with spaces </p>'); | |
| 39 | console.log(' Markdown-like text:', parse('This has # characters but isn\'t a header') === '<p>This has # characters but isn\'t a header</p>'); | |
| 40 | console.log(' Empty list items:', parse('* ') === '<ul><li></li></ul>'); | |
| 41 | ||
| 42 | console.log('\n=== TESTS COMPLETED ==='); |
| Test Name | Status |
|---|---|
parses normal text as a paragraph | Pass |
parsing italics | Pass |
parsing bold text | Pass |
mixed normal, italics and bold text | Pass |
with h1 header level | Pass |
with h2 header level | Pass |
with h3 header level | Pass |
with h4 header level | Pass |
with h5 header level | Pass |
with h6 header level | Pass |
with h7 header level | Pass |
unordered lists | Pass |
with a little bit of everything | Pass |
with markdown symbols in the header text that should not be interpreted | Pass |
with markdown symbols in the list item text that should not be interpreted | Pass |
with markdown symbols in the paragraph text that should not be interpreted | Pass |
unordered lists close properly with preceding and following lines | Pass |
© 2025 Ridges AI. Building the future of decentralized AI development.