diff --git a/Rakefile b/Rakefile
index 63a54ba0..79cddcd4 100755
--- a/Rakefile
+++ b/Rakefile
@@ -1,4 +1,6 @@
#!/usr/bin/env ruby
+$:.unshift File.join(File.dirname(__FILE__), 'test') unless $:.include? File.join(File.dirname(__FILE__), 'test')
+
require 'rubygems'
require 'rake'
require 'rake/testtask'
@@ -8,7 +10,7 @@ task :default => 'test'
Rake::TestTask.new(:test) do |t|
t.libs << '.' << 'lib' << 'test'
- t.pattern = 'test/*_test.rb'
+ t.pattern = 'test/lib/**/*_test.rb'
t.verbose = false
end
diff --git a/test/assign_test.rb b/test/assign_test.rb
deleted file mode 100644
index 95e9755a..00000000
--- a/test/assign_test.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require File.dirname(__FILE__) + '/helper'
-
-class AssignTest < Test::Unit::TestCase
- include Liquid
-
- def test_assigned_variable
- assert_template_result('.foo.','{% assign foo = values %}.{{ foo[0] }}.', 'values' => %w{foo bar baz})
- assert_template_result('.bar.','{% assign foo = values %}.{{ foo[1] }}.', 'values' => %w{foo bar baz})
- end
-
-end
\ No newline at end of file
diff --git a/test/helper.rb b/test/helper.rb
deleted file mode 100644
index b24c3d1f..00000000
--- a/test/helper.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/usr/bin/env ruby
-extras_path = File.join File.dirname(__FILE__), 'extra'
-$LOAD_PATH.unshift(extras_path) unless $LOAD_PATH.include? extras_path
-
-require 'test/unit'
-require 'test/unit/assertions'
-require 'caller'
-require 'breakpoint'
-require File.dirname(__FILE__) + '/../lib/liquid'
-
-
-module Test
- module Unit
- module Assertions
- include Liquid
- def assert_template_result(expected, template, assigns={}, message=nil)
- assert_equal expected, Template.parse(template).render(assigns)
- end
- end
- end
-end
\ No newline at end of file
diff --git a/test/include_tag_test.rb b/test/include_tag_test.rb
deleted file mode 100644
index f78b5788..00000000
--- a/test/include_tag_test.rb
+++ /dev/null
@@ -1,129 +0,0 @@
-require File.dirname(__FILE__) + '/helper'
-
-class TestFileSystem
- def read_template_file(template_path)
- case template_path
- when "product"
- "Product: {{ product.title }} "
-
- when "locale_variables"
- "Locale: {{echo1}} {{echo2}}"
-
- when "variant"
- "Variant: {{ variant.title }}"
-
- when "nested_template"
- "{% include 'header' %} {% include 'body' %} {% include 'footer' %}"
-
- when "body"
- "body {% include 'body_detail' %}"
-
- when "nested_product_template"
- "Product: {{ nested_product_template.title }} {%include 'details'%} "
-
- when "recursively_nested_template"
- "-{% include 'recursively_nested_template' %}"
-
- when "pick_a_source"
- "from TestFileSystem"
-
- else
- template_path
- end
- end
-end
-
-class OtherFileSystem
- def read_template_file(template_path)
- 'from OtherFileSystem'
- end
-end
-
-class IncludeTagTest < Test::Unit::TestCase
- include Liquid
-
- def setup
- Liquid::Template.file_system = TestFileSystem.new
- end
-
- def test_include_tag_looks_for_file_system_in_registers_first
- assert_equal 'from OtherFileSystem',
- Template.parse("{% include 'pick_a_source' %}").render({}, :registers => {:file_system => OtherFileSystem.new})
- end
-
-
- def test_include_tag_with
- assert_equal "Product: Draft 151cm ",
- Template.parse("{% include 'product' with products[0] %}").render( "products" => [ {'title' => 'Draft 151cm'}, {'title' => 'Element 155cm'} ] )
- end
-
- def test_include_tag_with_default_name
- assert_equal "Product: Draft 151cm ",
- Template.parse("{% include 'product' %}").render( "product" => {'title' => 'Draft 151cm'} )
- end
-
- def test_include_tag_for
-
- assert_equal "Product: Draft 151cm Product: Element 155cm ",
- Template.parse("{% include 'product' for products %}").render( "products" => [ {'title' => 'Draft 151cm'}, {'title' => 'Element 155cm'} ] )
- end
-
- def test_include_tag_with_local_variables
- assert_equal "Locale: test123 ",
- Template.parse("{% include 'locale_variables' echo1: 'test123' %}").render
- end
-
- def test_include_tag_with_multiple_local_variables
- assert_equal "Locale: test123 test321",
- Template.parse("{% include 'locale_variables' echo1: 'test123', echo2: 'test321' %}").render
- end
-
- def test_include_tag_with_multiple_local_variables_from_context
- assert_equal "Locale: test123 test321",
- Template.parse("{% include 'locale_variables' echo1: echo1, echo2: more_echos.echo2 %}").render('echo1' => 'test123', 'more_echos' => { "echo2" => 'test321'})
- end
-
- def test_nested_include_tag
- assert_equal "body body_detail",
- Template.parse("{% include 'body' %}").render
-
- assert_equal "header body body_detail footer",
- Template.parse("{% include 'nested_template' %}").render
- end
-
- def test_nested_include_with_variable
-
- assert_equal "Product: Draft 151cm details ",
- Template.parse("{% include 'nested_product_template' with product %}").render("product" => {"title" => 'Draft 151cm'})
-
- assert_equal "Product: Draft 151cm details Product: Element 155cm details ",
- Template.parse("{% include 'nested_product_template' for products %}").render("products" => [{"title" => 'Draft 151cm'}, {"title" => 'Element 155cm'}])
-
- end
-
- def test_recursively_included_template_does_not_produce_endless_loop
-
- infinite_file_system = Class.new do
- def read_template_file(template_path)
- "-{% include 'loop' %}"
- end
- end
-
- Liquid::Template.file_system = infinite_file_system.new
-
- assert_raise(Liquid::StackLevelError) do
- Template.parse("{% include 'loop' %}").render!
- end
-
- end
-
- def test_dynamically_choosen_template
-
- assert_equal "Test123", Template.parse("{% include template %}").render("template" => 'Test123')
- assert_equal "Test321", Template.parse("{% include template %}").render("template" => 'Test321')
-
- assert_equal "Product: Draft 151cm ", Template.parse("{% include template for product %}").render("template" => 'product', 'product' => { 'title' => 'Draft 151cm'})
-
- end
-
-end
diff --git a/test/lib/liquid/assign_test.rb b/test/lib/liquid/assign_test.rb
new file mode 100644
index 00000000..64cd59db
--- /dev/null
+++ b/test/lib/liquid/assign_test.rb
@@ -0,0 +1,15 @@
+require 'test_helper'
+
+class AssignTest < Test::Unit::TestCase
+ include Liquid
+
+ def test_assigned_variable
+ assert_template_result('.foo.',
+ '{% assign foo = values %}.{{ foo[0] }}.',
+ 'values' => %w{foo bar baz})
+
+ assert_template_result('.bar.',
+ '{% assign foo = values %}.{{ foo[1] }}.',
+ 'values' => %w{foo bar baz})
+ end
+end # AssignTest
diff --git a/test/block_test.rb b/test/lib/liquid/block_test.rb
similarity index 81%
rename from test/block_test.rb
rename to test/lib/liquid/block_test.rb
index 270938e5..9b13d7e1 100644
--- a/test/block_test.rb
+++ b/test/lib/liquid/block_test.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/helper'
+require 'test_helper'
class VariableTest < Test::Unit::TestCase
include Liquid
@@ -33,26 +33,26 @@ class VariableTest < Test::Unit::TestCase
def test_variable_many_embedded_fragments
template = Liquid::Template.parse(" {{funk}} {{so}} {{brother}} ")
assert_equal 7, template.root.nodelist.size
- assert_equal [String, Variable, String, Variable, String, Variable, String], block_types(template.root.nodelist)
+ assert_equal [String, Variable, String, Variable, String, Variable, String],
+ block_types(template.root.nodelist)
end
-
+
def test_with_block
template = Liquid::Template.parse(" {% comment %} {% endcomment %} ")
- assert_equal [String, Comment, String], block_types(template.root.nodelist)
+ assert_equal [String, Comment, String], block_types(template.root.nodelist)
assert_equal 3, template.root.nodelist.size
end
-
- def test_with_custom_tag
- Liquid::Template.register_tag("testtag", Block)
-
- assert_nothing_thrown do
- template = Liquid::Template.parse( "{% testtag %} {% endtesttag %}")
- end
+
+ def test_with_custom_tag
+ Liquid::Template.register_tag("testtag", Block)
+
+ assert_nothing_thrown do
+ template = Liquid::Template.parse( "{% testtag %} {% endtesttag %}")
+ end
end
-
+
private
-
- def block_types(nodelist)
- nodelist.collect { |node| node.class }
- end
-end
\ No newline at end of file
+ def block_types(nodelist)
+ nodelist.collect { |node| node.class }
+ end
+end # VariableTest
diff --git a/test/capture_test.rb b/test/lib/liquid/capture_test.rb
similarity index 53%
rename from test/capture_test.rb
rename to test/lib/liquid/capture_test.rb
index ea934064..cf27ff1d 100644
--- a/test/capture_test.rb
+++ b/test/lib/liquid/capture_test.rb
@@ -1,41 +1,40 @@
-require File.dirname(__FILE__) + '/helper'
+require 'test_helper'
class CaptureTest < Test::Unit::TestCase
include Liquid
-
+
def test_captures_block_content_in_variable
- assert_template_result("test string", "{% capture 'var' %}test string{% endcapture %}{{var}}", {})
+ assert_template_result("test string", "{% capture 'var' %}test string{% endcapture %}{{var}}", {})
end
def test_capture_to_variable_from_outer_scope_if_existing
template_source = <<-END_TEMPLATE
- {% assign var = '' %}
- {% if true %}
- {% capture var %}first-block-string{% endcapture %}
- {% endif %}
- {% if true %}
- {% capture var %}test-string{% endcapture %}
- {% endif %}
- {{var}}
+ {% assign var = '' %}
+ {% if true %}
+ {% capture var %}first-block-string{% endcapture %}
+ {% endif %}
+ {% if true %}
+ {% capture var %}test-string{% endcapture %}
+ {% endif %}
+ {{var}}
END_TEMPLATE
template = Template.parse(template_source)
rendered = template.render
assert_equal "test-string", rendered.gsub(/\s/, '')
end
-
+
def test_assigning_from_capture
template_source = <<-END_TEMPLATE
- {% assign first = '' %}
- {% assign second = '' %}
- {% for number in (1..3) %}
- {% capture first %}{{number}}{% endcapture %}
- {% assign second = first %}
- {% endfor %}
- {{ first }}-{{ second }}
+ {% assign first = '' %}
+ {% assign second = '' %}
+ {% for number in (1..3) %}
+ {% capture first %}{{number}}{% endcapture %}
+ {% assign second = first %}
+ {% endfor %}
+ {{ first }}-{{ second }}
END_TEMPLATE
template = Template.parse(template_source)
rendered = template.render
assert_equal "3-3", rendered.gsub(/\s/, '')
end
-
-end
\ No newline at end of file
+end # CaptureTest
diff --git a/test/condition_test.rb b/test/lib/liquid/condition_test.rb
similarity index 84%
rename from test/condition_test.rb
rename to test/lib/liquid/condition_test.rb
index 0a454826..50277982 100644
--- a/test/condition_test.rb
+++ b/test/lib/liquid/condition_test.rb
@@ -1,8 +1,8 @@
-require File.dirname(__FILE__) + '/helper'
+require 'test_helper'
class ConditionTest < Test::Unit::TestCase
include Liquid
-
+
def test_basic_condition
assert_equal false, Condition.new('1', '==', '2').evaluate
assert_equal true, Condition.new('1', '==', '1').evaluate
@@ -47,7 +47,7 @@ class ConditionTest < Test::Unit::TestCase
def test_contains_works_on_arrays
@context = Liquid::Context.new
@context['array'] = [1,2,3,4,5]
-
+
assert_evalutes_false "array", 'contains', '0'
assert_evalutes_true "array", 'contains', '1'
assert_evalutes_true "array", 'contains', '2'
@@ -55,61 +55,64 @@ class ConditionTest < Test::Unit::TestCase
assert_evalutes_true "array", 'contains', '4'
assert_evalutes_true "array", 'contains', '5'
assert_evalutes_false "array", 'contains', '6'
-
- assert_evalutes_false "array", 'contains', '"1"'
-
- end
+
+ assert_evalutes_false "array", 'contains', '"1"'
+
+ end
def test_contains_returns_false_for_nil_operands
@context = Liquid::Context.new
assert_evalutes_false "not_assigned", 'contains', '0'
assert_evalutes_false "0", 'contains', 'not_assigned'
- end
+ end
- def test_or_condition
+ def test_or_condition
condition = Condition.new('1', '==', '2')
assert_equal false, condition.evaluate
condition.or Condition.new('2', '==', '1')
-
+
assert_equal false, condition.evaluate
- condition.or Condition.new('1', '==', '1')
-
+ condition.or Condition.new('1', '==', '1')
+
assert_equal true, condition.evaluate
end
-
- def test_and_condition
+
+ def test_and_condition
condition = Condition.new('1', '==', '1')
assert_equal true, condition.evaluate
condition.and Condition.new('2', '==', '2')
-
+
assert_equal true, condition.evaluate
- condition.and Condition.new('2', '==', '1')
-
+ condition.and Condition.new('2', '==', '1')
+
assert_equal false, condition.evaluate
end
-
+
def test_should_allow_custom_proc_operator
- Condition.operators['starts_with'] = Proc.new { |cond, left, right| left =~ %r{^#{right}}}
-
+ Condition.operators['starts_with'] = Proc.new { |cond, left, right| left =~ %r{^#{right}} }
+
assert_evalutes_true "'bob'", 'starts_with', "'b'"
assert_evalutes_false "'bob'", 'starts_with', "'o'"
- ensure
- Condition.operators.delete 'starts_with'
+
+ ensure
+ Condition.operators.delete 'starts_with'
end
private
def assert_evalutes_true(left, op, right)
- assert Condition.new(left, op, right).evaluate(@context || Liquid::Context.new), "Evaluated false: #{left} #{op} #{right}"
+ assert Condition.new(left, op, right).evaluate(@context || Liquid::Context.new),
+ "Evaluated false: #{left} #{op} #{right}"
end
-
+
def assert_evalutes_false(left, op, right)
- assert !Condition.new(left, op, right).evaluate(@context || Liquid::Context.new), "Evaluated true: #{left} #{op} #{right}"
+ assert !Condition.new(left, op, right).evaluate(@context || Liquid::Context.new),
+ "Evaluated true: #{left} #{op} #{right}"
end
-end
\ No newline at end of file
+end # ConditionTest
\ No newline at end of file
diff --git a/test/context_test.rb b/test/lib/liquid/context_test.rb
similarity index 97%
rename from test/context_test.rb
rename to test/lib/liquid/context_test.rb
index 8137ceb8..c2c316f1 100644
--- a/test/context_test.rb
+++ b/test/lib/liquid/context_test.rb
@@ -1,4 +1,5 @@
-require File.dirname(__FILE__) + '/helper'
+require 'test_helper'
+
class HundredCentes
def to_liquid
100
@@ -62,7 +63,6 @@ class ArrayLike
end
end
-
class ContextTest < Test::Unit::TestCase
include Liquid
@@ -262,10 +262,10 @@ class ContextTest < Test::Unit::TestCase
def test_hash_to_array_transition
@context['colors'] = {
- 'Blue' => ['003366','336699', '6699CC', '99CCFF'],
- 'Green' => ['003300','336633', '669966', '99CC99'],
- 'Yellow' => ['CC9900','FFCC00', 'FFFF99', 'FFFFCC'],
- 'Red' => ['660000','993333', 'CC6666', 'FF9999']
+ 'Blue' => ['003366','336699', '6699CC', '99CCFF'],
+ 'Green' => ['003300','336633', '669966', '99CC99'],
+ 'Yellow' => ['CC9900','FFCC00', 'FFFF99', 'FFFFCC'],
+ 'Red' => ['660000','993333', 'CC6666', 'FF9999']
}
assert_equal '003366', @context['colors.Blue[0]']
@@ -475,5 +475,4 @@ class ContextTest < Test::Unit::TestCase
assert_kind_of CategoryDrop, @context['category']
assert_equal @context, @context['category'].context
end
-
-end
+end # ContextTest
diff --git a/test/drop_test.rb b/test/lib/liquid/drop_test.rb
similarity index 85%
rename from test/drop_test.rb
rename to test/lib/liquid/drop_test.rb
index 78a2f736..303d14a1 100644
--- a/test/drop_test.rb
+++ b/test/lib/liquid/drop_test.rb
@@ -1,6 +1,4 @@
-
-#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/helper'
+require 'test_helper'
class ContextDrop < Liquid::Drop
def scopes
@@ -10,7 +8,7 @@ class ContextDrop < Liquid::Drop
def scopes_as_array
(1..@context.scopes.size).to_a
end
-
+
def loop_pos
@context['forloop.index']
end
@@ -18,13 +16,12 @@ class ContextDrop < Liquid::Drop
def break
Breakpoint.breakpoint
end
-
+
def before_method(method)
return @context[method]
end
end
-
class ProductDrop < Liquid::Drop
class TextDrop < Liquid::Drop
@@ -50,42 +47,41 @@ class ProductDrop < Liquid::Drop
def catchall
CatchallDrop.new
end
-
+
def context
ContextDrop.new
end
-
+
protected
def callmenot
"protected"
end
-end
+end
+
+class EnumerableDrop < Liquid::Drop
-class EnumerableDrop < Liquid::Drop
-
def size
3
end
-
+
def each
yield 1
yield 2
yield 3
- end
+ end
end
-
class DropsTest < Test::Unit::TestCase
include Liquid
-
+
def test_product_drop
-
+
assert_nothing_raised do
tpl = Liquid::Template.parse( ' ' )
tpl.render('product' => ProductDrop.new)
end
end
-
+
def test_text_drop
output = Liquid::Template.parse( ' {{ product.texts.text }} ' ).render('product' => ProductDrop.new)
assert_equal ' text1 ', output
@@ -102,61 +98,56 @@ class DropsTest < Test::Unit::TestCase
output = Liquid::Template.parse( '{% for text in product.texts.array %} {{text}} {% endfor %}' ).render('product' => ProductDrop.new)
assert_equal ' text1 text2 ', output
end
-
+
def test_context_drop
output = Liquid::Template.parse( ' {{ context.bar }} ' ).render('context' => ContextDrop.new, 'bar' => "carrot")
assert_equal ' carrot ', output
end
-
+
def test_nested_context_drop
output = Liquid::Template.parse( ' {{ product.context.foo }} ' ).render('product' => ProductDrop.new, 'foo' => "monkey")
assert_equal ' monkey ', output
- end
+ end
def test_protected
output = Liquid::Template.parse( ' {{ product.callmenot }} ' ).render('product' => ProductDrop.new)
- assert_equal ' ', output
+ assert_equal ' ', output
end
-
+
def test_scope
- assert_equal '1', Liquid::Template.parse( '{{ context.scopes }}' ).render('context' => ContextDrop.new)
+ assert_equal '1', Liquid::Template.parse( '{{ context.scopes }}' ).render('context' => ContextDrop.new)
assert_equal '2', Liquid::Template.parse( '{%for i in dummy%}{{ context.scopes }}{%endfor%}' ).render('context' => ContextDrop.new, 'dummy' => [1])
assert_equal '3', Liquid::Template.parse( '{%for i in dummy%}{%for i in dummy%}{{ context.scopes }}{%endfor%}{%endfor%}' ).render('context' => ContextDrop.new, 'dummy' => [1])
end
-
+
def test_scope_though_proc
- assert_equal '1', Liquid::Template.parse( '{{ s }}' ).render('context' => ContextDrop.new, 's' => Proc.new{|c| c['context.scopes'] })
+ assert_equal '1', Liquid::Template.parse( '{{ s }}' ).render('context' => ContextDrop.new, 's' => Proc.new{|c| c['context.scopes'] })
assert_equal '2', Liquid::Template.parse( '{%for i in dummy%}{{ s }}{%endfor%}' ).render('context' => ContextDrop.new, 's' => Proc.new{|c| c['context.scopes'] }, 'dummy' => [1])
assert_equal '3', Liquid::Template.parse( '{%for i in dummy%}{%for i in dummy%}{{ s }}{%endfor%}{%endfor%}' ).render('context' => ContextDrop.new, 's' => Proc.new{|c| c['context.scopes'] }, 'dummy' => [1])
end
-
+
def test_scope_with_assigns
- assert_equal 'variable', Liquid::Template.parse( '{% assign a = "variable"%}{{a}}' ).render('context' => ContextDrop.new)
- assert_equal 'variable', Liquid::Template.parse( '{% assign a = "variable"%}{%for i in dummy%}{{a}}{%endfor%}' ).render('context' => ContextDrop.new, 'dummy' => [1])
- assert_equal 'test', Liquid::Template.parse( '{% assign header_gif = "test"%}{{header_gif}}' ).render('context' => ContextDrop.new)
- assert_equal 'test', Liquid::Template.parse( "{% assign header_gif = 'test'%}{{header_gif}}" ).render('context' => ContextDrop.new)
+ assert_equal 'variable', Liquid::Template.parse( '{% assign a = "variable"%}{{a}}' ).render('context' => ContextDrop.new)
+ assert_equal 'variable', Liquid::Template.parse( '{% assign a = "variable"%}{%for i in dummy%}{{a}}{%endfor%}' ).render('context' => ContextDrop.new, 'dummy' => [1])
+ assert_equal 'test', Liquid::Template.parse( '{% assign header_gif = "test"%}{{header_gif}}' ).render('context' => ContextDrop.new)
+ assert_equal 'test', Liquid::Template.parse( "{% assign header_gif = 'test'%}{{header_gif}}" ).render('context' => ContextDrop.new)
end
-
+
def test_scope_from_tags
- assert_equal '1', Liquid::Template.parse( '{% for i in context.scopes_as_array %}{{i}}{% endfor %}' ).render('context' => ContextDrop.new, 'dummy' => [1])
- assert_equal '12', Liquid::Template.parse( '{%for a in dummy%}{% for i in context.scopes_as_array %}{{i}}{% endfor %}{% endfor %}' ).render('context' => ContextDrop.new, 'dummy' => [1])
- assert_equal '123', Liquid::Template.parse( '{%for a in dummy%}{%for a in dummy%}{% for i in context.scopes_as_array %}{{i}}{% endfor %}{% endfor %}{% endfor %}' ).render('context' => ContextDrop.new, 'dummy' => [1])
+ assert_equal '1', Liquid::Template.parse( '{% for i in context.scopes_as_array %}{{i}}{% endfor %}' ).render('context' => ContextDrop.new, 'dummy' => [1])
+ assert_equal '12', Liquid::Template.parse( '{%for a in dummy%}{% for i in context.scopes_as_array %}{{i}}{% endfor %}{% endfor %}' ).render('context' => ContextDrop.new, 'dummy' => [1])
+ assert_equal '123', Liquid::Template.parse( '{%for a in dummy%}{%for a in dummy%}{% for i in context.scopes_as_array %}{{i}}{% endfor %}{% endfor %}{% endfor %}' ).render('context' => ContextDrop.new, 'dummy' => [1])
end
-
+
def test_access_context_from_drop
- assert_equal '123', Liquid::Template.parse( '{%for a in dummy%}{{ context.loop_pos }}{% endfor %}' ).render('context' => ContextDrop.new, 'dummy' => [1,2,3])
- end
-
- def test_enumerable_drop
+ assert_equal '123', Liquid::Template.parse( '{%for a in dummy%}{{ context.loop_pos }}{% endfor %}' ).render('context' => ContextDrop.new, 'dummy' => [1,2,3])
+ end
+
+ def test_enumerable_drop
assert_equal '123', Liquid::Template.parse( '{% for c in collection %}{{c}}{% endfor %}').render('collection' => EnumerableDrop.new)
end
- def test_enumerable_drop_size
+ def test_enumerable_drop_size
assert_equal '3', Liquid::Template.parse( '{{collection.size}}').render('collection' => EnumerableDrop.new)
end
-
-
-
-end
-
-
+end # DropsTest
diff --git a/test/error_handling_test.rb b/test/lib/liquid/error_handling_test.rb
similarity index 82%
rename from test/error_handling_test.rb
rename to test/lib/liquid/error_handling_test.rb
index b361d540..e561e3d1 100644
--- a/test/error_handling_test.rb
+++ b/test/lib/liquid/error_handling_test.rb
@@ -1,89 +1,69 @@
-
-#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/helper'
+require 'test_helper'
class ErrorDrop < Liquid::Drop
def standard_error
raise Liquid::StandardError, 'standard error'
- end
+ end
def argument_error
raise Liquid::ArgumentError, 'argument error'
- end
-
+ end
+
def syntax_error
raise Liquid::SyntaxError, 'syntax error'
- end
-
-end
+ end
+end
class ErrorHandlingTest < Test::Unit::TestCase
include Liquid
-
+
def test_standard_error
- assert_nothing_raised do
+ assert_nothing_raised do
template = Liquid::Template.parse( ' {{ errors.standard_error }} ' )
assert_equal ' Liquid error: standard error ', template.render('errors' => ErrorDrop.new)
-
+
assert_equal 1, template.errors.size
assert_equal StandardError, template.errors.first.class
end
end
-
- def test_syntax
- assert_nothing_raised do
-
+ def test_syntax
+
+ assert_nothing_raised do
+
template = Liquid::Template.parse( ' {{ errors.syntax_error }} ' )
assert_equal ' Liquid syntax error: syntax error ', template.render('errors' => ErrorDrop.new)
-
+
assert_equal 1, template.errors.size
assert_equal SyntaxError, template.errors.first.class
-
- end
-
- end
-
- def test_argument
- assert_nothing_raised do
-
+ end
+ end
+
+ def test_argument
+ assert_nothing_raised do
+
template = Liquid::Template.parse( ' {{ errors.argument_error }} ' )
assert_equal ' Liquid error: argument error ', template.render('errors' => ErrorDrop.new)
-
+
assert_equal 1, template.errors.size
assert_equal ArgumentError, template.errors.first.class
-
end
-
- end
-
- def test_missing_endtag_parse_time_error
-
- assert_raise(Liquid::SyntaxError) do
-
- template = Liquid::Template.parse(' {% for a in b %} ... ')
-
- end
-
end
-
-
+
+ def test_missing_endtag_parse_time_error
+ assert_raise(Liquid::SyntaxError) do
+ template = Liquid::Template.parse(' {% for a in b %} ... ')
+ end
+ end
+
def test_unrecognized_operator
-
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
-
-
+end # ErrorHandlingTest
diff --git a/test/file_system_test.rb b/test/lib/liquid/file_system_test.rb
similarity index 80%
rename from test/file_system_test.rb
rename to test/lib/liquid/file_system_test.rb
index d3ab9487..bbdffefc 100644
--- a/test/file_system_test.rb
+++ b/test/lib/liquid/file_system_test.rb
@@ -1,18 +1,17 @@
-#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/helper'
+require 'test_helper'
class FileSystemTest < Test::Unit::TestCase
include Liquid
-
+
def test_default
assert_raise(FileSystemError) do
BlankFileSystem.new.read_template_file("dummy")
end
end
-
+
def test_local
file_system = Liquid::LocalFileSystem.new("/some/path")
- assert_equal "/some/path/_mypartial.liquid" , file_system.full_path("mypartial")
+ assert_equal "/some/path/_mypartial.liquid" , file_system.full_path("mypartial")
assert_equal "/some/path/dir/_mypartial.liquid", file_system.full_path("dir/mypartial")
assert_raise(FileSystemError) do
@@ -20,11 +19,11 @@ class FileSystemTest < Test::Unit::TestCase
end
assert_raise(FileSystemError) do
- file_system.full_path("/dir/../../dir/mypartial")
+ file_system.full_path("/dir/../../dir/mypartial")
end
assert_raise(FileSystemError) do
file_system.full_path("/etc/passwd")
end
end
-end
\ No newline at end of file
+end # FileSystemTest
diff --git a/test/filter_test.rb b/test/lib/liquid/filter_test.rb
similarity index 97%
rename from test/filter_test.rb
rename to test/lib/liquid/filter_test.rb
index c66fe063..8b91e72d 100644
--- a/test/filter_test.rb
+++ b/test/lib/liquid/filter_test.rb
@@ -1,5 +1,4 @@
-#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/helper'
+require 'test_helper'
module MoneyFilter
def money(input)
@@ -92,4 +91,4 @@ class FiltersInTemplate < Test::Unit::TestCase
assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render(nil, CanadianMoneyFilter)
assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render(nil, [CanadianMoneyFilter])
end
-end
+end # FiltersTest
diff --git a/test/html_tag_test.rb b/test/lib/liquid/html_tag_test.rb
similarity index 81%
rename from test/html_tag_test.rb
rename to test/lib/liquid/html_tag_test.rb
index 546344e9..47d2ea38 100644
--- a/test/html_tag_test.rb
+++ b/test/lib/liquid/html_tag_test.rb
@@ -1,31 +1,29 @@
-require File.dirname(__FILE__) + '/helper'
+require 'test_helper'
class HtmlTagTest < Test::Unit::TestCase
include Liquid
-
+
def test_html_table
-
+
assert_template_result("
\n| 1 | 2 | 3 |
\n| 4 | 5 | 6 |
\n",
- '{% tablerow n in numbers cols:3%} {{n}} {% endtablerow %}',
+ '{% tablerow n in numbers cols:3%} {{n}} {% endtablerow %}',
'numbers' => [1,2,3,4,5,6])
assert_template_result("\n
\n",
- '{% tablerow n in numbers cols:3%} {{n}} {% endtablerow %}',
- 'numbers' => [])
+ '{% tablerow n in numbers cols:3%} {{n}} {% endtablerow %}',
+ 'numbers' => [])
end
-
+
def test_html_table_with_different_cols
assert_template_result("\n| 1 | 2 | 3 | 4 | 5 |
\n| 6 |
\n",
- '{% tablerow n in numbers cols:5%} {{n}} {% endtablerow %}',
+ '{% tablerow n in numbers cols:5%} {{n}} {% endtablerow %}',
'numbers' => [1,2,3,4,5,6])
-
+
end
-
+
def test_html_col_counter
assert_template_result("\n| 1 | 2 |
\n| 1 | 2 |
\n| 1 | 2 |
\n",
- '{% tablerow n in numbers cols:2%}{{tablerowloop.col}}{% endtablerow %}',
+ '{% tablerow n in numbers cols:2%}{{tablerowloop.col}}{% endtablerow %}',
'numbers' => [1,2,3,4,5,6])
-
end
-
-end
+end # HtmlTagTest
diff --git a/test/lib/liquid/include_tag_test.rb b/test/lib/liquid/include_tag_test.rb
new file mode 100644
index 00000000..ca1e34c3
--- /dev/null
+++ b/test/lib/liquid/include_tag_test.rb
@@ -0,0 +1,127 @@
+require 'test_helper'
+
+class TestFileSystem
+ def read_template_file(template_path)
+ case template_path
+ when "product"
+ "Product: {{ product.title }} "
+
+ when "locale_variables"
+ "Locale: {{echo1}} {{echo2}}"
+
+ when "variant"
+ "Variant: {{ variant.title }}"
+
+ when "nested_template"
+ "{% include 'header' %} {% include 'body' %} {% include 'footer' %}"
+
+ when "body"
+ "body {% include 'body_detail' %}"
+
+ when "nested_product_template"
+ "Product: {{ nested_product_template.title }} {%include 'details'%} "
+
+ when "recursively_nested_template"
+ "-{% include 'recursively_nested_template' %}"
+
+ when "pick_a_source"
+ "from TestFileSystem"
+
+ else
+ template_path
+ end
+ end
+end
+
+class OtherFileSystem
+ def read_template_file(template_path)
+ 'from OtherFileSystem'
+ end
+end
+
+class IncludeTagTest < Test::Unit::TestCase
+ include Liquid
+
+ def setup
+ Liquid::Template.file_system = TestFileSystem.new
+ end
+
+ def test_include_tag_looks_for_file_system_in_registers_first
+ assert_equal 'from OtherFileSystem',
+ Template.parse("{% include 'pick_a_source' %}").render({}, :registers => {:file_system => OtherFileSystem.new})
+ end
+
+
+ def test_include_tag_with
+ assert_equal "Product: Draft 151cm ",
+ Template.parse("{% include 'product' with products[0] %}").render( "products" => [ {'title' => 'Draft 151cm'}, {'title' => 'Element 155cm'} ] )
+ end
+
+ def test_include_tag_with_default_name
+ assert_equal "Product: Draft 151cm ",
+ Template.parse("{% include 'product' %}").render( "product" => {'title' => 'Draft 151cm'} )
+ end
+
+ def test_include_tag_for
+
+ assert_equal "Product: Draft 151cm Product: Element 155cm ",
+ Template.parse("{% include 'product' for products %}").render( "products" => [ {'title' => 'Draft 151cm'}, {'title' => 'Element 155cm'} ] )
+ end
+
+ def test_include_tag_with_local_variables
+ assert_equal "Locale: test123 ",
+ Template.parse("{% include 'locale_variables' echo1: 'test123' %}").render
+ end
+
+ def test_include_tag_with_multiple_local_variables
+ assert_equal "Locale: test123 test321",
+ Template.parse("{% include 'locale_variables' echo1: 'test123', echo2: 'test321' %}").render
+ end
+
+ def test_include_tag_with_multiple_local_variables_from_context
+ assert_equal "Locale: test123 test321",
+ Template.parse("{% include 'locale_variables' echo1: echo1, echo2: more_echos.echo2 %}").render('echo1' => 'test123', 'more_echos' => { "echo2" => 'test321'})
+ end
+
+ def test_nested_include_tag
+ assert_equal "body body_detail",
+ Template.parse("{% include 'body' %}").render
+
+ assert_equal "header body body_detail footer",
+ Template.parse("{% include 'nested_template' %}").render
+ end
+
+ def test_nested_include_with_variable
+
+ assert_equal "Product: Draft 151cm details ",
+ Template.parse("{% include 'nested_product_template' with product %}").render("product" => {"title" => 'Draft 151cm'})
+
+ assert_equal "Product: Draft 151cm details Product: Element 155cm details ",
+ Template.parse("{% include 'nested_product_template' for products %}").render("products" => [{"title" => 'Draft 151cm'}, {"title" => 'Element 155cm'}])
+
+ end
+
+ def test_recursively_included_template_does_not_produce_endless_loop
+
+ infinite_file_system = Class.new do
+ def read_template_file(template_path)
+ "-{% include 'loop' %}"
+ end
+ end
+
+ Liquid::Template.file_system = infinite_file_system.new
+
+ assert_raise(Liquid::StackLevelError) do
+ Template.parse("{% include 'loop' %}").render!
+ end
+
+ end
+
+ def test_dynamically_choosen_template
+
+ assert_equal "Test123", Template.parse("{% include template %}").render("template" => 'Test123')
+ assert_equal "Test321", Template.parse("{% include template %}").render("template" => 'Test321')
+
+ assert_equal "Product: Draft 151cm ", Template.parse("{% include template for product %}").render("template" => 'product', 'product' => { 'title' => 'Draft 151cm'})
+ end
+end # IncludeTagTest
\ No newline at end of file
diff --git a/test/module_ex_test.rb b/test/lib/liquid/module_ex_test.rb
similarity index 96%
rename from test/module_ex_test.rb
rename to test/lib/liquid/module_ex_test.rb
index 40d7e1c4..45bde8cf 100644
--- a/test/module_ex_test.rb
+++ b/test/lib/liquid/module_ex_test.rb
@@ -1,5 +1,4 @@
-#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/helper'
+require 'test_helper'
class TestClassA
liquid_methods :allowedA, :chainedB
@@ -39,31 +38,31 @@ end
class ModuleExTest < Test::Unit::TestCase
include Liquid
-
+
def setup
@a = TestClassA.new
@b = TestClassB.new
@c = TestClassC.new
end
-
+
def test_should_create_LiquidDropClass
assert TestClassA::LiquidDropClass
assert TestClassB::LiquidDropClass
assert TestClassC::LiquidDropClass
end
-
+
def test_should_respond_to_liquid
assert @a.respond_to?(:to_liquid)
assert @b.respond_to?(:to_liquid)
assert @c.respond_to?(:to_liquid)
end
-
+
def test_should_return_LiquidDropClass_object
assert @a.to_liquid.is_a?(TestClassA::LiquidDropClass)
assert @b.to_liquid.is_a?(TestClassB::LiquidDropClass)
assert @c.to_liquid.is_a?(TestClassC::LiquidDropClass)
end
-
+
def test_should_respond_to_liquid_methods
assert @a.to_liquid.respond_to?(:allowedA)
assert @a.to_liquid.respond_to?(:chainedB)
@@ -84,6 +83,5 @@ class ModuleExTest < Test::Unit::TestCase
assert_equal 'another_allowedC', Liquid::Template.parse("{{ a.chainedB.chainedC.another_allowedC }}").render('a'=>@a)
assert_equal '', Liquid::Template.parse("{{ a.restricted }}").render('a'=>@a)
assert_equal '', Liquid::Template.parse("{{ a.unknown }}").render('a'=>@a)
- end
-
-end
\ No newline at end of file
+ end
+end # ModuleExTest
diff --git a/test/output_test.rb b/test/lib/liquid/output_test.rb
similarity index 85%
rename from test/output_test.rb
rename to test/lib/liquid/output_test.rb
index 96d90903..c849c9d2 100644
--- a/test/output_test.rb
+++ b/test/lib/liquid/output_test.rb
@@ -1,20 +1,18 @@
-#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/helper'
+require 'test_helper'
module FunnyFilter
-
def make_funny(input)
- 'LOL'
+ 'LOL'
end
def cite_funny(input)
"LOL: #{input}"
- end
+ end
def add_smiley(input, smiley = ":-)")
"#{input} #{smiley}"
end
-
+
def add_tag(input, tag = "p", id = "foo")
%|<#{tag} id="#{id}">#{input}#{tag}>|
end
@@ -22,25 +20,24 @@ module FunnyFilter
def paragraph(input)
"#{input}
"
end
-
+
def link_to(name, url)
%|#{name}|
end
-end
+end
class OutputTest < Test::Unit::TestCase
include Liquid
def setup
- @assigns = {
+ @assigns = {
'best_cars' => 'bmw',
'car' => {'bmw' => 'good', 'gm' => 'bad'}
}
-
end
- def test_variable
+ def test_variable
text = %| {{best_cars}} |
expected = %| bmw |
@@ -53,35 +50,35 @@ class OutputTest < Test::Unit::TestCase
expected = %| good bad good |
assert_equal expected, Template.parse(text).render(@assigns)
end
-
+
def test_variable_piping
text = %( {{ car.gm | make_funny }} )
- expected = %| LOL |
-
+ expected = %| LOL |
+
assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
end
def test_variable_piping_with_input
text = %( {{ car.gm | cite_funny }} )
- expected = %| LOL: bad |
+ expected = %| LOL: bad |
assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
end
-
+
def test_variable_piping_with_args
text = %! {{ car.gm | add_smiley : ':-(' }} !
expected = %| bad :-( |
assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
end
-
+
def test_variable_piping_with_no_args
text = %! {{ car.gm | add_smiley }} !
expected = %| bad :-) |
assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
end
-
+
def test_multiple_variable_piping_with_args
text = %! {{ car.gm | add_smiley : ':-(' | add_smiley : ':-('}} !
expected = %| bad :-( :-( |
@@ -105,17 +102,15 @@ class OutputTest < Test::Unit::TestCase
def test_multiple_pipings
text = %( {{ best_cars | cite_funny | paragraph }} )
- expected = %| LOL: bmw
|
+ expected = %| LOL: bmw
|
assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
end
-
+
def test_link_to
text = %( {{ 'Typo' | link_to: 'http://typo.leetsoft.com' }} )
- expected = %| Typo |
+ expected = %| Typo |
- assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
+ assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
end
-
-
-end
\ No newline at end of file
+end # OutputTest
\ No newline at end of file
diff --git a/test/parsing_quirks_test.rb b/test/lib/liquid/parsing_quirks_test.rb
similarity index 78%
rename from test/parsing_quirks_test.rb
rename to test/lib/liquid/parsing_quirks_test.rb
index 2f2aa4a0..f5c4426e 100644
--- a/test/parsing_quirks_test.rb
+++ b/test/lib/liquid/parsing_quirks_test.rb
@@ -1,5 +1,4 @@
-#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/helper'
+require 'test_helper'
class ParsingQuirksTest < Test::Unit::TestCase
include Liquid
@@ -7,48 +6,47 @@ class ParsingQuirksTest < Test::Unit::TestCase
def test_error_with_css
text = %| div { font-weight: bold; } |
template = Template.parse(text)
-
+
assert_equal text, template.render
assert_equal [String], template.root.nodelist.collect {|i| i.class}
end
-
+
def test_raise_on_single_close_bracet
assert_raise(SyntaxError) do
- Template.parse("text {{method} oh nos!")
+ Template.parse("text {{method} oh nos!")
end
end
-
+
def test_raise_on_label_and_no_close_bracets
assert_raise(SyntaxError) do
Template.parse("TEST {{ ")
end
- end
-
+ end
+
def test_raise_on_label_and_no_close_bracets_percent
assert_raise(SyntaxError) do
Template.parse("TEST {% ")
end
end
-
+
def test_error_on_empty_filter
assert_nothing_raised do
- Template.parse("{{test |a|b|}}")
- Template.parse("{{test}}")
- Template.parse("{{|test|}}")
+ Template.parse("{{test |a|b|}}")
+ Template.parse("{{test}}")
+ Template.parse("{{|test|}}")
end
end
-
+
def test_meaningless_parens
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
-
+
def test_unexpected_characters_silently_eat_logic
markup = "true && false"
assert_template_result(' YES ',"{% if #{markup} %} YES {% endif %}")
markup = "false || true"
assert_template_result('',"{% if #{markup} %} YES {% endif %}")
end
-
-end
\ No newline at end of file
+end # ParsingQuirksTest
diff --git a/test/regexp_test.rb b/test/lib/liquid/regexp_test.rb
similarity index 66%
rename from test/regexp_test.rb
rename to test/lib/liquid/regexp_test.rb
index 10717c1b..280d62b0 100644
--- a/test/regexp_test.rb
+++ b/test/lib/liquid/regexp_test.rb
@@ -1,20 +1,20 @@
-require File.dirname(__FILE__) + '/helper'
-
+require 'test_helper'
+
class RegexpTest < Test::Unit::TestCase
include Liquid
def test_empty
assert_equal [], ''.scan(QuotedFragment)
end
-
+
def test_quote
assert_equal ['"arg 1"'], '"arg 1"'.scan(QuotedFragment)
end
-
+
def test_words
assert_equal ['arg1', 'arg2'], 'arg1 arg2'.scan(QuotedFragment)
end
-
+
def test_tags
assert_equal ['', '
'], '
'.scan(QuotedFragment)
assert_equal ['
'], '
'.scan(QuotedFragment)
@@ -32,14 +32,13 @@ class RegexpTest < Test::Unit::TestCase
def test_quoted_words_in_the_middle
assert_equal ['arg1', 'arg2', '"arg 3"', 'arg4'], 'arg1 arg2 "arg 3" arg4 '.scan(QuotedFragment)
end
-
+
def test_variable_parser
- assert_equal ['var'], 'var'.scan(VariableParser)
- assert_equal ['var', 'method'], 'var.method'.scan(VariableParser)
- assert_equal ['var', '[method]'], 'var[method]'.scan(VariableParser)
- assert_equal ['var', '[method]', '[0]'], 'var[method][0]'.scan(VariableParser)
- assert_equal ['var', '["method"]', '[0]'], 'var["method"][0]'.scan(VariableParser)
- assert_equal ['var', '[method]', '[0]', 'method'], 'var[method][0].method'.scan(VariableParser)
+ assert_equal ['var'], 'var'.scan(VariableParser)
+ assert_equal ['var', 'method'], 'var.method'.scan(VariableParser)
+ assert_equal ['var', '[method]'], 'var[method]'.scan(VariableParser)
+ assert_equal ['var', '[method]', '[0]'], 'var[method][0]'.scan(VariableParser)
+ assert_equal ['var', '["method"]', '[0]'], 'var["method"][0]'.scan(VariableParser)
+ assert_equal ['var', '[method]', '[0]', 'method'], 'var[method][0].method'.scan(VariableParser)
end
-
-end
\ No newline at end of file
+end # RegexpTest
diff --git a/test/security_test.rb b/test/lib/liquid/security_test.rb
similarity index 92%
rename from test/security_test.rb
rename to test/lib/liquid/security_test.rb
index 1ab0d6fa..413cdf6b 100644
--- a/test/security_test.rb
+++ b/test/lib/liquid/security_test.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/helper'
+require 'test_helper'
module SecurityFilter
def add_one(input)
@@ -12,22 +12,22 @@ class SecurityTest < Test::Unit::TestCase
def test_no_instance_eval
text = %( {{ '1+1' | instance_eval }} )
expected = %| 1+1 |
-
+
assert_equal expected, Template.parse(text).render(@assigns)
end
-
+
def test_no_existing_instance_eval
text = %( {{ '1+1' | __instance_eval__ }} )
expected = %| 1+1 |
-
+
assert_equal expected, Template.parse(text).render(@assigns)
end
-
+
def test_no_instance_eval_after_mixing_in_new_filter
text = %( {{ '1+1' | instance_eval }} )
expected = %| 1+1 |
-
+
assert_equal expected, Template.parse(text).render(@assigns)
end
@@ -35,7 +35,7 @@ class SecurityTest < Test::Unit::TestCase
def test_no_instance_eval_later_in_chain
text = %( {{ '1+1' | add_one | instance_eval }} )
expected = %| 1+1 + 1 |
-
+
assert_equal expected, Template.parse(text).render(@assigns, :filters => SecurityFilter)
end
-end
\ No newline at end of file
+end # SecurityTest
diff --git a/test/standard_filter_test.rb b/test/lib/liquid/standard_filter_test.rb
similarity index 98%
rename from test/standard_filter_test.rb
rename to test/lib/liquid/standard_filter_test.rb
index f9b10eb0..4e0dba45 100644
--- a/test/standard_filter_test.rb
+++ b/test/lib/liquid/standard_filter_test.rb
@@ -1,12 +1,9 @@
-#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/helper'
-
+require 'test_helper'
class Filters
include Liquid::StandardFilters
end
-
class StandardFiltersTest < Test::Unit::TestCase
include Liquid
@@ -180,5 +177,4 @@ class StandardFiltersTest < Test::Unit::TestCase
def test_cannot_access_private_methods
assert_template_result('a',"{{ 'a' | to_number }}")
end
-
-end
+end # StandardFiltersTest
diff --git a/test/strainer_test.rb b/test/lib/liquid/strainer_test.rb
similarity index 93%
rename from test/strainer_test.rb
rename to test/lib/liquid/strainer_test.rb
index f74eb1f3..fc92e10d 100644
--- a/test/strainer_test.rb
+++ b/test/lib/liquid/strainer_test.rb
@@ -1,5 +1,4 @@
-#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/helper'
+require 'test_helper'
class StrainerTest < Test::Unit::TestCase
include Liquid
@@ -23,4 +22,4 @@ class StrainerTest < Test::Unit::TestCase
def test_object_respond_to_missing
assert_equal Object.respond_to?(:respond_to_missing?), Strainer.create(nil).respond_to?(:respond_to_missing?)
end
-end
+end # StrainerTest
diff --git a/test/if_else_test.rb b/test/lib/liquid/tags/if_else_test.rb
similarity index 90%
rename from test/if_else_test.rb
rename to test/lib/liquid/tags/if_else_test.rb
index 2a8c1ad7..27662903 100644
--- a/test/if_else_test.rb
+++ b/test/lib/liquid/tags/if_else_test.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/helper'
+require 'test_helper'
class IfElseTest < Test::Unit::TestCase
include Liquid
@@ -6,7 +6,7 @@ class IfElseTest < Test::Unit::TestCase
def test_if
assert_template_result(' ',' {% if false %} this text should not go into the output {% endif %} ')
assert_template_result(' this text should go into the output ',
- ' {% if true %} this text should go into the output {% endif %} ')
+ ' {% if true %} this text should go into the output {% endif %} ')
assert_template_result(' you rock ?','{% if false %} you suck {% endif %} {% if true %} you rock {% endif %}?')
end
@@ -15,27 +15,27 @@ class IfElseTest < Test::Unit::TestCase
assert_template_result(' YES ','{% if true %} YES {% else %} NO {% endif %}')
assert_template_result(' YES ','{% if "foo" %} YES {% else %} NO {% endif %}')
end
-
- def test_if_boolean
- assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => true)
- end
-
- def test_if_or
- assert_template_result(' YES ','{% if a or b %} YES {% endif %}', 'a' => true, 'b' => true)
- assert_template_result(' YES ','{% if a or b %} YES {% endif %}', 'a' => true, 'b' => false)
- assert_template_result(' YES ','{% if a or b %} YES {% endif %}', 'a' => false, 'b' => true)
- assert_template_result('', '{% if a or b %} YES {% endif %}', 'a' => false, 'b' => false)
- assert_template_result(' YES ','{% if a or b or c %} YES {% endif %}', 'a' => false, 'b' => false, 'c' => true)
- assert_template_result('', '{% if a or b or c %} YES {% endif %}', 'a' => false, 'b' => false, 'c' => false)
+ def test_if_boolean
+ assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => true)
end
-
+
+ def test_if_or
+ assert_template_result(' YES ','{% if a or b %} YES {% endif %}', 'a' => true, 'b' => true)
+ assert_template_result(' YES ','{% if a or b %} YES {% endif %}', 'a' => true, 'b' => false)
+ assert_template_result(' YES ','{% if a or b %} YES {% endif %}', 'a' => false, 'b' => true)
+ assert_template_result('', '{% if a or b %} YES {% endif %}', 'a' => false, 'b' => false)
+
+ assert_template_result(' YES ','{% if a or b or c %} YES {% endif %}', 'a' => false, 'b' => false, 'c' => true)
+ assert_template_result('', '{% if a or b or c %} YES {% endif %}', 'a' => false, 'b' => false, 'c' => false)
+ end
+
def test_if_or_with_operators
- assert_template_result(' YES ','{% if a == true or b == true %} YES {% endif %}', 'a' => true, 'b' => true)
- assert_template_result(' YES ','{% if a == true or b == false %} YES {% endif %}', 'a' => true, 'b' => true)
- assert_template_result('','{% if a == false or b == false %} YES {% endif %}', 'a' => true, 'b' => true)
- end
-
+ assert_template_result(' YES ','{% if a == true or b == true %} YES {% endif %}', 'a' => true, 'b' => true)
+ assert_template_result(' YES ','{% if a == true or b == false %} YES {% endif %}', 'a' => true, 'b' => true)
+ assert_template_result('','{% if a == false or b == false %} YES {% endif %}', 'a' => true, 'b' => true)
+ end
+
def test_comparison_of_strings_containing_and_or_or
assert_nothing_raised do
awful_markup = "a == 'and' and b == 'or' and c == 'foo and bar' and d == 'bar or baz' and e == 'foo' and foo and bar"
@@ -43,7 +43,7 @@ class IfElseTest < Test::Unit::TestCase
assert_template_result(' YES ',"{% if #{awful_markup} %} YES {% endif %}", assigns)
end
end
-
+
def test_comparison_of_expressions_starting_with_and_or_or
assigns = {'order' => {'items_count' => 0}, 'android' => {'name' => 'Roy'}}
assert_nothing_raised do
@@ -57,18 +57,18 @@ class IfElseTest < Test::Unit::TestCase
assigns)
end
end
-
+
def test_if_and
- assert_template_result(' YES ','{% if true and true %} YES {% endif %}')
- assert_template_result('','{% if false and true %} YES {% endif %}')
- assert_template_result('','{% if false and true %} YES {% endif %}')
+ assert_template_result(' YES ','{% if true and true %} YES {% endif %}')
+ assert_template_result('','{% if false and true %} YES {% endif %}')
+ assert_template_result('','{% if false and true %} YES {% endif %}')
end
-
-
+
+
def test_hash_miss_generates_false
assert_template_result('','{% if foo.bar %} NO {% endif %}', 'foo' => {})
end
-
+
def test_if_from_variable
assert_template_result('','{% if var %} NO {% endif %}', 'var' => false)
assert_template_result('','{% if var %} NO {% endif %}', 'var' => nil)
@@ -76,7 +76,7 @@ class IfElseTest < Test::Unit::TestCase
assert_template_result('','{% if foo.bar %} NO {% endif %}', 'foo' => {})
assert_template_result('','{% if foo.bar %} NO {% endif %}', 'foo' => nil)
assert_template_result('','{% if foo.bar %} NO {% endif %}', 'foo' => true)
-
+
assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => "text")
assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => true)
assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => 1)
@@ -88,12 +88,12 @@ class IfElseTest < Test::Unit::TestCase
assert_template_result(' YES ','{% if foo.bar %} YES {% endif %}', 'foo' => {'bar' => 1 })
assert_template_result(' YES ','{% if foo.bar %} YES {% endif %}', 'foo' => {'bar' => {} })
assert_template_result(' YES ','{% if foo.bar %} YES {% endif %}', 'foo' => {'bar' => [] })
-
+
assert_template_result(' YES ','{% if var %} NO {% else %} YES {% endif %}', 'var' => false)
assert_template_result(' YES ','{% if var %} NO {% else %} YES {% endif %}', 'var' => nil)
assert_template_result(' YES ','{% if var %} YES {% else %} NO {% endif %}', 'var' => true)
assert_template_result(' YES ','{% if "foo" %} YES {% else %} NO {% endif %}', 'var' => "text")
-
+
assert_template_result(' YES ','{% if foo.bar %} NO {% else %} YES {% endif %}', 'foo' => {'bar' => false})
assert_template_result(' YES ','{% if foo.bar %} YES {% else %} NO {% endif %}', 'foo' => {'bar' => true})
assert_template_result(' YES ','{% if foo.bar %} YES {% else %} NO {% endif %}', 'foo' => {'bar' => "text"})
@@ -101,19 +101,19 @@ class IfElseTest < Test::Unit::TestCase
assert_template_result(' YES ','{% if foo.bar %} NO {% else %} YES {% endif %}', 'foo' => {})
assert_template_result(' YES ','{% if foo.bar %} NO {% else %} YES {% endif %}', 'notfoo' => {'bar' => true})
end
-
+
def test_nested_if
assert_template_result('', '{% if false %}{% if false %} NO {% endif %}{% endif %}')
assert_template_result('', '{% if false %}{% if true %} NO {% endif %}{% endif %}')
assert_template_result('', '{% if true %}{% if false %} NO {% endif %}{% endif %}')
assert_template_result(' YES ', '{% if true %}{% if true %} YES {% endif %}{% endif %}')
-
+
assert_template_result(' YES ', '{% if true %}{% if true %} YES {% else %} NO {% endif %}{% else %} NO {% endif %}')
assert_template_result(' YES ', '{% if true %}{% if false %} NO {% else %} YES {% endif %}{% else %} NO {% endif %}')
assert_template_result(' YES ', '{% if false %}{% if true %} NO {% else %} NONO {% endif %}{% else %} YES {% endif %}')
-
+
end
-
+
def test_comparisons_on_null
assert_template_result('','{% if null < 10 %} NO {% endif %}')
assert_template_result('','{% if null <= 10 %} NO {% endif %}')
@@ -125,29 +125,29 @@ class IfElseTest < Test::Unit::TestCase
assert_template_result('','{% if 10 >= null %} NO {% endif %}')
assert_template_result('','{% if 10 > null %} NO {% endif %}')
end
-
+
def test_else_if
assert_template_result('0','{% if 0 == 0 %}0{% elsif 1 == 1%}1{% else %}2{% endif %}')
assert_template_result('1','{% if 0 != 0 %}0{% elsif 1 == 1%}1{% else %}2{% endif %}')
assert_template_result('2','{% if 0 != 0 %}0{% elsif 1 != 1%}1{% else %}2{% endif %}')
-
- assert_template_result('elsif','{% if false %}if{% elsif true %}elsif{% endif %}')
+
+ assert_template_result('elsif','{% if false %}if{% elsif true %}elsif{% endif %}')
end
-
+
def test_syntax_error_no_variable
assert_raise(SyntaxError){ assert_template_result('', '{% if jerry == 1 %}')}
end
-
+
def test_syntax_error_no_expression
assert_raise(SyntaxError) { assert_template_result('', '{% if %}') }
end
-
+
def test_if_with_custom_condition
Condition.operators['contains'] = :[]
-
+
assert_template_result('yes', %({% if 'bob' contains 'o' %}yes{% endif %}))
assert_template_result('no', %({% if 'bob' contains 'f' %}yes{% else %}no{% endif %}))
ensure
Condition.operators.delete 'contains'
end
-end
\ No newline at end of file
+end # IfElseTest
diff --git a/test/standard_tag_test.rb b/test/lib/liquid/tags/standard_tag_test.rb
similarity index 60%
rename from test/standard_tag_test.rb
rename to test/lib/liquid/tags/standard_tag_test.rb
index 17d8df1a..4e14949d 100644
--- a/test/standard_tag_test.rb
+++ b/test/lib/liquid/tags/standard_tag_test.rb
@@ -1,10 +1,8 @@
-require File.dirname(__FILE__) + '/helper'
-
+require 'test_helper'
class StandardTagTest < Test::Unit::TestCase
include Liquid
-
def test_tag
tag = Tag.new('tag', [], [])
assert_equal 'liquid::tag', tag.name
@@ -14,6 +12,7 @@ class StandardTagTest < Test::Unit::TestCase
def test_no_transform
assert_template_result('this text should come out of the template without change...',
'this text should come out of the template without change...')
+
assert_template_result('blah','blah')
assert_template_result('','')
assert_template_result('|,.:','|,.:')
@@ -85,43 +84,48 @@ HERE
def test_for_helpers
assigns = {'array' => [1,2,3] }
- assert_template_result(' 1/3 2/3 3/3 ','{%for item in array%} {{forloop.index}}/{{forloop.length}} {%endfor%}',assigns)
- assert_template_result(' 1 2 3 ','{%for item in array%} {{forloop.index}} {%endfor%}',assigns)
- assert_template_result(' 0 1 2 ','{%for item in array%} {{forloop.index0}} {%endfor%}',assigns)
- assert_template_result(' 2 1 0 ','{%for item in array%} {{forloop.rindex0}} {%endfor%}',assigns)
- assert_template_result(' 3 2 1 ','{%for item in array%} {{forloop.rindex}} {%endfor%}',assigns)
- assert_template_result(' true false false ','{%for item in array%} {{forloop.first}} {%endfor%}',assigns)
- assert_template_result(' false false true ','{%for item in array%} {{forloop.last}} {%endfor%}',assigns)
+ assert_template_result(' 1/3 2/3 3/3 ',
+ '{%for item in array%} {{forloop.index}}/{{forloop.length}} {%endfor%}',
+ assigns)
+ assert_template_result(' 1 2 3 ', '{%for item in array%} {{forloop.index}} {%endfor%}', assigns)
+ assert_template_result(' 0 1 2 ', '{%for item in array%} {{forloop.index0}} {%endfor%}', assigns)
+ assert_template_result(' 2 1 0 ', '{%for item in array%} {{forloop.rindex0}} {%endfor%}', assigns)
+ assert_template_result(' 3 2 1 ', '{%for item in array%} {{forloop.rindex}} {%endfor%}', assigns)
+ assert_template_result(' true false false ', '{%for item in array%} {{forloop.first}} {%endfor%}', assigns)
+ assert_template_result(' false false true ', '{%for item in array%} {{forloop.last}} {%endfor%}', assigns)
end
def test_for_and_if
assigns = {'array' => [1,2,3] }
- assert_template_result('+--', '{%for item in array%}{% if forloop.first %}+{% else %}-{% endif %}{%endfor%}', assigns)
+ assert_template_result('+--',
+ '{%for item in array%}{% if forloop.first %}+{% else %}-{% endif %}{%endfor%}',
+ assigns)
end
def test_limiting
assigns = {'array' => [1,2,3,4,5,6,7,8,9,0]}
- assert_template_result('12','{%for i in array limit:2 %}{{ i }}{%endfor%}',assigns)
- assert_template_result('1234','{%for i in array limit:4 %}{{ i }}{%endfor%}',assigns)
- assert_template_result('3456','{%for i in array limit:4 offset:2 %}{{ i }}{%endfor%}',assigns)
- assert_template_result('3456','{%for i in array limit: 4 offset: 2 %}{{ i }}{%endfor%}',assigns)
+ assert_template_result('12', '{%for i in array limit:2 %}{{ i }}{%endfor%}', assigns)
+ assert_template_result('1234', '{%for i in array limit:4 %}{{ i }}{%endfor%}', assigns)
+ assert_template_result('3456', '{%for i in array limit:4 offset:2 %}{{ i }}{%endfor%}', assigns)
+ assert_template_result('3456', '{%for i in array limit: 4 offset: 2 %}{{ i }}{%endfor%}', assigns)
end
def test_dynamic_variable_limiting
assigns = {'array' => [1,2,3,4,5,6,7,8,9,0]}
assigns['limit'] = 2
assigns['offset'] = 2
- assert_template_result('34','{%for i in array limit: limit offset: offset %}{{ i }}{%endfor%}',assigns)
+
+ assert_template_result('34', '{%for i in array limit: limit offset: offset %}{{ i }}{%endfor%}', assigns)
end
def test_nested_for
assigns = {'array' => [[1,2],[3,4],[5,6]] }
- assert_template_result('123456','{%for item in array%}{%for i in item%}{{ i }}{%endfor%}{%endfor%}',assigns)
+ assert_template_result('123456', '{%for item in array%}{%for i in item%}{{ i }}{%endfor%}{%endfor%}', assigns)
end
def test_offset_only
assigns = {'array' => [1,2,3,4,5,6,7,8,9,0]}
- assert_template_result('890','{%for i in array offset:7 %}{{ i }}{%endfor%}',assigns)
+ assert_template_result('890', '{%for i in array offset:7 %}{{ i }}{%endfor%}', assigns)
end
def test_pause_resume
@@ -199,86 +203,131 @@ HERE
def test_assign
assigns = {'var' => 'content' }
- assert_template_result('var2: var2:content','var2:{{var2}} {%assign var2 = var%} var2:{{var2}}',assigns)
+ assert_template_result('var2: var2:content', 'var2:{{var2}} {%assign var2 = var%} var2:{{var2}}', assigns)
end
def test_hyphenated_assign
assigns = {'a-b' => '1' }
- assert_template_result('a-b:1 a-b:2','a-b:{{a-b}} {%assign a-b = 2 %}a-b:{{a-b}}',assigns)
+ assert_template_result('a-b:1 a-b:2', 'a-b:{{a-b}} {%assign a-b = 2 %}a-b:{{a-b}}', assigns)
end
def test_assign_with_colon_and_spaces
assigns = {'var' => {'a:b c' => {'paged' => '1' }}}
- assert_template_result('var2: 1','{%assign var2 = var["a:b c"].paged %}var2: {{var2}}',assigns)
+ assert_template_result('var2: 1', '{%assign var2 = var["a:b c"].paged %}var2: {{var2}}', assigns)
end
def test_capture
assigns = {'var' => 'content' }
- assert_template_result('content foo content foo ','{{ var2 }}{% capture var2 %}{{ var }} foo {% endcapture %}{{ var2 }}{{ var2 }}', assigns)
+ assert_template_result('content foo content foo ',
+ '{{ var2 }}{% capture var2 %}{{ var }} foo {% endcapture %}{{ var2 }}{{ var2 }}',
+ assigns)
end
def test_capture_detects_bad_syntax
assert_raise(SyntaxError) do
- assert_template_result('content foo content foo ','{{ var2 }}{% capture %}{{ var }} foo {% endcapture %}{{ var2 }}{{ var2 }}', {'var' => 'content' })
+ assert_template_result('content foo content foo ',
+ '{{ var2 }}{% capture %}{{ var }} foo {% endcapture %}{{ var2 }}{{ var2 }}',
+ {'var' => 'content' })
end
end
def test_case
assigns = {'condition' => 2 }
- assert_template_result(' its 2 ','{% case condition %}{% when 1 %} its 1 {% when 2 %} its 2 {% endcase %}', assigns)
+ assert_template_result(' its 2 ',
+ '{% case condition %}{% when 1 %} its 1 {% when 2 %} its 2 {% endcase %}',
+ assigns)
assigns = {'condition' => 1 }
- assert_template_result(' its 1 ','{% case condition %}{% when 1 %} its 1 {% when 2 %} its 2 {% endcase %}', assigns)
+ assert_template_result(' its 1 ',
+ '{% case condition %}{% when 1 %} its 1 {% when 2 %} its 2 {% endcase %}',
+ assigns)
assigns = {'condition' => 3 }
- assert_template_result('','{% case condition %}{% when 1 %} its 1 {% when 2 %} its 2 {% endcase %}', assigns)
+ assert_template_result('',
+ '{% case condition %}{% when 1 %} its 1 {% when 2 %} its 2 {% endcase %}',
+ assigns)
assigns = {'condition' => "string here" }
- assert_template_result(' hit ','{% case condition %}{% when "string here" %} hit {% endcase %}', assigns)
+ assert_template_result(' hit ',
+ '{% case condition %}{% when "string here" %} hit {% endcase %}',
+ assigns)
assigns = {'condition' => "bad string here" }
- assert_template_result('','{% case condition %}{% when "string here" %} hit {% endcase %}', assigns)
+ assert_template_result('',
+ '{% case condition %}{% when "string here" %} hit {% endcase %}',\
+ assigns)
end
def test_case_with_else
-
assigns = {'condition' => 5 }
- assert_template_result(' hit ','{% case condition %}{% when 5 %} hit {% else %} else {% endcase %}', assigns)
+ assert_template_result(' hit ',
+ '{% case condition %}{% when 5 %} hit {% else %} else {% endcase %}',
+ assigns)
assigns = {'condition' => 6 }
- assert_template_result(' else ','{% case condition %}{% when 5 %} hit {% else %} else {% endcase %}', assigns)
+ assert_template_result(' else ',
+ '{% case condition %}{% when 5 %} hit {% else %} else {% endcase %}',
+ assigns)
assigns = {'condition' => 6 }
- assert_template_result(' else ','{% case condition %} {% when 5 %} hit {% else %} else {% endcase %}', assigns)
-
-
+ assert_template_result(' else ',
+ '{% case condition %} {% when 5 %} hit {% else %} else {% endcase %}',
+ assigns)
end
def test_case_on_size
- assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [])
- assert_template_result('1' , '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1])
- assert_template_result('2' , '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1, 1])
- assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1, 1, 1])
- assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1, 1, 1, 1])
- assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1, 1, 1, 1, 1])
+ assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [])
+ assert_template_result('1', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1])
+ assert_template_result('2', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1, 1])
+ assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1, 1, 1])
+ assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1, 1, 1, 1])
+ assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1, 1, 1, 1, 1])
end
def test_case_on_size_with_else
- assert_template_result('else', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}', 'a' => [])
- assert_template_result('1', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}', 'a' => [1])
- assert_template_result('2', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}', 'a' => [1, 1])
- assert_template_result('else', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}', 'a' => [1, 1, 1])
- assert_template_result('else', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}', 'a' => [1, 1, 1, 1])
- assert_template_result('else', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}', 'a' => [1, 1, 1, 1, 1])
+ assert_template_result('else',
+ '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}',
+ 'a' => [])
+
+ assert_template_result('1',
+ '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}',
+ 'a' => [1])
+
+ assert_template_result('2',
+ '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}',
+ 'a' => [1, 1])
+
+ assert_template_result('else',
+ '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}',
+ 'a' => [1, 1, 1])
+
+ assert_template_result('else',
+ '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}',
+ 'a' => [1, 1, 1, 1])
+
+ assert_template_result('else',
+ '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}',
+ 'a' => [1, 1, 1, 1, 1])
end
def test_case_on_length_with_else
- assert_template_result('else', '{% case a.empty? %}{% when true %}true{% when false %}false{% else %}else{% endcase %}', {})
- assert_template_result('false', '{% case false %}{% when true %}true{% when false %}false{% else %}else{% endcase %}', {})
- assert_template_result('true', '{% case true %}{% when true %}true{% when false %}false{% else %}else{% endcase %}', {})
- assert_template_result('else', '{% case NULL %}{% when true %}true{% when false %}false{% else %}else{% endcase %}', {})
+ assert_template_result('else',
+ '{% case a.empty? %}{% when true %}true{% when false %}false{% else %}else{% endcase %}',
+ {})
+
+ assert_template_result('false',
+ '{% case false %}{% when true %}true{% when false %}false{% else %}else{% endcase %}',
+ {})
+
+ assert_template_result('true',
+ '{% case true %}{% when true %}true{% when false %}false{% else %}else{% endcase %}',
+ {})
+
+ assert_template_result('else',
+ '{% case NULL %}{% when true %}true{% when false %}false{% else %}else{% endcase %}',
+ {})
end
def test_assign_from_case
@@ -331,7 +380,8 @@ HERE
end
def test_assign_is_global
- assert_equal 'variable', Liquid::Template.parse( '{%for i in (1..2) %}{% assign a = "variable"%}{% endfor %}{{a}}' ).render
+ assert_equal 'variable',
+ Liquid::Template.parse( '{%for i in (1..2) %}{% assign a = "variable"%}{% endfor %}{{a}}' ).render
end
def test_case_detects_bad_syntax
@@ -345,31 +395,31 @@ HERE
end
-
-
def test_cycle
-
assert_template_result('one','{%cycle "one", "two"%}')
assert_template_result('one two','{%cycle "one", "two"%} {%cycle "one", "two"%}')
assert_template_result(' two','{%cycle "", "two"%} {%cycle "", "two"%}')
assert_template_result('one two one','{%cycle "one", "two"%} {%cycle "one", "two"%} {%cycle "one", "two"%}')
- assert_template_result('text-align: left text-align: right','{%cycle "text-align: left", "text-align: right" %} {%cycle "text-align: left", "text-align: right"%}')
-
+ assert_template_result('text-align: left text-align: right',
+ '{%cycle "text-align: left", "text-align: right" %} {%cycle "text-align: left", "text-align: right"%}')
end
def test_multiple_cycles
- assert_template_result('1 2 1 1 2 3 1','{%cycle 1,2%} {%cycle 1,2%} {%cycle 1,2%} {%cycle 1,2,3%} {%cycle 1,2,3%} {%cycle 1,2,3%} {%cycle 1,2,3%}')
+ assert_template_result('1 2 1 1 2 3 1',
+ '{%cycle 1,2%} {%cycle 1,2%} {%cycle 1,2%} {%cycle 1,2,3%} {%cycle 1,2,3%} {%cycle 1,2,3%} {%cycle 1,2,3%}')
end
def test_multiple_named_cycles
- assert_template_result('one one two two one one','{%cycle 1: "one", "two" %} {%cycle 2: "one", "two" %} {%cycle 1: "one", "two" %} {%cycle 2: "one", "two" %} {%cycle 1: "one", "two" %} {%cycle 2: "one", "two" %}')
+ assert_template_result('one one two two one one',
+ '{%cycle 1: "one", "two" %} {%cycle 2: "one", "two" %} {%cycle 1: "one", "two" %} {%cycle 2: "one", "two" %} {%cycle 1: "one", "two" %} {%cycle 2: "one", "two" %}')
end
def test_multiple_named_cycles_with_names_from_context
assigns = {"var1" => 1, "var2" => 2 }
- assert_template_result('one one two two one one','{%cycle var1: "one", "two" %} {%cycle var2: "one", "two" %} {%cycle var1: "one", "two" %} {%cycle var2: "one", "two" %} {%cycle var1: "one", "two" %} {%cycle var2: "one", "two" %}', assigns)
+ assert_template_result('one one two two one one',
+ '{%cycle var1: "one", "two" %} {%cycle var2: "one", "two" %} {%cycle var1: "one", "two" %} {%cycle var2: "one", "two" %} {%cycle var1: "one", "two" %} {%cycle var2: "one", "two" %}', assigns)
end
def test_size_of_array
@@ -383,10 +433,10 @@ HERE
end
def test_illegal_symbols
- assert_template_result('', '{% if true == empty %}?{% endif %}', {})
- assert_template_result('', '{% if true == null %}?{% endif %}', {})
- assert_template_result('', '{% if empty == true %}?{% endif %}', {})
- assert_template_result('', '{% if null == true %}?{% endif %}', {})
+ assert_template_result('', '{% if true == empty %}?{% endif %}', {})
+ assert_template_result('', '{% if true == null %}?{% endif %}', {})
+ assert_template_result('', '{% if empty == true %}?{% endif %}', {})
+ assert_template_result('', '{% if null == true %}?{% endif %}', {})
end
def test_for_reversed
@@ -402,4 +452,4 @@ HERE
assigns = {'array' => [ 1, 1, 1, 1] }
assert_template_result('1','{%for item in array%}{%ifchanged%}{{item}}{% endifchanged %}{%endfor%}',assigns)
end
-end
+end # StandardTagTest
diff --git a/test/statements_test.rb b/test/lib/liquid/tags/statements_test.rb
similarity index 95%
rename from test/statements_test.rb
rename to test/lib/liquid/tags/statements_test.rb
index 63a41040..5ab68cca 100644
--- a/test/statements_test.rb
+++ b/test/lib/liquid/tags/statements_test.rb
@@ -1,10 +1,8 @@
-#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/helper'
+require 'test_helper'
class StatementsTest < Test::Unit::TestCase
include Liquid
-
def test_true_eql_true
text = %| {% if true == true %} true {% else %} false {% endif %} |
expected = %| true |
@@ -69,46 +67,46 @@ class StatementsTest < Test::Unit::TestCase
expected = %| false |
assert_equal expected, Template.parse(text).render
end
-
+
def test_var_strings_equal
text = %| {% if var == "hello there!" %} true {% else %} false {% endif %} |
expected = %| true |
assert_equal expected, Template.parse(text).render('var' => 'hello there!')
end
-
+
def test_var_strings_are_not_equal
text = %| {% if "hello there!" == var %} true {% else %} false {% endif %} |
expected = %| true |
assert_equal expected, Template.parse(text).render('var' => 'hello there!')
end
-
+
def test_var_and_long_string_are_equal
text = %| {% if var == 'hello there!' %} true {% else %} false {% endif %} |
expected = %| true |
assert_equal expected, Template.parse(text).render('var' => 'hello there!')
end
-
+
def test_var_and_long_string_are_equal_backwards
text = %| {% if 'hello there!' == var %} true {% else %} false {% endif %} |
expected = %| true |
assert_equal expected, Template.parse(text).render('var' => 'hello there!')
end
-
- #def test_is_nil
+
+ #def test_is_nil
# text = %| {% if var != nil %} true {% else %} false {% end %} |
# @template.assigns = { 'var' => 'hello there!'}
# expected = %| true |
# assert_equal expected, @template.parse(text)
#end
-
- def test_is_collection_empty
+
+ def test_is_collection_empty
text = %| {% if array == empty %} true {% else %} false {% endif %} |
expected = %| true |
assert_equal expected, Template.parse(text).render('array' => [])
end
- def test_is_not_collection_empty
+ def test_is_not_collection_empty
text = %| {% if array == empty %} true {% else %} false {% endif %} |
expected = %| false |
assert_equal expected, Template.parse(text).render('array' => [1,2,3])
@@ -133,5 +131,4 @@ class StatementsTest < Test::Unit::TestCase
expected = %| true |
assert_equal expected, Template.parse(text).render('var' => 1 )
end
-
-end
\ No newline at end of file
+end # StatementsTest
diff --git a/test/unless_else_test.rb b/test/lib/liquid/tags/unless_else_test.rb
similarity index 88%
rename from test/unless_else_test.rb
rename to test/lib/liquid/tags/unless_else_test.rb
index 1c420ba8..21c4044b 100644
--- a/test/unless_else_test.rb
+++ b/test/lib/liquid/tags/unless_else_test.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/helper'
+require 'test_helper'
class UnlessElseTest < Test::Unit::TestCase
include Liquid
@@ -6,7 +6,7 @@ class UnlessElseTest < Test::Unit::TestCase
def test_unless
assert_template_result(' ',' {% unless true %} this text should not go into the output {% endunless %} ')
assert_template_result(' this text should go into the output ',
- ' {% unless false %} this text should go into the output {% endunless %} ')
+ ' {% unless false %} this text should go into the output {% endunless %} ')
assert_template_result(' you rock ?','{% unless true %} you suck {% endunless %} {% unless false %} you rock {% endunless %}?')
end
@@ -23,5 +23,4 @@ class UnlessElseTest < Test::Unit::TestCase
def test_unless_else_in_loop
assert_template_result ' TRUE 2 3 ', '{% for i in choices %}{% unless i %} {{ forloop.index }} {% else %} TRUE {% endunless %}{% endfor %}', 'choices' => [1, nil, false]
end
-
-end
\ No newline at end of file
+end # UnlessElseTest
diff --git a/test/template_test.rb b/test/lib/liquid/template_test.rb
similarity index 92%
rename from test/template_test.rb
rename to test/lib/liquid/template_test.rb
index 94f8ca86..92803ea5 100644
--- a/test/template_test.rb
+++ b/test/lib/liquid/template_test.rb
@@ -1,52 +1,52 @@
-require File.dirname(__FILE__) + '/helper'
+require 'test_helper'
class TemplateTest < Test::Unit::TestCase
include Liquid
-
+
def test_tokenize_strings
assert_equal [' '], Template.new.send(:tokenize, ' ')
assert_equal ['hello world'], Template.new.send(:tokenize, 'hello world')
- end
-
+ end
+
def test_tokenize_variables
assert_equal ['{{funk}}'], Template.new.send(:tokenize, '{{funk}}')
assert_equal [' ', '{{funk}}', ' '], Template.new.send(:tokenize, ' {{funk}} ')
assert_equal [' ', '{{funk}}', ' ', '{{so}}', ' ', '{{brother}}', ' '], Template.new.send(:tokenize, ' {{funk}} {{so}} {{brother}} ')
assert_equal [' ', '{{ funk }}', ' '], Template.new.send(:tokenize, ' {{ funk }} ')
- end
-
- def test_tokenize_blocks
+ end
+
+ def test_tokenize_blocks
assert_equal ['{%comment%}'], Template.new.send(:tokenize, '{%comment%}')
assert_equal [' ', '{%comment%}', ' '], Template.new.send(:tokenize, ' {%comment%} ')
-
+
assert_equal [' ', '{%comment%}', ' ', '{%endcomment%}', ' '], Template.new.send(:tokenize, ' {%comment%} {%endcomment%} ')
- assert_equal [' ', '{% comment %}', ' ', '{% endcomment %}', ' '], Template.new.send(:tokenize, " {% comment %} {% endcomment %} ")
- end
-
+ assert_equal [' ', '{% comment %}', ' ', '{% endcomment %}', ' '], Template.new.send(:tokenize, " {% comment %} {% endcomment %} ")
+ end
+
def test_instance_assigns_persist_on_same_template_object_between_parses
t = Template.new
assert_equal 'from instance assigns', t.parse("{% assign foo = 'from instance assigns' %}{{ foo }}").render
assert_equal 'from instance assigns', t.parse("{{ foo }}").render
end
-
+
def test_instance_assigns_persist_on_same_template_parsing_between_renders
t = Template.new.parse("{{ foo }}{% assign foo = 'foo' %}{{ foo }}")
assert_equal 'foo', t.render
assert_equal 'foofoo', t.render
end
-
+
def test_custom_assigns_do_not_persist_on_same_template
t = Template.new
assert_equal 'from custom assigns', t.parse("{{ foo }}").render('foo' => 'from custom assigns')
assert_equal '', t.parse("{{ foo }}").render
end
-
+
def test_custom_assigns_squash_instance_assigns
t = Template.new
assert_equal 'from instance assigns', t.parse("{% assign foo = 'from instance assigns' %}{{ foo }}").render
assert_equal 'from custom assigns', t.parse("{{ foo }}").render('foo' => 'from custom assigns')
end
-
+
def test_persistent_assigns_squash_instance_assigns
t = Template.new
assert_equal 'from instance assigns', t.parse("{% assign foo = 'from instance assigns' %}{{ foo }}").render
@@ -71,5 +71,4 @@ class TemplateTest < Test::Unit::TestCase
assert_equal '1', t.render(assigns)
@global = nil
end
-
-end
\ No newline at end of file
+end # TemplateTest
diff --git a/test/variable_test.rb b/test/lib/liquid/variable_test.rb
similarity index 98%
rename from test/variable_test.rb
rename to test/lib/liquid/variable_test.rb
index 2ce846b3..b17c2a7c 100644
--- a/test/variable_test.rb
+++ b/test/lib/liquid/variable_test.rb
@@ -1,5 +1,4 @@
-#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/helper'
+require 'test_helper'
class VariableTest < Test::Unit::TestCase
include Liquid
@@ -131,7 +130,7 @@ class VariableResolutionTest < Test::Unit::TestCase
template = Template.parse(%|{{ test.test }}|)
assert_equal 'worked', template.render('test' => {'test' => 'worked'})
end
-
+
def test_preset_assigns
template = Template.parse(%|{{ test }}|)
template.assigns['test'] = 'worked'
@@ -168,5 +167,4 @@ class VariableResolutionTest < Test::Unit::TestCase
}
assert_equal "Unknown variable 'test'", e.message
end
-
-end
\ No newline at end of file
+end # VariableTest
diff --git a/test/test_helper.rb b/test/test_helper.rb
new file mode 100644
index 00000000..f64c3013
--- /dev/null
+++ b/test/test_helper.rb
@@ -0,0 +1,26 @@
+#!/usr/bin/env ruby
+extras_path = File.join File.dirname(__FILE__), 'extra'
+$LOAD_PATH.unshift(extras_path) unless $LOAD_PATH.include? extras_path
+
+require 'test/unit'
+require 'test/unit/assertions'
+require 'caller'
+require 'breakpoint'
+require File.join File.dirname(__FILE__), '..', 'lib', 'liquid'
+
+
+module Test
+
+ module Unit
+
+ module Assertions
+ include Liquid
+
+ def assert_template_result(expected, template, assigns={}, message=nil)
+ assert_equal expected, Template.parse(template).render(assigns)
+ end
+ end # Assertions
+
+ end # Unit
+
+end # Test