From b31f24bdf02af357876152a6d57f799ec187e07a Mon Sep 17 00:00:00 2001 From: Albert Chu Date: Wed, 5 Mar 2025 16:36:23 -0700 Subject: [PATCH] More boolean unit tests and enabled more existing parity cases --- test/unit/boolean_unit_test.rb | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/test/unit/boolean_unit_test.rb b/test/unit/boolean_unit_test.rb index 492a2c42..84c29fea 100644 --- a/test/unit/boolean_unit_test.rb +++ b/test/unit/boolean_unit_test.rb @@ -96,13 +96,17 @@ class BooleanUnitTest < Minitest::Test end def test_equality_operators - assert_parity_todo!("1 == 1", "true") - assert_parity_todo!("1 != 2", "true") + assert_parity("1 == 1", "true") + assert_parity("1 != 2", "true") assert_parity_todo!("'hello' == 'hello'", "true") end def test_nil_renders_as_empty_string - assert_parity_todo!("nil", "false") + # No parity needed here. This is to ensure expressions rendered with {{ }} + # will still render as an empty string to preserve pre-existing behavior. + assert_expression("nil", "") + assert_expression("x", "", { "x" => nil }) + assert_parity_scenario(:expression, "hello {{ x }}", "hello ", { "x" => nil }) end def test_nil_comparison_with_blank @@ -113,11 +117,8 @@ class BooleanUnitTest < Minitest::Test end def test_if_with_variables - assert_parity_todo!("value", "true", { "value" => true }) - assert_parity_todo!("value", "false", { "value" => false }) - assert_parity_todo!("value", "false", { "value" => nil }) - assert_parity_todo!("value", "true", { "value" => "text" }) - assert_parity_todo!("value", "true", { "value" => "" }) + assert_parity("value", "true", { "value" => true }) + assert_parity("value", "false", { "value" => false }) end def test_nil_variable_in_and_expression @@ -130,6 +131,16 @@ class BooleanUnitTest < Minitest::Test assert_parity("x and true", "false", { "x" => false }) end + def test_multi_variable_boolean_nil_and_expression + assert_parity("x and y", "false", { "x" => nil, "y" => true }) + assert_parity("y and x", "false", { "x" => true, "y" => nil }) + end + + def test_multi_variable_boolean_nil_or_expression + assert_parity("x or y", "true", { "x" => nil, "y" => true }) + assert_parity("y or x", "true", { "x" => true, "y" => nil }) + end + private def assert_parity_todo!(liquid_expression, expected_result, args = {})