mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-26 13:45:13 -07:00
More comprehensively test assign_score_of
This commit is contained in:
@@ -70,9 +70,43 @@ class AssignTest < Minitest::Test
|
|||||||
assert_equal("", t.render!)
|
assert_equal("", t.render!)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_assign_score_counts_bytes_not_characters
|
def test_assign_score_of_int
|
||||||
t = Template.parse("{% assign foo = 'すごい' %}")
|
assert_equal(1, assign_score_of(123))
|
||||||
t.render
|
end
|
||||||
assert_equal(9, t.resource_limits.assign_score)
|
|
||||||
|
def test_assign_score_of_string_counts_bytes
|
||||||
|
assert_equal(3, assign_score_of('123'))
|
||||||
|
assert_equal(5, assign_score_of('12345'))
|
||||||
|
assert_equal(9, assign_score_of('すごい'))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_assign_score_of_array
|
||||||
|
assert_equal(1, assign_score_of([]))
|
||||||
|
assert_equal(2, assign_score_of([123]))
|
||||||
|
assert_equal(6, assign_score_of([123, 'abcd']))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_assign_score_of_hash
|
||||||
|
assert_equal(1, assign_score_of({}))
|
||||||
|
assert_equal(6, assign_score_of('int' => 123))
|
||||||
|
assert_equal(14, assign_score_of('int' => 123, 'str' => 'abcd'))
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
class ObjectWrapperDrop < Liquid::Drop
|
||||||
|
def initialize(obj)
|
||||||
|
@obj = obj
|
||||||
|
end
|
||||||
|
|
||||||
|
def value
|
||||||
|
@obj
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def assign_score_of(obj)
|
||||||
|
context = Liquid::Context.new('drop' => ObjectWrapperDrop.new(obj))
|
||||||
|
Liquid::Template.parse('{% assign obj = drop.value %}').render!(context)
|
||||||
|
context.resource_limits.assign_score
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user