Make Condition unit tests go through BinaryExpression

Instead of having Condition parse the left op right, make
BinaryExpression do it. Make sure all the tests pass as they
used to in the process.
This commit is contained in:
Charles-P. Clermont
2026-01-26 16:52:31 -05:00
parent 83f0ac5424
commit daae2186d2
2 changed files with 11 additions and 6 deletions
+2
View File
@@ -30,6 +30,8 @@ module Liquid
!equal_variables(left, right)
when 'contains'
contains(left, right)
else
raise(Liquid::ArgumentError, "Unknown operator #{operator}")
end
rescue ::ArgumentError => e
raise Liquid::ArgumentError, e.message
+9 -6
View File
@@ -170,18 +170,18 @@ class ConditionUnitTest < Minitest::Test
environment = Environment.build
parse_context = ParseContext.new(environment: environment)
parser = parse_context.new_parser('product.title')
result = Condition.parse_expression(parser)
result = parser.expression
assert_instance_of(VariableLookup, result)
assert_equal('product', result.name)
assert_equal(['title'], result.lookups)
end
def test_parse_expression_returns_method_literal_for_blank_and_empty
def test_parser_expression_returns_method_literal_for_blank_and_empty
environment = Environment.build
parse_context = ParseContext.new(environment: environment)
parser = parse_context.new_parser('blank')
result = Condition.parse_expression(parser)
result = parser.expression
assert_instance_of(MethodLiteral, result)
end
@@ -355,22 +355,25 @@ class ConditionUnitTest < Minitest::Test
private
def assert_evaluates_true(left, op, right)
expr = BinaryExpression.new(left, op, right)
assert(
Condition.new(left, op, right).evaluate(@context),
Condition.new(expr).evaluate(@context),
"Evaluated false: #{left.inspect} #{op} #{right.inspect}",
)
end
def assert_evaluates_false(left, op, right)
expr = BinaryExpression.new(left, op, right)
assert(
!Condition.new(left, op, right).evaluate(@context),
!Condition.new(expr).evaluate(@context),
"Evaluated true: #{left.inspect} #{op} #{right.inspect}",
)
end
def assert_evaluates_argument_error(left, op, right)
assert_raises(Liquid::ArgumentError) do
Condition.new(left, op, right).evaluate(@context)
expr = BinaryExpression.new(left, op, right)
Condition.new(expr).evaluate(@context)
end
end
end # ConditionTest