From 6aa4041c0f33da8420891b10d9d1f668ab7e0456 Mon Sep 17 00:00:00 2001 From: Guilherme Carreiro Date: Thu, 23 Oct 2025 10:01:01 +0200 Subject: [PATCH] Rename `with_error_mode(...)` to `with_error_modes(...)` --- test/integration/context_test.rb | 2 +- test/integration/error_handling_test.rb | 2 +- test/integration/expression_test.rb | 2 +- test/integration/parsing_quirks_test.rb | 20 +++++++------- test/integration/tags/cycle_tag_test.rb | 16 ++++++------ test/integration/tags/include_tag_test.rb | 20 +++++++------- test/integration/tags/render_tag_test.rb | 12 ++++----- test/integration/tags/table_row_test.rb | 32 +++++++++++------------ test/integration/variable_test.rb | 20 +++++++------- test/test_helper.rb | 2 +- test/unit/tags/case_tag_unit_test.rb | 20 +++++++------- test/unit/variable_unit_test.rb | 6 ++--- 12 files changed, 77 insertions(+), 77 deletions(-) diff --git a/test/integration/context_test.rb b/test/integration/context_test.rb index f6afaca5..f59147e2 100644 --- a/test/integration/context_test.rb +++ b/test/integration/context_test.rb @@ -632,7 +632,7 @@ class ContextTest < Minitest::Test end def test_has_key_will_not_add_an_error_for_missing_keys - with_error_mode(:strict) do + with_error_modes(:strict) do context = Context.new context.key?('unknown') assert_empty(context.errors) diff --git a/test/integration/error_handling_test.rb b/test/integration/error_handling_test.rb index 26b0e5f9..0fda83ca 100644 --- a/test/integration/error_handling_test.rb +++ b/test/integration/error_handling_test.rb @@ -67,7 +67,7 @@ class ErrorHandlingTest < Minitest::Test end def test_unrecognized_operator - with_error_mode(:strict) do + with_error_modes(:strict) do assert_raises(SyntaxError) do Liquid::Template.parse(' {% if 1 =! 2 %}ok{% endif %} ') end diff --git a/test/integration/expression_test.rb b/test/integration/expression_test.rb index fe54bd99..ae84fa36 100644 --- a/test/integration/expression_test.rb +++ b/test/integration/expression_test.rb @@ -27,7 +27,7 @@ class ExpressionTest < Minitest::Test assert_template_result("-17.42", "{{ -17.42 }}") assert_template_result("2.5", "{{ 2.5 }}") - with_error_mode(:lax) do + with_error_modes(:lax) do assert_expression_result(0.0, "0.....5") assert_expression_result(0.0, "-0..1") end diff --git a/test/integration/parsing_quirks_test.rb b/test/integration/parsing_quirks_test.rb index f5b483fc..b82ce86c 100644 --- a/test/integration/parsing_quirks_test.rb +++ b/test/integration/parsing_quirks_test.rb @@ -31,18 +31,18 @@ class ParsingQuirksTest < Minitest::Test def test_error_on_empty_filter assert(Template.parse("{{test}}")) - with_error_mode(:lax) do + with_error_modes(:lax) do assert(Template.parse("{{|test}}")) end - with_error_mode(:strict) do + with_error_modes(:strict) do assert_raises(SyntaxError) { Template.parse("{{|test}}") } assert_raises(SyntaxError) { Template.parse("{{test |a|b|}}") } end end def test_meaningless_parens_error - with_error_mode(:strict) do + with_error_modes(:strict) do assert_raises(SyntaxError) do markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false" Template.parse("{% if #{markup} %} YES {% endif %}") @@ -51,7 +51,7 @@ class ParsingQuirksTest < Minitest::Test end def test_unexpected_characters_syntax_error - with_error_mode(:strict) do + with_error_modes(:strict) do assert_raises(SyntaxError) do markup = "true && false" Template.parse("{% if #{markup} %} YES {% endif %}") @@ -70,7 +70,7 @@ class ParsingQuirksTest < Minitest::Test end def test_meaningless_parens_lax - with_error_mode(:lax) do + with_error_modes(:lax) do assigns = { 'b' => 'bar', 'c' => 'baz' } markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false" assert_template_result(' YES ', "{% if #{markup} %} YES {% endif %}", assigns) @@ -78,7 +78,7 @@ class ParsingQuirksTest < Minitest::Test end def test_unexpected_characters_silently_eat_logic_lax - with_error_mode(:lax) do + with_error_modes(:lax) do markup = "true && false" assert_template_result(' YES ', "{% if #{markup} %} YES {% endif %}") markup = "false || true" @@ -93,7 +93,7 @@ class ParsingQuirksTest < Minitest::Test end def test_unanchored_filter_arguments - with_error_mode(:lax) do + with_error_modes(:lax) do assert_template_result('hi', "{{ 'hi there' | split$$$:' ' | first }}") assert_template_result('x', "{{ 'X' | downcase) }}") @@ -106,14 +106,14 @@ class ParsingQuirksTest < Minitest::Test end def test_invalid_variables_work - with_error_mode(:lax) do + with_error_modes(:lax) do assert_template_result('bar', "{% assign 123foo = 'bar' %}{{ 123foo }}") assert_template_result('123', "{% assign 123 = 'bar' %}{{ 123 }}") end end def test_extra_dots_in_ranges - with_error_mode(:lax) do + with_error_modes(:lax) do assert_template_result('12345', "{% for i in (1...5) %}{{ i }}{% endfor %}") end end @@ -133,7 +133,7 @@ class ParsingQuirksTest < Minitest::Test end def test_incomplete_expression - with_error_mode(:lax) do + with_error_modes(:lax) do assert_template_result("false", "{{ false - }}") assert_template_result("false", "{{ false > }}") assert_template_result("false", "{{ false < }}") diff --git a/test/integration/tags/cycle_tag_test.rb b/test/integration/tags/cycle_tag_test.rb index 14d8997b..f3f865f0 100644 --- a/test/integration/tags/cycle_tag_test.rb +++ b/test/integration/tags/cycle_tag_test.rb @@ -96,12 +96,12 @@ class CycleTagTest < Minitest::Test template1 = "{% assign 5 = 'b' %}{% cycle .5, .4 %}" template2 = "{% cycle .5: 'a', 'b' %}" - with_error_mode(:lax, :strict) do + with_error_modes(:lax, :strict) do assert_template_result("b", template1) assert_template_result("a", template2) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do error1 = assert_raises(Liquid::SyntaxError) { Template.parse(template1) } error2 = assert_raises(Liquid::SyntaxError) { Template.parse(template2) } @@ -121,7 +121,7 @@ class CycleTagTest < Minitest::Test template4 = "#{assignments}{% cycle n e: 'a', 'b', 'c' %}" template5 = "#{assignments}{% cycle n e 'a', 'b', 'c' %}" - with_error_mode(:lax, :strict) do + with_error_modes(:lax, :strict) do assert_template_result("a", template1) assert_template_result("a", template2) assert_template_result("a", template3) @@ -129,7 +129,7 @@ class CycleTagTest < Minitest::Test assert_template_result("N", template5) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do error1 = assert_raises(Liquid::SyntaxError) { Template.parse(template1) } error2 = assert_raises(Liquid::SyntaxError) { Template.parse(template2) } error3 = assert_raises(Liquid::SyntaxError) { Template.parse(template3) } @@ -153,11 +153,11 @@ class CycleTagTest < Minitest::Test {% endfor %} LIQUID - with_error_mode(:lax, :strict) do + with_error_modes(:lax, :strict) do refute_nil(Template.parse(template)) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } assert_match(/Unexpected character =/, error.message) end @@ -170,11 +170,11 @@ class CycleTagTest < Minitest::Test {% endfor %} LIQUID - with_error_mode(:lax, :strict) do + with_error_modes(:lax, :strict) do refute_nil(Template.parse(template)) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } assert_match(/Unexpected character =/, error.message) end diff --git a/test/integration/tags/include_tag_test.rb b/test/integration/tags/include_tag_test.rb index b41a98c6..3ccd1779 100644 --- a/test/integration/tags/include_tag_test.rb +++ b/test/integration/tags/include_tag_test.rb @@ -205,7 +205,7 @@ class IncludeTagTest < Minitest::Test end def test_rigid_parsing_errors - with_error_mode(:lax, :strict) do + with_error_modes(:lax, :strict) do assert_template_result( 'hello value1 value2', '{% include "snippet" !!! arg1: "value1" ~~~ arg2: "value2" %}', @@ -213,7 +213,7 @@ class IncludeTagTest < Minitest::Test ) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do assert_syntax_error( '{% include "snippet" !!! arg1: "value1" ~~~ arg2: "value2" %}', ) @@ -303,13 +303,13 @@ class IncludeTagTest < Minitest::Test assert_raises(Liquid::SyntaxError) do Template.parse("{% include template %}", error_mode: :strict, environment: env).render!("template" => '{{ "X" || downcase }}') end - with_error_mode(:lax) do + with_error_modes(:lax) do assert_equal('x', Template.parse("{% include template %}", error_mode: :strict, include_options_blacklist: true, environment: env).render!("template" => '{{ "X" || downcase }}')) end assert_raises(Liquid::SyntaxError) do Template.parse("{% include template %}", error_mode: :strict, include_options_blacklist: [:locale], environment: env).render!("template" => '{{ "X" || downcase }}') end - with_error_mode(:lax) do + with_error_modes(:lax) do assert_equal('x', Template.parse("{% include template %}", error_mode: :strict, include_options_blacklist: [:error_mode], environment: env).render!("template" => '{{ "X" || downcase }}')) end end @@ -404,11 +404,11 @@ class IncludeTagTest < Minitest::Test def test_include_template_with_invalid_expression template = "{% include foo=>bar %}" - with_error_mode(:lax, :strict) do + with_error_modes(:lax, :strict) do refute_nil(Template.parse(template)) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } assert_match(/Unexpected character =/, error.message) end @@ -417,11 +417,11 @@ class IncludeTagTest < Minitest::Test def test_include_with_invalid_expression template = '{% include "snippet" with foo=>bar %}' - with_error_mode(:lax, :strict) do + with_error_modes(:lax, :strict) do refute_nil(Template.parse(template)) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } assert_match(/Unexpected character =/, error.message) end @@ -430,11 +430,11 @@ class IncludeTagTest < Minitest::Test def test_include_attribute_with_invalid_expression template = '{% include "snippet", key: foo=>bar %}' - with_error_mode(:lax, :strict) do + with_error_modes(:lax, :strict) do refute_nil(Template.parse(template)) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } assert_match(/Unexpected character =/, error.message) end diff --git a/test/integration/tags/render_tag_test.rb b/test/integration/tags/render_tag_test.rb index 12759daf..d6453fb5 100644 --- a/test/integration/tags/render_tag_test.rb +++ b/test/integration/tags/render_tag_test.rb @@ -106,7 +106,7 @@ class RenderTagTest < Minitest::Test end def test_rigid_parsing_errors - with_error_mode(:lax, :strict) do + with_error_modes(:lax, :strict) do assert_template_result( 'hello value1 value2', '{% render "snippet" !!! arg1: "value1" ~~~ arg2: "value2" %}', @@ -114,7 +114,7 @@ class RenderTagTest < Minitest::Test ) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do assert_syntax_error( '{% render "snippet" !!! arg1: "value1" ~~~ arg2: "value2" %}', ) @@ -318,11 +318,11 @@ class RenderTagTest < Minitest::Test def test_render_with_invalid_expression template = '{% render "snippet" with foo=>bar %}' - with_error_mode(:lax, :strict) do + with_error_modes(:lax, :strict) do refute_nil(Template.parse(template)) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } assert_match(/Unexpected character =/, error.message) end @@ -331,11 +331,11 @@ class RenderTagTest < Minitest::Test def test_render_attribute_with_invalid_expression template = '{% render "snippet", key: foo=>bar %}' - with_error_mode(:lax, :strict) do + with_error_modes(:lax, :strict) do refute_nil(Template.parse(template)) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } assert_match(/Unexpected character =/, error.message) end diff --git a/test/integration/tags/table_row_test.rb b/test/integration/tags/table_row_test.rb index 0f9b051f..828f7738 100644 --- a/test/integration/tags/table_row_test.rb +++ b/test/integration/tags/table_row_test.rb @@ -270,7 +270,7 @@ class TableRowTest < Minitest::Test 456 OUTPUT - with_error_mode(:rigid) do + with_error_modes(:rigid) do assert_template_result(expected, template) end end @@ -285,7 +285,7 @@ class TableRowTest < Minitest::Test 123 OUTPUT - with_error_mode(:rigid) do + with_error_modes(:rigid) do assert_template_result(expected, template) end end @@ -300,7 +300,7 @@ class TableRowTest < Minitest::Test 345 OUTPUT - with_error_mode(:rigid) do + with_error_modes(:rigid) do assert_template_result(expected, template) end end @@ -315,7 +315,7 @@ class TableRowTest < Minitest::Test 123 OUTPUT - with_error_mode(:rigid) do + with_error_modes(:rigid) do assert_template_result(expected, template) end end @@ -331,7 +331,7 @@ class TableRowTest < Minitest::Test 45 OUTPUT - with_error_mode(:rigid) do + with_error_modes(:rigid) do assert_template_result(expected, template) end end @@ -347,7 +347,7 @@ class TableRowTest < Minitest::Test 34 OUTPUT - with_error_mode(:rigid) do + with_error_modes(:rigid) do assert_template_result(expected, template, { 'numbers' => [1, 2, 3, 4] }) end end @@ -363,7 +363,7 @@ class TableRowTest < Minitest::Test 34 OUTPUT - with_error_mode(:rigid) do + with_error_modes(:rigid) do assert_template_result(expected, template, { 'obj' => { 'numbers' => [1, 2, 3, 4] } }) end end @@ -378,7 +378,7 @@ class TableRowTest < Minitest::Test 1020 OUTPUT - with_error_mode(:rigid) do + with_error_modes(:rigid) do assert_template_result(expected, template, { 'obj' => { 'numbers' => [10, 20] } }) end end @@ -393,7 +393,7 @@ class TableRowTest < Minitest::Test 123 OUTPUT - with_error_mode(:rigid) do + with_error_modes(:rigid) do assert_template_result(expected, template) end end @@ -401,7 +401,7 @@ class TableRowTest < Minitest::Test def test_tablerow_without_in_keyword_in_rigid_mode template = '{% tablerow i (1..10) %}{{ i }}{% endtablerow %}' - with_error_mode(:rigid) do + with_error_modes(:rigid) do error = assert_raises(SyntaxError) { Template.parse(template) } assert_equal("Liquid syntax error: For loops require an 'in' clause in \"i (1..10)\"", error.message) end @@ -410,7 +410,7 @@ class TableRowTest < Minitest::Test def test_tablerow_with_multiple_invalid_attributes_reports_first_in_rigid_mode template = '{% tablerow i in (1..10) invalid1: 5, invalid2: 10 %}{{ i }}{% endtablerow %}' - with_error_mode(:rigid) do + with_error_modes(:rigid) do error = assert_raises(SyntaxError) { Template.parse(template) } assert_equal("Liquid syntax error: Invalid attribute 'invalid1' in tablerow loop. Valid attributes are cols, limit, offset, and range in \"i in (1..10) invalid1: 5, invalid2: 10\"", error.message) end @@ -426,7 +426,7 @@ class TableRowTest < Minitest::Test OUTPUT - with_error_mode(:rigid) do + with_error_modes(:rigid) do assert_template_result(expected, template, { 'empty_array' => [] }) end end @@ -439,11 +439,11 @@ class TableRowTest < Minitest::Test 12345 OUTPUT - with_error_mode(:lax, :strict) do + with_error_modes(:lax, :strict) do assert_template_result(expected, template) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do error = assert_raises(SyntaxError) { Template.parse(template) } assert_match(/Invalid attribute 'invalid_attr'/, error.message) end @@ -452,7 +452,7 @@ class TableRowTest < Minitest::Test def test_tablerow_with_invalid_expression_strict_vs_rigid template = '{% tablerow i in (1..5) limit: foo=>bar %}{{ i }}{% endtablerow %}' - with_error_mode(:lax, :strict) do + with_error_modes(:lax, :strict) do expected = <<~OUTPUT @@ -460,7 +460,7 @@ class TableRowTest < Minitest::Test assert_template_result(expected, template) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do # Rigid mode validates expression syntax and rejects invalid expressions error = assert_raises(SyntaxError) { Template.parse(template) } assert_match(/Unexpected character =/, error.message) diff --git a/test/integration/variable_test.rb b/test/integration/variable_test.rb index 740ea9f9..f0f2bc40 100644 --- a/test/integration/variable_test.rb +++ b/test/integration/variable_test.rb @@ -213,12 +213,12 @@ class VariableTest < Minitest::Test def test_filter_with_single_trailing_comma template = '{{ "hello" | append: "world", }}' - with_error_mode(:strict) do + with_error_modes(:strict) do error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } assert_match(/is not a valid expression/, error.message) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do assert_template_result('helloworld', template) end end @@ -226,12 +226,12 @@ class VariableTest < Minitest::Test def test_multiple_filters_with_trailing_commas template = '{{ "hello" | append: "1", | append: "2", }}' - with_error_mode(:strict) do + with_error_modes(:strict) do error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } assert_match(/is not a valid expression/, error.message) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do assert_template_result('hello12', template) end end @@ -239,12 +239,12 @@ class VariableTest < Minitest::Test def test_filter_with_colon_but_no_arguments template = '{{ "test" | upcase: }}' - with_error_mode(:strict) do + with_error_modes(:strict) do error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } assert_match(/is not a valid expression/, error.message) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do assert_template_result('TEST', template) end end @@ -252,12 +252,12 @@ class VariableTest < Minitest::Test def test_filter_chain_with_colon_no_args template = '{{ "test" | append: "x" | upcase: }}' - with_error_mode(:strict) do + with_error_modes(:strict) do error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } assert_match(/is not a valid expression/, error.message) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do assert_template_result('TESTX', template) end end @@ -265,12 +265,12 @@ class VariableTest < Minitest::Test def test_combining_trailing_comma_and_empty_args template = '{{ "test" | append: "x", | upcase: }}' - with_error_mode(:strict) do + with_error_modes(:strict) do error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } assert_match(/is not a valid expression/, error.message) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do assert_template_result('TESTX', template) end end diff --git a/test/test_helper.rb b/test/test_helper.rb index a09f2277..293ea476 100755 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -82,7 +82,7 @@ module Minitest Environment.dangerously_override(environment, &blk) end - def with_error_mode(*modes) + def with_error_modes(*modes) old_mode = Liquid::Environment.default.error_mode modes.each do |mode| Liquid::Environment.default.error_mode = mode diff --git a/test/unit/tags/case_tag_unit_test.rb b/test/unit/tags/case_tag_unit_test.rb index e6a5abab..5e181f3e 100644 --- a/test/unit/tags/case_tag_unit_test.rb +++ b/test/unit/tags/case_tag_unit_test.rb @@ -20,11 +20,11 @@ class CaseTagUnitTest < Minitest::Test {%- endcase -%} LIQUID - with_error_mode(:lax, :strict) do + with_error_modes(:lax, :strict) do assert_template_result("one", template) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } assert_match(/Expected end_of_string but found/, error.message) @@ -41,11 +41,11 @@ class CaseTagUnitTest < Minitest::Test {%- endcase -%} LIQUID - with_error_mode(:lax, :strict) do + with_error_modes(:lax, :strict) do assert_template_result("one", template) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } assert_match(/Expected end_of_string but found/, error.message) @@ -62,7 +62,7 @@ class CaseTagUnitTest < Minitest::Test {%- endcase -%} LIQUID - with_error_mode(:lax, :strict, :rigid) do + with_error_modes(:lax, :strict, :rigid) do assert_template_result("one", template) end end @@ -77,7 +77,7 @@ class CaseTagUnitTest < Minitest::Test {%- endcase -%} LIQUID - with_error_mode(:lax, :strict, :rigid) do + with_error_modes(:lax, :strict, :rigid) do assert_template_result("one", template) end end @@ -93,11 +93,11 @@ class CaseTagUnitTest < Minitest::Test LIQUID assigns = { 'foo' => { 'bar' => 'baz' } } - with_error_mode(:lax, :strict) do + with_error_modes(:lax, :strict) do assert_template_result("one", template, assigns) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } assert_match(/Unexpected character =/, error.message) @@ -115,11 +115,11 @@ class CaseTagUnitTest < Minitest::Test LIQUID assigns = { 'foo' => { 'bar' => 'baz' } } - with_error_mode(:lax, :strict) do + with_error_modes(:lax, :strict) do assert_template_result("one", template, assigns) end - with_error_mode(:rigid) do + with_error_modes(:rigid) do error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } assert_match(/Unexpected character =/, error.message) diff --git a/test/unit/variable_unit_test.rb b/test/unit/variable_unit_test.rb index 82ac0330..b46fc23f 100644 --- a/test/unit/variable_unit_test.rb +++ b/test/unit/variable_unit_test.rb @@ -108,7 +108,7 @@ class VariableUnitTest < Minitest::Test assert_equal(VariableLookup.new('foo-bar'), create_variable('foo-bar').name) assert_equal(VariableLookup.new('foo-bar-2'), create_variable('foo-bar-2').name) - with_error_mode(:strict) do + with_error_modes(:strict) do assert_raises(Liquid::SyntaxError) { create_variable('foo - bar') } assert_raises(Liquid::SyntaxError) { create_variable('-foo') } assert_raises(Liquid::SyntaxError) { create_variable('2foo') } @@ -154,7 +154,7 @@ class VariableUnitTest < Minitest::Test end def test_strict_filter_argument_parsing - with_error_mode(:strict) do + with_error_modes(:strict) do assert_raises(SyntaxError) do create_variable(%( number_of_comments | pluralize: 'comment': 'comments' )) end @@ -162,7 +162,7 @@ class VariableUnitTest < Minitest::Test end def test_rigid_filter_argument_parsing - with_error_mode(:rigid) do + with_error_modes(:rigid) do # optional colon var = create_variable(%(n | f1 | f2:)) assert_equal([['f1', []], ['f2', []]], var.filters)