diff --git a/test/lib/marksmith/helper_test.rb b/test/lib/marksmith/helper_test.rb new file mode 100644 index 0000000..ca22956 --- /dev/null +++ b/test/lib/marksmith/helper_test.rb @@ -0,0 +1,142 @@ +require "test_helper" +require "marksmith/helper" + +class HelperTest < ActiveSupport::TestCase + include Marksmith::Helper + + test "marksmithed#renders simple markdown" do + body = "# Hello World\n\nThis is a test." + expected = "

Hello World

\n\n

This is a test.

\n" + + assert_equal expected, marksmithed(body) + end + + test "marksmithed#when rendering a header" do + body = "# Header" + expected = "

Header

\n" + + assert_equal expected, marksmithed(body) + end + + # Test rendering a list + test "marksmithed#when rendering a list" do + body = "- item1\n- item2" + expected = "\n" + + assert_equal expected, marksmithed(body) + end + + # Test rendering a code block + test "marksmithed#when rendering a code block" do + body = "```\ndef hello\n puts 'hello'\nend\n```" + expected = "
def hello\n  puts 'hello'\nend\n
\n" + + assert_equal expected, marksmithed(body) + end + + # Test rendering a table + test "marksmithed#when rendering a table" do + body = "| a | b |\n|---|---|\n| c | d |" + expected = "\n\n\n\n\n\n\n\n\n\n
ab
cd
\n" + + assert_equal expected, marksmithed(body) + end + + # Test rendering strikethrough text + test "marksmithed#when rendering strikethrough text" do + body = "This is ~~strikethrough~~ text." + expected = "

This is strikethrough text.

\n" + + assert_equal expected, marksmithed(body) + end + + # Test rendering underline text using single underscores (emphasis) + test "marksmithed#when rendering underline (emphasis) text" do + body = "This is _underline_ text." + expected = "

This is underline text.

\n" + + assert_equal expected, marksmithed(body) + end + + # Test rendering underline text using double underscores (underline) + test "marksmithed#when rendering strong text using double underscores" do + body = "This is __underline__ text." + expected = "

This is underline text.

\n" + + assert_equal expected, marksmithed(body) + end + + # Test rendering highlighted text + test "marksmithed#when rendering highlighted text" do + body = "This is ==highlighted== text." + expected = "

This is highlighted text.

\n" + + assert_equal expected, marksmithed(body) + end + + # Test rendering a blockquote + test "marksmithed#when rendering a blockquote" do + body = "> This is a blockquote." + expected = "
\n

This is a blockquote.

\n
\n" + + assert_equal expected, marksmithed(body) + end + + # Test rendering autolinks + test "marksmithed#when rendering autolinks" do + body = "Visit https://example.com" + expected = "

Visit https://example.com

\n" + + assert_equal expected, marksmithed(body) + end + + # Test rendering fenced code blocks with language specification + test "marksmithed#when rendering fenced code blocks with language" do + body = "```ruby\ndef hello\n puts 'hello'\nend\n```" + expected = "
def hello\n  puts 'hello'\nend\n
\n" + + assert_equal expected, marksmithed(body) + end + + # Test rendering hard line breaks + test "marksmithed#when rendering with hard line breaks" do + body = "Line1\nLine2" + expected = "

Line1\nLine2

\n" + + assert_equal expected, marksmithed(body) + end + + # Test rendering with lax spacing (multiple paragraphs without explicit breaks) + test "marksmithed#when rendering with lax spacing" do + body = "Paragraph one + +Paragraph two" + expected = "

Paragraph one

\n\n

Paragraph two

\n" + + assert_equal expected, marksmithed(body) + end + + # Test rendering emphasis and strong emphasis + test "marksmithed#when rendering emphasis and strong emphasis" do + body = "This is *emphasized* and this is **strongly emphasized**." + expected = "

This is emphasized and this is strongly emphasized.

\n" + + assert_equal expected, marksmithed(body) + end + + # Test rendering an empty string + test "marksmithed#when rendering an empty string" do + body = "" + expected = "" + + assert_equal expected, marksmithed(body) + end + + # Test handling of nil input + test "marksmithed#when handling nil input" do + body = nil + expected = "" + + assert_equal expected, marksmithed(body.to_s) + end +end