mirror of
https://github.com/kemko/liquid.git
synced 2026-01-03 08:45:42 +03:00
Some tests for whitespace collapsing
This commit is contained in:
67
test/liquid/blank_test.rb
Normal file
67
test/liquid/blank_test.rb
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user