require 'test_helper' class TrimModeTest < Minitest::Test include Liquid # Make sure the trim isn't applied to standard output def test_standard_output text = <<-END_TEMPLATE

{{ 'John' }}

END_TEMPLATE expected = <<-END_EXPECTED

John

END_EXPECTED assert_template_result(expected, text) end def test_variable_output_with_multiple_blank_lines text = <<-END_TEMPLATE

{{- 'John' -}}

END_TEMPLATE expected = <<-END_EXPECTED

John

END_EXPECTED assert_template_result(expected, text) end def test_tag_output_with_multiple_blank_lines text = <<-END_TEMPLATE

{%- if true -%} yes {%- endif -%}

END_TEMPLATE expected = <<-END_EXPECTED

yes

END_EXPECTED assert_template_result(expected, text) end # Make sure the trim isn't applied to standard tags def test_standard_tags whitespace = ' ' text = <<-END_TEMPLATE

{% if true %} yes {% endif %}

END_TEMPLATE expected = <<-END_EXPECTED

#{whitespace} yes #{whitespace}

END_EXPECTED assert_template_result(expected, text) text = <<-END_TEMPLATE

{% if false %} no {% endif %}

END_TEMPLATE expected = <<-END_EXPECTED

#{whitespace}

END_EXPECTED assert_template_result(expected, text) end # Make sure the trim isn't too agressive def test_no_trim_output 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 -%}

' expected = '

yes

' assert_template_result(expected, text) text = '

{%- if false -%}no{%- endif -%}

' expected = '

' assert_template_result(expected, text) end def test_single_line_outer_tag text = '

{%- if true %} yes {% endif -%}

' expected = '

yes

' assert_template_result(expected, text) text = '

{%- if false %} no {% endif -%}

' expected = '

' assert_template_result(expected, text) end def test_single_line_inner_tag text = '

{% if true -%} yes {%- endif %}

' expected = '

yes

' assert_template_result(expected, text) text = '

{% if false -%} no {%- endif %}

' expected = '

' assert_template_result(expected, text) end def test_single_line_post_tag text = '

{% if true -%} yes {% endif -%}

' expected = '

yes

' assert_template_result(expected, text) text = '

{% if false -%} no {% endif -%}

' expected = '

' assert_template_result(expected, text) end def test_single_line_pre_tag text = '

{%- if true %} yes {%- endif %}

' expected = '

yes

' assert_template_result(expected, text) text = '

{%- if false %} no {%- endif %}

' expected = '

' assert_template_result(expected, text) end def test_pre_trim_output text = <<-END_TEMPLATE

{{- 'John' }}

END_TEMPLATE expected = <<-END_EXPECTED

John

END_EXPECTED assert_template_result(expected, text) end def test_pre_trim_tags text = <<-END_TEMPLATE

{%- if true %} yes {%- endif %}

END_TEMPLATE expected = <<-END_EXPECTED

yes

END_EXPECTED assert_template_result(expected, text) text = <<-END_TEMPLATE

{%- if false %} no {%- endif %}

END_TEMPLATE expected = <<-END_EXPECTED

END_EXPECTED assert_template_result(expected, text) end def test_post_trim_output text = <<-END_TEMPLATE

{{ 'John' -}}

END_TEMPLATE expected = <<-END_EXPECTED

John

END_EXPECTED assert_template_result(expected, text) end def test_post_trim_tags text = <<-END_TEMPLATE

{% if true -%} yes {% endif -%}

END_TEMPLATE expected = <<-END_EXPECTED

yes

END_EXPECTED assert_template_result(expected, text) text = <<-END_TEMPLATE

{% if false -%} no {% endif -%}

END_TEMPLATE expected = <<-END_EXPECTED

END_EXPECTED assert_template_result(expected, text) end def test_pre_and_post_trim_tags text = <<-END_TEMPLATE

{%- if true %} yes {% endif -%}

END_TEMPLATE expected = <<-END_EXPECTED

yes

END_EXPECTED assert_template_result(expected, text) text = <<-END_TEMPLATE

{%- if false %} no {% endif -%}

END_TEMPLATE expected = <<-END_EXPECTED

END_EXPECTED assert_template_result(expected, text) end def test_post_and_pre_trim_tags text = <<-END_TEMPLATE

{% if true -%} yes {%- endif %}

END_TEMPLATE expected = <<-END_EXPECTED

yes

END_EXPECTED assert_template_result(expected, text) whitespace = ' ' text = <<-END_TEMPLATE

{% if false -%} no {%- endif %}

END_TEMPLATE expected = <<-END_EXPECTED

#{whitespace}

END_EXPECTED assert_template_result(expected, text) end def test_trim_output text = <<-END_TEMPLATE

{{- 'John' -}}

END_TEMPLATE expected = <<-END_EXPECTED

John

END_EXPECTED assert_template_result(expected, text) end def test_trim_tags text = <<-END_TEMPLATE

{%- if true -%} yes {%- endif -%}

END_TEMPLATE expected = <<-END_EXPECTED

yes

END_EXPECTED assert_template_result(expected, text) text = <<-END_TEMPLATE

{%- if false -%} no {%- endif -%}

END_TEMPLATE expected = <<-END_EXPECTED

END_EXPECTED assert_template_result(expected, text) end def test_whitespace_trim_output text = <<-END_TEMPLATE

{{- 'John' -}}, {{- '30' -}}

END_TEMPLATE expected = <<-END_EXPECTED

John,30

END_EXPECTED assert_template_result(expected, text) end def test_whitespace_trim_tags text = <<-END_TEMPLATE

{%- if true -%} yes {%- endif -%}

END_TEMPLATE expected = <<-END_EXPECTED

yes

END_EXPECTED assert_template_result(expected, text) text = <<-END_TEMPLATE

{%- if false -%} no {%- endif -%}

END_TEMPLATE expected = <<-END_EXPECTED

END_EXPECTED assert_template_result(expected, text) end def test_complex_trim_output text = <<-END_TEMPLATE

{{- 'John' -}} {{- '30' -}}

{{ 'John' -}} {{- '30' }} {{- 'John' }} {{ '30' -}}
END_TEMPLATE expected = <<-END_EXPECTED

John30

John30 John 30
END_EXPECTED assert_template_result(expected, text) end def test_complex_trim text = <<-END_TEMPLATE
{%- if true -%} {%- if true -%}

{{- 'John' -}}

{%- endif -%} {%- endif -%}
END_TEMPLATE expected = <<-END_EXPECTED

John

END_EXPECTED assert_template_result(expected, text) end def test_right_trim_followed_by_tag assert_template_result('ab c', '{{ "a" -}}{{ "b" }} c') end def test_raw_output whitespace = ' ' text = <<-END_TEMPLATE
{% raw %} {%- if true -%}

{{- 'John' -}}

{%- endif -%} {% endraw %}
END_TEMPLATE expected = <<-END_EXPECTED
#{whitespace} {%- if true -%}

{{- 'John' -}}

{%- endif -%} #{whitespace}
END_EXPECTED assert_template_result(expected, text) end end # TrimModeTest