From e3f403c6943d398406a9b3d974818e473362ced7 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Fri, 8 Jan 2021 14:58:24 -0500 Subject: [PATCH] Add test for serialization with line numbers --- test/unit/template_test.rb | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/test/unit/template_test.rb b/test/unit/template_test.rb index 24afeec6..b9597ad9 100644 --- a/test/unit/template_test.rb +++ b/test/unit/template_test.rb @@ -13,10 +13,32 @@ def test_serialize assert_equal('123', dump_load_eval('{% for i in (1..10) %}{{i}}{% if i == 3 %}{% break %}{% endif %}{% endfor %}')) end + def test_serialize_with_line_numbers + template = <<-LIQUID + Hello, + + {{ errors.standard_error }} will raise a standard error. + LIQUID + + expected = <<-TEXT + Hello, + + Liquid error (line 3): standard error will raise a standard error. + TEXT + + error_drop_klass = Class.new(Liquid::Drop) do + def standard_error + raise Liquid::StandardError, 'standard error' + end + end + + assert_equal(expected, dump_load_eval(template, { 'errors' => error_drop_klass.new }, { line_numbers: true })) + end + private - def dump_load_eval(source, assigns = {}) - serialize = Liquid::Template.parse(source).dump - Liquid::Template.load(serialize).render!(assigns) + def dump_load_eval(source, assigns = {}, options = {}) + serialize = Liquid::Template.parse(source, options).dump + Liquid::Template.load(serialize).render(assigns) end end