diff --git a/test/integration/assign_test.rb b/test/integration/assign_test.rb index e761a0873..0d72e71de 100644 --- a/test/integration/assign_test.rb +++ b/test/integration/assign_test.rb @@ -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 @@ -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 diff --git a/test/integration/parsing_quirks_test.rb b/test/integration/parsing_quirks_test.rb index e3f243126..744936c97 100644 --- a/test/integration/parsing_quirks_test.rb +++ b/test/integration/parsing_quirks_test.rb @@ -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 diff --git a/test/integration/standard_filter_test.rb b/test/integration/standard_filter_test.rb index f413e6f99..88d525c33 100644 --- a/test/integration/standard_filter_test.rb +++ b/test/integration/standard_filter_test.rb @@ -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 @@ -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= @@ -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 @@ -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 @@ -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 @@ -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 @@ -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
\nb
\nc", "{{ source | newline_to_br }}", 'source' => "a\nb\nc") - assert_template_result("a
\nb
\nc", "{{ source | newline_to_br }}", 'source' => "a\r\nb\nc") + assert_template_result("a
\nb
\nc", "{{ source | newline_to_br }}", { 'source' => "a\nb\nc" }) + assert_template_result("a
\nb
\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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/test/integration/tags/echo_test.rb b/test/integration/tags/echo_test.rb index c64932e33..dfe290e53 100644 --- a/test/integration/tags/echo_test.rb +++ b/test/integration/tags/echo_test.rb @@ -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 diff --git a/test/integration/tags/for_tag_test.rb b/test/integration/tags/for_tag_test.rb index f19d63009..68fd8321b 100644 --- a/test/integration/tags/for_tag_test.rb +++ b/test/integration/tags/for_tag_test.rb @@ -12,10 +12,10 @@ class ForTagTest < Minitest::Test include Liquid def test_for - assert_template_result(' yo yo yo yo ', '{%for item in array%} yo {%endfor%}', 'array' => [1, 2, 3, 4]) - assert_template_result('yoyo', '{%for item in array%}yo{%endfor%}', 'array' => [1, 2]) - assert_template_result(' yo ', '{%for item in array%} yo {%endfor%}', 'array' => [1]) - assert_template_result('', '{%for item in array%}{%endfor%}', 'array' => [1, 2]) + assert_template_result(' yo yo yo yo ', '{%for item in array%} yo {%endfor%}', { 'array' => [1, 2, 3, 4] }) + assert_template_result('yoyo', '{%for item in array%}yo{%endfor%}', { 'array' => [1, 2] }) + assert_template_result(' yo ', '{%for item in array%} yo {%endfor%}', { 'array' => [1] }) + assert_template_result('', '{%for item in array%}{%endfor%}', { 'array' => [1, 2] }) expected = < [1, 2, 3]) + assert_template_result(expected, template, { 'array' => [1, 2, 3] }) end def test_for_reversed @@ -45,30 +45,30 @@ def test_for_with_range Template.parse('{% for i in (a..2) %}{% endfor %}').render!("a" => [1, 2]) end - assert_template_result(' 0 1 2 3 ', '{% for item in (a..3) %} {{item}} {% endfor %}', "a" => "invalid integer") + assert_template_result(' 0 1 2 3 ', '{% for item in (a..3) %} {{item}} {% endfor %}', { "a" => "invalid integer" }) end def test_for_with_variable_range - assert_template_result(' 1 2 3 ', '{%for item in (1..foobar) %} {{item}} {%endfor%}', "foobar" => 3) + assert_template_result(' 1 2 3 ', '{%for item in (1..foobar) %} {{item}} {%endfor%}', { "foobar" => 3 }) end def test_for_with_hash_value_range foobar = { "value" => 3 } - assert_template_result(' 1 2 3 ', '{%for item in (1..foobar.value) %} {{item}} {%endfor%}', "foobar" => foobar) + assert_template_result(' 1 2 3 ', '{%for item in (1..foobar.value) %} {{item}} {%endfor%}', { "foobar" => foobar }) end def test_for_with_drop_value_range foobar = ThingWithValue.new - assert_template_result(' 1 2 3 ', '{%for item in (1..foobar.value) %} {{item}} {%endfor%}', "foobar" => foobar) + assert_template_result(' 1 2 3 ', '{%for item in (1..foobar.value) %} {{item}} {%endfor%}', { "foobar" => foobar }) end def test_for_with_variable - assert_template_result(' 1 2 3 ', '{%for item in array%} {{item}} {%endfor%}', 'array' => [1, 2, 3]) - assert_template_result('123', '{%for item in array%}{{item}}{%endfor%}', 'array' => [1, 2, 3]) - assert_template_result('123', '{% for item in array %}{{item}}{% endfor %}', 'array' => [1, 2, 3]) - assert_template_result('abcd', '{%for item in array%}{{item}}{%endfor%}', 'array' => ['a', 'b', 'c', 'd']) - assert_template_result('a b c', '{%for item in array%}{{item}}{%endfor%}', 'array' => ['a', ' ', 'b', ' ', 'c']) - assert_template_result('abc', '{%for item in array%}{{item}}{%endfor%}', 'array' => ['a', '', 'b', '', 'c']) + assert_template_result(' 1 2 3 ', '{%for item in array%} {{item}} {%endfor%}', { 'array' => [1, 2, 3] }) + assert_template_result('123', '{%for item in array%}{{item}}{%endfor%}', { 'array' => [1, 2, 3] }) + assert_template_result('123', '{% for item in array %}{{item}}{% endfor %}', { 'array' => [1, 2, 3] }) + assert_template_result('abcd', '{%for item in array%}{{item}}{%endfor%}', { 'array' => ['a', 'b', 'c', 'd'] }) + assert_template_result('a b c', '{%for item in array%}{{item}}{%endfor%}', { 'array' => ['a', ' ', 'b', ' ', 'c'] }) + assert_template_result('abc', '{%for item in array%}{{item}}{%endfor%}', { 'array' => ['a', '', 'b', '', 'c'] }) end def test_for_helpers @@ -92,9 +92,9 @@ def test_for_and_if end def test_for_else - assert_template_result('+++', '{%for item in array%}+{%else%}-{%endfor%}', 'array' => [1, 2, 3]) - assert_template_result('-', '{%for item in array%}+{%else%}-{%endfor%}', 'array' => []) - assert_template_result('-', '{%for item in array%}+{%else%}-{%endfor%}', 'array' => nil) + assert_template_result('+++', '{%for item in array%}+{%else%}-{%endfor%}', { 'array' => [1, 2, 3] }) + assert_template_result('-', '{%for item in array%}+{%else%}-{%endfor%}', { 'array' => [] }) + assert_template_result('-', '{%for item in array%}+{%else%}-{%endfor%}', { 'array' => nil }) end def test_limiting @@ -313,11 +313,11 @@ def test_for_tag_string assert_template_result('test string', '{%for val in string%}{{val}}{%endfor%}', - 'string' => "test string") + { 'string' => "test string" }) assert_template_result('test string', '{%for val in string limit:1%}{{val}}{%endfor%}', - 'string' => "test string") + { 'string' => "test string" }) assert_template_result('val-string-1-1-0-1-0-true-true-test string', '{%for val in string%}' \ @@ -330,7 +330,7 @@ def test_for_tag_string '{{forloop.first}}-' \ '{{forloop.last}}-' \ '{{val}}{%endfor%}', - 'string' => "test string") + { 'string' => "test string" }) end def test_for_parentloop_references_parent_loop @@ -338,7 +338,7 @@ def test_for_parentloop_references_parent_loop '{% for inner in outer %}{% for k in inner %}' \ '{{ forloop.parentloop.index }}.{{ forloop.index }} ' \ '{% endfor %}{% endfor %}', - 'outer' => [[1, 1, 1], [1, 1, 1]]) + { 'outer' => [[1, 1, 1], [1, 1, 1]] }) end def test_for_parentloop_nil_when_not_present @@ -346,7 +346,7 @@ def test_for_parentloop_nil_when_not_present '{% for inner in outer %}' \ '{{ forloop.parentloop.index }}.{{ forloop.index }} ' \ '{% endfor %}', - 'outer' => [[1, 1, 1], [1, 1, 1]]) + { 'outer' => [[1, 1, 1], [1, 1, 1]] }) end def test_inner_for_over_empty_input @@ -354,7 +354,7 @@ def test_inner_for_over_empty_input end def test_blank_string_not_iterable - assert_template_result('', "{% for char in characters %}I WILL NOT BE OUTPUT{% endfor %}", 'characters' => '') + assert_template_result('', "{% for char in characters %}I WILL NOT BE OUTPUT{% endfor %}", { 'characters' => '' }) end def test_bad_variable_naming_in_for_loop diff --git a/test/integration/tags/if_else_tag_test.rb b/test/integration/tags/if_else_tag_test.rb index 503d912b2..b550ea9e0 100644 --- a/test/integration/tags/if_else_tag_test.rb +++ b/test/integration/tags/if_else_tag_test.rb @@ -24,23 +24,23 @@ def test_if_else end def test_if_boolean - assert_template_result(' YES ', '{% if var %} YES {% endif %}', 'var' => true) + assert_template_result(' YES ', '{% if var %} YES {% endif %}', { 'var' => true }) end def test_if_or - assert_template_result(' YES ', '{% if a or b %} YES {% endif %}', 'a' => true, 'b' => true) - assert_template_result(' YES ', '{% if a or b %} YES {% endif %}', 'a' => true, 'b' => false) - assert_template_result(' YES ', '{% if a or b %} YES {% endif %}', 'a' => false, 'b' => true) - assert_template_result('', '{% if a or b %} YES {% endif %}', 'a' => false, 'b' => false) + assert_template_result(' YES ', '{% if a or b %} YES {% endif %}', { 'a' => true, 'b' => true }) + assert_template_result(' YES ', '{% if a or b %} YES {% endif %}', { 'a' => true, 'b' => false }) + assert_template_result(' YES ', '{% if a or b %} YES {% endif %}', { 'a' => false, 'b' => true }) + assert_template_result('', '{% if a or b %} YES {% endif %}', { 'a' => false, 'b' => false }) - assert_template_result(' YES ', '{% if a or b or c %} YES {% endif %}', 'a' => false, 'b' => false, 'c' => true) - assert_template_result('', '{% if a or b or c %} YES {% endif %}', 'a' => false, 'b' => false, 'c' => false) + assert_template_result(' YES ', '{% if a or b or c %} YES {% endif %}', { 'a' => false, 'b' => false, 'c' => true }) + assert_template_result('', '{% if a or b or c %} YES {% endif %}', { 'a' => false, 'b' => false, 'c' => false }) end def test_if_or_with_operators - assert_template_result(' YES ', '{% if a == true or b == true %} YES {% endif %}', 'a' => true, 'b' => true) - assert_template_result(' YES ', '{% if a == true or b == false %} YES {% endif %}', 'a' => true, 'b' => true) - assert_template_result('', '{% if a == false or b == false %} YES {% endif %}', 'a' => true, 'b' => true) + assert_template_result(' YES ', '{% if a == true or b == true %} YES {% endif %}', { 'a' => true, 'b' => true }) + assert_template_result(' YES ', '{% if a == true or b == false %} YES {% endif %}', { 'a' => true, 'b' => true }) + assert_template_result('', '{% if a == false or b == false %} YES {% endif %}', { 'a' => true, 'b' => true }) end def test_comparison_of_strings_containing_and_or_or @@ -66,40 +66,40 @@ def test_if_and end def test_hash_miss_generates_false - assert_template_result('', '{% if foo.bar %} NO {% endif %}', 'foo' => {}) + assert_template_result('', '{% if foo.bar %} NO {% endif %}', { 'foo' => {} }) end def test_if_from_variable - assert_template_result('', '{% if var %} NO {% endif %}', 'var' => false) - assert_template_result('', '{% if var %} NO {% endif %}', 'var' => nil) - assert_template_result('', '{% if foo.bar %} NO {% endif %}', 'foo' => { 'bar' => false }) - assert_template_result('', '{% if foo.bar %} NO {% endif %}', 'foo' => {}) - assert_template_result('', '{% if foo.bar %} NO {% endif %}', 'foo' => nil) - assert_template_result('', '{% if foo.bar %} NO {% endif %}', 'foo' => true) - - assert_template_result(' YES ', '{% if var %} YES {% endif %}', 'var' => "text") - assert_template_result(' YES ', '{% if var %} YES {% endif %}', 'var' => true) - assert_template_result(' YES ', '{% if var %} YES {% endif %}', 'var' => 1) - assert_template_result(' YES ', '{% if var %} YES {% endif %}', 'var' => {}) - assert_template_result(' YES ', '{% if var %} YES {% endif %}', 'var' => []) + assert_template_result('', '{% if var %} NO {% endif %}', { 'var' => false }) + assert_template_result('', '{% if var %} NO {% endif %}', { 'var' => nil }) + assert_template_result('', '{% if foo.bar %} NO {% endif %}', { 'foo' => { 'bar' => false } }) + assert_template_result('', '{% if foo.bar %} NO {% endif %}', { 'foo' => {} }) + assert_template_result('', '{% if foo.bar %} NO {% endif %}', { 'foo' => nil }) + assert_template_result('', '{% if foo.bar %} NO {% endif %}', { 'foo' => true }) + + assert_template_result(' YES ', '{% if var %} YES {% endif %}', { 'var' => "text" }) + assert_template_result(' YES ', '{% if var %} YES {% endif %}', { 'var' => true }) + assert_template_result(' YES ', '{% if var %} YES {% endif %}', { 'var' => 1 }) + assert_template_result(' YES ', '{% if var %} YES {% endif %}', { 'var' => {} }) + assert_template_result(' YES ', '{% if var %} YES {% endif %}', { 'var' => [] }) assert_template_result(' YES ', '{% if "foo" %} YES {% endif %}') - assert_template_result(' YES ', '{% if foo.bar %} YES {% endif %}', 'foo' => { 'bar' => true }) - assert_template_result(' YES ', '{% if foo.bar %} YES {% endif %}', 'foo' => { 'bar' => "text" }) - assert_template_result(' YES ', '{% if foo.bar %} YES {% endif %}', 'foo' => { 'bar' => 1 }) - assert_template_result(' YES ', '{% if foo.bar %} YES {% endif %}', 'foo' => { 'bar' => {} }) - assert_template_result(' YES ', '{% if foo.bar %} YES {% endif %}', 'foo' => { 'bar' => [] }) + assert_template_result(' YES ', '{% if foo.bar %} YES {% endif %}', { 'foo' => { 'bar' => true } }) + assert_template_result(' YES ', '{% if foo.bar %} YES {% endif %}', { 'foo' => { 'bar' => "text" } }) + assert_template_result(' YES ', '{% if foo.bar %} YES {% endif %}', { 'foo' => { 'bar' => 1 } }) + assert_template_result(' YES ', '{% if foo.bar %} YES {% endif %}', { 'foo' => { 'bar' => {} } }) + assert_template_result(' YES ', '{% if foo.bar %} YES {% endif %}', { 'foo' => { 'bar' => [] } }) - assert_template_result(' YES ', '{% if var %} NO {% else %} YES {% endif %}', 'var' => false) - assert_template_result(' YES ', '{% if var %} NO {% else %} YES {% endif %}', 'var' => nil) - assert_template_result(' YES ', '{% if var %} YES {% else %} NO {% endif %}', 'var' => true) - assert_template_result(' YES ', '{% if "foo" %} YES {% else %} NO {% endif %}', 'var' => "text") + assert_template_result(' YES ', '{% if var %} NO {% else %} YES {% endif %}', { 'var' => false }) + assert_template_result(' YES ', '{% if var %} NO {% else %} YES {% endif %}', { 'var' => nil }) + assert_template_result(' YES ', '{% if var %} YES {% else %} NO {% endif %}', { 'var' => true }) + assert_template_result(' YES ', '{% if "foo" %} YES {% else %} NO {% endif %}', { 'var' => "text" }) - assert_template_result(' YES ', '{% if foo.bar %} NO {% else %} YES {% endif %}', 'foo' => { 'bar' => false }) - assert_template_result(' YES ', '{% if foo.bar %} YES {% else %} NO {% endif %}', 'foo' => { 'bar' => true }) - assert_template_result(' YES ', '{% if foo.bar %} YES {% else %} NO {% endif %}', 'foo' => { 'bar' => "text" }) - assert_template_result(' YES ', '{% if foo.bar %} NO {% else %} YES {% endif %}', 'foo' => { 'notbar' => true }) - assert_template_result(' YES ', '{% if foo.bar %} NO {% else %} YES {% endif %}', 'foo' => {}) - assert_template_result(' YES ', '{% if foo.bar %} NO {% else %} YES {% endif %}', 'notfoo' => { 'bar' => true }) + assert_template_result(' YES ', '{% if foo.bar %} NO {% else %} YES {% endif %}', { 'foo' => { 'bar' => false } }) + assert_template_result(' YES ', '{% if foo.bar %} YES {% else %} NO {% endif %}', { 'foo' => { 'bar' => true } }) + assert_template_result(' YES ', '{% if foo.bar %} YES {% else %} NO {% endif %}', { 'foo' => { 'bar' => "text" } }) + assert_template_result(' YES ', '{% if foo.bar %} NO {% else %} YES {% endif %}', { 'foo' => { 'notbar' => true } }) + assert_template_result(' YES ', '{% if foo.bar %} NO {% else %} YES {% endif %}', { 'foo' => {} }) + assert_template_result(' YES ', '{% if foo.bar %} NO {% else %} YES {% endif %}', { 'notfoo' => { 'bar' => true } }) end def test_nested_if @@ -184,7 +184,7 @@ def test_multiple_conditions tests.each do |vals, expected| a, b, c = vals assigns = { 'a' => a, 'b' => b, 'c' => c } - assert_template_result(expected.to_s, tpl, assigns, assigns.to_s) + assert_template_result(expected.to_s, tpl, assigns, message: assigns.to_s) end end end diff --git a/test/integration/tags/include_tag_test.rb b/test/integration/tags/include_tag_test.rb index 73f487591..3f05b47bf 100644 --- a/test/integration/tags/include_tag_test.rb +++ b/test/integration/tags/include_tag_test.rb @@ -91,27 +91,31 @@ def test_include_tag_looks_for_file_system_in_registers_first def test_include_tag_with assert_template_result("Product: Draft 151cm ", - "{% include 'product' with products[0] %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }]) + "{% include 'product' with products[0] %}", + { "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }] }) end def test_include_tag_with_alias assert_template_result("Product: Draft 151cm ", - "{% include 'product_alias' with products[0] as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }]) + "{% include 'product_alias' with products[0] as product %}", + { "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }] }) end def test_include_tag_for_alias assert_template_result("Product: Draft 151cm Product: Element 155cm ", - "{% include 'product_alias' for products as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }]) + "{% include 'product_alias' for products as product %}", + { "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }] }) end def test_include_tag_with_default_name assert_template_result("Product: Draft 151cm ", - "{% include 'product' %}", "product" => { 'title' => 'Draft 151cm' }) + "{% include 'product' %}", { "product" => { 'title' => 'Draft 151cm' } }) end def test_include_tag_for assert_template_result("Product: Draft 151cm Product: Element 155cm ", - "{% include 'product' for products %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }]) + "{% include 'product' for products %}", + { "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }] }) end def test_include_tag_with_local_variables @@ -126,7 +130,7 @@ def test_include_tag_with_multiple_local_variables def test_include_tag_with_multiple_local_variables_from_context assert_template_result("Locale: test123 test321", "{% include 'locale_variables' echo1: echo1, echo2: more_echos.echo2 %}", - 'echo1' => 'test123', 'more_echos' => { "echo2" => 'test321' }) + { 'echo1' => 'test123', 'more_echos' => { "echo2" => 'test321' } }) end def test_included_templates_assigns_variables @@ -141,10 +145,10 @@ def test_nested_include_tag def test_nested_include_with_variable assert_template_result("Product: Draft 151cm details ", - "{% include 'nested_product_template' with product %}", "product" => { "title" => 'Draft 151cm' }) + "{% include 'nested_product_template' with product %}", { "product" => { "title" => 'Draft 151cm' } }) assert_template_result("Product: Draft 151cm details Product: Element 155cm details ", - "{% include 'nested_product_template' for products %}", "products" => [{ "title" => 'Draft 151cm' }, { "title" => 'Element 155cm' }]) + "{% include 'nested_product_template' for products %}", { "products" => [{ "title" => 'Draft 151cm' }, { "title" => 'Element 155cm' }] }) end def test_recursively_included_template_does_not_produce_endless_loop @@ -162,11 +166,11 @@ def read_template_file(_template_path) end def test_dynamically_choosen_template - assert_template_result("Test123", "{% include template %}", "template" => 'Test123') - assert_template_result("Test321", "{% include template %}", "template" => 'Test321') + assert_template_result("Test123", "{% include template %}", { "template" => 'Test123' }) + assert_template_result("Test321", "{% include template %}", { "template" => 'Test321' }) assert_template_result("Product: Draft 151cm ", "{% include template for product %}", - "template" => 'product', 'product' => { 'title' => 'Draft 151cm' }) + { "template" => 'product', 'product' => { 'title' => 'Draft 151cm' } }) end def test_include_tag_caches_second_read_of_same_partial @@ -250,9 +254,11 @@ def test_render_raise_argument_error_when_template_is_undefined def test_including_via_variable_value assert_template_result("from TestFileSystem", "{% assign page = 'pick_a_source' %}{% include page %}") - assert_template_result("Product: Draft 151cm ", "{% assign page = 'product' %}{% include page %}", "product" => { 'title' => 'Draft 151cm' }) + assert_template_result("Product: Draft 151cm ", "{% assign page = 'product' %}{% include page %}", + { "product" => { 'title' => 'Draft 151cm' } }) - assert_template_result("Product: Draft 151cm ", "{% assign page = 'product' %}{% include page for foo %}", "foo" => { 'title' => 'Draft 151cm' }) + assert_template_result("Product: Draft 151cm ", "{% assign page = 'product' %}{% include page for foo %}", + { "foo" => { 'title' => 'Draft 151cm' } }) end def test_including_with_strict_variables diff --git a/test/integration/tags/increment_tag_test.rb b/test/integration/tags/increment_tag_test.rb index d561a1b57..7ad5c3db1 100644 --- a/test/integration/tags/increment_tag_test.rb +++ b/test/integration/tags/increment_tag_test.rb @@ -15,11 +15,11 @@ def test_inc end def test_dec - assert_template_result('9', '{%decrement port %}', 'port' => 10) + assert_template_result('9', '{%decrement port %}', { 'port' => 10 }) assert_template_result('-1 -2', '{%decrement port %} {%decrement port%}', {}) assert_template_result('1 5 2 2 5', '{%increment port %} {%increment starboard%} ' \ '{%increment port %} {%decrement port%} ' \ - '{%decrement starboard %}', 'port' => 1, 'starboard' => 5) + '{%decrement starboard %}', { 'port' => 1, 'starboard' => 5 }) end end diff --git a/test/integration/tags/liquid_tag_test.rb b/test/integration/tags/liquid_tag_test.rb index b8eb88160..17ce00195 100644 --- a/test/integration/tags/liquid_tag_test.rb +++ b/test/integration/tags/liquid_tag_test.rb @@ -6,13 +6,13 @@ class LiquidTagTest < Minitest::Test include Liquid def test_liquid_tag - assert_template_result('1 2 3', <<~LIQUID, 'array' => [1, 2, 3]) + assert_template_result('1 2 3', <<~LIQUID, { 'array' => [1, 2, 3] }) {%- liquid echo array | join: " " -%} LIQUID - assert_template_result('1 2 3', <<~LIQUID, 'array' => [1, 2, 3]) + assert_template_result('1 2 3', <<~LIQUID, { 'array' => [1, 2, 3] }) {%- liquid for value in array echo value @@ -23,7 +23,7 @@ def test_liquid_tag -%} LIQUID - assert_template_result('4 8 12 6', <<~LIQUID, 'array' => [1, 2, 3]) + assert_template_result('4 8 12 6', <<~LIQUID, { 'array' => [1, 2, 3] }) {%- liquid for value in array assign double_value = value | times: 2 diff --git a/test/integration/tags/render_tag_test.rb b/test/integration/tags/render_tag_test.rb index 1af22b9bc..086255250 100644 --- a/test/integration/tags/render_tag_test.rb +++ b/test/integration/tags/render_tag_test.rb @@ -19,7 +19,7 @@ def test_render_tag_looks_for_file_system_in_registers_first def test_render_passes_named_arguments_into_inner_scope Liquid::Template.file_system = StubFileSystem.new('product' => '{{ inner_product.title }}') assert_template_result('My Product', '{% render "product", inner_product: outer_product %}', - 'outer_product' => { 'title' => 'My Product' }) + { 'outer_product' => { 'title' => 'My Product' } }) end def test_render_accepts_literals_as_arguments @@ -151,7 +151,8 @@ def test_render_tag_with ) assert_template_result("Product: Draft 151cm ", - "{% render 'product' with products[0] %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }]) + "{% render 'product' with products[0] %}", + { "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }] }) end def test_render_tag_with_alias @@ -161,7 +162,8 @@ def test_render_tag_with_alias ) assert_template_result("Product: Draft 151cm ", - "{% render 'product_alias' with products[0] as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }]) + "{% render 'product_alias' with products[0] as product %}", + { "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }] }) end def test_render_tag_for_alias @@ -171,7 +173,8 @@ def test_render_tag_for_alias ) assert_template_result("Product: Draft 151cm Product: Element 155cm ", - "{% render 'product_alias' for products as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }]) + "{% render 'product_alias' for products as product %}", + { "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }] }) end def test_render_tag_for @@ -181,7 +184,8 @@ def test_render_tag_for ) assert_template_result("Product: Draft 151cm Product: Element 155cm ", - "{% render 'product' for products %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }]) + "{% render 'product' for products %}", + { "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }] }) end def test_render_tag_forloop @@ -190,7 +194,8 @@ def test_render_tag_forloop ) assert_template_result("Product: Draft 151cm first index:1 Product: Element 155cm last index:2 ", - "{% render 'product' for products %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }]) + "{% render 'product' for products %}", + { "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }] }) end def test_render_tag_for_drop @@ -199,7 +204,7 @@ def test_render_tag_for_drop ) assert_template_result("123", - "{% render 'loop' for loop as value %}", "loop" => TestEnumerable.new) + "{% render 'loop' for loop as value %}", { "loop" => TestEnumerable.new }) end def test_render_tag_with_drop @@ -208,6 +213,6 @@ def test_render_tag_with_drop ) assert_template_result("TestEnumerable", - "{% render 'loop' with loop as value %}", "loop" => TestEnumerable.new) + "{% render 'loop' with loop as value %}", { "loop" => TestEnumerable.new }) end end diff --git a/test/integration/tags/standard_tag_test.rb b/test/integration/tags/standard_tag_test.rb index ea7dca158..c0ee8aea6 100644 --- a/test/integration/tags/standard_tag_test.rb +++ b/test/integration/tags/standard_tag_test.rb @@ -71,7 +71,7 @@ def test_capture_detects_bad_syntax assert_raises(SyntaxError) do assert_template_result('content foo content foo ', '{{ var2 }}{% capture %}{{ var }} foo {% endcapture %}{{ var2 }}{{ var2 }}', - 'var' => 'content') + { 'var' => 'content' }) end end @@ -120,38 +120,38 @@ def test_case_with_else end def test_case_on_size - assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => []) - assert_template_result('1', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1]) - assert_template_result('2', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1, 1]) - assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1, 1, 1]) - assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1, 1, 1, 1]) - assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1, 1, 1, 1, 1]) + assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', { 'a' => [] }) + assert_template_result('1', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', { 'a' => [1] }) + assert_template_result('2', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', { 'a' => [1, 1] }) + assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', { 'a' => [1, 1, 1] }) + assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', { 'a' => [1, 1, 1, 1] }) + assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', { 'a' => [1, 1, 1, 1, 1] }) end def test_case_on_size_with_else assert_template_result('else', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}', - 'a' => []) + { 'a' => [] }) assert_template_result('1', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}', - 'a' => [1]) + { 'a' => [1] }) assert_template_result('2', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}', - 'a' => [1, 1]) + { 'a' => [1, 1] }) assert_template_result('else', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}', - 'a' => [1, 1, 1]) + { 'a' => [1, 1, 1] }) assert_template_result('else', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}', - 'a' => [1, 1, 1, 1]) + { 'a' => [1, 1, 1, 1] }) assert_template_result('else', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}', - 'a' => [1, 1, 1, 1, 1]) + { 'a' => [1, 1, 1, 1, 1] }) end def test_case_on_length_with_else @@ -185,37 +185,37 @@ def test_assign_from_case def test_case_when_or code = '{% case condition %}{% when 1 or 2 or 3 %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}' - assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => 1) - assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => 2) - assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => 3) - assert_template_result(' its 4 ', code, 'condition' => 4) - assert_template_result('', code, 'condition' => 5) + assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => 1 }) + assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => 2 }) + assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => 3 }) + assert_template_result(' its 4 ', code, { 'condition' => 4 }) + assert_template_result('', code, { 'condition' => 5 }) code = '{% case condition %}{% when 1 or "string" or null %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}' - assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => 1) - assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => 'string') - assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => nil) - assert_template_result('', code, 'condition' => 'something else') + assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => 1 }) + assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => 'string' }) + assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => nil }) + assert_template_result('', code, { 'condition' => 'something else' }) end def test_case_when_comma code = '{% case condition %}{% when 1, 2, 3 %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}' - assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => 1) - assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => 2) - assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => 3) - assert_template_result(' its 4 ', code, 'condition' => 4) - assert_template_result('', code, 'condition' => 5) + assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => 1 }) + assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => 2 }) + assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => 3 }) + assert_template_result(' its 4 ', code, { 'condition' => 4 }) + assert_template_result('', code, { 'condition' => 5 }) code = '{% case condition %}{% when 1, "string", null %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}' - assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => 1) - assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => 'string') - assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => nil) - assert_template_result('', code, 'condition' => 'something else') + assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => 1 }) + assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => 'string' }) + assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => nil }) + assert_template_result('', code, { 'condition' => 'something else' }) end def test_case_when_comma_and_blank_body code = '{% case condition %}{% when 1, 2 %} {% assign r = "result" %} {% endcase %}{{ r }}' - assert_template_result('result', code, 'condition' => 2) + assert_template_result('result', code, { 'condition' => 2 }) end def test_assign diff --git a/test/integration/tags/statements_test.rb b/test/integration/tags/statements_test.rb index d1c55c991..f8cd3ab21 100644 --- a/test/integration/tags/statements_test.rb +++ b/test/integration/tags/statements_test.rb @@ -60,22 +60,22 @@ def test_strings_not_equal def test_var_strings_equal text = ' {% if var == "hello there!" %} true {% else %} false {% endif %} ' - assert_template_result(' true ', text, 'var' => 'hello there!') + assert_template_result(' true ', text, { 'var' => 'hello there!' }) end def test_var_strings_are_not_equal text = ' {% if "hello there!" == var %} true {% else %} false {% endif %} ' - assert_template_result(' true ', text, 'var' => 'hello there!') + assert_template_result(' true ', text, { 'var' => 'hello there!' }) end def test_var_and_long_string_are_equal text = " {% if var == 'hello there!' %} true {% else %} false {% endif %} " - assert_template_result(' true ', text, 'var' => 'hello there!') + assert_template_result(' true ', text, { 'var' => 'hello there!' }) end def test_var_and_long_string_are_equal_backwards text = " {% if 'hello there!' == var %} true {% else %} false {% endif %} " - assert_template_result(' true ', text, 'var' => 'hello there!') + assert_template_result(' true ', text, { 'var' => 'hello there!' }) end # def test_is_nil @@ -87,27 +87,27 @@ def test_var_and_long_string_are_equal_backwards def test_is_collection_empty text = ' {% if array == empty %} true {% else %} false {% endif %} ' - assert_template_result(' true ', text, 'array' => []) + assert_template_result(' true ', text, { 'array' => [] }) end def test_is_not_collection_empty text = ' {% if array == empty %} true {% else %} false {% endif %} ' - assert_template_result(' false ', text, 'array' => [1, 2, 3]) + assert_template_result(' false ', text, { 'array' => [1, 2, 3] }) end def test_nil text = ' {% if var == nil %} true {% else %} false {% endif %} ' - assert_template_result(' true ', text, 'var' => nil) + assert_template_result(' true ', text, { 'var' => nil }) text = ' {% if var == null %} true {% else %} false {% endif %} ' - assert_template_result(' true ', text, 'var' => nil) + assert_template_result(' true ', text, { 'var' => nil }) end def test_not_nil text = ' {% if var != nil %} true {% else %} false {% endif %} ' - assert_template_result(' true ', text, 'var' => 1) + assert_template_result(' true ', text, { 'var' => 1 }) text = ' {% if var != null %} true {% else %} false {% endif %} ' - assert_template_result(' true ', text, 'var' => 1) + assert_template_result(' true ', text, { 'var' => 1 }) end end # StatementsTest diff --git a/test/integration/tags/table_row_test.rb b/test/integration/tags/table_row_test.rb index 71df4f38c..a5ecf1406 100644 --- a/test/integration/tags/table_row_test.rb +++ b/test/integration/tags/table_row_test.rb @@ -20,47 +20,49 @@ def each(&block) def test_table_row assert_template_result("\n 1 2 3 \n 4 5 6 \n", '{% tablerow n in numbers cols:3%} {{n}} {% endtablerow %}', - 'numbers' => [1, 2, 3, 4, 5, 6]) + { 'numbers' => [1, 2, 3, 4, 5, 6] }) assert_template_result("\n\n", '{% tablerow n in numbers cols:3%} {{n}} {% endtablerow %}', - 'numbers' => []) + { 'numbers' => [] }) end def test_table_row_with_different_cols assert_template_result("\n 1 2 3 4 5 \n 6 \n", '{% tablerow n in numbers cols:5%} {{n}} {% endtablerow %}', - 'numbers' => [1, 2, 3, 4, 5, 6]) + { 'numbers' => [1, 2, 3, 4, 5, 6] }) end def test_table_col_counter assert_template_result("\n12\n12\n12\n", '{% tablerow n in numbers cols:2%}{{tablerowloop.col}}{% endtablerow %}', - 'numbers' => [1, 2, 3, 4, 5, 6]) + { 'numbers' => [1, 2, 3, 4, 5, 6] }) end def test_quoted_fragment assert_template_result("\n 1 2 3 \n 4 5 6 \n", "{% tablerow n in collections.frontpage cols:3%} {{n}} {% endtablerow %}", - 'collections' => { 'frontpage' => [1, 2, 3, 4, 5, 6] }) + { 'collections' => { 'frontpage' => [1, 2, 3, 4, 5, 6] } }) assert_template_result("\n 1 2 3 \n 4 5 6 \n", "{% tablerow n in collections['frontpage'] cols:3%} {{n}} {% endtablerow %}", - 'collections' => { 'frontpage' => [1, 2, 3, 4, 5, 6] }) + { 'collections' => { 'frontpage' => [1, 2, 3, 4, 5, 6] } }) end def test_enumerable_drop assert_template_result("\n 1 2 3 \n 4 5 6 \n", '{% tablerow n in numbers cols:3%} {{n}} {% endtablerow %}', - 'numbers' => ArrayDrop.new([1, 2, 3, 4, 5, 6])) + { 'numbers' => ArrayDrop.new([1, 2, 3, 4, 5, 6]) }) end def test_offset_and_limit assert_template_result("\n 1 2 3 \n 4 5 6 \n", '{% tablerow n in numbers cols:3 offset:1 limit:6%} {{n}} {% endtablerow %}', - 'numbers' => [0, 1, 2, 3, 4, 5, 6, 7]) + { 'numbers' => [0, 1, 2, 3, 4, 5, 6, 7] }) end def test_blank_string_not_iterable - assert_template_result("\n\n", "{% tablerow char in characters cols:3 %}I WILL NOT BE OUTPUT{% endtablerow %}", 'characters' => '') + assert_template_result("\n\n", + "{% tablerow char in characters cols:3 %}I WILL NOT BE OUTPUT{% endtablerow %}", + { 'characters' => '' }) end end diff --git a/test/integration/tags/unless_else_tag_test.rb b/test/integration/tags/unless_else_tag_test.rb index f5c9c7f8c..174fb7901 100644 --- a/test/integration/tags/unless_else_tag_test.rb +++ b/test/integration/tags/unless_else_tag_test.rb @@ -19,10 +19,10 @@ def test_unless_else end def test_unless_in_loop - assert_template_result('23', '{% for i in choices %}{% unless i %}{{ forloop.index }}{% endunless %}{% endfor %}', 'choices' => [1, nil, false]) + assert_template_result('23', '{% for i in choices %}{% unless i %}{{ forloop.index }}{% endunless %}{% endfor %}', { 'choices' => [1, nil, false] }) end def test_unless_else_in_loop - assert_template_result(' TRUE 2 3 ', '{% for i in choices %}{% unless i %} {{ forloop.index }} {% else %} TRUE {% endunless %}{% endfor %}', 'choices' => [1, nil, false]) + assert_template_result(' TRUE 2 3 ', '{% for i in choices %}{% unless i %} {{ forloop.index }} {% else %} TRUE {% endunless %}{% endfor %}', { 'choices' => [1, nil, false] }) end end # UnlessElseTest diff --git a/test/integration/variable_test.rb b/test/integration/variable_test.rb index 5c8755019..9ac4fd5d7 100644 --- a/test/integration/variable_test.rb +++ b/test/integration/variable_test.rb @@ -12,34 +12,34 @@ def test_simple_variable end def test_variable_render_calls_to_liquid - assert_template_result('foobar', '{{ foo }}', 'foo' => ThingWithToLiquid.new) + assert_template_result('foobar', '{{ foo }}', { 'foo' => ThingWithToLiquid.new }) end def test_variable_lookup_calls_to_liquid_value - assert_template_result('1', '{{ foo }}', 'foo' => IntegerDrop.new('1')) - assert_template_result('2', '{{ list[foo] }}', 'foo' => IntegerDrop.new('1'), 'list' => [1, 2, 3]) - assert_template_result('one', '{{ list[foo] }}', 'foo' => IntegerDrop.new('1'), 'list' => { 1 => 'one' }) - assert_template_result('Yay', '{{ foo }}', 'foo' => BooleanDrop.new(true)) - assert_template_result('YAY', '{{ foo | upcase }}', 'foo' => BooleanDrop.new(true)) + assert_template_result('1', '{{ foo }}', { 'foo' => IntegerDrop.new('1') }) + assert_template_result('2', '{{ list[foo] }}', { 'foo' => IntegerDrop.new('1'), 'list' => [1, 2, 3] }) + assert_template_result('one', '{{ list[foo] }}', { 'foo' => IntegerDrop.new('1'), 'list' => { 1 => 'one' } }) + assert_template_result('Yay', '{{ foo }}', { 'foo' => BooleanDrop.new(true) }) + assert_template_result('YAY', '{{ foo | upcase }}', { 'foo' => BooleanDrop.new(true) }) end def test_if_tag_calls_to_liquid_value - assert_template_result('one', '{% if foo == 1 %}one{% endif %}', 'foo' => IntegerDrop.new('1')) - assert_template_result('one', '{% if 0 < foo %}one{% endif %}', 'foo' => IntegerDrop.new('1')) - assert_template_result('one', '{% if foo > 0 %}one{% endif %}', 'foo' => IntegerDrop.new('1')) - assert_template_result('true', '{% if foo == true %}true{% endif %}', 'foo' => BooleanDrop.new(true)) - assert_template_result('true', '{% if foo %}true{% endif %}', 'foo' => BooleanDrop.new(true)) + assert_template_result('one', '{% if foo == 1 %}one{% endif %}', { 'foo' => IntegerDrop.new('1') }) + assert_template_result('one', '{% if 0 < foo %}one{% endif %}', { 'foo' => IntegerDrop.new('1') }) + assert_template_result('one', '{% if foo > 0 %}one{% endif %}', { 'foo' => IntegerDrop.new('1') }) + assert_template_result('true', '{% if foo == true %}true{% endif %}', { 'foo' => BooleanDrop.new(true) }) + assert_template_result('true', '{% if foo %}true{% endif %}', { 'foo' => BooleanDrop.new(true) }) - assert_template_result('', '{% if foo %}true{% endif %}', 'foo' => BooleanDrop.new(false)) - assert_template_result('', '{% if foo == true %}True{% endif %}', 'foo' => BooleanDrop.new(false)) + assert_template_result('', '{% if foo %}true{% endif %}', { 'foo' => BooleanDrop.new(false) }) + assert_template_result('', '{% if foo == true %}True{% endif %}', { 'foo' => BooleanDrop.new(false) }) end def test_unless_tag_calls_to_liquid_value - assert_template_result('', '{% unless foo %}true{% endunless %}', 'foo' => BooleanDrop.new(true)) + assert_template_result('', '{% unless foo %}true{% endunless %}', { 'foo' => BooleanDrop.new(true) }) end def test_case_tag_calls_to_liquid_value - assert_template_result('One', '{% case foo %}{% when 1 %}One{% endcase %}', 'foo' => IntegerDrop.new('1')) + assert_template_result('One', '{% case foo %}{% when 1 %}One{% endcase %}', { 'foo' => IntegerDrop.new('1') }) end def test_simple_with_whitespaces @@ -49,8 +49,8 @@ def test_simple_with_whitespaces end def test_expression_with_whitespace_in_square_brackets - assert_template_result('result', "{{ a[ 'b' ] }}", 'a' => { 'b' => 'result' }) - assert_template_result('result', "{{ a[ [ 'b' ] ] }}", 'b' => 'c', 'a' => { 'c' => 'result' }) + assert_template_result('result', "{{ a[ 'b' ] }}", { 'a' => { 'b' => 'result' } }) + assert_template_result('result', "{{ a[ [ 'b' ] ] }}", { 'b' => 'c', 'a' => { 'c' => 'result' } }) end def test_ignore_unknown @@ -69,8 +69,8 @@ def test_using_empty_as_variable_name end def test_hash_scoping - assert_template_result('worked', "{{ test.test }}", 'test' => { 'test' => 'worked' }) - assert_template_result('worked', "{{ test . test }}", 'test' => { 'test' => 'worked' }) + assert_template_result('worked', "{{ test.test }}", { 'test' => { 'test' => 'worked' } }) + assert_template_result('worked', "{{ test . test }}", { 'test' => { 'test' => 'worked' } }) end def test_false_renders_as_false @@ -125,14 +125,14 @@ def test_multiline_variable end def test_render_symbol - assert_template_result('bar', '{{ foo }}', 'foo' => :bar) + assert_template_result('bar', '{{ foo }}', { 'foo' => :bar }) end def test_dynamic_find_var - assert_template_result('bar', '{{ [key] }}', 'key' => 'foo', 'foo' => 'bar') + assert_template_result('bar', '{{ [key] }}', { 'key' => 'foo', 'foo' => 'bar' }) end def test_raw_value_variable - assert_template_result('bar', '{{ [key] }}', 'key' => 'foo', 'foo' => 'bar') + assert_template_result('bar', '{{ [key] }}', { 'key' => 'foo', 'foo' => 'bar' }) end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 874dd8f47..3afc80579 100755 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -37,19 +37,13 @@ def fixture(name) module Assertions include Liquid - def assert_template_result(expected, template, assigns = {}, message = nil) + def assert_template_result(expected, template, assigns = {}, message: nil) assert_equal(expected, Template.parse(template, line_numbers: true).render!(assigns), message) end - def assert_template_result_matches(expected, template, assigns = {}, message = nil) - return assert_template_result(expected, template, assigns, message) unless expected.is_a?(Regexp) - - assert_match(expected, Template.parse(template, line_numbers: true).render!(assigns), message) - end - - def assert_match_syntax_error(match, template, assigns = {}) + def assert_match_syntax_error(match, template) exception = assert_raises(Liquid::SyntaxError) do - Template.parse(template, line_numbers: true).render(assigns) + Template.parse(template, line_numbers: true).render end assert_match(match, exception.message) end