Extract Parser#string out of Expression.parse

This commit is contained in:
Charles-P. Clermont
2026-01-26 16:52:17 -05:00
parent 85d73e462d
commit 2a86852eb3
2 changed files with 19 additions and 1 deletions
+11 -1
View File
@@ -48,7 +48,17 @@ module Liquid
end
def expression
parse_expression(expression_string)
token = @tokens[@p]
case token[0]
when :string
string
else
parse_expression(expression_string)
end
end
def string
consume(:string)[1..-2]
end
def argument_string
+8
View File
@@ -58,6 +58,14 @@ class ParserUnitTest < Minitest::Test
assert_equal('"wut"', p.expression_string)
end
def test_string
p = new_parser("'s1' \"s2\" 'this \"s3\"' \"that 's4'\"")
assert_equal('s1', p.string)
assert_equal('s2', p.string)
assert_equal('this "s3"', p.string)
assert_equal("that 's4'", p.string)
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)