diff --git a/t/00-load.t b/t/00-load.t new file mode 100755 index 0000000..6aa8d60 --- /dev/null +++ b/t/00-load.t @@ -0,0 +1,9 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use Test::More tests => 1; +use MarkdownParser; + +ok( 1, 'Module loaded successfully' ); + diff --git a/t/01-headers.t b/t/01-headers.t new file mode 100755 index 0000000..76e2110 --- /dev/null +++ b/t/01-headers.t @@ -0,0 +1,16 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use Test::More tests => 6; +use MarkdownParser; + +my $parser = MarkdownParser->new(); + +is( $parser->parse("# Header 1"), "
Simple paragraph
\n", + "Single paragraph" +); +is( + $parser->parse("First paragraph\n\nSecond paragraph"), + "First paragraph
\nSecond paragraph
\n", + "Multiple paragraphs" +); +is( + $parser->parse("Paragraph with\nmultiple lines"), + "Paragraph with multiple lines
\n", + "Multi-line paragraph" +); + diff --git a/t/03-formatting.t b/t/03-formatting.t new file mode 100755 index 0000000..f17edcc --- /dev/null +++ b/t/03-formatting.t @@ -0,0 +1,65 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use Test::More tests => 11; +use MarkdownParser; + +my $parser = MarkdownParser->new(); + +is( + $parser->parse("**bold text**"), + "bold text
\n", + "Bold with **" +); +is( + $parser->parse("__bold text__"), + "bold text
\n", + "Bold with __" +); +is( + $parser->parse("*italic text*"), + "italic text
\n", + "Italic with *" +); +is( + $parser->parse("_italic text_"), + "italic text
\n", + "Italic with _" +); +is( + $parser->parse("**bold** and *italic*"), + "bold and italic
\n", + "Bold and italic together" +); +is( + $parser->parse("Text with **bold** in middle"), + "Text with bold in middle
\n", + "Bold in middle of text" +); +is( + $parser->parse("Text with *italic* in middle"), + "Text with italic in middle
\n", + "Italic in middle of text" +); +is( + $parser->parse("**bold** *italic* **bold again**"), +"bold italic bold again
\n", + "Multiple formatting" +); +is( + $parser->parse("***bold text***"), + "bold text
\n", + "Bold with ***" +); +is( + $parser->parse("**bold *italic* bold**"), + "bold italic bold
\n", + "Nested formatting" +); +is( + $parser->parse("___bold text___"), + "bold text
\n", + "Bold with ___" +); + diff --git a/t/04-links-images.t b/t/04-links-images.t new file mode 100755 index 0000000..60b9949 --- /dev/null +++ b/t/04-links-images.t @@ -0,0 +1,44 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use Test::More tests => 8; +use MarkdownParser; + +my $parser = MarkdownParser->new(); + +is( + $parser->parse("[link text](http://example.com)"), + "\n", + "Simple link" +); +is( + $parser->parse("[link with spaces](https://example.com/path)"), + "\n", + "Link with path" +); +is( + $parser->parse(""), + "

Click me
\n", + "JavaScript protocol blocked in links" +); +is( + $parser->parse("[Click me](data:text/html,)"), + "Click me
\n", + "Data protocol blocked in links" +); +is( $parser->parse(")"), + "Image
\n", "JavaScript protocol blocked in images" ); +is( $parser->parse(""), + "Image
\n", "File protocol blocked in images" ); + diff --git a/t/05-lists.t b/t/05-lists.t new file mode 100755 index 0000000..8d9a77c --- /dev/null +++ b/t/05-lists.t @@ -0,0 +1,40 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use Test::More tests => 6; +use MarkdownParser; + +my $parser = MarkdownParser->new(); + +is( + $parser->parse("- Item 1\n- Item 2\n- Item 3"), + "inline code
Text with code in it
\ncode block\n\n",
+ "Code block"
+);
+is(
+ $parser->parse("```\nline 1\nline 2\nline 3\n```"),
+ "\nline 1\nline 2\nline 3\n\n",
+ "Multi-line code block"
+);
+is(
+ $parser->parse("```\n```"),
+ "\n\n",
+ "Empty code block"
+);
+
diff --git a/t/07-blockquotes.t b/t/07-blockquotes.t
new file mode 100755
index 0000000..512986c
--- /dev/null
+++ b/t/07-blockquotes.t
@@ -0,0 +1,25 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use Test::More tests => 3;
+use MarkdownParser;
+
+my $parser = MarkdownParser->new();
+
+is(
+ $parser->parse("> Quote text"),
+ "\n\n", + "Simple blockquote" +); +is( + $parser->parse("> First line\n> Second line"), + "Quote text
\n
\n\n", + "Multi-line blockquote" +); +is( + $parser->parse("> Quote with **bold**"), + "First line
\nSecond line
\n
\n\n", + "Blockquote with formatting" +); + diff --git a/t/08-horizontal-rules.t b/t/08-horizontal-rules.t new file mode 100755 index 0000000..2f09b94 --- /dev/null +++ b/t/08-horizontal-rules.t @@ -0,0 +1,13 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use Test::More tests => 3; +use MarkdownParser; + +my $parser = MarkdownParser->new(); + +is( $parser->parse("---"), "Quote with bold
\n
This is a paragraph with bold and italic text.
+Paragraph one.
+++Blockquote here
+
Another paragraph.
+EOF + +is( $parser->parse($input), $expected, "Document with blockquote" ); + +$input = <<'EOF'; +# Code Example + +Here is some `inline code` and a code block: + +``` +function test() { + return true; +} +``` +EOF + +$expected = <<'EOF'; +Here is some inline code and a code block:
+function test() {
+ return true;
+}
+
+EOF
+
+is( $parser->parse($input), $expected, "Document with code" );
+
+$input = <<'EOF';
+# Header
+
+Paragraph with [link](url) and .
+
+---
+
+## Another Header
+EOF
+
+$expected = <<'EOF';
+Paragraph with link and
.
Text with <tag>
\n", + "HTML tags escaped" +); +is( + $parser->parse("Text with & symbol"), + "Text with & symbol
\n", + "Ampersand escaped" +); +is( + $parser->parse('Text with "quotes"'), + "Text with "quotes"
\n", + "Quotes escaped" +); +is( + $parser->parse("Text with 'apostrophe'"), + "Text with 'apostrophe'
\n", + "Apostrophe escaped" +); + diff --git a/t/11-tables.t b/t/11-tables.t new file mode 100644 index 0000000..c0017ab --- /dev/null +++ b/t/11-tables.t @@ -0,0 +1,111 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use Test::More tests => 4; +use MarkdownParser; + +my $parser = MarkdownParser->new(); + +my $input = <<'EOF'; +| Header 1 | Header 2 | +|----------|----------| +| Cell 1 | Cell 2 | +| Cell 3 | Cell 4 | +EOF + +my $expected = <<'EOF'; +| Header 1 | +Header 2 | +
|---|---|
| Cell 1 | +Cell 2 | +
| Cell 3 | +Cell 4 | +
| Name | +Age | +
|---|---|
| John | +25 | +
| Jane | +30 | +
| Col1 | +Col2 | +
|---|---|
| Data | +Info | +
More text.
+EOF + +is( $parser->parse($input), $expected, "Table with surrounding content" ); + +$input = <<'EOF'; +| **Bold** | *Italic* | [Link](url) | +|----------|----------|-------------| +| Text | More | Info | +EOF + +$expected = <<'EOF'; +| Bold | +Italic | +Link | +
|---|---|---|
| Text | +More | +Info | +