mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-16 09:20:42 -07:00
Change Parser#expression to build the parsed expression
This commit is contained in:
@@ -77,7 +77,7 @@ class ConditionUnitTest < Minitest::Test
|
||||
def test_contains_works_on_arrays
|
||||
@context = Liquid::Context.new
|
||||
@context['array'] = [1, 2, 3, 4, 5]
|
||||
array_expr = VariableLookup.new("array")
|
||||
array_expr = parse_variable_lookup("array")
|
||||
|
||||
assert_evaluates_false(array_expr, 'contains', 0)
|
||||
assert_evaluates_true(array_expr, 'contains', 1)
|
||||
@@ -91,8 +91,8 @@ class ConditionUnitTest < Minitest::Test
|
||||
|
||||
def test_contains_returns_false_for_nil_operands
|
||||
@context = Liquid::Context.new
|
||||
assert_evaluates_false(VariableLookup.new('not_assigned'), 'contains', '0')
|
||||
assert_evaluates_false(0, 'contains', VariableLookup.new('not_assigned'))
|
||||
assert_evaluates_false(parse_variable_lookup('not_assigned'), 'contains', '0')
|
||||
assert_evaluates_false(0, 'contains', parse_variable_lookup('not_assigned'))
|
||||
end
|
||||
|
||||
def test_contains_return_false_on_wrong_data_type
|
||||
@@ -145,11 +145,20 @@ class ConditionUnitTest < Minitest::Test
|
||||
@context = Liquid::Context.new
|
||||
@context['one'] = @context['another'] = "gnomeslab-and-or-liquid"
|
||||
|
||||
assert_evaluates_true(VariableLookup.new("one"), '==', VariableLookup.new("another"))
|
||||
assert_evaluates_true(parse_variable_lookup("one"), '==', parse_variable_lookup("another"))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def parse_variable_lookup(markup)
|
||||
if Liquid::Template.error_mode == :strict
|
||||
p = Liquid::Parser.new(markup)
|
||||
VariableLookup.strict_parse(p)
|
||||
else
|
||||
VariableLookup.lax_parse(markup)
|
||||
end
|
||||
end
|
||||
|
||||
def assert_evaluates_true(left, op, right)
|
||||
assert(Condition.new(left, op, right).evaluate(@context),
|
||||
"Evaluated false: #{left} #{op} #{right}")
|
||||
|
||||
Reference in New Issue
Block a user