LOL: bmw
) assert_equal expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]) end def test_link_to - text = %( {{ 'Typo' | link_to: 'http://typo.leetsoft.com' }} ) + text = %( {{ 'Typo' | link_to: 'http://typo.leetsoft.com' }} ) expected = %( Typo ) assert_equal expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]) diff --git a/test/integration/parsing_quirks_test.rb b/test/integration/parsing_quirks_test.rb index 58ca3f3..c210b48 100644 --- a/test/integration/parsing_quirks_test.rb +++ b/test/integration/parsing_quirks_test.rb @@ -72,7 +72,7 @@ class ParsingQuirksTest < Minitest::Test def test_meaningless_parens_lax with_error_mode(:lax) do assigns = { 'b' => 'bar', 'c' => 'baz' } - markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false" + markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false" assert_template_result(' YES ', "{% if #{markup} %} YES {% endif %}", assigns) end end diff --git a/test/integration/security_test.rb b/test/integration/security_test.rb index dec33df..28e9d39 100644 --- a/test/integration/security_test.rb +++ b/test/integration/security_test.rb @@ -16,28 +16,28 @@ class SecurityTest < Minitest::Test end def test_no_instance_eval - text = %( {{ '1+1' | instance_eval }} ) + text = %( {{ '1+1' | instance_eval }} ) expected = %( 1+1 ) assert_equal expected, Template.parse(text).render!(@assigns) end def test_no_existing_instance_eval - text = %( {{ '1+1' | __instance_eval__ }} ) + text = %( {{ '1+1' | __instance_eval__ }} ) expected = %( 1+1 ) assert_equal expected, Template.parse(text).render!(@assigns) end def test_no_instance_eval_after_mixing_in_new_filter - text = %( {{ '1+1' | instance_eval }} ) + text = %( {{ '1+1' | instance_eval }} ) expected = %( 1+1 ) assert_equal expected, Template.parse(text).render!(@assigns) end def test_no_instance_eval_later_in_chain - text = %( {{ '1+1' | add_one | instance_eval }} ) + text = %( {{ '1+1' | add_one | instance_eval }} ) expected = %( 1+1 + 1 ) assert_equal expected, Template.parse(text).render!(@assigns, filters: SecurityFilter) @@ -68,13 +68,13 @@ class SecurityTest < Minitest::Test def test_max_depth_nested_blocks_does_not_raise_exception depth = Liquid::Block::MAX_DEPTH - code = "{% if true %}" * depth + "rendered" + "{% endif %}" * depth + code = "{% if true %}" * depth + "rendered" + "{% endif %}" * depth assert_equal "rendered", Template.parse(code).render! end def test_more_than_max_depth_nested_blocks_raises_exception depth = Liquid::Block::MAX_DEPTH + 1 - code = "{% if true %}" * depth + "rendered" + "{% endif %}" * depth + code = "{% if true %}" * depth + "rendered" + "{% endif %}" * depth assert_raises(Liquid::StackLevelError) do Template.parse(code).render! end diff --git a/test/integration/standard_filter_test.rb b/test/integration/standard_filter_test.rb index 7a4bf83..bf28539 100644 --- a/test/integration/standard_filter_test.rb +++ b/test/integration/standard_filter_test.rb @@ -204,7 +204,7 @@ class StandardFiltersTest < Minitest::Test end def test_sort_when_property_is_sometimes_missing_puts_nils_last - input = [ + input = [ { "price" => 4, "handle" => "alpha" }, { "handle" => "beta" }, { "price" => 1, "handle" => "gamma" }, @@ -232,7 +232,7 @@ class StandardFiltersTest < Minitest::Test end def test_sort_natural_when_property_is_sometimes_missing_puts_nils_last - input = [ + input = [ { "price" => "4", "handle" => "alpha" }, { "handle" => "beta" }, { "price" => "1", "handle" => "gamma" }, @@ -250,7 +250,7 @@ class StandardFiltersTest < Minitest::Test end def test_sort_natural_case_check - input = [ + input = [ { "key" => "X" }, { "key" => "Y" }, { "key" => "Z" }, @@ -386,7 +386,7 @@ class StandardFiltersTest < Minitest::Test def test_legacy_map_on_hashes_with_dynamic_key template = "{% assign key = 'foo' %}{{ thing | map: key | map: 'bar' }}" - hash = { "foo" => { "bar" => 42 } } + hash = { "foo" => { "bar" => 42 } } assert_template_result "42", template, "thing" => hash end @@ -397,8 +397,8 @@ class StandardFiltersTest < Minitest::Test end def test_map_over_proc - drop = TestDrop.new - p = proc { drop } + drop = TestDrop.new + p = proc { drop } templ = '{{ procs | map: "test" }}' assert_template_result "testfoo", templ, "procs" => [p] end @@ -768,7 +768,7 @@ class StandardFiltersTest < Minitest::Test private def with_timezone(tz) - old_tz = ENV['TZ'] + old_tz = ENV['TZ'] ENV['TZ'] = tz yield ensure diff --git a/test/integration/tags/break_tag_test.rb b/test/integration/tags/break_tag_test.rb index a67a8b5..c3a4679 100644 --- a/test/integration/tags/break_tag_test.rb +++ b/test/integration/tags/break_tag_test.rb @@ -8,8 +8,8 @@ class BreakTagTest < Minitest::Test # tests that no weird errors are raised if break is called outside of a # block def test_break_with_no_block - assigns = { 'i' => 1 } - markup = '{% break %}' + assigns = { 'i' => 1 } + markup = '{% break %}' expected = '' assert_template_result(expected, markup, assigns) diff --git a/test/integration/tags/continue_tag_test.rb b/test/integration/tags/continue_tag_test.rb index 0530a71..00cca17 100644 --- a/test/integration/tags/continue_tag_test.rb +++ b/test/integration/tags/continue_tag_test.rb @@ -8,8 +8,8 @@ class ContinueTagTest < Minitest::Test # tests that no weird errors are raised if continue is called outside of a # block def test_continue_with_no_block - assigns = {} - markup = '{% continue %}' + assigns = {} + markup = '{% continue %}' expected = '' assert_template_result(expected, markup, assigns) diff --git a/test/integration/tags/for_tag_test.rb b/test/integration/tags/for_tag_test.rb index 0377fcf..667efac 100644 --- a/test/integration/tags/for_tag_test.rb +++ b/test/integration/tags/for_tag_test.rb @@ -106,7 +106,7 @@ HERE end def test_limiting_with_invalid_limit - assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } + assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } template = <<-MKUP {% for i in array limit: true offset: 1 %} {{ i }} @@ -120,7 +120,7 @@ HERE end def test_limiting_with_invalid_offset - assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } + assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } template = <<-MKUP {% for i in array limit: 1 offset: true %} {{ i }} @@ -134,8 +134,8 @@ HERE end def test_dynamic_variable_limiting - assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } - assigns['limit'] = 2 + assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } + assigns['limit'] = 2 assigns['offset'] = 2 assert_template_result('34', '{%for i in array limit: limit offset: offset %}{{ i }}{%endfor%}', assigns) @@ -152,8 +152,8 @@ HERE end def test_pause_resume - assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } - markup = <<-MKUP + assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } + markup = <<-MKUP {%for i in array.items limit: 3 %}{{i}}{%endfor%} next {%for i in array.items offset:continue limit: 3 %}{{i}}{%endfor%} @@ -171,8 +171,8 @@ HERE end def test_pause_resume_limit - assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } - markup = <<-MKUP + assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } + markup = <<-MKUP {%for i in array.items limit:3 %}{{i}}{%endfor%} next {%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%} @@ -190,8 +190,8 @@ HERE end def test_pause_resume_big_limit - assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } - markup = <<-MKUP + assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } + markup = <<-MKUP {%for i in array.items limit:3 %}{{i}}{%endfor%} next {%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%} @@ -209,8 +209,8 @@ HERE end def test_pause_resume_big_offset - assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } - markup = '{%for i in array.items limit:3 %}{{i}}{%endfor%} + assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } + markup = '{%for i in array.items limit:3 %}{{i}}{%endfor%} next {%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%} next @@ -226,26 +226,26 @@ HERE def test_for_with_break assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] } } - markup = '{% for i in array.items %}{% break %}{% endfor %}' + markup = '{% for i in array.items %}{% break %}{% endfor %}' expected = "" assert_template_result(expected, markup, assigns) - markup = '{% for i in array.items %}{{ i }}{% break %}{% endfor %}' + markup = '{% for i in array.items %}{{ i }}{% break %}{% endfor %}' expected = "1" assert_template_result(expected, markup, assigns) - markup = '{% for i in array.items %}{% break %}{{ i }}{% endfor %}' + markup = '{% for i in array.items %}{% break %}{{ i }}{% endfor %}' expected = "" assert_template_result(expected, markup, assigns) - markup = '{% for i in array.items %}{{ i }}{% if i > 3 %}{% break %}{% endif %}{% endfor %}' + markup = '{% for i in array.items %}{{ i }}{% if i > 3 %}{% break %}{% endif %}{% endfor %}' expected = "1234" assert_template_result(expected, markup, assigns) # tests to ensure it only breaks out of the local for loop # and not all of them. - assigns = { 'array' => [[1, 2], [3, 4], [5, 6]] } - markup = '{% for item in array %}' \ + assigns = { 'array' => [[1, 2], [3, 4], [5, 6]] } + markup = '{% for item in array %}' \ '{% for i in item %}' \ '{% if i == 1 %}' \ '{% break %}' \ @@ -257,8 +257,8 @@ HERE assert_template_result(expected, markup, assigns) # test break does nothing when unreached - assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } } - markup = '{% for i in array.items %}{% if i == 9999 %}{% break %}{% endif %}{{ i }}{% endfor %}' + assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } } + markup = '{% for i in array.items %}{% if i == 9999 %}{% break %}{% endif %}{{ i }}{% endfor %}' expected = '12345' assert_template_result(expected, markup, assigns) end @@ -266,29 +266,29 @@ HERE def test_for_with_continue assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } } - markup = '{% for i in array.items %}{% continue %}{% endfor %}' + markup = '{% for i in array.items %}{% continue %}{% endfor %}' expected = "" assert_template_result(expected, markup, assigns) - markup = '{% for i in array.items %}{{ i }}{% continue %}{% endfor %}' + markup = '{% for i in array.items %}{{ i }}{% continue %}{% endfor %}' expected = "12345" assert_template_result(expected, markup, assigns) - markup = '{% for i in array.items %}{% continue %}{{ i }}{% endfor %}' + markup = '{% for i in array.items %}{% continue %}{{ i }}{% endfor %}' expected = "" assert_template_result(expected, markup, assigns) - markup = '{% for i in array.items %}{% if i > 3 %}{% continue %}{% endif %}{{ i }}{% endfor %}' + markup = '{% for i in array.items %}{% if i > 3 %}{% continue %}{% endif %}{{ i }}{% endfor %}' expected = "123" assert_template_result(expected, markup, assigns) - markup = '{% for i in array.items %}{% if i == 3 %}{% continue %}{% else %}{{ i }}{% endif %}{% endfor %}' + markup = '{% for i in array.items %}{% if i == 3 %}{% continue %}{% else %}{{ i }}{% endif %}{% endfor %}' expected = "1245" assert_template_result(expected, markup, assigns) # tests to ensure it only continues the local for loop and not all of them. - assigns = { 'array' => [[1, 2], [3, 4], [5, 6]] } - markup = '{% for item in array %}' \ + assigns = { 'array' => [[1, 2], [3, 4], [5, 6]] } + markup = '{% for item in array %}' \ '{% for i in item %}' \ '{% if i == 1 %}' \ '{% continue %}' \ @@ -300,8 +300,8 @@ HERE assert_template_result(expected, markup, assigns) # test continue does nothing when unreached - assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } } - markup = '{% for i in array.items %}{% if i == 9999 %}{% continue %}{% endif %}{{ i }}{% endfor %}' + assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } } + markup = '{% for i in array.items %}{% if i == 9999 %}{% continue %}{% endif %}{{ i }}{% endfor %}' expected = '12345' assert_template_result(expected, markup, assigns) end @@ -389,8 +389,8 @@ HERE end def test_iterate_with_each_when_no_limit_applied - loader = LoaderDrop.new([1, 2, 3, 4, 5]) - assigns = { 'items' => loader } + loader = LoaderDrop.new([1, 2, 3, 4, 5]) + assigns = { 'items' => loader } expected = '12345' template = '{% for item in items %}{{item}}{% endfor %}' assert_template_result(expected, template, assigns) @@ -399,8 +399,8 @@ HERE end def test_iterate_with_load_slice_when_limit_applied - loader = LoaderDrop.new([1, 2, 3, 4, 5]) - assigns = { 'items' => loader } + loader = LoaderDrop.new([1, 2, 3, 4, 5]) + assigns = { 'items' => loader } expected = '1' template = '{% for item in items limit:1 %}{{item}}{% endfor %}' assert_template_result(expected, template, assigns) @@ -409,8 +409,8 @@ HERE end def test_iterate_with_load_slice_when_limit_and_offset_applied - loader = LoaderDrop.new([1, 2, 3, 4, 5]) - assigns = { 'items' => loader } + loader = LoaderDrop.new([1, 2, 3, 4, 5]) + assigns = { 'items' => loader } expected = '34' template = '{% for item in items offset:2 limit:2 %}{{item}}{% endfor %}' assert_template_result(expected, template, assigns) @@ -419,11 +419,11 @@ HERE end def test_iterate_with_load_slice_returns_same_results_as_without - loader = LoaderDrop.new([1, 2, 3, 4, 5]) + loader = LoaderDrop.new([1, 2, 3, 4, 5]) loader_assigns = { 'items' => loader } - array_assigns = { 'items' => [1, 2, 3, 4, 5] } - expected = '34' - template = '{% for item in items offset:2 limit:2 %}{{item}}{% endfor %}' + array_assigns = { 'items' => [1, 2, 3, 4, 5] } + expected = '34' + template = '{% for item in items offset:2 limit:2 %}{{item}}{% endfor %}' assert_template_result(expected, template, loader_assigns) assert_template_result(expected, template, array_assigns) end diff --git a/test/integration/tags/if_else_tag_test.rb b/test/integration/tags/if_else_tag_test.rb index dfbc537..d54b2fb 100644 --- a/test/integration/tags/if_else_tag_test.rb +++ b/test/integration/tags/if_else_tag_test.rb @@ -45,7 +45,7 @@ class IfElseTagTest < Minitest::Test def test_comparison_of_strings_containing_and_or_or awful_markup = "a == 'and' and b == 'or' and c == 'foo and bar' and d == 'bar or baz' and e == 'foo' and foo and bar" - assigns = { 'a' => 'and', 'b' => 'or', 'c' => 'foo and bar', 'd' => 'bar or baz', 'e' => 'foo', 'foo' => true, 'bar' => true } + assigns = { 'a' => 'and', 'b' => 'or', 'c' => 'foo and bar', 'd' => 'bar or baz', 'e' => 'foo', 'foo' => true, 'bar' => true } assert_template_result(' YES ', "{% if #{awful_markup} %} YES {% endif %}", assigns) end @@ -142,7 +142,7 @@ class IfElseTagTest < Minitest::Test end def test_if_with_custom_condition - original_op = Condition.operators['contains'] + original_op = Condition.operators['contains'] Condition.operators['contains'] = :[] assert_template_result('yes', %({% if 'bob' contains 'o' %}yes{% endif %})) @@ -152,7 +152,7 @@ class IfElseTagTest < Minitest::Test end def test_operators_are_ignored_unless_isolated - original_op = Condition.operators['contains'] + original_op = Condition.operators['contains'] Condition.operators['contains'] = :[] assert_template_result('yes', diff --git a/test/integration/tags/include_tag_test.rb b/test/integration/tags/include_tag_test.rb index ef96081..686d482 100644 --- a/test/integration/tags/include_tag_test.rb +++ b/test/integration/tags/include_tag_test.rb @@ -51,7 +51,7 @@ class CountingFileSystem attr_reader :count def read_template_file(_template_path) @count ||= 0 - @count += 1 + @count += 1 'from CountingFileSystem' end end @@ -179,7 +179,7 @@ class IncludeTagTest < Minitest::Test end def test_custom_include_tag - original_tag = Liquid::Template.tags['include'] + original_tag = Liquid::Template.tags['include'] Liquid::Template.tags['include'] = CustomInclude begin assert_equal "custom_foo", @@ -190,7 +190,7 @@ class IncludeTagTest < Minitest::Test end def test_custom_include_tag_within_if_statement - original_tag = Liquid::Template.tags['include'] + original_tag = Liquid::Template.tags['include'] Liquid::Template.tags['include'] = CustomInclude begin assert_equal "custom_foo_if_true", diff --git a/test/integration/tags/render_tag_test.rb b/test/integration/tags/render_tag_test.rb index 656ec8e..154783a 100644 --- a/test/integration/tags/render_tag_test.rb +++ b/test/integration/tags/render_tag_test.rb @@ -47,7 +47,7 @@ class RenderTagTest < Minitest::Test with_taint_mode :error do template = Liquid::Template.parse('{% render "snippet", unsafe: unsafe %}') - context = Context.new('unsafe' => (+'unsafe').tap(&:taint)) + context = Context.new('unsafe' => (+'unsafe').tap(&:taint)) template.render(context) assert_equal [Liquid::TaintedError], template.errors.map(&:class) @@ -60,7 +60,7 @@ class RenderTagTest < Minitest::Test with_taint_mode :warn do template = Liquid::Template.parse('{% render "snippet", unsafe: unsafe %}') - context = Context.new('unsafe' => (+'unsafe').tap(&:taint)) + context = Context.new('unsafe' => (+'unsafe').tap(&:taint)) template.render(context) assert_equal [Liquid::TaintedError], context.warnings.map(&:class) diff --git a/test/integration/tags/standard_tag_test.rb b/test/integration/tags/standard_tag_test.rb index 72b5a37..7939cd3 100644 --- a/test/integration/tags/standard_tag_test.rb +++ b/test/integration/tags/standard_tag_test.rb @@ -174,7 +174,7 @@ class StandardTagTest < Minitest::Test def test_assign_from_case # Example from the shopify forums - code = "{% case collection.handle %}{% when 'menswear-jackets' %}{% assign ptitle = 'menswear' %}{% when 'menswear-t-shirts' %}{% assign ptitle = 'menswear' %}{% else %}{% assign ptitle = 'womenswear' %}{% endcase %}{{ ptitle }}" + code = "{% case collection.handle %}{% when 'menswear-jackets' %}{% assign ptitle = 'menswear' %}{% when 'menswear-t-shirts' %}{% assign ptitle = 'menswear' %}{% else %}{% assign ptitle = 'womenswear' %}{% endcase %}{{ ptitle }}" template = Liquid::Template.parse(code) assert_equal "menswear", template.render!("collection" => { 'handle' => 'menswear-jackets' }) assert_equal "menswear", template.render!("collection" => { 'handle' => 'menswear-t-shirts' }) diff --git a/test/integration/template_test.rb b/test/integration/template_test.rb index 9f21d39..48549f5 100644 --- a/test/integration/template_test.rb +++ b/test/integration/template_test.rb @@ -73,29 +73,29 @@ class TemplateTest < Minitest::Test end def test_persistent_assigns_squash_instance_assigns - t = Template.new + t = Template.new assert_equal 'from instance assigns', t.parse("{% assign foo = 'from instance assigns' %}{{ foo }}").render! t.assigns['foo'] = 'from persistent assigns' assert_equal 'from persistent assigns', t.parse("{{ foo }}").render! end def test_lambda_is_called_once_from_persistent_assigns_over_multiple_parses_and_renders - t = Template.new + t = Template.new t.assigns['number'] = -> { @global ||= 0 - @global += 1 + @global += 1 } assert_equal '1', t.parse("{{number}}").render! assert_equal '1', t.parse("{{number}}").render! assert_equal '1', t.render! - @global = nil + @global = nil end def test_lambda_is_called_once_from_custom_assigns_over_multiple_parses_and_renders - t = Template.new + t = Template.new assigns = { 'number' => -> { @global ||= 0 - @global += 1 + @global += 1 } } assert_equal '1', t.parse("{{number}}").render!(assigns) assert_equal '1', t.parse("{{number}}").render!(assigns) @@ -104,13 +104,13 @@ class TemplateTest < Minitest::Test end def test_resource_limits_works_with_custom_length_method - t = Template.parse("{% assign foo = bar %}") + t = Template.parse("{% assign foo = bar %}") t.resource_limits.render_length_limit = 42 assert_equal "", t.render!("bar" => SomethingWithLength.new) end def test_resource_limits_render_length - t = Template.parse("0123456789") + t = Template.parse("0123456789") t.resource_limits.render_length_limit = 5 assert_equal "Liquid error: Memory limits exceeded", t.render assert t.resource_limits.reached? @@ -121,12 +121,12 @@ class TemplateTest < Minitest::Test end def test_resource_limits_render_score - t = Template.parse("{% for a in (1..10) %} {% for a in (1..10) %} foo {% endfor %} {% endfor %}") + t = Template.parse("{% for a in (1..10) %} {% for a in (1..10) %} foo {% endfor %} {% endfor %}") t.resource_limits.render_score_limit = 50 assert_equal "Liquid error: Memory limits exceeded", t.render assert t.resource_limits.reached? - t = Template.parse("{% for a in (1..100) %} foo {% endfor %}") + t = Template.parse("{% for a in (1..100) %} foo {% endfor %}") t.resource_limits.render_score_limit = 50 assert_equal "Liquid error: Memory limits exceeded", t.render assert t.resource_limits.reached? @@ -137,7 +137,7 @@ class TemplateTest < Minitest::Test end def test_resource_limits_assign_score - t = Template.parse("{% assign foo = 42 %}{% assign bar = 23 %}") + t = Template.parse("{% assign foo = 42 %}{% assign bar = 23 %}") t.resource_limits.assign_score_limit = 1 assert_equal "Liquid error: Memory limits exceeded", t.render assert t.resource_limits.reached? @@ -169,7 +169,7 @@ class TemplateTest < Minitest::Test end def test_resource_limits_aborts_rendering_after_first_error - t = Template.parse("{% for a in (1..100) %} foo1 {% endfor %} bar {% for a in (1..100) %} foo2 {% endfor %}") + t = Template.parse("{% for a in (1..100) %} foo1 {% endfor %} bar {% for a in (1..100) %} foo2 {% endfor %}") t.resource_limits.render_score_limit = 50 assert_equal "Liquid error: Memory limits exceeded", t.render assert t.resource_limits.reached? @@ -184,19 +184,19 @@ class TemplateTest < Minitest::Test end def test_render_length_persists_between_blocks - t = Template.parse("{% if true %}aaaa{% endif %}") + t = Template.parse("{% if true %}aaaa{% endif %}") t.resource_limits.render_length_limit = 7 assert_equal "Liquid error: Memory limits exceeded", t.render t.resource_limits.render_length_limit = 8 assert_equal "aaaa", t.render - t = Template.parse("{% if true %}aaaa{% endif %}{% if true %}bbb{% endif %}") + t = Template.parse("{% if true %}aaaa{% endif %}{% if true %}bbb{% endif %}") t.resource_limits.render_length_limit = 13 assert_equal "Liquid error: Memory limits exceeded", t.render t.resource_limits.render_length_limit = 14 assert_equal "aaaabbb", t.render - t = Template.parse("{% if true %}a{% endif %}{% if true %}b{% endif %}{% if true %}a{% endif %}{% if true %}b{% endif %}{% if true %}a{% endif %}{% if true %}b{% endif %}") + t = Template.parse("{% if true %}a{% endif %}{% if true %}b{% endif %}{% if true %}a{% endif %}{% if true %}b{% endif %}{% if true %}a{% endif %}{% if true %}b{% endif %}") t.resource_limits.render_length_limit = 5 assert_equal "Liquid error: Memory limits exceeded", t.render t.resource_limits.render_length_limit = 11 @@ -206,7 +206,7 @@ class TemplateTest < Minitest::Test end def test_render_length_uses_number_of_bytes_not_characters - t = Template.parse("{% if true %}すごい{% endif %}") + t = Template.parse("{% if true %}すごい{% endif %}") t.resource_limits.render_length_limit = 10 assert_equal "Liquid error: Memory limits exceeded", t.render t.resource_limits.render_length_limit = 18 @@ -215,7 +215,7 @@ class TemplateTest < Minitest::Test def test_default_resource_limits_unaffected_by_render_with_context context = Context.new - t = Template.parse("{% for a in (1..100) %} {% assign foo = 1 %} {% endfor %}") + t = Template.parse("{% for a in (1..100) %} {% assign foo = 1 %} {% endfor %}") t.render!(context) assert context.resource_limits.assign_score > 0 assert context.resource_limits.render_score > 0 @@ -223,9 +223,9 @@ class TemplateTest < Minitest::Test end def test_can_use_drop_as_context - t = Template.new + t = Template.new t.registers['lulz'] = 'haha' - drop = TemplateContextDrop.new + drop = TemplateContextDrop.new assert_equal 'fizzbuzz', t.parse('{{foo}}').render!(drop) assert_equal 'bar', t.parse('{{bar}}').render!(drop) assert_equal 'haha', t.parse("{{baz}}").render!(drop) @@ -233,7 +233,7 @@ class TemplateTest < Minitest::Test def test_render_bang_force_rethrow_errors_on_passed_context context = Context.new('drop' => ErroneousDrop.new) - t = Template.new.parse('{{ drop.bad_method }}') + t = Template.new.parse('{{ drop.bad_method }}') e = assert_raises RuntimeError do t.render!(context) @@ -243,7 +243,7 @@ class TemplateTest < Minitest::Test def test_exception_renderer_that_returns_string exception = nil - handler = ->(e) { + handler = ->(e) { exception = e '' } @@ -267,20 +267,20 @@ class TemplateTest < Minitest::Test def test_global_filter_option_on_render global_filter_proc = ->(output) { "#{output} filtered" } - rendered_template = Template.parse("{{name}}").render({ "name" => "bob" }, global_filter: global_filter_proc) + rendered_template = Template.parse("{{name}}").render({ "name" => "bob" }, global_filter: global_filter_proc) assert_equal 'bob filtered', rendered_template end def test_global_filter_option_when_native_filters_exist global_filter_proc = ->(output) { "#{output} filtered" } - rendered_template = Template.parse("{{name | upcase}}").render({ "name" => "bob" }, global_filter: global_filter_proc) + rendered_template = Template.parse("{{name | upcase}}").render({ "name" => "bob" }, global_filter: global_filter_proc) assert_equal 'BOB filtered', rendered_template end def test_undefined_variables - t = Template.parse("{{x}} {{y}} {{z.a}} {{z.b}} {{z.c.d}}") + t = Template.parse("{{x}} {{y}} {{z.a}} {{z.b}} {{z.c.d}}") result = t.render({ 'x' => 33, 'z' => { 'a' => 32, 'c' => { 'e' => 31 } } }, strict_variables: true) assert_equal '33 32 ', result @@ -295,8 +295,8 @@ class TemplateTest < Minitest::Test def test_nil_value_does_not_raise Liquid::Template.error_mode = :strict - t = Template.parse("some{{x}}thing") - result = t.render!({ 'x' => nil }, strict_variables: true) + t = Template.parse("some{{x}}thing") + result = t.render!({ 'x' => nil }, strict_variables: true) assert_equal 0, t.errors.count assert_equal 'something', result @@ -311,8 +311,8 @@ class TemplateTest < Minitest::Test end def test_undefined_drop_methods - d = DropWithUndefinedMethod.new - t = Template.new.parse('{{ foo }} {{ woot }}') + d = DropWithUndefinedMethod.new + t = Template.new.parse('{{ foo }} {{ woot }}') result = t.render(d, strict_variables: true) assert_equal 'foo ', result @@ -330,13 +330,13 @@ class TemplateTest < Minitest::Test end def test_undefined_filters - t = Template.parse("{{a}} {{x | upcase | somefilter1 | somefilter2 | somefilter3}}") + t = Template.parse("{{a}} {{x | upcase | somefilter1 | somefilter2 | somefilter3}}") filters = Module.new do def somefilter3(v) "-#{v}-" end end - result = t.render({ 'a' => 123, 'x' => 'foo' }, filters: [filters], strict_filters: true) + result = t.render({ 'a' => 123, 'x' => 'foo' }, filters: [filters], strict_filters: true) assert_equal '123 ', result assert_equal 1, t.errors.count @@ -353,11 +353,11 @@ class TemplateTest < Minitest::Test end def test_using_range_literal_works_as_expected - t = Template.parse("{% assign foo = (x..y) %}{{ foo }}") + t = Template.parse("{% assign foo = (x..y) %}{{ foo }}") result = t.render('x' => 1, 'y' => 5) assert_equal '1..5', result - t = Template.parse("{% assign nums = (x..y) %}{% for num in nums %}{{ num }}{% endfor %}") + t = Template.parse("{% assign nums = (x..y) %}{% for num in nums %}{{ num }}{% endfor %}") result = t.render('x' => 1, 'y' => 5) assert_equal '12345', result end diff --git a/test/integration/trim_mode_test.rb b/test/integration/trim_mode_test.rb index 4c4d4c8..438f86b 100644 --- a/test/integration/trim_mode_test.rb +++ b/test/integration/trim_mode_test.rb @@ -7,7 +7,7 @@ class TrimModeTest < Minitest::Test # Make sure the trim isn't applied to standard output def test_standard_output - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE{{ 'John' }} @@ -25,7 +25,7 @@ class TrimModeTest < Minitest::Test end def test_variable_output_with_multiple_blank_lines - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
@@ -45,7 +45,7 @@ class TrimModeTest < Minitest::Test end def test_tag_output_with_multiple_blank_lines - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
@@ -69,7 +69,7 @@ class TrimModeTest < Minitest::Test # Make sure the trim isn't applied to standard tags def test_standard_tags whitespace = ' ' - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
{% if true %} @@ -78,7 +78,7 @@ class TrimModeTest < Minitest::Test
#{whitespace} @@ -89,7 +89,7 @@ class TrimModeTest < Minitest::Test END_EXPECTED assert_template_result(expected, text) - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
{% if false %} @@ -110,64 +110,64 @@ class TrimModeTest < Minitest::Test # Make sure the trim isn't too agressive def test_no_trim_output - text = '
{{- \'John\' -}}
' + text = '{{- \'John\' -}}
' expected = 'John
' assert_template_result(expected, text) end # Make sure the trim isn't too agressive def test_no_trim_tags - text = '{%- if true -%}yes{%- endif -%}
' + text = '{%- if true -%}yes{%- endif -%}
' expected = 'yes
' assert_template_result(expected, text) - text = '{%- if false -%}no{%- endif -%}
' + text = '{%- if false -%}no{%- endif -%}
' expected = '' assert_template_result(expected, text) end def test_single_line_outer_tag - text = '{%- if true %} yes {% endif -%}
' + text = '{%- if true %} yes {% endif -%}
' expected = 'yes
' assert_template_result(expected, text) - text = '{%- if false %} no {% endif -%}
' + text = '{%- if false %} no {% endif -%}
' expected = '' assert_template_result(expected, text) end def test_single_line_inner_tag - text = '{% if true -%} yes {%- endif %}
' + text = '{% if true -%} yes {%- endif %}
' expected = 'yes
' assert_template_result(expected, text) - text = '{% if false -%} no {%- endif %}
' + text = '{% if false -%} no {%- endif %}
' expected = '' assert_template_result(expected, text) end def test_single_line_post_tag - text = '
{% if true -%} yes {% endif -%}
' + text = '{% if true -%} yes {% endif -%}
' expected = 'yes
' assert_template_result(expected, text) - text = '{% if false -%} no {% endif -%}
' + text = '{% if false -%} no {% endif -%}
' expected = '' assert_template_result(expected, text) end def test_single_line_pre_tag - text = '
{%- if true %} yes {%- endif %}
' + text = '{%- if true %} yes {%- endif %}
' expected = 'yes
' assert_template_result(expected, text) - text = '{%- if false %} no {%- endif %}
' + text = '{%- if false %} no {%- endif %}
' expected = '' assert_template_result(expected, text) end def test_pre_trim_output - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
{{- 'John' }} @@ -184,7 +184,7 @@ class TrimModeTest < Minitest::Test end def test_pre_trim_tags - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
{%- if true %} @@ -202,7 +202,7 @@ class TrimModeTest < Minitest::Test END_EXPECTED assert_template_result(expected, text) - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
{%- if false %} @@ -221,7 +221,7 @@ class TrimModeTest < Minitest::Test end def test_post_trim_output - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
{{ 'John' -}} @@ -238,7 +238,7 @@ class TrimModeTest < Minitest::Test end def test_post_trim_tags - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
{% if true -%} @@ -256,7 +256,7 @@ class TrimModeTest < Minitest::Test END_EXPECTED assert_template_result(expected, text) - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
{% if false -%} @@ -275,7 +275,7 @@ class TrimModeTest < Minitest::Test end def test_pre_and_post_trim_tags - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
{%- if true %} @@ -293,7 +293,7 @@ class TrimModeTest < Minitest::Test END_EXPECTED assert_template_result(expected, text) - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
{%- if false %} @@ -311,7 +311,7 @@ class TrimModeTest < Minitest::Test end def test_post_and_pre_trim_tags - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
{% if true -%} @@ -330,7 +330,7 @@ class TrimModeTest < Minitest::Test assert_template_result(expected, text) whitespace = ' ' - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
{% if false -%} @@ -339,7 +339,7 @@ class TrimModeTest < Minitest::Test
#{whitespace} @@ -350,7 +350,7 @@ class TrimModeTest < Minitest::Test end def test_trim_output - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
{{- 'John' -}} @@ -366,7 +366,7 @@ class TrimModeTest < Minitest::Test end def test_trim_tags - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
{%- if true -%} @@ -382,7 +382,7 @@ class TrimModeTest < Minitest::Test END_EXPECTED assert_template_result(expected, text) - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
{%- if false -%} @@ -400,7 +400,7 @@ class TrimModeTest < Minitest::Test end def test_whitespace_trim_output - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
{{- 'John' -}}, @@ -417,7 +417,7 @@ class TrimModeTest < Minitest::Test end def test_whitespace_trim_tags - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
{%- if true -%} @@ -433,7 +433,7 @@ class TrimModeTest < Minitest::Test END_EXPECTED assert_template_result(expected, text) - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
{%- if false -%} @@ -451,7 +451,7 @@ class TrimModeTest < Minitest::Test end def test_complex_trim_output - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
{{- 'John' -}} @@ -481,7 +481,7 @@ class TrimModeTest < Minitest::Test end def test_complex_trim - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE