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 = "
This is a test.
\n" + + assert_equal expected, marksmithed(body) + end + + test "marksmithed#when rendering a header" do + body = "# Header" + 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 = "a | \nb | \n
---|---|
c | \nd | \n
This is strikethrough text.
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\n" + + assert_equal expected, marksmithed(body) + end + + # Test rendering autolinks + test "marksmithed#when rendering autolinks" do + body = "Visit https://example.com" + expected = "This is a blockquote.
\n
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\nParagraph 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