From 013802c8774e80fbcc78b52a51ce911aad5f25e4 Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Tue, 15 Sep 2020 09:11:38 -0400 Subject: [PATCH] Move some unit tests without internal coupling to integration tests since I would like to continue supporting these tests in liquid-c in the foreseeable future. --- test/integration/block_test.rb | 44 ++++++++++++++++++ .../context_test} | 2 +- test/integration/tag_test.rb | 45 ++++++++++++++++++ test/unit/block_unit_test.rb | 46 +------------------ test/unit/tag_unit_test.rb | 38 --------------- 5 files changed, 91 insertions(+), 84 deletions(-) rename test/{unit/context_unit_test.rb => integration/context_test} (99%) create mode 100644 test/integration/tag_test.rb diff --git a/test/integration/block_test.rb b/test/integration/block_test.rb index 0120600d..5cc2aa46 100644 --- a/test/integration/block_test.rb +++ b/test/integration/block_test.rb @@ -11,4 +11,48 @@ class BlockTest < Minitest::Test end assert_equal(exc.message, "Liquid syntax error: 'endunless' is not a valid delimiter for if tags. use endif") end + + def test_with_custom_tag + with_custom_tag('testtag', Block) do + assert Liquid::Template.parse("{% testtag %} {% endtesttag %}") + end + end + + def test_custom_block_tags_have_a_default_render_to_output_buffer_method_for_backwards_compatibility + klass1 = Class.new(Block) do + def render(*) + 'hello' + end + end + + with_custom_tag('blabla', klass1) do + template = Liquid::Template.parse("{% blabla %} bla {% endblabla %}") + + assert_equal 'hello', template.render + + buf = +'' + output = template.render({}, output: buf) + assert_equal 'hello', output + assert_equal 'hello', buf + assert_equal buf.object_id, output.object_id + end + + klass2 = Class.new(klass1) do + def render(*) + 'foo' + super + 'bar' + end + end + + with_custom_tag('blabla', klass2) do + template = Liquid::Template.parse("{% blabla %} foo {% endblabla %}") + + assert_equal 'foohellobar', template.render + + buf = +'' + output = template.render({}, output: buf) + assert_equal 'foohellobar', output + assert_equal 'foohellobar', buf + assert_equal buf.object_id, output.object_id + end + end end diff --git a/test/unit/context_unit_test.rb b/test/integration/context_test similarity index 99% rename from test/unit/context_unit_test.rb rename to test/integration/context_test index cec56089..85f1b1f0 100644 --- a/test/unit/context_unit_test.rb +++ b/test/integration/context_test @@ -65,7 +65,7 @@ class ArrayLike end end -class ContextUnitTest < Minitest::Test +class ContextTest < Minitest::Test include Liquid def setup diff --git a/test/integration/tag_test.rb b/test/integration/tag_test.rb new file mode 100644 index 00000000..3ee1f942 --- /dev/null +++ b/test/integration/tag_test.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require 'test_helper' + +class TagTest < Minitest::Test + include Liquid + + def test_custom_tags_have_a_default_render_to_output_buffer_method_for_backwards_compatibility + klass1 = Class.new(Tag) do + def render(*) + 'hello' + end + end + + with_custom_tag('blabla', klass1) do + template = Liquid::Template.parse("{% blabla %}") + + assert_equal 'hello', template.render + + buf = +'' + output = template.render({}, output: buf) + assert_equal 'hello', output + assert_equal 'hello', buf + assert_equal buf.object_id, output.object_id + end + + klass2 = Class.new(klass1) do + def render(*) + 'foo' + super + 'bar' + end + end + + with_custom_tag('blabla', klass2) do + template = Liquid::Template.parse("{% blabla %}") + + assert_equal 'foohellobar', template.render + + buf = +'' + output = template.render({}, output: buf) + assert_equal 'foohellobar', output + assert_equal 'foohellobar', buf + assert_equal buf.object_id, output.object_id + end + end +end diff --git a/test/unit/block_unit_test.rb b/test/unit/block_unit_test.rb index 9b3103d3..42093ef1 100644 --- a/test/unit/block_unit_test.rb +++ b/test/unit/block_unit_test.rb @@ -45,53 +45,9 @@ class BlockUnitTest < Minitest::Test assert_equal(3, template.root.nodelist.size) end - def test_with_custom_tag - with_custom_tag('testtag', Block) do - assert Liquid::Template.parse("{% testtag %} {% endtesttag %}") - end - end - - def test_custom_block_tags_have_a_default_render_to_output_buffer_method_for_backwards_compatibility - klass1 = Class.new(Block) do - def render(*) - 'hello' - end - end - - with_custom_tag('blabla', klass1) do - template = Liquid::Template.parse("{% blabla %} bla {% endblabla %}") - - assert_equal 'hello', template.render - - buf = +'' - output = template.render({}, output: buf) - assert_equal 'hello', output - assert_equal 'hello', buf - assert_equal buf.object_id, output.object_id - end - - klass2 = Class.new(klass1) do - def render(*) - 'foo' + super + 'bar' - end - end - - with_custom_tag('blabla', klass2) do - template = Liquid::Template.parse("{% blabla %} foo {% endblabla %}") - - assert_equal 'foohellobar', template.render - - buf = +'' - output = template.render({}, output: buf) - assert_equal 'foohellobar', output - assert_equal 'foohellobar', buf - assert_equal buf.object_id, output.object_id - end - end - private def block_types(nodelist) nodelist.collect(&:class) end -end # VariableTest +end diff --git a/test/unit/tag_unit_test.rb b/test/unit/tag_unit_test.rb index d72d3b2f..b814b1b7 100644 --- a/test/unit/tag_unit_test.rb +++ b/test/unit/tag_unit_test.rb @@ -20,42 +20,4 @@ class TagUnitTest < Minitest::Test tag = Tag.parse("some_tag", "", Tokenizer.new(""), ParseContext.new) assert_equal('some_tag', tag.tag_name) end - - def test_custom_tags_have_a_default_render_to_output_buffer_method_for_backwards_compatibility - klass1 = Class.new(Tag) do - def render(*) - 'hello' - end - end - - with_custom_tag('blabla', klass1) do - template = Liquid::Template.parse("{% blabla %}") - - assert_equal 'hello', template.render - - buf = +'' - output = template.render({}, output: buf) - assert_equal 'hello', output - assert_equal 'hello', buf - assert_equal buf.object_id, output.object_id - end - - klass2 = Class.new(klass1) do - def render(*) - 'foo' + super + 'bar' - end - end - - with_custom_tag('blabla', klass2) do - template = Liquid::Template.parse("{% blabla %}") - - assert_equal 'foohellobar', template.render - - buf = +'' - output = template.render({}, output: buf) - assert_equal 'foohellobar', output - assert_equal 'foohellobar', buf - assert_equal buf.object_id, output.object_id - end - end end