Consolidate contextualization of inputs via the context

This commit is contained in:
Thierry Joyal
2022-03-07 12:49:28 -05:00
parent 7357dcf185
commit 1bf77d7798
6 changed files with 85 additions and 26 deletions
+35 -3
View File
@@ -34,6 +34,10 @@ class TestDrop < Liquid::Drop
def registers
@context.registers
end
def to_s
"TestDrop(value:#{@value})"
end
end
class TestModel
@@ -467,10 +471,38 @@ class StandardFiltersTest < Minitest::Test
end
def test_map_over_proc
drop = TestDrop.new(value: "testfoo")
drop = TestDrop.new(value: "123")
p = proc { drop }
templ = '{{ procs | map: "value" }}'
assert_template_result("testfoo", templ, "procs" => [p])
assert_template_result("123", templ, "procs" => [p])
end
def test_join_over_proc
drop = TestDrop.new(value: "123")
p = proc { drop }
templ = '{{ procs | join }}'
assert_template_result('TestDrop(value:123)', templ, "procs" => [p])
end
def test_sort_over_proc
drop = TestDrop.new(value: "123")
p = proc { drop }
templ = '{{ procs | sort: "value" }}'
assert_template_result("TestDrop(value:123)", templ, "procs" => [p])
end
def test_where_over_proc
drop = TestDrop.new(value: "123")
p = proc { drop }
templ = '{{ procs | where: "value", "123" }}'
assert_template_result("TestDrop(value:123)", templ, "procs" => [p])
end
def test_uniq_over_proc
drop = TestDrop.new(value: "123")
p = proc { drop }
templ = '{{ procs | uniq }}'
assert_template_result("TestDrop(value:123)", templ, "procs" => [p])
end
def test_map_over_drops_returning_procs
@@ -888,7 +920,7 @@ class StandardFiltersTest < Minitest::Test
{ foo: "bar" },
[{ "foo" => "bar" }, { "foo" => 123 }, { "foo" => nil }, { "foo" => true }, { "foo" => ["foo", "bar"] }],
{ 1 => "bar" },
["foo", 123, nil, true, false, Drop, ["foo"], { foo: "bar" }],
["foo", 123, nil, true, false, ["foo"], { foo: "bar" }],
]
StandardFilters.public_instance_methods(false).each do |method|
arg_count = @filters.method(method).arity
+28 -6
View File
@@ -272,14 +272,36 @@ class StandardTagTest < Minitest::Test
'{%cycle var1: "one", "two" %} {%cycle var2: "one", "two" %} {%cycle var1: "one", "two" %} {%cycle var2: "one", "two" %} {%cycle var1: "one", "two" %} {%cycle var2: "one", "two" %}', assigns)
end
def test_size_of_array
assigns = { "array" => [1, 2, 3, 4] }
assert_template_result('array has 4 elements', "array has {{ array.size }} elements", assigns)
def test_command_methods_of_array
assigns = { "array" => [11, 22, 33] }
assert_template_result("3", "{{ array.size }}", assigns)
assert_template_result("11", "{{ array.first }}", assigns)
assert_template_result("33", "{{ array.last }}", assigns)
end
def test_size_of_hash
assigns = { "hash" => { a: 1, b: 2, c: 3, d: 4 } }
assert_template_result('hash has 4 elements', "hash has {{ hash.size }} elements", assigns)
def test_command_methods_of_hash
assigns = { "hash" => { a: 11, b: 22, c: 33 } }
assert_template_result("3", "{{ hash.size }}", assigns)
assert_template_result("a11", "{{ hash.first }}", assigns)
assert_template_result("a", "{{ hash.first.first }}", assigns)
assert_template_result("11", "{{ hash.first.last }}", assigns)
assert_template_result("", "{{ hash.last }}", assigns)
end
def test_command_methods_with_proc
skip("Liquid-C does not properly resolve Procs in with command methods") if ENV['LIQUID_C'] == '1'
assigns = { "array" => [proc { "test" }] }
assert_template_result("test", "{{ array.first }}", assigns)
assigns = { "hash" => { a: proc { "test" } } }
assert_template_result("test", "{{ hash.first.last }}", assigns)
end
def test_illegal_symbols