diff --git a/Rakefile b/Rakefile index cd69268..6296027 100755 --- a/Rakefile +++ b/Rakefile @@ -8,7 +8,7 @@ task :default => 'test' desc 'run test suite with default parser' Rake::TestTask.new(:base_test) do |t| t.libs << '.' << 'lib' << 'test' - t.test_files = FileList['test/liquid/**/*_test.rb'] + t.test_files = FileList['test/{integration,unit}/**/*_test.rb'] t.verbose = false end diff --git a/test/liquid/assign_test.rb b/test/integration/assign_test.rb similarity index 100% rename from test/liquid/assign_test.rb rename to test/integration/assign_test.rb diff --git a/test/liquid/blank_test.rb b/test/integration/blank_test.rb similarity index 100% rename from test/liquid/blank_test.rb rename to test/integration/blank_test.rb diff --git a/test/liquid/capture_test.rb b/test/integration/capture_test.rb similarity index 100% rename from test/liquid/capture_test.rb rename to test/integration/capture_test.rb diff --git a/test/integration/context_test.rb b/test/integration/context_test.rb new file mode 100644 index 0000000..aba8267 --- /dev/null +++ b/test/integration/context_test.rb @@ -0,0 +1,24 @@ +require 'test_helper' + +class ContextTest < Test::Unit::TestCase + include Liquid + + def test_override_global_filter + global = Module.new do + def notice(output) + "Global #{output}" + end + end + + local = Module.new do + def notice(output) + "Local #{output}" + end + end + + Template.register_filter(global) + assert_equal 'Global test', Template.parse("{{'test' | notice }}").render! + assert_equal 'Local test', Template.parse("{{'test' | notice }}").render!({}, :filters => [local]) + end + +end diff --git a/test/liquid/drop_test.rb b/test/integration/drop_test.rb similarity index 100% rename from test/liquid/drop_test.rb rename to test/integration/drop_test.rb diff --git a/test/liquid/error_handling_test.rb b/test/integration/error_handling_test.rb similarity index 100% rename from test/liquid/error_handling_test.rb rename to test/integration/error_handling_test.rb diff --git a/test/liquid/filter_test.rb b/test/integration/filter_test.rb similarity index 100% rename from test/liquid/filter_test.rb rename to test/integration/filter_test.rb diff --git a/test/liquid/hash_ordering_test.rb b/test/integration/hash_ordering_test.rb similarity index 100% rename from test/liquid/hash_ordering_test.rb rename to test/integration/hash_ordering_test.rb diff --git a/test/liquid/output_test.rb b/test/integration/output_test.rb similarity index 100% rename from test/liquid/output_test.rb rename to test/integration/output_test.rb diff --git a/test/liquid/parsing_quirks_test.rb b/test/integration/parsing_quirks_test.rb similarity index 91% rename from test/liquid/parsing_quirks_test.rb rename to test/integration/parsing_quirks_test.rb index fcf3d95..044b0b0 100644 --- a/test/liquid/parsing_quirks_test.rb +++ b/test/integration/parsing_quirks_test.rb @@ -3,12 +3,9 @@ require 'test_helper' class ParsingQuirksTest < Test::Unit::TestCase include Liquid - 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} + def test_parsing_css + text = " div { font-weight: bold; } " + assert_equal text, Template.parse(text).render! end def test_raise_on_single_close_bracet diff --git a/test/liquid/security_test.rb b/test/integration/security_test.rb similarity index 83% rename from test/liquid/security_test.rb rename to test/integration/security_test.rb index dfd1728..d512583 100644 --- a/test/liquid/security_test.rb +++ b/test/integration/security_test.rb @@ -54,10 +54,10 @@ class SecurityTest < Test::Unit::TestCase def test_does_not_add_drop_methods_to_symbol_table current_symbols = Symbol.all_symbols - drop = Drop.new - drop.invoke_drop("custom_method_1") - drop.invoke_drop("custom_method_2") - drop.invoke_drop("custom_method_3") + assigns = { 'drop' => Drop.new } + assert_equal "", Template.parse("{{ drop.custom_method_1 }}", assigns).render! + assert_equal "", Template.parse("{{ drop.custom_method_2 }}", assigns).render! + assert_equal "", Template.parse("{{ drop.custom_method_3 }}", assigns).render! assert_equal [], (Symbol.all_symbols - current_symbols) end diff --git a/test/liquid/standard_filter_test.rb b/test/integration/standard_filter_test.rb similarity index 100% rename from test/liquid/standard_filter_test.rb rename to test/integration/standard_filter_test.rb diff --git a/test/liquid/tags/break_tag_test.rb b/test/integration/tags/break_tag_test.rb similarity index 100% rename from test/liquid/tags/break_tag_test.rb rename to test/integration/tags/break_tag_test.rb diff --git a/test/liquid/tags/continue_tag_test.rb b/test/integration/tags/continue_tag_test.rb similarity index 100% rename from test/liquid/tags/continue_tag_test.rb rename to test/integration/tags/continue_tag_test.rb diff --git a/test/liquid/tags/for_tag_test.rb b/test/integration/tags/for_tag_test.rb similarity index 97% rename from test/liquid/tags/for_tag_test.rb rename to test/integration/tags/for_tag_test.rb index 2f8d006..4dde8a4 100644 --- a/test/liquid/tags/for_tag_test.rb +++ b/test/integration/tags/for_tag_test.rb @@ -295,16 +295,6 @@ HERE assert_template_result(expected, template, assigns) end - def test_for_nodelist - template = Liquid::Template.parse('{% for item in items %}FOR{% endfor %}') - assert_equal ['FOR'], template.root.nodelist[0].nodelist - end - - def test_for_else_nodelist - template = Liquid::Template.parse('{% for item in items %}FOR{% else %}ELSE{% endfor %}') - assert_equal ['FOR', 'ELSE'], template.root.nodelist[0].nodelist - end - class LoaderDrop < Liquid::Drop attr_accessor :each_called, :load_slice_called diff --git a/test/liquid/tags/if_else_tag_test.rb b/test/integration/tags/if_else_tag_test.rb similarity index 97% rename from test/liquid/tags/if_else_tag_test.rb rename to test/integration/tags/if_else_tag_test.rb index 61c4bc8..afd12bd 100644 --- a/test/liquid/tags/if_else_tag_test.rb +++ b/test/integration/tags/if_else_tag_test.rb @@ -158,14 +158,9 @@ class IfElseTagTest < Test::Unit::TestCase %({% if 'gnomeslab-and-or-liquid' contains 'gnomeslab-and-or-liquid' %}yes{% endif %})) end - def test_if_nodelist - template = Liquid::Template.parse('{% if true %}IF{% else %}ELSE{% endif %}') - assert_equal ['IF', 'ELSE'], template.root.nodelist[0].nodelist - end - def test_operators_are_whitelisted assert_raise(SyntaxError) do assert_template_result('', %({% if 1 or throw or or 1 %}yes{% endif %})) end end -end # IfElseTest +end diff --git a/test/liquid/tags/include_tag_test.rb b/test/integration/tags/include_tag_test.rb similarity index 100% rename from test/liquid/tags/include_tag_test.rb rename to test/integration/tags/include_tag_test.rb diff --git a/test/liquid/tags/increment_tag_test.rb b/test/integration/tags/increment_tag_test.rb similarity index 100% rename from test/liquid/tags/increment_tag_test.rb rename to test/integration/tags/increment_tag_test.rb diff --git a/test/liquid/tags/raw_tag_test.rb b/test/integration/tags/raw_tag_test.rb similarity index 100% rename from test/liquid/tags/raw_tag_test.rb rename to test/integration/tags/raw_tag_test.rb diff --git a/test/liquid/tags/standard_tag_test.rb b/test/integration/tags/standard_tag_test.rb similarity index 98% rename from test/liquid/tags/standard_tag_test.rb rename to test/integration/tags/standard_tag_test.rb index e4e5e85..acb9970 100644 --- a/test/liquid/tags/standard_tag_test.rb +++ b/test/integration/tags/standard_tag_test.rb @@ -3,12 +3,6 @@ require 'test_helper' class StandardTagTest < Test::Unit::TestCase include Liquid - def test_tag - tag = Tag.parse('tag', [], [], {}) - assert_equal 'liquid::tag', tag.name - assert_equal '', tag.render(Context.new) - end - 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...') diff --git a/test/liquid/tags/statements_test.rb b/test/integration/tags/statements_test.rb similarity index 100% rename from test/liquid/tags/statements_test.rb rename to test/integration/tags/statements_test.rb diff --git a/test/liquid/tags/table_row_test.rb b/test/integration/tags/table_row_test.rb similarity index 100% rename from test/liquid/tags/table_row_test.rb rename to test/integration/tags/table_row_test.rb diff --git a/test/liquid/tags/unless_else_tag_test.rb b/test/integration/tags/unless_else_tag_test.rb similarity index 100% rename from test/liquid/tags/unless_else_tag_test.rb rename to test/integration/tags/unless_else_tag_test.rb diff --git a/test/liquid/template_test.rb b/test/integration/template_test.rb similarity index 77% rename from test/liquid/template_test.rb rename to test/integration/template_test.rb index f58f8b8..be853c7 100644 --- a/test/liquid/template_test.rb +++ b/test/integration/template_test.rb @@ -25,26 +25,6 @@ end 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 - - 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 - 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 - 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! @@ -157,18 +137,4 @@ class TemplateTest < Test::Unit::TestCase assert_equal 'bar', t.parse('{{bar}}').render!(drop) assert_equal 'haha', t.parse("{{baz}}").render!(drop) end - - def test_sets_default_localization_in_document - t = Template.new - t.parse('') - assert_instance_of I18n, t.root.options[:locale] - end - - def test_sets_default_localization_in_context_with_quick_initialization - t = Template.new - t.parse('{{foo}}', :locale => I18n.new(fixture("en_locale.yml"))) - - assert_instance_of I18n, t.root.options[:locale] - assert_equal fixture("en_locale.yml"), t.root.options[:locale].path - end end diff --git a/test/integration/variable_test.rb b/test/integration/variable_test.rb new file mode 100644 index 0000000..0bcfb25 --- /dev/null +++ b/test/integration/variable_test.rb @@ -0,0 +1,68 @@ +require 'test_helper' + +class VariableTest < Test::Unit::TestCase + include Liquid + + def test_simple_variable + template = Template.parse(%|{{test}}|) + assert_equal 'worked', template.render!('test' => 'worked') + assert_equal 'worked wonderfully', template.render!('test' => 'worked wonderfully') + end + + def test_simple_with_whitespaces + template = Template.parse(%| {{ test }} |) + assert_equal ' worked ', template.render!('test' => 'worked') + assert_equal ' worked wonderfully ', template.render!('test' => 'worked wonderfully') + end + + def test_ignore_unknown + template = Template.parse(%|{{ test }}|) + assert_equal '', template.render! + end + + def test_hash_scoping + 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' + assert_equal 'worked', template.render! + end + + def test_reuse_parsed_template + template = Template.parse(%|{{ greeting }} {{ name }}|) + template.assigns['greeting'] = 'Goodbye' + assert_equal 'Hello Tobi', template.render!('greeting' => 'Hello', 'name' => 'Tobi') + assert_equal 'Hello ', template.render!('greeting' => 'Hello', 'unknown' => 'Tobi') + assert_equal 'Hello Brian', template.render!('greeting' => 'Hello', 'name' => 'Brian') + assert_equal 'Goodbye Brian', template.render!('name' => 'Brian') + assert_equal({'greeting'=>'Goodbye'}, template.assigns) + end + + def test_assigns_not_polluted_from_template + template = Template.parse(%|{{ test }}{% assign test = 'bar' %}{{ test }}|) + template.assigns['test'] = 'baz' + assert_equal 'bazbar', template.render! + assert_equal 'bazbar', template.render! + assert_equal 'foobar', template.render!('test' => 'foo') + assert_equal 'bazbar', template.render! + end + + def test_hash_with_default_proc + template = Template.parse(%|Hello {{ test }}|) + assigns = Hash.new { |h,k| raise "Unknown variable '#{k}'" } + assigns['test'] = 'Tobi' + assert_equal 'Hello Tobi', template.render!(assigns) + assigns.delete('test') + e = assert_raises(RuntimeError) { + template.render!(assigns) + } + assert_equal "Unknown variable 'test'", e.message + end + + def test_multiline_variable + assert_equal 'worked', Template.parse("{{\ntest\n}}").render!('test' => 'worked') + end +end diff --git a/test/liquid/block_test.rb b/test/unit/block_unit_test.rb similarity index 97% rename from test/liquid/block_test.rb rename to test/unit/block_unit_test.rb index f4b4494..ca46474 100644 --- a/test/liquid/block_test.rb +++ b/test/unit/block_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class BlockTest < Test::Unit::TestCase +class BlockUnitTest < Test::Unit::TestCase include Liquid def test_blankspace diff --git a/test/liquid/condition_test.rb b/test/unit/condition_unit_test.rb similarity index 98% rename from test/liquid/condition_test.rb rename to test/unit/condition_unit_test.rb index 3e57897..c17bcf9 100644 --- a/test/liquid/condition_test.rb +++ b/test/unit/condition_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class ConditionTest < Test::Unit::TestCase +class ConditionUnitTest < Test::Unit::TestCase include Liquid def test_basic_condition diff --git a/test/liquid/context_test.rb b/test/unit/context_unit_test.rb similarity index 95% rename from test/liquid/context_test.rb rename to test/unit/context_unit_test.rb index b2af0df..8f4d6ed 100644 --- a/test/liquid/context_test.rb +++ b/test/unit/context_unit_test.rb @@ -63,7 +63,7 @@ class ArrayLike end end -class ContextTest < Test::Unit::TestCase +class ContextUnitTest < Test::Unit::TestCase include Liquid def setup @@ -162,24 +162,6 @@ class ContextTest < Test::Unit::TestCase end - def test_override_global_filter - global = Module.new do - def notice(output) - "Global #{output}" - end - end - - local = Module.new do - def notice(output) - "Local #{output}" - end - end - - Template.register_filter(global) - assert_equal 'Global test', Template.parse("{{'test' | notice }}").render! - assert_equal 'Local test', Template.parse("{{'test' | notice }}").render!({}, :filters => [local]) - end - def test_only_intended_filters_make_it_there filter = Module.new do diff --git a/test/liquid/file_system_test.rb b/test/unit/file_system_unit_test.rb similarity index 95% rename from test/liquid/file_system_test.rb rename to test/unit/file_system_unit_test.rb index 4b2a2f1..31bccb2 100644 --- a/test/liquid/file_system_test.rb +++ b/test/unit/file_system_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class FileSystemTest < Test::Unit::TestCase +class FileSystemUnitTest < Test::Unit::TestCase include Liquid def test_default diff --git a/test/liquid/i18n_test.rb b/test/unit/i18n_unit_test.rb similarity index 95% rename from test/liquid/i18n_test.rb rename to test/unit/i18n_unit_test.rb index 82e6f38..cc05400 100644 --- a/test/liquid/i18n_test.rb +++ b/test/unit/i18n_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class I18nTest < Test::Unit::TestCase +class I18nUnitTest < Test::Unit::TestCase include Liquid def setup diff --git a/test/liquid/lexer_test.rb b/test/unit/lexer_unit_test.rb similarity index 97% rename from test/liquid/lexer_test.rb rename to test/unit/lexer_unit_test.rb index 6027263..7ff2bb1 100644 --- a/test/liquid/lexer_test.rb +++ b/test/unit/lexer_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class LexerTest < Test::Unit::TestCase +class LexerUnitTest < Test::Unit::TestCase include Liquid def test_strings diff --git a/test/liquid/module_ex_test.rb b/test/unit/module_ex_unit_test.rb similarity index 97% rename from test/liquid/module_ex_test.rb rename to test/unit/module_ex_unit_test.rb index 88562c8..5cefb7f 100644 --- a/test/liquid/module_ex_test.rb +++ b/test/unit/module_ex_unit_test.rb @@ -36,7 +36,7 @@ class TestClassC::LiquidDropClass end end -class ModuleExTest < Test::Unit::TestCase +class ModuleExUnitTest < Test::Unit::TestCase include Liquid def setup diff --git a/test/liquid/parser_test.rb b/test/unit/parser_unit_test.rb similarity index 98% rename from test/liquid/parser_test.rb rename to test/unit/parser_unit_test.rb index a9f848f..b10a176 100644 --- a/test/liquid/parser_test.rb +++ b/test/unit/parser_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class ParserTest < Test::Unit::TestCase +class ParserUnitTest < Test::Unit::TestCase include Liquid def test_consume diff --git a/test/liquid/regexp_test.rb b/test/unit/regexp_unit_test.rb similarity index 97% rename from test/liquid/regexp_test.rb rename to test/unit/regexp_unit_test.rb index 667d5bb..808c28d 100644 --- a/test/liquid/regexp_test.rb +++ b/test/unit/regexp_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class RegexpTest < Test::Unit::TestCase +class RegexpUnitTest < Test::Unit::TestCase include Liquid def test_empty diff --git a/test/liquid/strainer_test.rb b/test/unit/strainer_unit_test.rb similarity index 97% rename from test/liquid/strainer_test.rb rename to test/unit/strainer_unit_test.rb index d302557..aa0296c 100644 --- a/test/liquid/strainer_test.rb +++ b/test/unit/strainer_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class StrainerTest < Test::Unit::TestCase +class StrainerUnitTest < Test::Unit::TestCase include Liquid module AccessScopeFilters diff --git a/test/unit/tag_unit_test.rb b/test/unit/tag_unit_test.rb new file mode 100644 index 0000000..e9111aa --- /dev/null +++ b/test/unit/tag_unit_test.rb @@ -0,0 +1,11 @@ +require 'test_helper' + +class TagUnitTest < Test::Unit::TestCase + include Liquid + + def test_tag + tag = Tag.parse('tag', [], [], {}) + assert_equal 'liquid::tag', tag.name + assert_equal '', tag.render(Context.new) + end +end diff --git a/test/liquid/tags/case_tag_test.rb b/test/unit/tags/case_tag_unit_test.rb similarity index 81% rename from test/liquid/tags/case_tag_test.rb rename to test/unit/tags/case_tag_unit_test.rb index f117856..ddb8d83 100644 --- a/test/liquid/tags/case_tag_test.rb +++ b/test/unit/tags/case_tag_unit_test.rb @@ -1,10 +1,10 @@ require 'test_helper' -class CaseTagTest < Test::Unit::TestCase +class CaseTagUnitTest < Test::Unit::TestCase include Liquid def test_case_nodelist template = Liquid::Template.parse('{% case var %}{% when true %}WHEN{% else %}ELSE{% endcase %}') assert_equal ['WHEN', 'ELSE'], template.root.nodelist[0].nodelist end -end # CaseTest +end diff --git a/test/unit/tags/for_tag_unit_test.rb b/test/unit/tags/for_tag_unit_test.rb new file mode 100644 index 0000000..07ac184 --- /dev/null +++ b/test/unit/tags/for_tag_unit_test.rb @@ -0,0 +1,13 @@ +require 'test_helper' + +class ForTagUnitTest < Test::Unit::TestCase + def test_for_nodelist + template = Liquid::Template.parse('{% for item in items %}FOR{% endfor %}') + assert_equal ['FOR'], template.root.nodelist[0].nodelist + end + + def test_for_else_nodelist + template = Liquid::Template.parse('{% for item in items %}FOR{% else %}ELSE{% endfor %}') + assert_equal ['FOR', 'ELSE'], template.root.nodelist[0].nodelist + end +end diff --git a/test/unit/tags/if_tag_unit_test.rb b/test/unit/tags/if_tag_unit_test.rb new file mode 100644 index 0000000..209e3c2 --- /dev/null +++ b/test/unit/tags/if_tag_unit_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class IfTagUnitTest < Test::Unit::TestCase + def test_if_nodelist + template = Liquid::Template.parse('{% if true %}IF{% else %}ELSE{% endif %}') + assert_equal ['IF', 'ELSE'], template.root.nodelist[0].nodelist + end +end diff --git a/test/unit/template_unit_test.rb b/test/unit/template_unit_test.rb new file mode 100644 index 0000000..3186a45 --- /dev/null +++ b/test/unit/template_unit_test.rb @@ -0,0 +1,19 @@ +require 'test_helper' + +class TemplateUnitTest < Test::Unit::TestCase + include Liquid + + def test_sets_default_localization_in_document + t = Template.new + t.parse('') + assert_instance_of I18n, t.root.options[:locale] + end + + def test_sets_default_localization_in_context_with_quick_initialization + t = Template.new + t.parse('{{foo}}', :locale => I18n.new(fixture("en_locale.yml"))) + + assert_instance_of I18n, t.root.options[:locale] + assert_equal fixture("en_locale.yml"), t.root.options[:locale].path + end +end diff --git a/test/unit/tokenizer_unit_test.rb b/test/unit/tokenizer_unit_test.rb new file mode 100644 index 0000000..e8f4a0d --- /dev/null +++ b/test/unit/tokenizer_unit_test.rb @@ -0,0 +1,29 @@ +require 'test_helper' + +class TokenizerTest < Test::Unit::TestCase + def test_tokenize_strings + assert_equal [' '], tokenize(' ') + assert_equal ['hello world'], tokenize('hello world') + end + + def test_tokenize_variables + assert_equal ['{{funk}}'], tokenize('{{funk}}') + assert_equal [' ', '{{funk}}', ' '], tokenize(' {{funk}} ') + assert_equal [' ', '{{funk}}', ' ', '{{so}}', ' ', '{{brother}}', ' '], tokenize(' {{funk}} {{so}} {{brother}} ') + assert_equal [' ', '{{ funk }}', ' '], tokenize(' {{ funk }} ') + end + + def test_tokenize_blocks + assert_equal ['{%comment%}'], tokenize('{%comment%}') + assert_equal [' ', '{%comment%}', ' '], tokenize(' {%comment%} ') + + assert_equal [' ', '{%comment%}', ' ', '{%endcomment%}', ' '], tokenize(' {%comment%} {%endcomment%} ') + assert_equal [' ', '{% comment %}', ' ', '{% endcomment %}', ' '], tokenize(" {% comment %} {% endcomment %} ") + end + + private + + def tokenize(source) + Liquid::Template.new.send(:tokenize, source) + end +end diff --git a/test/liquid/variable_test.rb b/test/unit/variable_unit_test.rb similarity index 63% rename from test/liquid/variable_test.rb rename to test/unit/variable_unit_test.rb index 00210df..4c1cfbc 100644 --- a/test/liquid/variable_test.rb +++ b/test/unit/variable_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class VariableTest < Test::Unit::TestCase +class VariableUnitTest < Test::Unit::TestCase include Liquid def test_variable @@ -134,71 +134,3 @@ class VariableTest < Test::Unit::TestCase end end end - - -class VariableResolutionTest < Test::Unit::TestCase - include Liquid - - def test_simple_variable - template = Template.parse(%|{{test}}|) - assert_equal 'worked', template.render!('test' => 'worked') - assert_equal 'worked wonderfully', template.render!('test' => 'worked wonderfully') - end - - def test_simple_with_whitespaces - template = Template.parse(%| {{ test }} |) - assert_equal ' worked ', template.render!('test' => 'worked') - assert_equal ' worked wonderfully ', template.render!('test' => 'worked wonderfully') - end - - def test_ignore_unknown - template = Template.parse(%|{{ test }}|) - assert_equal '', template.render! - end - - def test_hash_scoping - 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' - assert_equal 'worked', template.render! - end - - def test_reuse_parsed_template - template = Template.parse(%|{{ greeting }} {{ name }}|) - template.assigns['greeting'] = 'Goodbye' - assert_equal 'Hello Tobi', template.render!('greeting' => 'Hello', 'name' => 'Tobi') - assert_equal 'Hello ', template.render!('greeting' => 'Hello', 'unknown' => 'Tobi') - assert_equal 'Hello Brian', template.render!('greeting' => 'Hello', 'name' => 'Brian') - assert_equal 'Goodbye Brian', template.render!('name' => 'Brian') - assert_equal({'greeting'=>'Goodbye'}, template.assigns) - end - - def test_assigns_not_polluted_from_template - template = Template.parse(%|{{ test }}{% assign test = 'bar' %}{{ test }}|) - template.assigns['test'] = 'baz' - assert_equal 'bazbar', template.render! - assert_equal 'bazbar', template.render! - assert_equal 'foobar', template.render!('test' => 'foo') - assert_equal 'bazbar', template.render! - end - - def test_hash_with_default_proc - template = Template.parse(%|Hello {{ test }}|) - assigns = Hash.new { |h,k| raise "Unknown variable '#{k}'" } - assigns['test'] = 'Tobi' - assert_equal 'Hello Tobi', template.render!(assigns) - assigns.delete('test') - e = assert_raises(RuntimeError) { - template.render!(assigns) - } - assert_equal "Unknown variable 'test'", e.message - end - - def test_multiline_variable - assert_equal 'worked', Template.parse("{{\ntest\n}}").render!('test' => 'worked') - end -end # VariableTest