mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Add tests for new public methods
This commit is contained in:
@@ -196,6 +196,80 @@ class DocTagUnitTest < Minitest::Test
|
|||||||
)
|
)
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def traversal(template)
|
def traversal(template)
|
||||||
|
|||||||
Reference in New Issue
Block a user