Extract Parser#range_lookup out of Expression.parse

This commit is contained in:
Charles-P. Clermont
2026-01-26 16:52:17 -05:00
parent 8b04c52ab2
commit dff829ec72
4 changed files with 25 additions and 3 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ class ExpressionTest < Minitest::Test
"{{ (false..true) }}",
)
assert_match_syntax_error(
"Liquid syntax error (line 1): Invalid expression type '(1..2)' in range expression",
"Liquid syntax error (line 1): Invalid expression type '1..2' in range expression",
"{{ ((1..2)..3) }}",
)
end
+9
View File
@@ -102,6 +102,15 @@ class ParserUnitTest < Minitest::Test
assert_equal('title', v.lookups[0])
end
def test_range_lookup
p = new_parser('(0..5) (a..b)')
assert_equal((0..5), p.expression)
r2 = p.expression
assert(r2.is_a?(RangeLookup))
assert_equal((1..4), r2.evaluate(Context.new({ 'a' => 1, 'b' => 4 })))
end
def test_ranges
p = new_parser("(5..7) (1.5..9.6) (young..old) (hi[5].wat..old)")
assert_equal('(5..7)', p.expression_string)