Align blank-body error tests with strict2 behavior

Assisted-By: devx/b8d3b9bd-01a3-41b1-90f8-632318b798e4
This commit is contained in:
Ian Ker-Seymer
2026-09-15 15:48:20 -04:00
parent 3c8e24bc94
commit 9fefd47801
2 changed files with 20 additions and 18 deletions
@@ -14,60 +14,60 @@ class BlankBodyErrorHandlingTest < Minitest::Test
error = assert_raises(Liquid::ArgumentError) do error = assert_raises(Liquid::ArgumentError) do
Liquid::Template.parse(source, line_numbers: true, error_mode: error_mode).render!(assigns) Liquid::Template.parse(source, line_numbers: true, error_mode: error_mode).render!(assigns)
end end
assert_includes error.message, message if message assert_includes(error.message, message) if message
end end
def test_blank_if_body_suppresses_inline_error_text_in_lax_and_strict def test_blank_if_body_suppresses_inline_error_text_in_lax_and_strict
[:lax, :strict].each do |mode| [:lax, :strict].each do |mode|
assert_equal '', render_inline('{% if 5 > "x" %}{% endif %}', error_mode: mode) assert_equal('', render_inline('{% if 5 > "x" %}{% endif %}', error_mode: mode))
end end
end end
def test_blank_unless_body_suppresses_inline_error_text_in_lax_and_strict def test_blank_unless_body_suppresses_inline_error_text_in_lax_and_strict
[:lax, :strict].each do |mode| [:lax, :strict].each do |mode|
assert_equal '', render_inline('{% unless 5 > "x" %} {% endunless %}', error_mode: mode) assert_equal('', render_inline('{% unless 5 > "x" %} {% endunless %}', error_mode: mode))
end end
end end
def test_blank_for_body_suppresses_inline_error_text_in_lax_and_strict def test_blank_for_body_suppresses_inline_error_text_in_lax_and_strict
[:lax, :strict].each do |mode| [:lax, :strict].each do |mode|
assert_equal '', render_inline('{% for i in (1..3) offset: xs %}{% endfor %}', error_mode: mode, assigns: { 'xs' => 'bad' }) assert_equal('', render_inline('{% for i in (1..3) offset: xs %}{% endfor %}', error_mode: mode, assigns: { 'xs' => 'bad' }))
end end
end end
def test_strict2_blank_if_body_shows_inline_error_text def test_strict2_blank_if_body_shows_inline_error_text
assert_equal COMPARISON_ERROR, render_inline('{% if 5 > "x" %}{% endif %}', error_mode: :strict2) assert_equal(COMPARISON_ERROR, render_inline('{% if 5 > "x" %}{% endif %}', error_mode: :strict2))
end end
def test_strict2_whitespace_if_body_shows_inline_error_text def test_strict2_whitespace_if_body_shows_inline_error_text
assert_equal COMPARISON_ERROR, render_inline('{% if 5 > "x" %} {% endif %}', error_mode: :strict2) assert_equal(COMPARISON_ERROR, render_inline('{% if 5 > "x" %} {% endif %}', error_mode: :strict2))
end end
def test_strict2_assign_if_body_shows_inline_error_text def test_strict2_assign_if_body_shows_inline_error_text
assert_equal COMPARISON_ERROR, render_inline('{% if 5 > "x" %}{% assign a = 1 %}{% endif %}', error_mode: :strict2) assert_equal(COMPARISON_ERROR, render_inline('{% if 5 > "x" %}{% assign a = 1 %}{% endif %}', error_mode: :strict2))
end end
def test_strict2_comment_if_body_shows_inline_error_text def test_strict2_comment_if_body_shows_inline_error_text
assert_equal COMPARISON_ERROR, render_inline('{% if 5 > "x" %}{% comment %}c{% endcomment %}{% endif %}', error_mode: :strict2) assert_equal(COMPARISON_ERROR, render_inline('{% if 5 > "x" %}{% comment %}c{% endcomment %}{% endif %}', error_mode: :strict2))
end end
def test_strict2_capture_if_body_shows_inline_error_text def test_strict2_capture_if_body_shows_inline_error_text
assert_equal COMPARISON_ERROR, render_inline('{% if 5 > "x" %}{% capture c %}text{% endcapture %}{% endif %}', error_mode: :strict2) assert_equal(COMPARISON_ERROR, render_inline('{% if 5 > "x" %}{% capture c %}text{% endcapture %}{% endif %}', error_mode: :strict2))
end end
def test_strict2_blank_unless_body_shows_inline_error_text def test_strict2_blank_unless_body_shows_inline_error_text
assert_equal COMPARISON_ERROR, render_inline('{% unless 5 > "x" %} {% endunless %}', error_mode: :strict2) assert_equal(COMPARISON_ERROR, render_inline('{% unless 5 > "x" %} {% endunless %}', error_mode: :strict2))
end end
def test_strict2_blank_for_body_shows_inline_error_text def test_strict2_blank_for_body_shows_inline_error_text
assert_equal INVALID_INTEGER_ERROR, render_inline('{% for i in (1..3) offset: xs %}{% endfor %}', error_mode: :strict2, assigns: { 'xs' => 'bad' }) assert_equal(INVALID_INTEGER_ERROR, render_inline('{% for i in (1..3) offset: xs %}{% endfor %}', error_mode: :strict2, assigns: { 'xs' => 'bad' }))
end end
def test_nonblank_bodies_show_inline_error_text_in_all_modes def test_nonblank_bodies_show_inline_error_text_in_all_modes
[:lax, :strict, :strict2].each do |mode| [:lax, :strict, :strict2].each do |mode|
assert_equal COMPARISON_ERROR, render_inline('{% if 5 > "x" %}{% echo 1 %}{% endif %}', error_mode: mode) assert_equal(COMPARISON_ERROR, render_inline('{% if 5 > "x" %}{% echo 1 %}{% endif %}', error_mode: mode))
assert_equal COMPARISON_ERROR, render_inline('{% if 5 > "x" %}{{ "" }}{% endif %}', error_mode: mode) assert_equal(COMPARISON_ERROR, render_inline('{% if 5 > "x" %}{{ "" }}{% endif %}', error_mode: mode))
assert_equal COMPARISON_ERROR, render_inline('{% if 5 > "x" %}{% else %}E{% endif %}', error_mode: mode) assert_equal(COMPARISON_ERROR, render_inline('{% if 5 > "x" %}{% else %}E{% endif %}', error_mode: mode))
end end
end end
+2
View File
@@ -265,12 +265,14 @@ class ErrorHandlingTest < Minitest::Test
end end
def test_bug_compatible_silencing_of_errors_in_blank_nodes def test_bug_compatible_silencing_of_errors_in_blank_nodes
with_error_modes(:lax, :strict) do
output = Liquid::Template.parse("{% assign x = 0 %}{% if 1 < '2' %}not blank{% assign x = 3 %}{% endif %}{{ x }}").render output = Liquid::Template.parse("{% assign x = 0 %}{% if 1 < '2' %}not blank{% assign x = 3 %}{% endif %}{{ x }}").render
assert_equal("Liquid error: comparison of Integer with String failed0", output) assert_equal("Liquid error: comparison of Integer with String failed0", output)
output = Liquid::Template.parse("{% assign x = 0 %}{% if 1 < '2' %}{% assign x = 3 %}{% endif %}{{ x }}").render output = Liquid::Template.parse("{% assign x = 0 %}{% if 1 < '2' %}{% assign x = 3 %}{% endif %}{{ x }}").render
assert_equal("0", output) assert_equal("0", output)
end end
end
def test_syntax_error_is_raised_with_template_name def test_syntax_error_is_raised_with_template_name
file_system = StubFileSystem.new("snippet" => "1\n2\n{{ 1") file_system = StubFileSystem.new("snippet" => "1\n2\n{{ 1")