Run test suite with both parsers

This commit is contained in:
Tristan Hume
2013-08-01 12:49:36 -04:00
parent f6eacbf875
commit 824231284c
5 changed files with 55 additions and 24 deletions
+4 -3
View File
@@ -63,9 +63,10 @@ class ErrorHandlingTest < Test::Unit::TestCase
end
def test_unrecognized_operator
Template.error_mode = :strict
assert_raise(SyntaxError) do
Liquid::Template.parse(' {% if 1 =! 2 %}ok{% endif %} ')
with_error_mode(:strict) do
assert_raise(SyntaxError) do
Liquid::Template.parse(' {% if 1 =! 2 %}ok{% endif %} ')
end
end
end
+20 -14
View File
@@ -34,26 +34,32 @@ class ParsingQuirksTest < Test::Unit::TestCase
Template.parse("{{test}}")
Template.parse("{{|test}}")
end
assert_raise(SyntaxError) do
Template.parse("{{test |a|b|}}")
with_error_mode(:strict) do
assert_raise(SyntaxError) do
Template.parse("{{test |a|b|}}")
end
end
end
def test_meaningless_parens_error
assert_raise(SyntaxError) do
markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false"
Template.parse("{% if #{markup} %} YES {% endif %}")
with_error_mode(:strict) do
assert_raise(SyntaxError) do
markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false"
Template.parse("{% if #{markup} %} YES {% endif %}")
end
end
end
def test_unexpected_characters_syntax_error
assert_raise(SyntaxError) do
markup = "true && false"
Template.parse("{% if #{markup} %} YES {% endif %}")
end
assert_raise(SyntaxError) do
markup = "false || true"
Template.parse("{% if #{markup} %} YES {% endif %}")
with_error_mode(:strict) do
assert_raise(SyntaxError) do
markup = "true && false"
Template.parse("{% if #{markup} %} YES {% endif %}")
end
assert_raise(SyntaxError) do
markup = "false || true"
Template.parse("{% if #{markup} %} YES {% endif %}")
end
end
end
@@ -66,7 +72,7 @@ class ParsingQuirksTest < Test::Unit::TestCase
end
def test_meaningless_parens_lax
with_lax_parsing do
with_error_mode(:lax) 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)
@@ -74,7 +80,7 @@ class ParsingQuirksTest < Test::Unit::TestCase
end
def test_unexpected_characters_silently_eat_logic_lax
with_lax_parsing do
with_error_mode(:lax) do
markup = "true && false"
assert_template_result(' YES ',"{% if #{markup} %} YES {% endif %}")
markup = "false || true"
+4 -2
View File
@@ -127,8 +127,10 @@ class VariableTest < Test::Unit::TestCase
end
def test_strict_filter_argument_parsing
assert_raises(SyntaxError) do
Variable.new(%! number_of_comments | pluralize: 'comment': 'comments' !)
with_error_mode(:strict) do
assert_raises(SyntaxError) do
Variable.new(%! number_of_comments | pluralize: 'comment': 'comments' !)
end
end
end
end
+13 -4
View File
@@ -9,7 +9,15 @@ rescue LoadError
end
require File.join(File.dirname(__FILE__), '..', 'lib', 'liquid')
Liquid::Template.error_mode = :strict
mode = :strict
if ARGV.last == 'lax'
puts "-- LAX ERROR MODE"
ARGV.pop
mode = :lax
else
puts "-- STRICT ERROR MODE"
end
Liquid::Template.error_mode = mode
module Test
@@ -27,10 +35,11 @@ module Test
assert_match expected, Template.parse(template).render(assigns)
end
def with_lax_parsing
Liquid::Template.error_mode = :lax
def with_error_mode(mode)
old_mode = Liquid::Template.error_mode
Liquid::Template.error_mode = mode
yield
Liquid::Template.error_mode = :strict
Liquid::Template.error_mode = old_mode
end
end # Assertions
end # Unit