diff --git a/test/liquid/blank_test.rb b/test/liquid/blank_test.rb new file mode 100644 index 0000000..33feb8f --- /dev/null +++ b/test/liquid/blank_test.rb @@ -0,0 +1,67 @@ +require 'test_helper' + +class BlankTest < Test::Unit::TestCase + include Liquid + N = 10 + + def wrap_in_for(body) + "{% for i in (1..#{N}) %}#{body}{% endfor %}" + end + + def wrap_in_if(body) + "{% if true %}#{body}{% endif %}" + end + + def wrap(body) + wrap_in_for(body) + wrap_in_if(body) + end + + def test_loops_are_blank + assert_template_result("", wrap_in_for(" ")) + end + + def test_if_else_are_blank + assert_template_result("", "{% if true %} {% elsif false %} {% else %} {% endif %}") + end + + def test_unless_is_blank + assert_template_result("", wrap("{% unless true %} {% endunless %}")) + end + + def test_comments_are_blank + assert_template_result("", wrap(" {% comment %} whatever {% endcomment %} ")) + end + + def test_captures_are_blank + assert_template_result("", wrap(" {% capture foo %} whatever {% endcapture %} ")) + end + + def test_nested_blocks_are_blank_but_only_if_all_children_are + assert_template_result("", wrap(wrap(" "))) + assert_template_result("\n but this not "*(N+1), + wrap(%q{{% if true %} {% comment %} this is blank {% endcomment %} {% endif %} + {% if true %} but this not {% endif %}})) + end + + def test_assigns_are_blank + assert_template_result("", wrap(' {% assign foo = "bar" %} ')) + end + + def test_whitespace_is_blank + assert_template_result("", wrap(" ")) + assert_template_result("", wrap("\t")) + end + + def test_whitespace_is_not_blank_if_other_stuff_is_present + body = " x " + assert_template_result(body*(N+1), wrap(body)) + end + + def test_raw_is_not_blank + assert_template_result(" "*(N+1), wrap("{% raw %} {% endraw %}")) + end + + def test_variables_are_not_blank + assert_template_result(" "*(N+1), wrap(' {{ "" }} ')) + end +end