diff --git a/test/liquid/error_handling_test.rb b/test/liquid/error_handling_test.rb index b92660a..550cade 100644 --- a/test/liquid/error_handling_test.rb +++ b/test/liquid/error_handling_test.rb @@ -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 diff --git a/test/liquid/parsing_quirks_test.rb b/test/liquid/parsing_quirks_test.rb index cbe8c50..458b05a 100644 --- a/test/liquid/parsing_quirks_test.rb +++ b/test/liquid/parsing_quirks_test.rb @@ -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 diff --git a/test/liquid/variable_test.rb b/test/liquid/variable_test.rb index 882c157..ee3ef08 100644 --- a/test/liquid/variable_test.rb +++ b/test/liquid/variable_test.rb @@ -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' !) diff --git a/test/test_helper.rb b/test/test_helper.rb index 30dd9a1..c0c4ffa 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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