mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-15 08:50:45 -07:00
Run test suite with both parsers
This commit is contained in:
@@ -7,12 +7,25 @@ require 'rubygems/package_task'
|
|||||||
|
|
||||||
task :default => 'test'
|
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.libs << '.' << 'lib' << 'test'
|
||||||
t.test_files = FileList['test/liquid/**/*_test.rb']
|
t.test_files = FileList['test/liquid/**/*_test.rb']
|
||||||
t.verbose = false
|
t.verbose = false
|
||||||
end
|
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'))
|
gemspec = eval(File.read('liquid.gemspec'))
|
||||||
Gem::PackageTask.new(gemspec) do |pkg|
|
Gem::PackageTask.new(gemspec) do |pkg|
|
||||||
pkg.gem_spec = gemspec
|
pkg.gem_spec = gemspec
|
||||||
|
|||||||
@@ -63,11 +63,12 @@ class ErrorHandlingTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_unrecognized_operator
|
def test_unrecognized_operator
|
||||||
Template.error_mode = :strict
|
with_error_mode(:strict) do
|
||||||
assert_raise(SyntaxError) do
|
assert_raise(SyntaxError) do
|
||||||
Liquid::Template.parse(' {% if 1 =! 2 %}ok{% endif %} ')
|
Liquid::Template.parse(' {% if 1 =! 2 %}ok{% endif %} ')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_lax_unrecognized_operator
|
def test_lax_unrecognized_operator
|
||||||
assert_nothing_raised do
|
assert_nothing_raised do
|
||||||
|
|||||||
@@ -34,19 +34,24 @@ class ParsingQuirksTest < Test::Unit::TestCase
|
|||||||
Template.parse("{{test}}")
|
Template.parse("{{test}}")
|
||||||
Template.parse("{{|test}}")
|
Template.parse("{{|test}}")
|
||||||
end
|
end
|
||||||
|
with_error_mode(:strict) do
|
||||||
assert_raise(SyntaxError) do
|
assert_raise(SyntaxError) do
|
||||||
Template.parse("{{test |a|b|}}")
|
Template.parse("{{test |a|b|}}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_meaningless_parens_error
|
def test_meaningless_parens_error
|
||||||
|
with_error_mode(:strict) do
|
||||||
assert_raise(SyntaxError) do
|
assert_raise(SyntaxError) do
|
||||||
markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false"
|
markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false"
|
||||||
Template.parse("{% if #{markup} %} YES {% endif %}")
|
Template.parse("{% if #{markup} %} YES {% endif %}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_unexpected_characters_syntax_error
|
def test_unexpected_characters_syntax_error
|
||||||
|
with_error_mode(:strict) do
|
||||||
assert_raise(SyntaxError) do
|
assert_raise(SyntaxError) do
|
||||||
markup = "true && false"
|
markup = "true && false"
|
||||||
Template.parse("{% if #{markup} %} YES {% endif %}")
|
Template.parse("{% if #{markup} %} YES {% endif %}")
|
||||||
@@ -56,6 +61,7 @@ class ParsingQuirksTest < Test::Unit::TestCase
|
|||||||
Template.parse("{% if #{markup} %} YES {% endif %}")
|
Template.parse("{% if #{markup} %} YES {% endif %}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_no_error_on_lax_empty_filter
|
def test_no_error_on_lax_empty_filter
|
||||||
assert_nothing_raised do
|
assert_nothing_raised do
|
||||||
@@ -66,7 +72,7 @@ class ParsingQuirksTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_meaningless_parens_lax
|
def test_meaningless_parens_lax
|
||||||
with_lax_parsing do
|
with_error_mode(:lax) do
|
||||||
assigns = {'b' => 'bar', 'c' => 'baz'}
|
assigns = {'b' => 'bar', 'c' => 'baz'}
|
||||||
markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false"
|
markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false"
|
||||||
assert_template_result(' YES ',"{% if #{markup} %} YES {% endif %}", assigns)
|
assert_template_result(' YES ',"{% if #{markup} %} YES {% endif %}", assigns)
|
||||||
@@ -74,7 +80,7 @@ class ParsingQuirksTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_unexpected_characters_silently_eat_logic_lax
|
def test_unexpected_characters_silently_eat_logic_lax
|
||||||
with_lax_parsing do
|
with_error_mode(:lax) do
|
||||||
markup = "true && false"
|
markup = "true && false"
|
||||||
assert_template_result(' YES ',"{% if #{markup} %} YES {% endif %}")
|
assert_template_result(' YES ',"{% if #{markup} %} YES {% endif %}")
|
||||||
markup = "false || true"
|
markup = "false || true"
|
||||||
|
|||||||
@@ -127,11 +127,13 @@ class VariableTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_strict_filter_argument_parsing
|
def test_strict_filter_argument_parsing
|
||||||
|
with_error_mode(:strict) do
|
||||||
assert_raises(SyntaxError) do
|
assert_raises(SyntaxError) do
|
||||||
Variable.new(%! number_of_comments | pluralize: 'comment': 'comments' !)
|
Variable.new(%! number_of_comments | pluralize: 'comment': 'comments' !)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
class VariableResolutionTest < Test::Unit::TestCase
|
class VariableResolutionTest < Test::Unit::TestCase
|
||||||
|
|||||||
+13
-4
@@ -9,7 +9,15 @@ rescue LoadError
|
|||||||
end
|
end
|
||||||
require File.join(File.dirname(__FILE__), '..', 'lib', 'liquid')
|
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
|
module Test
|
||||||
@@ -27,10 +35,11 @@ module Test
|
|||||||
assert_match expected, Template.parse(template).render(assigns)
|
assert_match expected, Template.parse(template).render(assigns)
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_lax_parsing
|
def with_error_mode(mode)
|
||||||
Liquid::Template.error_mode = :lax
|
old_mode = Liquid::Template.error_mode
|
||||||
|
Liquid::Template.error_mode = mode
|
||||||
yield
|
yield
|
||||||
Liquid::Template.error_mode = :strict
|
Liquid::Template.error_mode = old_mode
|
||||||
end
|
end
|
||||||
end # Assertions
|
end # Assertions
|
||||||
end # Unit
|
end # Unit
|
||||||
|
|||||||
Reference in New Issue
Block a user