mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-16 09:20:42 -07:00
Extract Parser#variable_lookup out of Expression.parse
This commit is contained in:
@@ -45,7 +45,7 @@ class ParserUnitTest < Minitest::Test
|
||||
assert_equal(false, p.look(:number, 1))
|
||||
end
|
||||
|
||||
def test_expressions
|
||||
def test_expression_string
|
||||
p = new_parser("hi.there hi?[5].there? hi.there.bob")
|
||||
assert_equal('hi.there', p.expression_string)
|
||||
assert_equal('hi?[5].there?', p.expression_string)
|
||||
@@ -58,6 +58,25 @@ class ParserUnitTest < Minitest::Test
|
||||
assert_equal('"wut"', p.expression_string)
|
||||
end
|
||||
|
||||
def test_expression
|
||||
p = new_parser("hi.there hi?[5].there? hi.there.bob")
|
||||
v1 = p.expression
|
||||
v2 = p.expression
|
||||
v3 = p.expression
|
||||
assert(v1.is_a?(VariableLookup) && v1.name == 'hi' && v1.lookups[0] == 'there')
|
||||
assert(v2.is_a?(VariableLookup) && v2.name == 'hi?' && v2.lookups[0] == 5)
|
||||
assert(v3.is_a?(VariableLookup) && v3.name == 'hi' && v3.lookups[0] == 'there')
|
||||
|
||||
p = new_parser("567 6.0 'lol' \"wut\" true false (0..5)")
|
||||
assert_equal(567, p.expression)
|
||||
assert_equal(6.0, p.expression)
|
||||
assert_equal('lol', p.expression)
|
||||
assert_equal('wut', p.expression)
|
||||
assert_equal(true, p.expression)
|
||||
assert_equal(false, p.expression)
|
||||
assert_equal((0..5), p.expression)
|
||||
end
|
||||
|
||||
def test_number
|
||||
p = new_parser('-1 0 1 2.0')
|
||||
assert_equal(-1, p.number)
|
||||
@@ -74,6 +93,15 @@ class ParserUnitTest < Minitest::Test
|
||||
assert_equal("that 's4'", p.string)
|
||||
end
|
||||
|
||||
def test_unnamed_variable_lookup
|
||||
p = new_parser('[key].title')
|
||||
v = p.expression
|
||||
assert(v.is_a?(VariableLookup))
|
||||
assert(v.name.is_a?(VariableLookup))
|
||||
assert_equal('key', v.name.name)
|
||||
assert_equal('title', v.lookups[0])
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user