Remove redundant tests where rigid and strict modes have the same

behavior
This commit is contained in:
Guilherme Carreiro
2025-10-27 16:33:31 +01:00
committed by Guilherme Carreiro
parent 0bc69b86b7
commit 5248025439
+16 -136
View File
@@ -5,31 +5,6 @@ require 'test_helper'
class RigidModeUnitTest < Minitest::Test
include Liquid
def test_direct_parse_expression_comparison
test_cases = [
'{{ foo bar }}',
'{{ user.name first }}',
'{{ items[0] next }}',
'{{ products[0].name extra }}',
]
test_cases.each do |template|
refute_nil(lax_parse(template))
assert_raises(SyntaxError) { strict_parse(template) }
assert_raises(SyntaxError) { rigid_parse(template) }
end
end
def test_comparison_strict_vs_rigid_with_space_separated_lookups
template = '{{ product title }}'
output = lax_parse(template).render({ 'product' => { 'title' => 'Snow' } })
assert_equal('{"title"=>"Snow"}', output)
assert_raises(SyntaxError) { strict_parse(template) }
assert_raises(SyntaxError) { rigid_parse(template) }
end
def test_tablerow_limit_with_invalid_expression
skip
@@ -72,9 +47,8 @@ class RigidModeUnitTest < Minitest::Test
refute_nil(lax_parse(template))
refute_nil(strict_parse(template))
error = assert_raises(SyntaxError) do
rigid_parse(template)
end
error = assert_raises(SyntaxError) { rigid_parse(template) }
assert_match(/Unexpected character =/, error.message)
end
@@ -88,9 +62,8 @@ class RigidModeUnitTest < Minitest::Test
refute_nil(lax_parse(template))
refute_nil(strict_parse(template))
error = assert_raises(SyntaxError) do
rigid_parse(template)
end
error = assert_raises(SyntaxError) { rigid_parse(template) }
assert_match(/Unexpected character =/, error.message)
end
@@ -105,9 +78,8 @@ class RigidModeUnitTest < Minitest::Test
refute_nil(lax_parse(template))
refute_nil(strict_parse(template))
error = assert_raises(SyntaxError) do
rigid_parse(template)
end
error = assert_raises(SyntaxError) { rigid_parse(template) }
assert_match(/Unexpected character =/, error.message)
end
@@ -117,9 +89,8 @@ class RigidModeUnitTest < Minitest::Test
refute_nil(lax_parse(template))
refute_nil(strict_parse(template))
error = assert_raises(SyntaxError) do
rigid_parse(template)
end
error = assert_raises(SyntaxError) { rigid_parse(template) }
assert_match(/Unexpected character =/, error.message)
end
@@ -129,9 +100,8 @@ class RigidModeUnitTest < Minitest::Test
refute_nil(lax_parse(template))
refute_nil(strict_parse(template))
error = assert_raises(SyntaxError) do
rigid_parse(template)
end
error = assert_raises(SyntaxError) { rigid_parse(template) }
assert_match(/Unexpected character =/, error.message)
end
@@ -141,9 +111,8 @@ class RigidModeUnitTest < Minitest::Test
refute_nil(lax_parse(template))
refute_nil(strict_parse(template))
error = assert_raises(SyntaxError) do
rigid_parse(template)
end
error = assert_raises(SyntaxError) { rigid_parse(template) }
assert_match(/Unexpected character =/, error.message)
end
@@ -153,9 +122,8 @@ class RigidModeUnitTest < Minitest::Test
refute_nil(lax_parse(template))
refute_nil(strict_parse(template))
error = assert_raises(SyntaxError) do
rigid_parse(template)
end
error = assert_raises(SyntaxError) { rigid_parse(template) }
assert_match(/Unexpected character =/, error.message)
end
@@ -165,99 +133,11 @@ class RigidModeUnitTest < Minitest::Test
refute_nil(lax_parse(template))
refute_nil(strict_parse(template))
error = assert_raises(SyntaxError) do
rigid_parse(template)
end
error = assert_raises(SyntaxError) { rigid_parse(template) }
assert_match(/Unexpected character =/, error.message)
end
def test_valid_expressions_work_in_rigid_mode
test_cases = {
'{{ foo }}' => { 'foo' => 'bar' },
'{{ foo.bar }}' => { 'foo' => { 'bar' => 'baz' } },
'{{ items[0] }}' => { 'items' => ['first', 'second'] },
'{{ product.variants[0].title }}' => { 'product' => { 'variants' => [{ 'title' => 'Small' }] } },
'{{ "hello" }}' => {},
'{{ 42 }}' => {},
'{{ 3.14 }}' => {},
}
test_cases.each do |template_str, data|
lax_result = lax_parse(template_str).render(data)
assert(lax_result.is_a?(String), "Lax mode should render '#{template_str}'")
strict_result = strict_parse(template_str).render(data)
assert(strict_result.is_a?(String), "Strict mode should render '#{template_str}'")
rigid_result = rigid_parse(template_str).render(data)
assert(rigid_result.is_a?(String), "Rigid mode should render '#{template_str}'")
end
end
def test_rigid_mode_with_ranges
template = <<~LIQUID
{% for i in (1..3) %}{{ i }}{% endfor %}
LIQUID
lax_result = lax_parse(template).render
assert_equal("123\n", lax_result)
strict_result = strict_parse(template).render
assert_equal("123\n", strict_result)
rigid_result = rigid_parse(template).render
assert_equal("123\n", rigid_result)
end
def test_rigid_mode_with_variable_ranges
template = <<~LIQUID
{% for i in (start..end) %}{{ i }}{% endfor %}
LIQUID
data = { 'start' => 1, 'end' => 3 }
lax_result = lax_parse(template).render(data)
assert_equal("123\n", lax_result)
strict_result = strict_parse(template).render(data)
assert_equal("123\n", strict_result)
rigid_result = rigid_parse(template).render(data)
assert_equal("123\n", rigid_result)
end
def test_rigid_mode_valid_filters
template = <<~LIQUID
{{ "hello" | upcase | prepend: "Say: " }}
LIQUID
lax_result = lax_parse(template).render
assert_equal("Say: HELLO\n", lax_result)
strict_result = strict_parse(template).render
assert_equal("Say: HELLO\n", strict_result)
rigid_result = rigid_parse(template).render
assert_equal("Say: HELLO\n", rigid_result)
end
def test_rigid_mode_valid_filter_with_correct_variable_args
template = <<~LIQUID
{{ "hello" | append: world.name }}
LIQUID
data = { 'world' => { 'name' => ' world' } }
lax_result = lax_parse(template).render(data)
assert_equal("hello world\n", lax_result)
strict_result = strict_parse(template).render(data)
assert_equal("hello world\n", strict_result)
rigid_result = rigid_parse(template).render(data)
assert_equal("hello world\n", rigid_result)
end
def test_empty_expression_handling
ctx_rigid = ParseContext.new(environment: rigid)