Skip to content

Commit

Permalink
refactor comment tag unit test to use test helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ggmichaelgo committed Nov 8, 2023
1 parent 2abf52d commit a681e73
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions test/unit/tags/comment_tag_unit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class CommentTagUnitTest < Minitest::Test
def test_does_not_parse_nodes_inside_a_comment
template = Liquid::Template.parse(<<~LIQUID.chomp, line_numbers: true)
assert_template_result("", <<~LIQUID.chomp)
{% comment %}
{% if true %}
{% if ... %}
Expand All @@ -16,33 +16,40 @@ def test_does_not_parse_nodes_inside_a_comment
{% endcase %}
{% endcomment %}
LIQUID

assert_equal("", template.render)
end

def test_allows_incomplete_tags_inside_a_comment
template = Liquid::Template.parse(<<~LIQUID.chomp, line_numbers: true)
assert_template_result("", <<~LIQUID.chomp)
{% comment %}
{% assign foo = "1"
{% endcomment %}
LIQUID

assert_equal("", template.render)
assert_template_result("", <<~LIQUID.chomp)
{% comment %}
{% comment %}
{% invalid
{% endcomment %}
{% endcomment %}
LIQUID

assert_template_result("", <<~LIQUID.chomp)
{% comment %}
{% {{ {%- endcomment %}
LIQUID
end

def test_child_comment_tags_need_to_be_closed
template = Liquid::Template.parse(<<~LIQUID.chomp, line_numbers: true)
assert_template_result("", <<~LIQUID.chomp)
{% comment %}
{% comment %}
{% comment %}{% endcomment %}
{% endcomment %}
{% endcomment %}
LIQUID

assert_equal("", template.render)

assert_raises(Liquid::SyntaxError) do
Liquid::Template.parse(<<~LIQUID.chomp, line_numbers: true)
assert_template_result("", <<~LIQUID.chomp)
{% comment %}
{% comment %}
{% comment %}
Expand All @@ -53,18 +60,16 @@ def test_child_comment_tags_need_to_be_closed
end

def test_child_raw_tags_need_to_be_closed
template = Liquid::Template.parse(<<~LIQUID.chomp, line_numbers: true)
assert_template_result("", <<~LIQUID.chomp)
{% comment %}
{% raw %}
{% endcomment %}
{% endraw %}
{% endcomment %}
LIQUID

assert_equal("", template.render)

assert_raises(Liquid::SyntaxError) do
Liquid::Template.parse(<<~LIQUID.chomp, line_numbers: true)
Liquid::Template.parse(<<~LIQUID.chomp)
{% comment %}
{% raw %}
{% endcomment %}
Expand Down

0 comments on commit a681e73

Please sign in to comment.