Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reserve keyword arguments for new options in assert_template_result #1612

Merged
merged 3 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions test/integration/assign_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,21 @@ def test_assign_with_hyphen_in_variable_name
def test_assigned_variable
assert_template_result('.foo.',
'{% assign foo = values %}.{{ foo[0] }}.',
'values' => %w(foo bar baz))
{ 'values' => %w(foo bar baz) })

assert_template_result('.bar.',
'{% assign foo = values %}.{{ foo[1] }}.',
'values' => %w(foo bar baz))
{ 'values' => %w(foo bar baz) })
end

def test_assign_with_filter
assert_template_result('.bar.',
'{% assign foo = values | split: "," %}.{{ foo[1] }}.',
'values' => "foo,bar,baz")
{ 'values' => "foo,bar,baz" })
end

def test_assign_syntax_error
assert_match_syntax_error(/assign/,
'{% assign foo not values %}.',
'values' => "foo,bar,baz")
assert_match_syntax_error(/assign/, '{% assign foo not values %}.')
end

def test_assign_uses_error_mode
Expand All @@ -50,7 +48,7 @@ def test_assign_uses_error_mode

def test_expression_with_whitespace_in_square_brackets
source = "{% assign r = a[ 'b' ] %}{{ r }}"
assert_template_result('result', source, 'a' => { 'b' => 'result' })
assert_template_result('result', source, { 'a' => { 'b' => 'result' } })
end

def test_assign_score_exceeding_resource_limit
Expand Down
2 changes: 1 addition & 1 deletion test/integration/parsing_quirks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,6 @@ def test_lookup_on_var_with_literal_name
end

def test_contains_in_id
assert_template_result(' YES ', '{% if containsallshipments == true %} YES {% endif %}', 'containsallshipments' => true)
assert_template_result(' YES ', '{% if containsallshipments == true %} YES {% endif %}', { 'containsallshipments' => true })
end
end # ParsingQuirksTest
90 changes: 45 additions & 45 deletions test/integration/standard_filter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def test_legacy_reverse_hash
def test_map
assert_equal([1, 2, 3, 4], @filters.map([{ "a" => 1 }, { "a" => 2 }, { "a" => 3 }, { "a" => 4 }], 'a'))
assert_template_result('abc', "{{ ary | map:'foo' | map:'bar' }}",
'ary' => [{ 'foo' => { 'bar' => 'a' } }, { 'foo' => { 'bar' => 'b' } }, { 'foo' => { 'bar' => 'c' } }])
{ 'ary' => [{ 'foo' => { 'bar' => 'a' } }, { 'foo' => { 'bar' => 'b' } }, { 'foo' => { 'bar' => 'c' } }] })
end

def test_map_doesnt_call_arbitrary_stuff
Expand All @@ -436,7 +436,7 @@ def test_map_doesnt_call_arbitrary_stuff

def test_map_calls_to_liquid
t = TestThing.new
assert_template_result("woot: 1", '{{ foo | map: "whatever" }}', "foo" => [t])
assert_template_result("woot: 1", '{{ foo | map: "whatever" }}', { "foo" => [t] })
end

def test_map_calls_context=
Expand All @@ -451,13 +451,13 @@ def test_map_calls_context=

def test_map_on_hashes
assert_template_result("4217", '{{ thing | map: "foo" | map: "bar" }}',
"thing" => { "foo" => [{ "bar" => 42 }, { "bar" => 17 }] })
{ "thing" => { "foo" => [{ "bar" => 42 }, { "bar" => 17 }] } })
end

def test_legacy_map_on_hashes_with_dynamic_key
template = "{% assign key = 'foo' %}{{ thing | map: key | map: 'bar' }}"
hash = { "foo" => { "bar" => 42 } }
assert_template_result("42", template, "thing" => hash)
assert_template_result("42", template, { "thing" => hash })
end

def test_sort_calls_to_liquid
Expand All @@ -470,7 +470,7 @@ def test_map_over_proc
drop = TestDrop.new(value: "testfoo")
p = proc { drop }
templ = '{{ procs | map: "value" }}'
assert_template_result("testfoo", templ, "procs" => [p])
assert_template_result("testfoo", templ, { "procs" => [p] })
end

def test_map_over_drops_returning_procs
Expand All @@ -483,11 +483,11 @@ def test_map_over_drops_returning_procs
},
]
templ = '{{ drops | map: "proc" }}'
assert_template_result("foobar", templ, "drops" => drops)
assert_template_result("foobar", templ, { "drops" => drops })
end

def test_map_works_on_enumerables
assert_template_result("123", '{{ foo | map: "foo" }}', "foo" => TestEnumerable.new)
assert_template_result("123", '{{ foo | map: "foo" }}', { "foo" => TestEnumerable.new })
end

def test_map_returns_empty_on_2d_input_array
Expand All @@ -514,16 +514,16 @@ def test_map_returns_empty_with_no_property
end

def test_sort_works_on_enumerables
assert_template_result("213", '{{ foo | sort: "bar" | map: "foo" }}', "foo" => TestEnumerable.new)
assert_template_result("213", '{{ foo | sort: "bar" | map: "foo" }}', { "foo" => TestEnumerable.new })
end

def test_first_and_last_call_to_liquid
assert_template_result('foobar', '{{ foo | first }}', 'foo' => [ThingWithToLiquid.new])
assert_template_result('foobar', '{{ foo | last }}', 'foo' => [ThingWithToLiquid.new])
assert_template_result('foobar', '{{ foo | first }}', { 'foo' => [ThingWithToLiquid.new] })
assert_template_result('foobar', '{{ foo | last }}', { 'foo' => [ThingWithToLiquid.new] })
end

def test_truncate_calls_to_liquid
assert_template_result("wo...", '{{ foo | truncate: 5 }}', "foo" => TestThing.new)
assert_template_result("wo...", '{{ foo | truncate: 5 }}', { "foo" => TestThing.new })
end

def test_date
Expand Down Expand Up @@ -597,42 +597,42 @@ def test_pipes_in_string_arguments
end

def test_strip
assert_template_result('ab c', "{{ source | strip }}", 'source' => " ab c ")
assert_template_result('ab c', "{{ source | strip }}", 'source' => " \tab c \n \t")
assert_template_result('ab c', "{{ source | strip }}", { 'source' => " ab c " })
assert_template_result('ab c', "{{ source | strip }}", { 'source' => " \tab c \n \t" })
end

def test_lstrip
assert_template_result('ab c ', "{{ source | lstrip }}", 'source' => " ab c ")
assert_template_result("ab c \n \t", "{{ source | lstrip }}", 'source' => " \tab c \n \t")
assert_template_result('ab c ', "{{ source | lstrip }}", { 'source' => " ab c " })
assert_template_result("ab c \n \t", "{{ source | lstrip }}", { 'source' => " \tab c \n \t" })
end

def test_rstrip
assert_template_result(" ab c", "{{ source | rstrip }}", 'source' => " ab c ")
assert_template_result(" \tab c", "{{ source | rstrip }}", 'source' => " \tab c \n \t")
assert_template_result(" ab c", "{{ source | rstrip }}", { 'source' => " ab c " })
assert_template_result(" \tab c", "{{ source | rstrip }}", { 'source' => " \tab c \n \t" })
end

def test_strip_newlines
assert_template_result('abc', "{{ source | strip_newlines }}", 'source' => "a\nb\nc")
assert_template_result('abc', "{{ source | strip_newlines }}", 'source' => "a\r\nb\nc")
assert_template_result('abc', "{{ source | strip_newlines }}", { 'source' => "a\nb\nc" })
assert_template_result('abc', "{{ source | strip_newlines }}", { 'source' => "a\r\nb\nc" })
end

def test_newlines_to_br
assert_template_result("a<br />\nb<br />\nc", "{{ source | newline_to_br }}", 'source' => "a\nb\nc")
assert_template_result("a<br />\nb<br />\nc", "{{ source | newline_to_br }}", 'source' => "a\r\nb\nc")
assert_template_result("a<br />\nb<br />\nc", "{{ source | newline_to_br }}", { 'source' => "a\nb\nc" })
assert_template_result("a<br />\nb<br />\nc", "{{ source | newline_to_br }}", { 'source' => "a\r\nb\nc" })
end

def test_plus
assert_template_result("2", "{{ 1 | plus:1 }}")
assert_template_result("2.0", "{{ '1' | plus:'1.0' }}")

assert_template_result("5", "{{ price | plus:'2' }}", 'price' => NumberLikeThing.new(3))
assert_template_result("5", "{{ price | plus:'2' }}", { 'price' => NumberLikeThing.new(3) })
end

def test_minus
assert_template_result("4", "{{ input | minus:operand }}", 'input' => 5, 'operand' => 1)
assert_template_result("4", "{{ input | minus:operand }}", { 'input' => 5, 'operand' => 1 })
assert_template_result("2.3", "{{ '4.3' | minus:'2' }}")

assert_template_result("5", "{{ price | minus:'2' }}", 'price' => NumberLikeThing.new(7))
assert_template_result("5", "{{ price | minus:'2' }}", { 'price' => NumberLikeThing.new(7) })
end

def test_abs
Expand All @@ -655,7 +655,7 @@ def test_times
assert_template_result("7.25", "{{ 0.0725 | times:100 }}")
assert_template_result("-7.25", '{{ "-0.0725" | times:100 }}')
assert_template_result("7.25", '{{ "-0.0725" | times: -100 }}')
assert_template_result("4", "{{ price | times:2 }}", 'price' => NumberLikeThing.new(2))
assert_template_result("4", "{{ price | times:2 }}", { 'price' => NumberLikeThing.new(2) })
end

def test_divided_by
Expand All @@ -670,7 +670,7 @@ def test_divided_by
assert_template_result("4", "{{ 1 | modulo: 0 }}")
end

assert_template_result("5", "{{ price | divided_by:2 }}", 'price' => NumberLikeThing.new(10))
assert_template_result("5", "{{ price | divided_by:2 }}", { 'price' => NumberLikeThing.new(10) })
end

def test_modulo
Expand All @@ -679,39 +679,39 @@ def test_modulo
assert_template_result("4", "{{ 1 | modulo: 0 }}")
end

assert_template_result("1", "{{ price | modulo:2 }}", 'price' => NumberLikeThing.new(3))
assert_template_result("1", "{{ price | modulo:2 }}", { 'price' => NumberLikeThing.new(3) })
end

def test_round
assert_template_result("5", "{{ input | round }}", 'input' => 4.6)
assert_template_result("5", "{{ input | round }}", { 'input' => 4.6 })
assert_template_result("4", "{{ '4.3' | round }}")
assert_template_result("4.56", "{{ input | round: 2 }}", 'input' => 4.5612)
assert_template_result("4.56", "{{ input | round: 2 }}", { 'input' => 4.5612 })
assert_raises(Liquid::FloatDomainError) do
assert_template_result("4", "{{ 1.0 | divided_by: 0.0 | round }}")
end

assert_template_result("5", "{{ price | round }}", 'price' => NumberLikeThing.new(4.6))
assert_template_result("4", "{{ price | round }}", 'price' => NumberLikeThing.new(4.3))
assert_template_result("5", "{{ price | round }}", { 'price' => NumberLikeThing.new(4.6) })
assert_template_result("4", "{{ price | round }}", { 'price' => NumberLikeThing.new(4.3) })
end

def test_ceil
assert_template_result("5", "{{ input | ceil }}", 'input' => 4.6)
assert_template_result("5", "{{ input | ceil }}", { 'input' => 4.6 })
assert_template_result("5", "{{ '4.3' | ceil }}")
assert_raises(Liquid::FloatDomainError) do
assert_template_result("4", "{{ 1.0 | divided_by: 0.0 | ceil }}")
end

assert_template_result("5", "{{ price | ceil }}", 'price' => NumberLikeThing.new(4.6))
assert_template_result("5", "{{ price | ceil }}", { 'price' => NumberLikeThing.new(4.6) })
end

def test_floor
assert_template_result("4", "{{ input | floor }}", 'input' => 4.6)
assert_template_result("4", "{{ input | floor }}", { 'input' => 4.6 })
assert_template_result("4", "{{ '4.3' | floor }}")
assert_raises(Liquid::FloatDomainError) do
assert_template_result("4", "{{ 1.0 | divided_by: 0.0 | floor }}")
end

assert_template_result("5", "{{ price | floor }}", 'price' => NumberLikeThing.new(5.4))
assert_template_result("5", "{{ price | floor }}", { 'price' => NumberLikeThing.new(5.4) })
end

def test_at_most
Expand All @@ -720,9 +720,9 @@ def test_at_most
assert_template_result("5", "{{ 5 | at_most:6 }}")

assert_template_result("4.5", "{{ 4.5 | at_most:5 }}")
assert_template_result("5", "{{ width | at_most:5 }}", 'width' => NumberLikeThing.new(6))
assert_template_result("4", "{{ width | at_most:5 }}", 'width' => NumberLikeThing.new(4))
assert_template_result("4", "{{ 5 | at_most: width }}", 'width' => NumberLikeThing.new(4))
assert_template_result("5", "{{ width | at_most:5 }}", { 'width' => NumberLikeThing.new(6) })
assert_template_result("4", "{{ width | at_most:5 }}", { 'width' => NumberLikeThing.new(4) })
assert_template_result("4", "{{ 5 | at_most: width }}", { 'width' => NumberLikeThing.new(4) })
end

def test_at_least
Expand All @@ -731,9 +731,9 @@ def test_at_least
assert_template_result("6", "{{ 5 | at_least:6 }}")

assert_template_result("5", "{{ 4.5 | at_least:5 }}")
assert_template_result("6", "{{ width | at_least:5 }}", 'width' => NumberLikeThing.new(6))
assert_template_result("5", "{{ width | at_least:5 }}", 'width' => NumberLikeThing.new(4))
assert_template_result("6", "{{ 5 | at_least: width }}", 'width' => NumberLikeThing.new(6))
assert_template_result("6", "{{ width | at_least:5 }}", { 'width' => NumberLikeThing.new(6) })
assert_template_result("5", "{{ width | at_least:5 }}", { 'width' => NumberLikeThing.new(4) })
assert_template_result("6", "{{ 5 | at_least: width }}", { 'width' => NumberLikeThing.new(6) })
end

def test_append
Expand Down Expand Up @@ -766,8 +766,8 @@ def test_default
assert_equal("bar", @filters.default([], "bar"))
assert_equal("bar", @filters.default({}, "bar"))
assert_template_result('bar', "{{ false | default: 'bar' }}")
assert_template_result('bar', "{{ drop | default: 'bar' }}", 'drop' => BooleanDrop.new(false))
assert_template_result('Yay', "{{ drop | default: 'bar' }}", 'drop' => BooleanDrop.new(true))
assert_template_result('bar', "{{ drop | default: 'bar' }}", { 'drop' => BooleanDrop.new(false) })
assert_template_result('Yay', "{{ drop | default: 'bar' }}", { 'drop' => BooleanDrop.new(true) })
end

def test_default_handle_false
Expand All @@ -778,8 +778,8 @@ def test_default_handle_false
assert_equal("bar", @filters.default([], "bar", "allow_false" => true))
assert_equal("bar", @filters.default({}, "bar", "allow_false" => true))
assert_template_result('false', "{{ false | default: 'bar', allow_false: true }}")
assert_template_result('Nay', "{{ drop | default: 'bar', allow_false: true }}", 'drop' => BooleanDrop.new(false))
assert_template_result('Yay', "{{ drop | default: 'bar', allow_false: true }}", 'drop' => BooleanDrop.new(true))
assert_template_result('Nay', "{{ drop | default: 'bar', allow_false: true }}", { 'drop' => BooleanDrop.new(false) })
assert_template_result('Yay', "{{ drop | default: 'bar', allow_false: true }}", { 'drop' => BooleanDrop.new(true) })
end

def test_cannot_access_private_methods
Expand Down
2 changes: 1 addition & 1 deletion test/integration/tags/echo_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class EchoTest < Minitest::Test
include Liquid

def test_echo_outputs_its_input
assert_template_result('BAR', <<~LIQUID, 'variable-name' => 'bar')
assert_template_result('BAR', <<~LIQUID, { 'variable-name' => 'bar' })
{%- echo variable-name | upcase -%}
LIQUID
end
Expand Down
Loading