From 4b57b2bbd9ac00e950d298c058995c698becfc9e Mon Sep 17 00:00:00 2001 From: Albert Chu Date: Wed, 12 Mar 2025 14:08:45 -0600 Subject: [PATCH] Reintroduced broken conditional operators behaviour present in liquid main --- .../expression/comparison_expression.rb | 2 +- test/unit/boolean_unit_test.rb | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/liquid/expression/comparison_expression.rb b/lib/liquid/expression/comparison_expression.rb index 189ea952..fb57fd20 100644 --- a/lib/liquid/expression/comparison_expression.rb +++ b/lib/liquid/expression/comparison_expression.rb @@ -3,7 +3,7 @@ module Liquid class Expression class ComparisonExpression - COMPARISON_REGEX = /\A\s*(.+?)\s*(==|!=|<>|<=|>=|<|>|contains)\s*(.+)\s*\z/ + COMPARISON_REGEX = /\A\s*(.+?)\s+(==|!=|<>|<=|>=|<|>|contains)\s+(.+)\s*\z/ class << self def comparison?(markup) diff --git a/test/unit/boolean_unit_test.rb b/test/unit/boolean_unit_test.rb index f44413a4..20ea382e 100644 --- a/test/unit/boolean_unit_test.rb +++ b/test/unit/boolean_unit_test.rb @@ -368,15 +368,9 @@ class BooleanUnitTest < Minitest::Test assert_equal("false", act_output) end - # Note for Guilherme: - # This test actually does not pass in `main` branch right now however it does pass correctly in our changes. - # I am keeping it because it shows we fixed a bug with existing liquid. - # - # The functionality in main is that this liquid evaluates to false `{% if current_variant.id==variant.id %}selected{%- endif -%}` - # because of the missing whitespace around the boolean operator. - # - # Question for project channel: Do we need to respect the existing behaviour or can we keep this new (-improved, imo) behaviour? - def test_variant_selected_attribute_when_ids_match + # TESTING TECHNICALLY INCORRECT BEHAVIOUR OF LIQUID-RUBY + # If liquid-vm fails this test, we should change it. + def test_conditions_with_boolean_operators_without_whitespace_around_operator # Define the Liquid template focusing on the selected attribute template = <<~LIQUID @@ -394,8 +388,14 @@ class BooleanUnitTest < Minitest::Test } # Expected output + # Note: Ideally we would like the whitespace around the boolean operator to be optional. + # So the more correct expected output would be: + # + # + # + # However, the existing behaviour in liquid-ruby is that the whitespace is required around the boolean operator. expected_output = <<~HTML - + HTML # Render the template with the context