From f3638b3eb448599fa8efbd5fa18ee9e7c1394006 Mon Sep 17 00:00:00 2001 From: Christophe Naud-Dulude Date: Tue, 30 Nov 2021 11:56:49 -0500 Subject: [PATCH] Test parsing of Liquid code in comments --- lib/liquid/tags/echo.rb | 4 ++++ test/integration/tags/comment_tag_test.rb | 25 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/integration/tags/comment_tag_test.rb diff --git a/lib/liquid/tags/echo.rb b/lib/liquid/tags/echo.rb index 19026a08..4101d5a2 100644 --- a/lib/liquid/tags/echo.rb +++ b/lib/liquid/tags/echo.rb @@ -15,15 +15,19 @@ module Liquid attr_reader :variable def initialize(tag_name, markup, parse_context) + puts "Initializing Echo tag" super @variable = Variable.new(markup, parse_context) end def render(context) + puts "Render Echo tag" @variable.render_to_output_buffer(context, +'') end class ParseTreeVisitor < Liquid::ParseTreeVisitor + puts "ParseTreeVisitor Echo tag" + def children [@node.variable] end diff --git a/test/integration/tags/comment_tag_test.rb b/test/integration/tags/comment_tag_test.rb new file mode 100644 index 00000000..0e433b1a --- /dev/null +++ b/test/integration/tags/comment_tag_test.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'test_helper' + +class CommentTagTest < Minitest::Test + include Liquid + + def test_single_line_comments_parse + assert_template_result('Before comment', <<~LIQUID) + Before comment + {%- comment -%} + Regular text comment + Liquid in comment: {% echo 'Hi from comment' %} + {%- endcomment -%} + LIQUID + end + + def test_multi_line_comments_parse + assert_template_result('Before comment', <<~LIQUID) + Before comment + {%- comment -%} Regular text comment {%- endcomment -%} + {%- comment -%} Liquid in comment: {% echo 'Hi from comment' %} {%- endcomment -%} + LIQUID + end +end # CommentTagTest