Compare commits

..

5 Commits

Author SHA1 Message Date
Dylan Thacker-Smith
9567794a7a Only use MethodLiteral in condition expressions 2020-09-22 11:57:40 -04:00
Dylan Thacker-Smith
cddd8ea4ff Extract rescue code from BlockBody#render_node for re-use in liquid-c 2020-09-16 09:31:36 -04:00
Dylan Thacker-Smith
9917924adb Move some unit tests without internal coupling to integration tests
since I would like to continue supporting these tests in liquid-c
in the foreseeable future.
2020-09-15 16:32:12 -04:00
Dylan Thacker-Smith
17c3e9989a Move test/integration/parse_tree_visitor_test.rb to test/unit
The ParseTreeVisitor exposes the liquid internals that won't be
kept compatible with liquid-c, so move it out of the integration
tests directory so that we can easily ignore it when testing liquid-c
2020-09-15 16:32:12 -04:00
Dylan Thacker-Smith
2777b9d06c Allow creating symbols that are garbage collected in a test 2020-09-15 16:32:12 -04:00
5 changed files with 7 additions and 47 deletions

View File

@@ -153,11 +153,7 @@ module Liquid
if token[2] == WhitespaceControl
previous_token = @nodelist.last
if previous_token.is_a?(String)
first_byte = previous_token.getbyte(0)
previous_token.rstrip!
if previous_token.empty? && parse_context[:bug_compatible_whitespace_trimming] && first_byte
previous_token << first_byte
end
end
end
parse_context.trim_whitespace = (token[-3] == WhitespaceControl)

View File

@@ -34,6 +34,10 @@ module Liquid
@method_name = method_name
@to_s = to_s
end
def to_liquid
to_s
end
end
@@method_literals = {

View File

@@ -18,16 +18,15 @@ module Liquid
attr_accessor :exception_renderer, :template_name, :partial, :global_filter, :strict_variables, :strict_filters
# rubocop:disable Metrics/ParameterLists
def self.build(environments: {}, outer_scope: {}, registers: {}, rethrow_errors: false, resource_limits: nil, static_environments: [])
def self.build(environments: {}, outer_scope: {}, registers: {}, rethrow_errors: false, resource_limits: nil, static_environments: {})
new(environments, outer_scope, registers, rethrow_errors, resource_limits, static_environments)
end
def initialize(environments = {}, outer_scope = {}, registers = {}, rethrow_errors = false, resource_limits = nil, static_environments = [])
def initialize(environments = {}, outer_scope = {}, registers = {}, rethrow_errors = false, resource_limits = nil, static_environments = {})
@environments = [environments]
@environments.flatten!
static_environments = [static_environments] if static_environments.is_a?(Hash)
@static_environments = static_environments.map(&:freeze).freeze
@static_environments = [static_environments].flat_map(&:freeze).freeze
@scopes = [(outer_scope || {})]
@registers = registers
@errors = []

View File

@@ -492,17 +492,6 @@ class ContextTest < Minitest::Test
assert_equal('static', context['unshadowed'])
end
def test_static_environments_are_frozen
context = Context.build(
static_environments: [{
'lazy' => -> { 1 }
}],
)
assert_raises(FrozenError) do
context['lazy']
end
end
def test_apply_global_filter_when_no_global_filter_exist
context = Context.new
assert_equal('hi', context.apply_global_filter('hi'))

View File

@@ -528,32 +528,4 @@ class TrimModeTest < Minitest::Test
END_EXPECTED
assert_template_result(expected, text)
end
def test_pre_trim_blank_preceding_text
template = Liquid::Template.parse("\n{%- raw %}{% endraw %}")
assert_equal("", template.render)
template = Liquid::Template.parse("\n{%- if true %}{% endif %}")
assert_equal("", template.render)
template = Liquid::Template.parse("{{ 'B' }} \n{%- if true %}C{% endif %}")
assert_equal("BC", template.render)
end
def test_bug_compatible_pre_trim
template = Liquid::Template.parse("\n {%- raw %}{% endraw %}", bug_compatible_whitespace_trimming: true)
assert_equal("\n", template.render)
template = Liquid::Template.parse("\n {%- if true %}{% endif %}", bug_compatible_whitespace_trimming: true)
assert_equal("\n", template.render)
template = Liquid::Template.parse("{{ 'B' }} \n{%- if true %}C{% endif %}", bug_compatible_whitespace_trimming: true)
assert_equal("B C", template.render)
template = Liquid::Template.parse("B\n {%- raw %}{% endraw %}", bug_compatible_whitespace_trimming: true)
assert_equal("B", template.render)
template = Liquid::Template.parse("B\n {%- if true %}{% endif %}", bug_compatible_whitespace_trimming: true)
assert_equal("B", template.render)
end
end # TrimModeTest