mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-16 17:30:43 -07:00
Fix liquid tag nested in outer block
This commit is contained in:
@@ -81,6 +81,18 @@ class LiquidTagTest < Minitest::Test
|
||||
assert_match_syntax_error("syntax error (line 3): Unknown tag 'error'", "{% liquid echo ''\n \n error %}")
|
||||
end
|
||||
|
||||
def test_nested_liquid_tag
|
||||
assert_usage_increment("liquid_tag_contains_outer_tag", times: 0) do
|
||||
assert_template_result('good', <<~LIQUID)
|
||||
{%- if true %}
|
||||
{%- liquid
|
||||
echo "good"
|
||||
%}
|
||||
{%- endif -%}
|
||||
LIQUID
|
||||
end
|
||||
end
|
||||
|
||||
def test_cannot_open_blocks_living_past_a_liquid_tag
|
||||
assert_match_syntax_error("syntax error (line 3): 'if' tag was never closed", <<~LIQUID)
|
||||
{%- liquid
|
||||
@@ -91,11 +103,13 @@ class LiquidTagTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_quirk_can_close_blocks_created_before_a_liquid_tag
|
||||
assert_template_result("42", <<~LIQUID)
|
||||
{%- if true -%}
|
||||
42
|
||||
{%- liquid endif -%}
|
||||
LIQUID
|
||||
assert_usage_increment("liquid_tag_contains_outer_tag") do
|
||||
assert_template_result("42", <<~LIQUID)
|
||||
{%- if true -%}
|
||||
42
|
||||
{%- liquid endif -%}
|
||||
LIQUID
|
||||
end
|
||||
end
|
||||
|
||||
def test_liquid_tag_in_raw
|
||||
|
||||
@@ -58,6 +58,23 @@ module Minitest
|
||||
assert_match(match, exception.message)
|
||||
end
|
||||
|
||||
def assert_usage_increment(name, times: 1)
|
||||
old_method = Liquid::Usage.method(:increment)
|
||||
calls = 0
|
||||
begin
|
||||
Liquid::Usage.singleton_class.send(:remove_method, :increment)
|
||||
Liquid::Usage.define_singleton_method(:increment) do |got_name|
|
||||
calls += 1 if got_name == name
|
||||
old_method.call(got_name)
|
||||
end
|
||||
yield
|
||||
ensure
|
||||
Liquid::Usage.singleton_class.send(:remove_method, :increment)
|
||||
Liquid::Usage.define_singleton_method(:increment, old_method)
|
||||
end
|
||||
assert_equal(times, calls, "Number of calls to Usage.increment with #{name.inspect}")
|
||||
end
|
||||
|
||||
def with_global_filter(*globals)
|
||||
original_global_filters = Liquid::StrainerFactory.instance_variable_get(:@global_filters)
|
||||
Liquid::StrainerFactory.instance_variable_set(:@global_filters, [])
|
||||
|
||||
Reference in New Issue
Block a user