From 2c2f5826d58286e1eb2b31f2a536c2bb5606ee7a Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Fri, 21 Oct 2022 11:43:58 -0400 Subject: [PATCH 1/2] Change increment/decrement tests to avoid relying on input So these can be tested using language tests, without needing support for counter value input, which isn't needed if input is provided through the static environment. --- test/integration/tags/increment_tag_test.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/test/integration/tags/increment_tag_test.rb b/test/integration/tags/increment_tag_test.rb index 7ad5c3db..666d2d56 100644 --- a/test/integration/tags/increment_tag_test.rb +++ b/test/integration/tags/increment_tag_test.rb @@ -6,20 +6,21 @@ class IncrementTagTest < Minitest::Test include Liquid def test_inc - assert_template_result('0', '{%increment port %}', {}) - assert_template_result('0 1', '{%increment port %} {%increment port%}', {}) + assert_template_result('0 1', '{%increment port %} {{ port }}') + assert_template_result(' 0 1 2', '{{port}} {%increment port %} {%increment port%} {{port}}') assert_template_result('0 0 1 2 1', '{%increment port %} {%increment starboard%} ' \ '{%increment port %} {%increment port%} ' \ - '{%increment starboard %}', {}) + '{%increment starboard %}') end def test_dec - 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', + assert_template_result('-1 -1', '{%decrement port %} {{ port }}', { 'port' => 10 }) + assert_template_result(' -1 -2 -2', '{{port}} {%decrement port %} {%decrement port%} {{port}}') + assert_template_result('0 1 2 0 3 1 1 3', + '{%increment starboard %} {%increment starboard%} {%increment starboard%} ' \ '{%increment port %} {%increment starboard%} ' \ '{%increment port %} {%decrement port%} ' \ - '{%decrement starboard %}', { 'port' => 1, 'starboard' => 5 }) + '{%decrement starboard %}') end end From a39422feac532c245ceb9d6a15b8ac91d3d73431 Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Fri, 21 Oct 2022 11:45:29 -0400 Subject: [PATCH 2/2] Use static environment assert_template_result input values To match how we use liquid in practice --- test/test_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 23f0a42a..052f7091 100755 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -44,7 +44,7 @@ module Minitest template = Liquid::Template.parse(template, line_numbers: true, error_mode: error_mode&.to_sym) file_system = StubFileSystem.new(partials) if partials registers = Liquid::Registers.new(file_system: file_system) - context = Liquid::Context.build(environments: assigns, rethrow_errors: !render_errors, registers: registers) + context = Liquid::Context.build(static_environments: assigns, rethrow_errors: !render_errors, registers: registers) output = template.render(context) assert_equal(expected, output, message) end