mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-18 02:10:41 -07:00
Fix an int the cycle tag, add extra unit tests, and updated parser switcher:
- Fixed NoMethod error with .peek (using look instead)
- Add friendlier error message when {% cycle %}
This commit is contained in:
committed by
Guilherme Carreiro
parent
75c95d0791
commit
327790cdce
@@ -46,18 +46,34 @@ class CycleTagTest < Minitest::Test
|
||||
assert_template_result("11", template)
|
||||
end
|
||||
|
||||
def test_cycle_tag_without_arguments
|
||||
error = assert_raises(Liquid::SyntaxError) do
|
||||
Template.parse("{% cycle %}")
|
||||
end
|
||||
|
||||
assert_match(/Syntax Error in 'cycle' - Valid syntax: cycle \[name :\] var/, error.message)
|
||||
end
|
||||
|
||||
def test_cycle_tag_with_error_mode
|
||||
# QuotedFragment is more permissive than what Parser#expression allows.
|
||||
temlate1 = "{% assign 5 = 'b' %}{% cycle .5, .4 %}"
|
||||
temlate2 = "{% cycle .5: 'a', 'b' %}"
|
||||
|
||||
[:lax, :strict].each do |mode|
|
||||
with_error_mode(mode) do
|
||||
assert_template_result("a", "{% cycle .5: 'a', 'b' %}")
|
||||
assert_template_result("b", "{% assign 5 = 'b' %}{% cycle .5, .4 %}")
|
||||
assert_template_result("b", temlate1)
|
||||
assert_template_result("a", temlate2)
|
||||
end
|
||||
end
|
||||
|
||||
with_error_mode(:rigid) do
|
||||
assert_raises(Liquid::SyntaxError) { Template.parse("{% cycle .5: 'a', 'b' %}") }
|
||||
assert_raises(Liquid::SyntaxError) { Template.parse("{% cycle .5, .4 %}") }
|
||||
error1 = assert_raises(Liquid::SyntaxError) { Template.parse(temlate1) }
|
||||
error2 = assert_raises(Liquid::SyntaxError) { Template.parse(temlate2) }
|
||||
|
||||
expected_error = /Liquid syntax error: \[:dot, "."\] is not a valid expression/
|
||||
|
||||
assert_match(expected_error, error1.message)
|
||||
assert_match(expected_error, error2.message)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user