mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-02 16:45:12 -07:00
Reintroduced broken conditional operators behaviour present in liquid main
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
module Liquid
|
module Liquid
|
||||||
class Expression
|
class Expression
|
||||||
class ComparisonExpression
|
class ComparisonExpression
|
||||||
COMPARISON_REGEX = /\A\s*(.+?)\s*(==|!=|<>|<=|>=|<|>|contains)\s*(.+)\s*\z/
|
COMPARISON_REGEX = /\A\s*(.+?)\s+(==|!=|<>|<=|>=|<|>|contains)\s+(.+)\s*\z/
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def comparison?(markup)
|
def comparison?(markup)
|
||||||
|
|||||||
@@ -368,15 +368,9 @@ class BooleanUnitTest < Minitest::Test
|
|||||||
assert_equal("false", act_output)
|
assert_equal("false", act_output)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Note for Guilherme:
|
# TESTING TECHNICALLY INCORRECT BEHAVIOUR OF LIQUID-RUBY
|
||||||
# This test actually does not pass in `main` branch right now however it does pass correctly in our changes.
|
# If liquid-vm fails this test, we should change it.
|
||||||
# I am keeping it because it shows we fixed a bug with existing liquid.
|
def test_conditions_with_boolean_operators_without_whitespace_around_operator
|
||||||
#
|
|
||||||
# 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
|
|
||||||
# Define the Liquid template focusing on the selected attribute
|
# Define the Liquid template focusing on the selected attribute
|
||||||
template = <<~LIQUID
|
template = <<~LIQUID
|
||||||
<option variant_id="{{ variant.id }}" {% if current_variant.id==variant.id %}selected{%- endif -%}>{{ variant.title }}</option>
|
<option variant_id="{{ variant.id }}" {% if current_variant.id==variant.id %}selected{%- endif -%}>{{ variant.title }}</option>
|
||||||
@@ -394,8 +388,14 @@ class BooleanUnitTest < Minitest::Test
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Expected output
|
# Expected output
|
||||||
|
# Note: Ideally we would like the whitespace around the boolean operator to be optional.
|
||||||
|
# So the more correct expected output would be:
|
||||||
|
#
|
||||||
|
# <option variant_id="420" selected>Default Title</option>
|
||||||
|
#
|
||||||
|
# However, the existing behaviour in liquid-ruby is that the whitespace is required around the boolean operator.
|
||||||
expected_output = <<~HTML
|
expected_output = <<~HTML
|
||||||
<option variant_id="420" selected>Default Title</option>
|
<option variant_id="420" >Default Title</option>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
# Render the template with the context
|
# Render the template with the context
|
||||||
|
|||||||
Reference in New Issue
Block a user