Fix assert_template_result tests not picking up Liquid::Environment.default.error_mode

The `rake test` command gave us the impression that we were running all the tests
on all the error modes, that was false.
This commit is contained in:
Charles-P. Clermont
2025-10-27 16:33:31 +01:00
committed by Guilherme Carreiro
parent 1be1e36a8d
commit 34ab3bdc8e
5 changed files with 15 additions and 7 deletions
+1
View File
@@ -78,6 +78,7 @@ module Liquid
# Parse remaining comma-separated expressions # Parse remaining comma-separated expressions
while p.consume?(:comma) while p.consume?(:comma)
break if p.look(:end_of_string) break if p.look(:end_of_string)
@variables << maybe_dup_lookup(safe_parse_expression(p)) @variables << maybe_dup_lookup(safe_parse_expression(p))
end end
+7 -2
View File
@@ -26,8 +26,12 @@ class ExpressionTest < Minitest::Test
def test_float def test_float
assert_template_result("-17.42", "{{ -17.42 }}") assert_template_result("-17.42", "{{ -17.42 }}")
assert_template_result("2.5", "{{ 2.5 }}") assert_template_result("2.5", "{{ 2.5 }}")
assert_expression_result(0.0, "0.....5")
assert_expression_result(0.0, "-0..1") with_error_mode(:lax) do
assert_expression_result(0.0, "0.....5")
assert_expression_result(0.0, "-0..1")
end
assert_expression_result(1.5, "1.5") assert_expression_result(1.5, "1.5")
# this is a unfortunate quirky behavior of Liquid # this is a unfortunate quirky behavior of Liquid
@@ -61,6 +65,7 @@ class ExpressionTest < Minitest::Test
assert_template_result( assert_template_result(
"", "",
"{{ - 'theme.css' - }}", "{{ - 'theme.css' - }}",
error_mode: :lax,
) )
end end
-1
View File
@@ -3,7 +3,6 @@
require 'test_helper' require 'test_helper'
class CycleTagTest < Minitest::Test class CycleTagTest < Minitest::Test
def test_simple_cycle_inside_for_loop def test_simple_cycle_inside_for_loop
template = <<~LIQUID template = <<~LIQUID
{%- for i in (1..3) -%} {%- for i in (1..3) -%}
+6 -3
View File
@@ -138,7 +138,7 @@ class TableRowTest < Minitest::Test
def test_tablerow_loop_drop_attributes def test_tablerow_loop_drop_attributes
template = <<~LIQUID.chomp template = <<~LIQUID.chomp
{% tablerow i in (1...2) %} {% tablerow i in (1..2) %}
col: {{ tablerowloop.col }} col: {{ tablerowloop.col }}
col0: {{ tablerowloop.col0 }} col0: {{ tablerowloop.col0 }}
col_first: {{ tablerowloop.col_first }} col_first: {{ tablerowloop.col_first }}
@@ -192,12 +192,14 @@ class TableRowTest < Minitest::Test
assert_template_result( assert_template_result(
"Liquid error (line 1): invalid integer", "Liquid error (line 1): invalid integer",
'{% tablerow n in (1...10) limit:true %} {{n}} {% endtablerow %}', '{% tablerow n in (1...10) limit:true %} {{n}} {% endtablerow %}',
error_mode: :warn,
render_errors: true, render_errors: true,
) )
assert_template_result( assert_template_result(
"Liquid error (line 1): invalid integer", "Liquid error (line 1): invalid integer",
'{% tablerow n in (1...10) offset:true %} {{n}} {% endtablerow %}', '{% tablerow n in (1...10) offset:true %} {{n}} {% endtablerow %}',
error_mode: :warn,
render_errors: true, render_errors: true,
) )
@@ -205,18 +207,19 @@ class TableRowTest < Minitest::Test
"Liquid error (line 1): invalid integer", "Liquid error (line 1): invalid integer",
'{% tablerow n in (1...10) cols:true %} {{n}} {% endtablerow %}', '{% tablerow n in (1...10) cols:true %} {{n}} {% endtablerow %}',
render_errors: true, render_errors: true,
error_mode: :warn,
) )
end end
def test_table_row_handles_interrupts def test_table_row_handles_interrupts
assert_template_result( assert_template_result(
"<tr class=\"row1\">\n<td class=\"col1\"> 1 </td></tr>\n", "<tr class=\"row1\">\n<td class=\"col1\"> 1 </td></tr>\n",
'{% tablerow n in (1...3) cols:2 %} {{n}} {% break %} {{n}} {% endtablerow %}', '{% tablerow n in (1..3) cols:2 %} {{n}} {% break %} {{n}} {% endtablerow %}',
) )
assert_template_result( assert_template_result(
"<tr class=\"row1\">\n<td class=\"col1\"> 1 </td><td class=\"col2\"> 2 </td></tr>\n<tr class=\"row2\"><td class=\"col1\"> 3 </td></tr>\n", "<tr class=\"row1\">\n<td class=\"col1\"> 1 </td><td class=\"col2\"> 2 </td></tr>\n<tr class=\"row2\"><td class=\"col1\"> 3 </td></tr>\n",
'{% tablerow n in (1...3) cols:2 %} {{n}} {% continue %} {{n}} {% endtablerow %}', '{% tablerow n in (1..3) cols:2 %} {{n}} {% continue %} {{n}} {% endtablerow %}',
) )
end end
+1 -1
View File
@@ -34,7 +34,7 @@ module Minitest
def assert_template_result( def assert_template_result(
expected, template, assigns = {}, expected, template, assigns = {},
message: nil, partials: nil, error_mode: nil, render_errors: false, message: nil, partials: nil, error_mode: Liquid::Environment.default.error_mode, render_errors: false,
template_factory: nil template_factory: nil
) )
file_system = StubFileSystem.new(partials || {}) file_system = StubFileSystem.new(partials || {})