mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-18 18:30:40 -07:00
Fix SelfDrop equality
This commit is contained in:
@@ -35,6 +35,20 @@ module Liquid
|
|||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ==(other)
|
||||||
|
other.is_a?(SelfDrop) && other.self_context.equal?(@self_context)
|
||||||
|
end
|
||||||
|
|
||||||
|
alias_method :eql?, :==
|
||||||
|
|
||||||
|
def hash
|
||||||
|
@self_context.object_id.hash
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
attr_reader :self_context
|
||||||
|
|
||||||
undef context=
|
undef context=
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -77,6 +77,24 @@ class SelfDropContextTest < Minitest::Test
|
|||||||
assert_template_result('42', '{{ self.x }}', { 'x' => 42 })
|
assert_template_result('42', '{{ self.x }}', { 'x' => 42 })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_self_drop_repeated_lookups_compare_equal_for_same_context
|
||||||
|
context = Context.new
|
||||||
|
|
||||||
|
assert_equal(context.find_variable("self"), context.find_variable("self"))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_assigned_self_drop_compares_equal_to_itself
|
||||||
|
assert_template_result('T', '{% assign s = self %}{% if s == s %}T{% else %}F{% endif %}')
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_distinct_self_assignments_compare_equal_for_same_context
|
||||||
|
assert_template_result('T', '{% assign a = self %}{% assign b = self %}{% if a == b %}T{% else %}F{% endif %}')
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_bare_self_compares_equal_to_bare_self
|
||||||
|
assert_template_result('T', '{% if self == self %}T{% else %}F{% endif %}')
|
||||||
|
end
|
||||||
|
|
||||||
def test_self_drop_with_strict_variables_does_not_raise_for_defined_var
|
def test_self_drop_with_strict_variables_does_not_raise_for_defined_var
|
||||||
t = Template.parse('{{ self.x }}')
|
t = Template.parse('{{ self.x }}')
|
||||||
result = t.render({ 'x' => 42 }, strict_variables: true)
|
result = t.render({ 'x' => 42 }, strict_variables: true)
|
||||||
|
|||||||
Reference in New Issue
Block a user