mirror of
https://github.com/kemko/liquid.git
synced 2026-01-03 08:45:42 +03:00
Add back tests for lax parsing
This commit is contained in:
@@ -58,7 +58,7 @@ class ErrorHandlingTest < Test::Unit::TestCase
|
||||
|
||||
def test_missing_endtag_parse_time_error
|
||||
assert_raise(Liquid::SyntaxError) do
|
||||
template = Liquid::Template.parse(' {% for a in b %} ... ')
|
||||
Liquid::Template.parse(' {% for a in b %} ... ')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -68,6 +68,17 @@ class ErrorHandlingTest < Test::Unit::TestCase
|
||||
Liquid::Template.parse(' {% if 1 =! 2 %}ok{% endif %} ')
|
||||
end
|
||||
end
|
||||
|
||||
def test_lax_unrecognized_operator
|
||||
with_lax_parsing do
|
||||
assert_nothing_raised do
|
||||
template = Liquid::Template.parse(' {% if 1 =! 2 %}ok{% endif %} ')
|
||||
assert_equal ' Liquid error: Unknown operator =! ', template.render
|
||||
assert_equal 1, template.errors.size
|
||||
assert_equal Liquid::ArgumentError, template.errors.first.class
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Liquid should not catch Exceptions that are not subclasses of StandardError, like Interrupt and NoMemoryError
|
||||
def test_exceptions_propagate
|
||||
|
||||
@@ -40,7 +40,7 @@ class ParsingQuirksTest < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def test_meaningless_parens
|
||||
def test_meaningless_parens_error
|
||||
Template.error_mode = :strict
|
||||
assert_raise(SyntaxError) do
|
||||
markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false"
|
||||
@@ -48,7 +48,7 @@ class ParsingQuirksTest < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def test_unexpected_characters_silently_eat_logic
|
||||
def test_unexpected_characters_syntax_error
|
||||
Template.error_mode = :strict
|
||||
assert_raise(SyntaxError) do
|
||||
markup = "true && false"
|
||||
@@ -59,4 +59,31 @@ class ParsingQuirksTest < Test::Unit::TestCase
|
||||
Template.parse("{% if #{markup} %} YES {% endif %}")
|
||||
end
|
||||
end
|
||||
|
||||
def test_no_error_on_lax_empty_filter
|
||||
with_lax_parsing do
|
||||
assert_nothing_raised do
|
||||
Template.parse("{{test |a|b|}}")
|
||||
Template.parse("{{test}}")
|
||||
Template.parse("{{|test|}}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_meaningless_parens_lax
|
||||
with_lax_parsing do
|
||||
assigns = {'b' => 'bar', 'c' => 'baz'}
|
||||
markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false"
|
||||
assert_template_result(' YES ',"{% if #{markup} %} YES {% endif %}", assigns)
|
||||
end
|
||||
end
|
||||
|
||||
def test_unexpected_characters_silently_eat_logic_lax
|
||||
with_lax_parsing do
|
||||
markup = "true && false"
|
||||
assert_template_result(' YES ',"{% if #{markup} %} YES {% endif %}")
|
||||
markup = "false || true"
|
||||
assert_template_result('',"{% if #{markup} %} YES {% endif %}")
|
||||
end
|
||||
end
|
||||
end # ParsingQuirksTest
|
||||
|
||||
@@ -73,6 +73,14 @@ class VariableTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_symbol
|
||||
with_lax_parsing do
|
||||
var = Variable.new("http://disney.com/logo.gif | image: 'med' ")
|
||||
assert_equal "http://disney.com/logo.gif", var.name
|
||||
assert_equal [["image",["'med'"]]], var.filters
|
||||
end
|
||||
end
|
||||
|
||||
def test_string_to_filter
|
||||
var = Variable.new("'http://disney.com/logo.gif' | image: 'med' ")
|
||||
assert_equal "'http://disney.com/logo.gif'", var.name
|
||||
assert_equal [["image",["'med'"]]], var.filters
|
||||
@@ -114,6 +122,14 @@ class VariableTest < Test::Unit::TestCase
|
||||
assert_equal [['things',["greeting: \"world\"","farewell: 'goodbye'"]]], var.filters
|
||||
end
|
||||
|
||||
def test_lax_filter_argument_parsing
|
||||
with_lax_parsing do
|
||||
var = Variable.new(%! number_of_comments | pluralize: 'comment': 'comments' !)
|
||||
assert_equal 'number_of_comments', var.name
|
||||
assert_equal [['pluralize',["'comment'","'comments'"]]], var.filters
|
||||
end
|
||||
end
|
||||
|
||||
def test_strict_filter_argument_parsing
|
||||
assert_raises(SyntaxError) do
|
||||
Variable.new(%! number_of_comments | pluralize: 'comment': 'comments' !)
|
||||
|
||||
@@ -9,6 +9,8 @@ rescue LoadError
|
||||
end
|
||||
require File.join(File.dirname(__FILE__), '..', 'lib', 'liquid')
|
||||
|
||||
Liquid::Template.error_mode = :strict
|
||||
|
||||
|
||||
module Test
|
||||
module Unit
|
||||
@@ -24,6 +26,12 @@ module Test
|
||||
|
||||
assert_match expected, Template.parse(template).render(assigns)
|
||||
end
|
||||
|
||||
def with_lax_parsing
|
||||
Liquid::Template.error_mode = :lax
|
||||
yield
|
||||
Liquid::Template.error_mode = :strict
|
||||
end
|
||||
end # Assertions
|
||||
end # Unit
|
||||
end # Test
|
||||
|
||||
Reference in New Issue
Block a user