mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user