mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-20 11:20:41 -07:00
Remove Expression#safe_parse
This commit is contained in:
@@ -25,10 +25,6 @@ module Liquid
|
|||||||
FLOAT_REGEX = /\A(-?\d+)\.\d+\z/
|
FLOAT_REGEX = /\A(-?\d+)\.\d+\z/
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def safe_parse(parser, ss = StringScanner.new(""), cache = nil)
|
|
||||||
parse(parser.expression_string, ss, cache)
|
|
||||||
end
|
|
||||||
|
|
||||||
def parse(markup, ss = StringScanner.new(""), cache = nil)
|
def parse(markup, ss = StringScanner.new(""), cache = nil)
|
||||||
return unless markup
|
return unless markup
|
||||||
|
|
||||||
|
|||||||
@@ -134,30 +134,30 @@ class ExpressionTest < Minitest::Test
|
|||||||
assert(parse_context.instance_variable_get(:@expression_cache).nil?)
|
assert(parse_context.instance_variable_get(:@expression_cache).nil?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_safe_parse_with_variable_lookup
|
def test_parser_expression_with_variable_lookup
|
||||||
parse_context = Liquid::ParseContext.new
|
parse_context = Liquid::ParseContext.new
|
||||||
parser = parse_context.new_parser('product.title')
|
parser = parse_context.new_parser('product.title')
|
||||||
result = Liquid::Expression.safe_parse(parser)
|
result = parser.expression
|
||||||
|
|
||||||
assert_instance_of(Liquid::VariableLookup, result)
|
assert_instance_of(Liquid::VariableLookup, result)
|
||||||
assert_equal('product', result.name)
|
assert_equal('product', result.name)
|
||||||
assert_equal(['title'], result.lookups)
|
assert_equal(['title'], result.lookups)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_safe_parse_with_number
|
def test_parser_expression_with_number
|
||||||
parse_context = Liquid::ParseContext.new
|
parse_context = Liquid::ParseContext.new
|
||||||
parser = parse_context.new_parser('42')
|
parser = parse_context.new_parser('42')
|
||||||
result = Liquid::Expression.safe_parse(parser)
|
result = parser.expression
|
||||||
|
|
||||||
assert_equal(42, result)
|
assert_equal(42, result)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_safe_parse_raises_syntax_error_for_invalid_expression
|
def test_parser_expression_raises_syntax_error_for_invalid_expression
|
||||||
parse_context = Liquid::ParseContext.new
|
parse_context = Liquid::ParseContext.new
|
||||||
parser = parse_context.new_parser('')
|
parser = parse_context.new_parser('')
|
||||||
|
|
||||||
error = assert_raises(Liquid::SyntaxError) do
|
error = assert_raises(Liquid::SyntaxError) do
|
||||||
Liquid::Expression.safe_parse(parser)
|
parser.expression
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_match(/is not a valid expression/, error.message)
|
assert_match(/is not a valid expression/, error.message)
|
||||||
|
|||||||
Reference in New Issue
Block a user