diff --git a/test/unit/tags/doc_tag_unit_test.rb b/test/unit/tags/doc_tag_unit_test.rb index 64b950b7..223f3ca0 100644 --- a/test/unit/tags/doc_tag_unit_test.rb +++ b/test/unit/tags/doc_tag_unit_test.rb @@ -196,6 +196,80 @@ class DocTagUnitTest < Minitest::Test ) end + def test_doc_tag_blank_with_empty_content + template_source = "{% doc %}{% enddoc %}" + + doc_tag = nil + ParseTreeVisitor + .for(Template.parse(template_source).root) + .add_callback_for(Liquid::Doc) do |tag| + doc_tag = tag + end + .visit + + assert_equal(true, doc_tag.blank?) + end + + def test_doc_tag_blank_with_content + template_source = "{% doc %}Some documentation{% enddoc %}" + + doc_tag = nil + ParseTreeVisitor + .for(Template.parse(template_source).root) + .add_callback_for(Liquid::Doc) do |tag| + doc_tag = tag + end + .visit + + assert_equal(false, doc_tag.blank?) + end + + def test_doc_tag_blank_with_whitespace_only + template_source = "{% doc %} {% enddoc %}" + + doc_tag = nil + ParseTreeVisitor + .for(Template.parse(template_source).root) + .add_callback_for(Liquid::Doc) do |tag| + doc_tag = tag + end + .visit + + assert_equal(false, doc_tag.blank?) + end + + def test_doc_tag_nodelist_returns_array_with_body + doc_content = "Documentation content\n@param {string} foo" + template_source = "{% doc %}#{doc_content}{% enddoc %}" + + doc_tag = nil + ParseTreeVisitor + .for(Template.parse(template_source).root) + .add_callback_for(Liquid::Doc) do |tag| + doc_tag = tag + end + .visit + + assert_equal([doc_content], doc_tag.nodelist) + assert_equal(1, doc_tag.nodelist.length) + assert_equal(doc_content, doc_tag.nodelist.first) + end + + def test_doc_tag_nodelist_with_empty_content + template_source = "{% doc %}{% enddoc %}" + + doc_tag = nil + ParseTreeVisitor + .for(Template.parse(template_source).root) + .add_callback_for(Liquid::Doc) do |tag| + doc_tag = tag + end + .visit + + assert_equal([""], doc_tag.nodelist) + assert_equal(1, doc_tag.nodelist.length) + end + private def traversal(template)