From 018442b7d1ff1e5e0570c4eacf55d8afa27e4a1e Mon Sep 17 00:00:00 2001 From: Guilherme Carreiro Date: Wed, 22 Oct 2025 12:09:32 +0200 Subject: [PATCH] Covered changes with more tests, remove redundant cases, and the new `with_error_mode(*modes)` Most of changes update this: ``` [:lax, :strict].each do |mode| with_error_mode(mode) do assert_template_result(... ``` to be this: ``` with_error_mode(:lax, :strict) do assert_template_result(... ``` --- lib/liquid/tags/case.rb | 1 - lib/liquid/tags/cycle.rb | 1 - lib/liquid/template.rb | 4 +- test/integration/tags/cycle_tag_test.rb | 56 +++++-- test/integration/tags/include_tag_test.rb | 57 +++++-- test/integration/tags/render_tag_test.rb | 44 +++-- test/integration/tags/table_row_test.rb | 173 +++++++------------- test/unit/condition_unit_test.rb | 31 ++++ test/unit/rigid_mode_unit_test.rb | 191 ---------------------- test/unit/tags/case_tag_unit_test.rb | 28 ++-- 10 files changed, 229 insertions(+), 357 deletions(-) delete mode 100644 test/unit/rigid_mode_unit_test.rb diff --git a/lib/liquid/tags/case.rb b/lib/liquid/tags/case.rb index bdf329a2..926e4107 100644 --- a/lib/liquid/tags/case.rb +++ b/lib/liquid/tags/case.rb @@ -123,7 +123,6 @@ module Liquid block.attach(body) @blocks << block - # Temporarily until support :or lexeme. break unless parser.id?('or') || parser.consume?(:comma) end diff --git a/lib/liquid/tags/cycle.rb b/lib/liquid/tags/cycle.rb index 51fa9714..639ed9a5 100644 --- a/lib/liquid/tags/cycle.rb +++ b/lib/liquid/tags/cycle.rb @@ -90,7 +90,6 @@ module Liquid end end - # Temporarily until we migrate def strict_parse(markup) lax_parse(markup) end diff --git a/lib/liquid/template.rb b/lib/liquid/template.rb index acda1e4d..5d349abd 100644 --- a/lib/liquid/template.rb +++ b/lib/liquid/template.rb @@ -24,8 +24,8 @@ module Liquid # Sets how strict the parser should be. # :lax acts like liquid 2.5 and silently ignores malformed tags in most cases. # :warn is the default and will give deprecation warnings when invalid syntax is used. - # :strict will enforce correct syntax. - # :rigid is stricter even. + # :strict enforces correct syntax for most tags + # :rigid enforces correct syntax for all tags def error_mode=(mode) Deprecations.warn("Template.error_mode=", "Environment#error_mode=") Environment.default.error_mode = mode diff --git a/test/integration/tags/cycle_tag_test.rb b/test/integration/tags/cycle_tag_test.rb index c41fb68e..14d8997b 100644 --- a/test/integration/tags/cycle_tag_test.rb +++ b/test/integration/tags/cycle_tag_test.rb @@ -96,11 +96,9 @@ class CycleTagTest < Minitest::Test template1 = "{% assign 5 = 'b' %}{% cycle .5, .4 %}" template2 = "{% cycle .5: 'a', 'b' %}" - [:lax, :strict].each do |mode| - with_error_mode(mode) do - assert_template_result("b", template1) - assert_template_result("a", template2) - end + with_error_mode(:lax, :strict) do + assert_template_result("b", template1) + assert_template_result("a", template2) end with_error_mode(:rigid) do @@ -123,14 +121,12 @@ class CycleTagTest < Minitest::Test template4 = "#{assignments}{% cycle n e: 'a', 'b', 'c' %}" template5 = "#{assignments}{% cycle n e 'a', 'b', 'c' %}" - [:lax, :strict].each do |mode| - with_error_mode(mode) do - assert_template_result("a", template1) - assert_template_result("a", template2) - assert_template_result("a", template3) - assert_template_result("N", template4) - assert_template_result("N", template5) - end + with_error_mode(:lax, :strict) do + assert_template_result("a", template1) + assert_template_result("a", template2) + assert_template_result("a", template3) + assert_template_result("N", template4) + assert_template_result("N", template5) end with_error_mode(:rigid) do @@ -149,4 +145,38 @@ class CycleTagTest < Minitest::Test assert_match(expected_error, error5.message) end end + + def test_cycle_name_with_invalid_expression + template = <<~LIQUID + {% for i in (1..3) %} + {% cycle foo=>bar: "a", "b" %} + {% endfor %} + LIQUID + + with_error_mode(:lax, :strict) do + refute_nil(Template.parse(template)) + end + + with_error_mode(:rigid) do + error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } + assert_match(/Unexpected character =/, error.message) + end + end + + def test_cycle_variable_with_invalid_expression + template = <<~LIQUID + {% for i in (1..3) %} + {% cycle foo=>bar, "a", "b" %} + {% endfor %} + LIQUID + + with_error_mode(:lax, :strict) do + refute_nil(Template.parse(template)) + end + + with_error_mode(:rigid) do + error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } + assert_match(/Unexpected character =/, error.message) + end + end end diff --git a/test/integration/tags/include_tag_test.rb b/test/integration/tags/include_tag_test.rb index 9f92f1b2..b41a98c6 100644 --- a/test/integration/tags/include_tag_test.rb +++ b/test/integration/tags/include_tag_test.rb @@ -205,24 +205,20 @@ class IncludeTagTest < Minitest::Test end def test_rigid_parsing_errors - [:lax, :strict].each do |mode| - with_error_mode(mode) do - assert_template_result( - 'hello value1 value2', - '{% include "snippet" !!! arg1: "value1" ~~~ arg2: "value2" %}', - partials: { 'snippet' => 'hello {{ arg1 }} {{ arg2 }}' }, - ) - end + with_error_mode(:lax, :strict) do + assert_template_result( + 'hello value1 value2', + '{% include "snippet" !!! arg1: "value1" ~~~ arg2: "value2" %}', + partials: { 'snippet' => 'hello {{ arg1 }} {{ arg2 }}' }, + ) end - [:rigid].each do |mode| + with_error_mode(:rigid) do assert_syntax_error( '{% include "snippet" !!! arg1: "value1" ~~~ arg2: "value2" %}', - error_mode: mode, ) assert_syntax_error( '{% include "snippet" | filter %}', - error_mode: mode, ) end end @@ -404,4 +400,43 @@ class IncludeTagTest < Minitest::Test render_errors: true, ) end + + def test_include_template_with_invalid_expression + template = "{% include foo=>bar %}" + + with_error_mode(:lax, :strict) do + refute_nil(Template.parse(template)) + end + + with_error_mode(:rigid) do + error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } + assert_match(/Unexpected character =/, error.message) + end + end + + def test_include_with_invalid_expression + template = '{% include "snippet" with foo=>bar %}' + + with_error_mode(:lax, :strict) do + refute_nil(Template.parse(template)) + end + + with_error_mode(:rigid) do + error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } + assert_match(/Unexpected character =/, error.message) + end + end + + def test_include_attribute_with_invalid_expression + template = '{% include "snippet", key: foo=>bar %}' + + with_error_mode(:lax, :strict) do + refute_nil(Template.parse(template)) + end + + with_error_mode(:rigid) do + error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } + assert_match(/Unexpected character =/, error.message) + end + end end # IncludeTagTest diff --git a/test/integration/tags/render_tag_test.rb b/test/integration/tags/render_tag_test.rb index 15a0adc2..e2f4530a 100644 --- a/test/integration/tags/render_tag_test.rb +++ b/test/integration/tags/render_tag_test.rb @@ -106,24 +106,20 @@ class RenderTagTest < Minitest::Test end def test_rigid_parsing_errors - [:lax, :strict].each do |mode| - with_error_mode(mode) do - assert_template_result( - 'hello value1 value2', - '{% render "snippet" !!! arg1: "value1" ~~~ arg2: "value2" %}', - partials: { 'snippet' => 'hello {{ arg1 }} {{ arg2 }}' }, - ) - end + with_error_mode(:lax, :strict) do + assert_template_result( + 'hello value1 value2', + '{% render "snippet" !!! arg1: "value1" ~~~ arg2: "value2" %}', + partials: { 'snippet' => 'hello {{ arg1 }} {{ arg2 }}' }, + ) end - [:rigid].each do |mode| + with_error_mode(:rigid) do assert_syntax_error( '{% render "snippet" !!! arg1: "value1" ~~~ arg2: "value2" %}', - error_mode: mode, ) assert_syntax_error( '{% render "snippet" | filter %}', - error_mode: mode, ) end end @@ -318,4 +314,30 @@ class RenderTagTest < Minitest::Test render_errors: true, ) end + + def test_render_with_invalid_expression + template = '{% render "snippet" with foo=>bar %}' + + with_error_mode(:lax, :strict) do + refute_nil(Template.parse(template)) + end + + with_error_mode(:rigid) do + error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } + assert_match(/Unexpected character =/, error.message) + end + end + + def test_render_attribute_with_invalid_expression + template = '{% render "snippet", key: foo=>bar %}' + + with_error_mode(:lax, :strict) do + refute_nil(Template.parse(template)) + end + + with_error_mode(:rigid) do + error = assert_raises(Liquid::SyntaxError) { Template.parse(template) } + assert_match(/Unexpected character =/, error.message) + end + end end diff --git a/test/integration/tags/table_row_test.rb b/test/integration/tags/table_row_test.rb index 81444945..0f9b051f 100644 --- a/test/integration/tags/table_row_test.rb +++ b/test/integration/tags/table_row_test.rb @@ -270,8 +270,9 @@ class TableRowTest < Minitest::Test 456 OUTPUT - result = Template.parse(template, environment: rigid_environment).render - assert_equal(expected, result) + with_error_mode(:rigid) do + assert_template_result(expected, template) + end end def test_tablerow_with_limit_attribute_in_rigid_mode @@ -284,8 +285,9 @@ class TableRowTest < Minitest::Test 123 OUTPUT - result = Template.parse(template, environment: rigid_environment).render - assert_equal(expected, result) + with_error_mode(:rigid) do + assert_template_result(expected, template) + end end def test_tablerow_with_offset_attribute_in_rigid_mode @@ -298,8 +300,9 @@ class TableRowTest < Minitest::Test 345 OUTPUT - result = Template.parse(template, environment: rigid_environment).render - assert_equal(expected, result) + with_error_mode(:rigid) do + assert_template_result(expected, template) + end end def test_tablerow_with_range_attribute_in_rigid_mode @@ -312,8 +315,9 @@ class TableRowTest < Minitest::Test 123 OUTPUT - result = Template.parse(template, environment: rigid_environment).render - assert_equal(expected, result) + with_error_mode(:rigid) do + assert_template_result(expected, template) + end end def test_tablerow_with_multiple_attributes_in_rigid_mode @@ -327,8 +331,9 @@ class TableRowTest < Minitest::Test 45 OUTPUT - result = Template.parse(template, environment: rigid_environment).render - assert_equal(expected, result) + with_error_mode(:rigid) do + assert_template_result(expected, template) + end end def test_tablerow_with_variable_collection_in_rigid_mode @@ -342,8 +347,9 @@ class TableRowTest < Minitest::Test 34 OUTPUT - result = Template.parse(template, environment: rigid_environment).render('numbers' => [1, 2, 3, 4]) - assert_equal(expected, result) + with_error_mode(:rigid) do + assert_template_result(expected, template, { 'numbers' => [1, 2, 3, 4] }) + end end def test_tablerow_with_dotted_access_in_rigid_mode @@ -357,8 +363,9 @@ class TableRowTest < Minitest::Test 34 OUTPUT - result = Template.parse(template, environment: rigid_environment).render('obj' => { 'numbers' => [1, 2, 3, 4] }) - assert_equal(expected, result) + with_error_mode(:rigid) do + assert_template_result(expected, template, { 'obj' => { 'numbers' => [1, 2, 3, 4] } }) + end end def test_tablerow_with_bracketed_access_in_rigid_mode @@ -371,8 +378,9 @@ class TableRowTest < Minitest::Test 1020 OUTPUT - result = Template.parse(template, environment: rigid_environment).render('obj' => { 'numbers' => [10, 20] }) - assert_equal(expected, result) + with_error_mode(:rigid) do + assert_template_result(expected, template, { 'obj' => { 'numbers' => [10, 20] } }) + end end def test_tablerow_without_attributes_in_rigid_mode @@ -385,79 +393,27 @@ class TableRowTest < Minitest::Test 123 OUTPUT - result = Template.parse(template, environment: rigid_environment).render - assert_equal(expected, result) - end - - def test_tablerow_with_trailing_comma_in_rigid_mode - template = <<~LIQUID.chomp - {% tablerow i in (1..3) cols: 2, %}{{ i }}{% endtablerow %} - LIQUID - - expected = <<~OUTPUT - - 12 - 3 - OUTPUT - - result = Template.parse(template, environment: rigid_environment).render - assert_equal(expected, result) - end - - def test_tablerow_with_invalid_attribute_name_in_rigid_mode - template = '{% tablerow i in (1..10) invalid_attr: 5 %}{{ i }}{% endtablerow %}' - error = assert_raises(SyntaxError) do - Template.parse(template, environment: rigid_environment) + with_error_mode(:rigid) do + assert_template_result(expected, template) end - assert_equal("Liquid syntax error: Invalid attribute 'invalid_attr' in tablerow loop. Valid attributes are cols, limit, offset, and range in \"i in (1..10) invalid_attr: 5\"", error.message) - end - - def test_tablerow_with_invalid_expression_in_limit_in_rigid_mode - template = '{% tablerow i in (1..10) limit: foo=>bar %}{{ i }}{% endtablerow %}' - error = assert_raises(SyntaxError) do - Template.parse(template, environment: rigid_environment) - end - assert_equal("Liquid syntax error: Unexpected character = in \"i in (1..10) limit: foo=>bar\"", error.message) - end - - def test_tablerow_with_invalid_expression_in_offset_in_rigid_mode - template = '{% tablerow i in (1..10) offset: foo=>bar %}{{ i }}{% endtablerow %}' - error = assert_raises(SyntaxError) do - Template.parse(template, environment: rigid_environment) - end - assert_equal("Liquid syntax error: Unexpected character = in \"i in (1..10) offset: foo=>bar\"", error.message) - end - - def test_tablerow_with_invalid_expression_in_cols_in_rigid_mode - template = '{% tablerow i in (1..10) cols: foo=>bar %}{{ i }}{% endtablerow %}' - error = assert_raises(SyntaxError) do - Template.parse(template, environment: rigid_environment) - end - assert_equal("Liquid syntax error: Unexpected character = in \"i in (1..10) cols: foo=>bar\"", error.message) - end - - def test_tablerow_with_invalid_expression_in_range_in_rigid_mode - template = '{% tablerow i in (1..10) range: foo=>bar %}{{ i }}{% endtablerow %}' - error = assert_raises(SyntaxError) do - Template.parse(template, environment: rigid_environment) - end - assert_equal("Liquid syntax error: Unexpected character = in \"i in (1..10) range: foo=>bar\"", error.message) end def test_tablerow_without_in_keyword_in_rigid_mode template = '{% tablerow i (1..10) %}{{ i }}{% endtablerow %}' - error = assert_raises(SyntaxError) do - Template.parse(template, environment: rigid_environment) + + with_error_mode(: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 - assert_equal("Liquid syntax error: For loops require an 'in' clause in \"i (1..10)\"", error.message) end def test_tablerow_with_multiple_invalid_attributes_reports_first_in_rigid_mode template = '{% tablerow i in (1..10) invalid1: 5, invalid2: 10 %}{{ i }}{% endtablerow %}' - error = assert_raises(SyntaxError) do - Template.parse(template, environment: rigid_environment) + + with_error_mode(: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 - 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 def test_tablerow_with_empty_collection_in_rigid_mode @@ -470,49 +426,44 @@ class TableRowTest < Minitest::Test OUTPUT - result = Template.parse(template, environment: rigid_environment).render('empty_array' => []) - assert_equal(expected, result) + with_error_mode(:rigid) do + assert_template_result(expected, template, { 'empty_array' => [] }) + end end - def test_tablerow_lax_mode_still_accepts_invalid_attributes - template = <<~LIQUID.chomp - {% tablerow i in (1..3) invalid_attr: 5 %}{{ i }}{% endtablerow %} - LIQUID + def test_tablerow_with_invalid_attribute_strict_vs_rigid + template = '{% tablerow i in (1..5) invalid_attr: 10 %}{{ i }}{% endtablerow %}' expected = <<~OUTPUT - 123 + 12345 OUTPUT - result = Template.parse(template, environment: lax_environment).render - assert_equal(expected, result) + with_error_mode(:lax, :strict) do + assert_template_result(expected, template) + end + + with_error_mode(:rigid) do + error = assert_raises(SyntaxError) { Template.parse(template) } + assert_match(/Invalid attribute 'invalid_attr'/, error.message) + end end - def test_tablerow_strict_mode_still_accepts_invalid_attributes - template = <<~LIQUID.chomp - {% tablerow i in (1..3) invalid_attr: 5 %}{{ i }}{% endtablerow %} - LIQUID + def test_tablerow_with_invalid_expression_strict_vs_rigid + template = '{% tablerow i in (1..5) limit: foo=>bar %}{{ i }}{% endtablerow %}' - expected = <<~OUTPUT - - 123 - OUTPUT + with_error_mode(:lax, :strict) do + expected = <<~OUTPUT + + + OUTPUT + assert_template_result(expected, template) + end - result = Template.parse(template, environment: strict_environment).render - assert_equal(expected, result) - end - - private - - def rigid_environment - Environment.build(error_mode: :rigid) - end - - def strict_environment - Environment.build(error_mode: :strict) - end - - def lax_environment - Environment.build(error_mode: :lax) + with_error_mode(:rigid) do + # Rigid mode validates expression syntax and rejects invalid expressions + error = assert_raises(SyntaxError) { Template.parse(template) } + assert_match(/Unexpected character =/, error.message) + end end end diff --git a/test/unit/condition_unit_test.rb b/test/unit/condition_unit_test.rb index acc71dc4..f5206ff5 100644 --- a/test/unit/condition_unit_test.rb +++ b/test/unit/condition_unit_test.rb @@ -166,6 +166,37 @@ class ConditionUnitTest < Minitest::Test assert_includes(err.lines.map(&:strip), expected) end + def test_parse_expression_in_strict_mode + environment = Environment.build(error_mode: :strict) + parse_context = ParseContext.new(environment: environment) + result = Condition.parse_expression(parse_context, 'product.title') + + assert_instance_of(VariableLookup, result) + assert_equal('product', result.name) + assert_equal(['title'], result.lookups) + end + + def test_parse_expression_in_rigid_mode_raises_internal_error + environment = Environment.build(error_mode: :rigid) + parse_context = ParseContext.new(environment: environment) + + error = assert_raises(Liquid::InternalError) do + Condition.parse_expression(parse_context, 'product.title') + end + + assert_match(/unsafe parse_expression cannot be used in rigid mode/, error.message) + end + + def test_parse_expression_with_safe_true_in_rigid_mode + environment = Environment.build(error_mode: :rigid) + parse_context = ParseContext.new(environment: environment) + result = Condition.parse_expression(parse_context, 'product.title', safe: true) + + assert_instance_of(VariableLookup, result) + assert_equal('product', result.name) + assert_equal(['title'], result.lookups) + end + private def assert_evaluates_true(left, op, right) diff --git a/test/unit/rigid_mode_unit_test.rb b/test/unit/rigid_mode_unit_test.rb deleted file mode 100644 index 60ac0423..00000000 --- a/test/unit/rigid_mode_unit_test.rb +++ /dev/null @@ -1,191 +0,0 @@ -# frozen_string_literal: true - -require 'test_helper' - -class RigidModeUnitTest < Minitest::Test - include Liquid - - def test_tablerow_limit_with_invalid_expression - template = <<~LIQUID - {% tablerow i in (1..10) limit: foo=>bar %} - {{ i }} - {% endtablerow %} - LIQUID - - refute_nil(lax_parse(template)) - refute_nil(strict_parse(template)) - - error = assert_raises(SyntaxError) do - rigid_parse(template) - end - assert_match(/Unexpected character =/, error.message) - end - - def test_tablerow_offset_with_invalid_expression - template = <<~LIQUID - {% tablerow i in (1..10) offset: foo=>bar %} - {{ i }} - {% endtablerow %} - LIQUID - - refute_nil(lax_parse(template)) - refute_nil(strict_parse(template)) - - error = assert_raises(SyntaxError) do - rigid_parse(template) - end - assert_match(/Unexpected character =/, error.message) - end - - def test_tablerow_with_invalid_attribute - template = <<~LIQUID - {% tablerow i in (1..10) invalid_attr: 5 %} - {{ i }} - {% endtablerow %} - LIQUID - - refute_nil(lax_parse(template)) - refute_nil(strict_parse(template)) - - error = assert_raises(SyntaxError) do - rigid_parse(template) - end - - assert_match(/Invalid attribute 'invalid_attr'/, error.message) - assert_match(/Valid attributes are cols, limit, offset, and range/, error.message) - end - - def test_cycle_name_with_invalid_expression - template = <<~LIQUID - {% for i in (1..3) %} - {% cycle foo=>bar: "a", "b" %} - {% endfor %} - LIQUID - - refute_nil(lax_parse(template)) - refute_nil(strict_parse(template)) - - error = assert_raises(SyntaxError) { rigid_parse(template) } - - assert_match(/Unexpected character =/, error.message) - end - - def test_cycle_variable_with_invalid_expression - template = <<~LIQUID - {% for i in (1..3) %} - {% cycle foo=>bar, "a", "b" %} - {% endfor %} - LIQUID - - refute_nil(lax_parse(template)) - refute_nil(strict_parse(template)) - - error = assert_raises(SyntaxError) { rigid_parse(template) } - - assert_match(/Unexpected character =/, error.message) - end - - def test_case_with_invalid_expression - template = <<~LIQUID - {% case foo=>bar %} - {% when 1 %} - one - {% endcase %} - LIQUID - - refute_nil(lax_parse(template)) - refute_nil(strict_parse(template)) - - error = assert_raises(SyntaxError) { rigid_parse(template) } - - assert_match(/Unexpected character =/, error.message) - end - - def test_include_template_with_invalid_expression - template = "{% include foo=>bar %}" - - refute_nil(lax_parse(template)) - refute_nil(strict_parse(template)) - - error = assert_raises(SyntaxError) { rigid_parse(template) } - - assert_match(/Unexpected character =/, error.message) - end - - def test_include_with_invalid_expression - template = '{% include "snippet" with foo=>bar %}' - - refute_nil(lax_parse(template)) - refute_nil(strict_parse(template)) - - error = assert_raises(SyntaxError) { rigid_parse(template) } - - assert_match(/Unexpected character =/, error.message) - end - - def test_include_attribute_with_invalid_expression - template = '{% include "snippet", key: foo=>bar %}' - - refute_nil(lax_parse(template)) - refute_nil(strict_parse(template)) - - error = assert_raises(SyntaxError) { rigid_parse(template) } - - assert_match(/Unexpected character =/, error.message) - end - - def test_render_with_invalid_expression - template = '{% render "snippet" with foo=>bar %}' - - refute_nil(lax_parse(template)) - refute_nil(strict_parse(template)) - - error = assert_raises(SyntaxError) { rigid_parse(template) } - - assert_match(/Unexpected character =/, error.message) - end - - def test_render_attribute_with_invalid_expression - template = '{% render "snippet", key: foo=>bar %}' - - refute_nil(lax_parse(template)) - refute_nil(strict_parse(template)) - - error = assert_raises(SyntaxError) { rigid_parse(template) } - - assert_match(/Unexpected character =/, error.message) - end - - def test_empty_expression_handling - ctx_rigid = ParseContext.new(environment: rigid) - - assert_nil(ctx_rigid.parse_expression('', safe: true)) - assert_nil(ctx_rigid.parse_expression(' ', safe: true)) - end - - private - - def rigid_parse(source) - Template.parse(source, environment: rigid) - end - - def strict_parse(source) - Template.parse(source, environment: strict) - end - - def lax_parse(source) - Template.parse(source, environment: lax) - end - - def lax - Environment.build(error_mode: :lax) - end - - def rigid - Environment.build(error_mode: :rigid) - end - - def strict - Environment.build(error_mode: :strict) - end -end diff --git a/test/unit/tags/case_tag_unit_test.rb b/test/unit/tags/case_tag_unit_test.rb index 687cf9d9..c0bc2c34 100644 --- a/test/unit/tags/case_tag_unit_test.rb +++ b/test/unit/tags/case_tag_unit_test.rb @@ -20,8 +20,8 @@ class CaseTagUnitTest < Minitest::Test {%- endcase -%} LIQUID - [:lax, :strict].each do |mode| - with_error_mode(mode) { assert_template_result("one", template) } + with_error_mode(:lax, :strict) do + assert_template_result("one", template) end with_error_mode(:rigid) do @@ -41,8 +41,8 @@ class CaseTagUnitTest < Minitest::Test {%- endcase -%} LIQUID - [:lax, :strict].each do |mode| - with_error_mode(mode) { assert_template_result("one", template) } + with_error_mode(:lax, :strict) do + assert_template_result("one", template) end with_error_mode(:rigid) do @@ -62,8 +62,8 @@ class CaseTagUnitTest < Minitest::Test {%- endcase -%} LIQUID - [:lax, :strict, :rigid].each do |mode| - with_error_mode(mode) { assert_template_result("one", template) } + with_error_mode(:lax, :strict, :rigid) do + assert_template_result("one", template) end end @@ -77,8 +77,8 @@ class CaseTagUnitTest < Minitest::Test {%- endcase -%} LIQUID - [:lax, :strict, :rigid].each do |mode| - with_error_mode(mode) { assert_template_result("one", template) } + with_error_mode(:lax, :strict, :rigid) do + assert_template_result("one", template) end end @@ -93,10 +93,8 @@ class CaseTagUnitTest < Minitest::Test LIQUID assigns = { 'foo' => { 'bar' => 'baz' } } - [:lax, :strict].each do |mode| - with_error_mode(mode) do - assert_template_result("one", template, assigns) - end + with_error_mode(:lax, :strict) do + assert_template_result("one", template, assigns) end with_error_mode(:rigid) do @@ -117,10 +115,8 @@ class CaseTagUnitTest < Minitest::Test LIQUID assigns = { 'foo' => { 'bar' => 'baz' } } - [:lax, :strict].each do |mode| - with_error_mode(mode) do - assert_template_result("one", template, assigns) - end + with_error_mode(:lax, :strict) do + assert_template_result("one", template, assigns) end with_error_mode(:rigid) do