mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-15 08:50:45 -07:00
Update infrastructure that handles parsing switching:
* Remove development helpers from parse context * Simplify strict_parse_with_error_mode_fallback and update documentation * Add unit tests for `Liquid::Expression` and `Liquid::ParseContext` * Update test helpers to work better with the `:rigid` mode
This commit is contained in:
committed by
Guilherme Carreiro
parent
4cd367d971
commit
738540a601
@@ -71,7 +71,6 @@ class ExpressionTest < Minitest::Test
|
||||
|
||||
def test_expression_cache
|
||||
skip("Liquid-C does not support Expression caching") if defined?(Liquid::C) && Liquid::C.enabled
|
||||
skip("Rigid mode does not use Expression caching") if Liquid::Environment.default.error_mode == :rigid
|
||||
|
||||
cache = {}
|
||||
template = <<~LIQUID
|
||||
@@ -93,7 +92,6 @@ class ExpressionTest < Minitest::Test
|
||||
|
||||
def test_expression_cache_with_true_boolean
|
||||
skip("Liquid-C does not support Expression caching") if defined?(Liquid::C) && Liquid::C.enabled
|
||||
skip("Rigid mode does not use Expression caching") if Liquid::Environment.default.error_mode == :rigid
|
||||
|
||||
template = <<~LIQUID
|
||||
{% assign x = 1 %}
|
||||
@@ -118,7 +116,6 @@ class ExpressionTest < Minitest::Test
|
||||
|
||||
def test_expression_cache_with_lru_redux
|
||||
skip("Liquid-C does not support Expression caching") if defined?(Liquid::C) && Liquid::C.enabled
|
||||
skip("Rigid mode does not use Expression caching") if Liquid::Environment.default.error_mode == :rigid
|
||||
|
||||
cache = LruRedux::Cache.new(10)
|
||||
template = <<~LIQUID
|
||||
@@ -140,7 +137,6 @@ class ExpressionTest < Minitest::Test
|
||||
|
||||
def test_disable_expression_cache
|
||||
skip("Liquid-C does not support Expression caching") if defined?(Liquid::C) && Liquid::C.enabled
|
||||
skip("Rigid mode does not use Expression caching") if Liquid::Environment.default.error_mode == :rigid
|
||||
|
||||
template = <<~LIQUID
|
||||
{% assign x = 1 %}
|
||||
@@ -156,6 +152,35 @@ class ExpressionTest < Minitest::Test
|
||||
assert(parse_context.instance_variable_get(:@expression_cache).nil?)
|
||||
end
|
||||
|
||||
def test_safe_parse_with_variable_lookup
|
||||
parse_context = Liquid::ParseContext.new
|
||||
parser = parse_context.new_parser('product.title')
|
||||
result = Liquid::Expression.safe_parse(parser)
|
||||
|
||||
assert_instance_of(Liquid::VariableLookup, result)
|
||||
assert_equal('product', result.name)
|
||||
assert_equal(['title'], result.lookups)
|
||||
end
|
||||
|
||||
def test_safe_parse_with_number
|
||||
parse_context = Liquid::ParseContext.new
|
||||
parser = parse_context.new_parser('42')
|
||||
result = Liquid::Expression.safe_parse(parser)
|
||||
|
||||
assert_equal(42, result)
|
||||
end
|
||||
|
||||
def test_safe_parse_raises_syntax_error_for_invalid_expression
|
||||
parse_context = Liquid::ParseContext.new
|
||||
parser = parse_context.new_parser('')
|
||||
|
||||
error = assert_raises(Liquid::SyntaxError) do
|
||||
Liquid::Expression.safe_parse(parser)
|
||||
end
|
||||
|
||||
assert_match(/is not a valid expression/, error.message)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def assert_expression_result(expect, markup, **assigns)
|
||||
|
||||
Reference in New Issue
Block a user