mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
Run test suite with both parsers
This commit is contained in:
15
Rakefile
15
Rakefile
@@ -7,12 +7,25 @@ require 'rubygems/package_task'
|
||||
|
||||
task :default => 'test'
|
||||
|
||||
Rake::TestTask.new(:test) do |t|
|
||||
Rake::TestTask.new(:lax_test) do |t|
|
||||
t.libs << '.' << 'lib' << 'test'
|
||||
t.test_files = FileList['test/liquid/**/*_test.rb']
|
||||
t.options = 'lax'
|
||||
t.verbose = false
|
||||
end
|
||||
|
||||
Rake::TestTask.new(:strict_test) do |t|
|
||||
t.libs << '.' << 'lib' << 'test'
|
||||
t.test_files = FileList['test/liquid/**/*_test.rb']
|
||||
t.verbose = false
|
||||
end
|
||||
|
||||
desc 'runs test suite with both strict and lax parsers'
|
||||
task :test do
|
||||
Rake::Task['lax_test'].invoke
|
||||
Rake::Task['strict_test'].invoke
|
||||
end
|
||||
|
||||
gemspec = eval(File.read('liquid.gemspec'))
|
||||
Gem::PackageTask.new(gemspec) do |pkg|
|
||||
pkg.gem_spec = gemspec
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user