mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-16 17:30:43 -07:00
Support usecase where a nil variable value is used in a logical expression
This commit is contained in:
@@ -106,10 +106,10 @@ class BooleanUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_nil_comparison_with_blank
|
||||
assert_parity_todo!("nil_value == blank", "false")
|
||||
assert_parity_todo!("nil_value != blank", "true")
|
||||
assert_parity_todo!("undefined != blank", "true")
|
||||
assert_parity_todo!("undefined == blank", "false")
|
||||
assert_parity("nil_value == blank", "false")
|
||||
assert_parity("nil_value != blank", "true")
|
||||
assert_parity("undefined != blank", "true")
|
||||
assert_parity("undefined == blank", "false")
|
||||
end
|
||||
|
||||
def test_if_with_variables
|
||||
@@ -121,7 +121,13 @@ class BooleanUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_nil_variable_in_and_expression
|
||||
assert_parity_todo!("x and true", "false", { "x" => nil })
|
||||
assert_parity("x and true", "false", { "x" => nil })
|
||||
assert_parity("true and x", "false", { "x" => nil })
|
||||
end
|
||||
|
||||
def test_boolean_variable_in_and_expression
|
||||
assert_parity("true and x", "false", { "x" => false })
|
||||
assert_parity("x and true", "false", { "x" => false })
|
||||
end
|
||||
|
||||
private
|
||||
@@ -133,10 +139,18 @@ class BooleanUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def assert_parity(liquid_expression, expected_result, args = {})
|
||||
assert_parity_scenario(:condition, "{% if #{liquid_expression} %}true{% else %}false{% endif %}", expected_result, args)
|
||||
assert_condition(liquid_expression, expected_result, args)
|
||||
assert_expression(liquid_expression, expected_result, args)
|
||||
end
|
||||
|
||||
def assert_expression(liquid_expression, expected_result, args = {})
|
||||
assert_parity_scenario(:expression, "{{ #{liquid_expression} }}", expected_result, args)
|
||||
end
|
||||
|
||||
def assert_condition(liquid_condition, expected_result, args = {})
|
||||
assert_parity_scenario(:condition, "{% if #{liquid_condition} %}true{% else %}false{% endif %}", expected_result, args)
|
||||
end
|
||||
|
||||
def assert_parity_scenario(kind, template, exp_output, args = {})
|
||||
act_output = Liquid::Template.parse(template).render(args)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user