liquid 2.6.3 → 3.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +42 -13
  3. data/README.md +27 -2
  4. data/lib/liquid.rb +11 -11
  5. data/lib/liquid/block.rb +75 -45
  6. data/lib/liquid/condition.rb +15 -11
  7. data/lib/liquid/context.rb +68 -29
  8. data/lib/liquid/document.rb +3 -3
  9. data/lib/liquid/drop.rb +17 -1
  10. data/lib/liquid/file_system.rb +17 -6
  11. data/lib/liquid/i18n.rb +39 -0
  12. data/lib/liquid/interrupts.rb +1 -1
  13. data/lib/liquid/lexer.rb +51 -0
  14. data/lib/liquid/locales/en.yml +22 -0
  15. data/lib/liquid/parser.rb +90 -0
  16. data/lib/liquid/standardfilters.rb +115 -52
  17. data/lib/liquid/strainer.rb +14 -4
  18. data/lib/liquid/tag.rb +42 -7
  19. data/lib/liquid/tags/assign.rb +10 -8
  20. data/lib/liquid/tags/break.rb +1 -1
  21. data/lib/liquid/tags/capture.rb +10 -8
  22. data/lib/liquid/tags/case.rb +13 -13
  23. data/lib/liquid/tags/comment.rb +9 -2
  24. data/lib/liquid/tags/continue.rb +1 -4
  25. data/lib/liquid/tags/cycle.rb +5 -7
  26. data/lib/liquid/tags/decrement.rb +3 -4
  27. data/lib/liquid/tags/for.rb +69 -36
  28. data/lib/liquid/tags/if.rb +52 -25
  29. data/lib/liquid/tags/ifchanged.rb +2 -2
  30. data/lib/liquid/tags/include.rb +8 -7
  31. data/lib/liquid/tags/increment.rb +4 -8
  32. data/lib/liquid/tags/raw.rb +3 -3
  33. data/lib/liquid/tags/table_row.rb +73 -0
  34. data/lib/liquid/tags/unless.rb +2 -4
  35. data/lib/liquid/template.rb +69 -10
  36. data/lib/liquid/utils.rb +13 -4
  37. data/lib/liquid/variable.rb +59 -8
  38. data/lib/liquid/version.rb +1 -1
  39. data/test/fixtures/en_locale.yml +9 -0
  40. data/test/{liquid → integration}/assign_test.rb +6 -0
  41. data/test/integration/blank_test.rb +106 -0
  42. data/test/{liquid → integration}/capture_test.rb +2 -2
  43. data/test/integration/context_test.rb +33 -0
  44. data/test/integration/drop_test.rb +245 -0
  45. data/test/{liquid → integration}/error_handling_test.rb +31 -2
  46. data/test/{liquid → integration}/filter_test.rb +7 -7
  47. data/test/{liquid → integration}/hash_ordering_test.rb +0 -0
  48. data/test/{liquid → integration}/output_test.rb +12 -12
  49. data/test/integration/parsing_quirks_test.rb +94 -0
  50. data/test/{liquid → integration}/security_test.rb +9 -9
  51. data/test/{liquid → integration}/standard_filter_test.rb +103 -33
  52. data/test/{liquid → integration}/tags/break_tag_test.rb +0 -0
  53. data/test/{liquid → integration}/tags/continue_tag_test.rb +0 -0
  54. data/test/{liquid → integration}/tags/for_tag_test.rb +78 -0
  55. data/test/{liquid → integration}/tags/if_else_tag_test.rb +1 -1
  56. data/test/integration/tags/include_tag_test.rb +212 -0
  57. data/test/{liquid → integration}/tags/increment_tag_test.rb +0 -0
  58. data/test/{liquid → integration}/tags/raw_tag_test.rb +1 -0
  59. data/test/{liquid → integration}/tags/standard_tag_test.rb +24 -22
  60. data/test/integration/tags/statements_test.rb +113 -0
  61. data/test/{liquid/tags/html_tag_test.rb → integration/tags/table_row_test.rb} +5 -5
  62. data/test/{liquid → integration}/tags/unless_else_tag_test.rb +0 -0
  63. data/test/{liquid → integration}/template_test.rb +66 -42
  64. data/test/integration/variable_test.rb +72 -0
  65. data/test/test_helper.rb +32 -7
  66. data/test/{liquid/block_test.rb → unit/block_unit_test.rb} +1 -1
  67. data/test/{liquid/condition_test.rb → unit/condition_unit_test.rb} +19 -1
  68. data/test/{liquid/context_test.rb → unit/context_unit_test.rb} +27 -19
  69. data/test/{liquid/file_system_test.rb → unit/file_system_unit_test.rb} +7 -1
  70. data/test/unit/i18n_unit_test.rb +37 -0
  71. data/test/unit/lexer_unit_test.rb +48 -0
  72. data/test/{liquid/module_ex_test.rb → unit/module_ex_unit_test.rb} +7 -7
  73. data/test/unit/parser_unit_test.rb +82 -0
  74. data/test/{liquid/regexp_test.rb → unit/regexp_unit_test.rb} +3 -3
  75. data/test/{liquid/strainer_test.rb → unit/strainer_unit_test.rb} +19 -1
  76. data/test/unit/tag_unit_test.rb +11 -0
  77. data/test/unit/tags/case_tag_unit_test.rb +10 -0
  78. data/test/unit/tags/for_tag_unit_test.rb +13 -0
  79. data/test/unit/tags/if_tag_unit_test.rb +8 -0
  80. data/test/unit/template_unit_test.rb +69 -0
  81. data/test/unit/tokenizer_unit_test.rb +29 -0
  82. data/test/{liquid/variable_test.rb → unit/variable_unit_test.rb} +17 -67
  83. metadata +117 -73
  84. data/lib/extras/liquid_view.rb +0 -51
  85. data/lib/liquid/htmltags.rb +0 -73
  86. data/test/liquid/drop_test.rb +0 -180
  87. data/test/liquid/parsing_quirks_test.rb +0 -52
  88. data/test/liquid/tags/include_tag_test.rb +0 -166
  89. data/test/liquid/tags/statements_test.rb +0 -134
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class FileSystemTest < Test::Unit::TestCase
3
+ class FileSystemUnitTest < Test::Unit::TestCase
4
4
  include Liquid
5
5
 
6
6
  def test_default
@@ -26,4 +26,10 @@ class FileSystemTest < Test::Unit::TestCase
26
26
  file_system.full_path("/etc/passwd")
27
27
  end
28
28
  end
29
+
30
+ def test_custom_template_filename_patterns
31
+ file_system = Liquid::LocalFileSystem.new("/some/path", "%s.html")
32
+ assert_equal "/some/path/mypartial.html" , file_system.full_path("mypartial")
33
+ assert_equal "/some/path/dir/mypartial.html", file_system.full_path("dir/mypartial")
34
+ end
29
35
  end # FileSystemTest
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+ class I18nUnitTest < Test::Unit::TestCase
4
+ include Liquid
5
+
6
+ def setup
7
+ @i18n = I18n.new(fixture("en_locale.yml"))
8
+ end
9
+
10
+ def test_simple_translate_string
11
+ assert_equal "less is more", @i18n.translate("simple")
12
+ end
13
+
14
+ def test_nested_translate_string
15
+ assert_equal "something wasn't right", @i18n.translate("errors.syntax.oops")
16
+ end
17
+
18
+ def test_single_string_interpolation
19
+ assert_equal "something different", @i18n.translate("whatever", :something => "different")
20
+ end
21
+
22
+ # def test_raises_translation_error_on_undefined_interpolation_key
23
+ # assert_raise I18n::TranslationError do
24
+ # @i18n.translate("whatever", :oopstypos => "yes")
25
+ # end
26
+ # end
27
+
28
+ def test_raises_unknown_translation
29
+ assert_raise I18n::TranslationError do
30
+ @i18n.translate("doesnt_exist")
31
+ end
32
+ end
33
+
34
+ def test_sets_default_path_to_en
35
+ assert_equal I18n::DEFAULT_LOCALE, I18n.new.path
36
+ end
37
+ end
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ class LexerUnitTest < Test::Unit::TestCase
4
+ include Liquid
5
+
6
+ def test_strings
7
+ tokens = Lexer.new(%! 'this is a test""' "wat 'lol'"!).tokenize
8
+ assert_equal [[:string,%!'this is a test""'!], [:string, %!"wat 'lol'"!], [:end_of_string]], tokens
9
+ end
10
+
11
+ def test_integer
12
+ tokens = Lexer.new('hi 50').tokenize
13
+ assert_equal [[:id,'hi'], [:number, '50'], [:end_of_string]], tokens
14
+ end
15
+
16
+ def test_float
17
+ tokens = Lexer.new('hi 5.0').tokenize
18
+ assert_equal [[:id,'hi'], [:number, '5.0'], [:end_of_string]], tokens
19
+ end
20
+
21
+ def test_comparison
22
+ tokens = Lexer.new('== <> contains').tokenize
23
+ assert_equal [[:comparison,'=='], [:comparison, '<>'], [:comparison, 'contains'], [:end_of_string]], tokens
24
+ end
25
+
26
+ def test_specials
27
+ tokens = Lexer.new('| .:').tokenize
28
+ assert_equal [[:pipe, '|'], [:dot, '.'], [:colon, ':'], [:end_of_string]], tokens
29
+ tokens = Lexer.new('[,]').tokenize
30
+ assert_equal [[:open_square, '['], [:comma, ','], [:close_square, ']'], [:end_of_string]], tokens
31
+ end
32
+
33
+ def test_fancy_identifiers
34
+ tokens = Lexer.new('hi! five?').tokenize
35
+ assert_equal [[:id,'hi!'], [:id, 'five?'], [:end_of_string]], tokens
36
+ end
37
+
38
+ def test_whitespace
39
+ tokens = Lexer.new("five|\n\t ==").tokenize
40
+ assert_equal [[:id,'five'], [:pipe, '|'], [:comparison, '=='], [:end_of_string]], tokens
41
+ end
42
+
43
+ def test_unexpected_character
44
+ assert_raises(SyntaxError) do
45
+ Lexer.new("%").tokenize
46
+ end
47
+ end
48
+ end
@@ -36,7 +36,7 @@ class TestClassC::LiquidDropClass
36
36
  end
37
37
  end
38
38
 
39
- class ModuleExTest < Test::Unit::TestCase
39
+ class ModuleExUnitTest < Test::Unit::TestCase
40
40
  include Liquid
41
41
 
42
42
  def setup
@@ -77,11 +77,11 @@ class ModuleExTest < Test::Unit::TestCase
77
77
  end
78
78
 
79
79
  def test_should_use_regular_objects_as_drops
80
- assert_equal 'allowedA', Liquid::Template.parse("{{ a.allowedA }}").render('a'=>@a)
81
- assert_equal 'allowedB', Liquid::Template.parse("{{ a.chainedB.allowedB }}").render('a'=>@a)
82
- assert_equal 'allowedC', Liquid::Template.parse("{{ a.chainedB.chainedC.allowedC }}").render('a'=>@a)
83
- assert_equal 'another_allowedC', Liquid::Template.parse("{{ a.chainedB.chainedC.another_allowedC }}").render('a'=>@a)
84
- assert_equal '', Liquid::Template.parse("{{ a.restricted }}").render('a'=>@a)
85
- assert_equal '', Liquid::Template.parse("{{ a.unknown }}").render('a'=>@a)
80
+ assert_template_result 'allowedA', "{{ a.allowedA }}", 'a'=>@a
81
+ assert_template_result 'allowedB', "{{ a.chainedB.allowedB }}", 'a'=>@a
82
+ assert_template_result 'allowedC', "{{ a.chainedB.chainedC.allowedC }}", 'a'=>@a
83
+ assert_template_result 'another_allowedC', "{{ a.chainedB.chainedC.another_allowedC }}", 'a'=>@a
84
+ assert_template_result '', "{{ a.restricted }}", 'a'=>@a
85
+ assert_template_result '', "{{ a.unknown }}", 'a'=>@a
86
86
  end
87
87
  end # ModuleExTest
@@ -0,0 +1,82 @@
1
+ require 'test_helper'
2
+
3
+ class ParserUnitTest < Test::Unit::TestCase
4
+ include Liquid
5
+
6
+ def test_consume
7
+ p = Parser.new("wat: 7")
8
+ assert_equal 'wat', p.consume(:id)
9
+ assert_equal ':', p.consume(:colon)
10
+ assert_equal '7', p.consume(:number)
11
+ end
12
+
13
+ def test_jump
14
+ p = Parser.new("wat: 7")
15
+ p.jump(2)
16
+ assert_equal '7', p.consume(:number)
17
+ end
18
+
19
+ def test_consume?
20
+ p = Parser.new("wat: 7")
21
+ assert_equal 'wat', p.consume?(:id)
22
+ assert_equal false, p.consume?(:dot)
23
+ assert_equal ':', p.consume(:colon)
24
+ assert_equal '7', p.consume?(:number)
25
+ end
26
+
27
+ def test_id?
28
+ p = Parser.new("wat 6 Peter Hegemon")
29
+ assert_equal 'wat', p.id?('wat')
30
+ assert_equal false, p.id?('endgame')
31
+ assert_equal '6', p.consume(:number)
32
+ assert_equal 'Peter', p.id?('Peter')
33
+ assert_equal false, p.id?('Achilles')
34
+ end
35
+
36
+ def test_look
37
+ p = Parser.new("wat 6 Peter Hegemon")
38
+ assert_equal true, p.look(:id)
39
+ assert_equal 'wat', p.consume(:id)
40
+ assert_equal false, p.look(:comparison)
41
+ assert_equal true, p.look(:number)
42
+ assert_equal true, p.look(:id, 1)
43
+ assert_equal false, p.look(:number, 1)
44
+ end
45
+
46
+ def test_expressions
47
+ p = Parser.new("hi.there hi[5].! hi.there.bob")
48
+ assert_equal 'hi.there', p.expression
49
+ assert_equal 'hi[5].!', p.expression
50
+ assert_equal 'hi.there.bob', p.expression
51
+
52
+ p = Parser.new("567 6.0 'lol' \"wut\"")
53
+ assert_equal '567', p.expression
54
+ assert_equal '6.0', p.expression
55
+ assert_equal "'lol'", p.expression
56
+ assert_equal '"wut"', p.expression
57
+ end
58
+
59
+ def test_ranges
60
+ p = Parser.new("(5..7) (1.5..9.6) (young..old) (hi[5].wat..old)")
61
+ assert_equal '(5..7)', p.expression
62
+ assert_equal '(1.5..9.6)', p.expression
63
+ assert_equal '(young..old)', p.expression
64
+ assert_equal '(hi[5].wat..old)', p.expression
65
+ end
66
+
67
+ def test_arguments
68
+ p = Parser.new("filter: hi.there[5], keyarg: 7")
69
+ assert_equal 'filter', p.consume(:id)
70
+ assert_equal ':', p.consume(:colon)
71
+ assert_equal 'hi.there[5]', p.argument
72
+ assert_equal ',', p.consume(:comma)
73
+ assert_equal 'keyarg: 7', p.argument
74
+ end
75
+
76
+ def test_invalid_expression
77
+ assert_raises(SyntaxError) do
78
+ p = Parser.new("==")
79
+ p.expression
80
+ end
81
+ end
82
+ end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class RegexpTest < Test::Unit::TestCase
3
+ class RegexpUnitTest < Test::Unit::TestCase
4
4
  include Liquid
5
5
 
6
6
  def test_empty
@@ -21,11 +21,11 @@ class RegexpTest < Test::Unit::TestCase
21
21
  assert_equal ['<style', 'class="hello">', '</style>'], %|<style class="hello">' </style>|.scan(QuotedFragment)
22
22
  end
23
23
 
24
- def test_quoted_words
24
+ def test_double_quoted_words
25
25
  assert_equal ['arg1', 'arg2', '"arg 3"'], 'arg1 arg2 "arg 3"'.scan(QuotedFragment)
26
26
  end
27
27
 
28
- def test_quoted_words
28
+ def test_single_quoted_words
29
29
  assert_equal ['arg1', 'arg2', "'arg 3'"], 'arg1 arg2 \'arg 3\''.scan(QuotedFragment)
30
30
  end
31
31
 
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class StrainerTest < Test::Unit::TestCase
3
+ class StrainerUnitTest < Test::Unit::TestCase
4
4
  include Liquid
5
5
 
6
6
  module AccessScopeFilters
@@ -22,6 +22,13 @@ class StrainerTest < Test::Unit::TestCase
22
22
  assert_equal "public", strainer.invoke("public_filter")
23
23
  end
24
24
 
25
+ def test_stainer_raises_argument_error
26
+ strainer = Strainer.create(nil)
27
+ assert_raises(Liquid::ArgumentError) do
28
+ strainer.invoke("public_filter", 1)
29
+ end
30
+ end
31
+
25
32
  def test_strainer_only_invokes_public_filter_methods
26
33
  strainer = Strainer.create(nil)
27
34
  assert_equal false, strainer.invokable?('__test__')
@@ -49,4 +56,15 @@ class StrainerTest < Test::Unit::TestCase
49
56
  assert_equal "has_method?", strainer.invoke("invoke", "has_method?", "invoke")
50
57
  end
51
58
 
59
+ def test_strainer_uses_a_class_cache_to_avoid_method_cache_invalidation
60
+ a, b = Module.new, Module.new
61
+ strainer = Strainer.create(nil, [a,b])
62
+ assert_kind_of Strainer, strainer
63
+ assert_kind_of a, strainer
64
+ assert_kind_of b, strainer
65
+ Strainer.class_variable_get(:@@filters).each do |m|
66
+ assert_kind_of m, strainer
67
+ end
68
+ end
69
+
52
70
  end # StrainerTest
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ class TagUnitTest < Test::Unit::TestCase
4
+ include Liquid
5
+
6
+ def test_tag
7
+ tag = Tag.parse('tag', [], [], {})
8
+ assert_equal 'liquid::tag', tag.name
9
+ assert_equal '', tag.render(Context.new)
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ class CaseTagUnitTest < Test::Unit::TestCase
4
+ include Liquid
5
+
6
+ def test_case_nodelist
7
+ template = Liquid::Template.parse('{% case var %}{% when true %}WHEN{% else %}ELSE{% endcase %}')
8
+ assert_equal ['WHEN', 'ELSE'], template.root.nodelist[0].nodelist
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+
3
+ class ForTagUnitTest < Test::Unit::TestCase
4
+ def test_for_nodelist
5
+ template = Liquid::Template.parse('{% for item in items %}FOR{% endfor %}')
6
+ assert_equal ['FOR'], template.root.nodelist[0].nodelist
7
+ end
8
+
9
+ def test_for_else_nodelist
10
+ template = Liquid::Template.parse('{% for item in items %}FOR{% else %}ELSE{% endfor %}')
11
+ assert_equal ['FOR', 'ELSE'], template.root.nodelist[0].nodelist
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class IfTagUnitTest < Test::Unit::TestCase
4
+ def test_if_nodelist
5
+ template = Liquid::Template.parse('{% if true %}IF{% else %}ELSE{% endif %}')
6
+ assert_equal ['IF', 'ELSE'], template.root.nodelist[0].nodelist
7
+ end
8
+ end
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+
3
+ class TemplateUnitTest < Test::Unit::TestCase
4
+ include Liquid
5
+
6
+ def test_sets_default_localization_in_document
7
+ t = Template.new
8
+ t.parse('')
9
+ assert_instance_of I18n, t.root.options[:locale]
10
+ end
11
+
12
+ def test_sets_default_localization_in_context_with_quick_initialization
13
+ t = Template.new
14
+ t.parse('{{foo}}', :locale => I18n.new(fixture("en_locale.yml")))
15
+
16
+ assert_instance_of I18n, t.root.options[:locale]
17
+ assert_equal fixture("en_locale.yml"), t.root.options[:locale].path
18
+ end
19
+
20
+ def test_with_cache_classes_tags_returns_the_same_class
21
+ original_cache_setting = Liquid.cache_classes
22
+ Liquid.cache_classes = true
23
+
24
+ original_klass = Class.new
25
+ Object.send(:const_set, :CustomTag, original_klass)
26
+ Template.register_tag('custom', CustomTag)
27
+
28
+ Object.send(:remove_const, :CustomTag)
29
+
30
+ new_klass = Class.new
31
+ Object.send(:const_set, :CustomTag, new_klass)
32
+
33
+ assert Template.tags['custom'].equal?(original_klass)
34
+ ensure
35
+ Object.send(:remove_const, :CustomTag)
36
+ Template.tags.delete('custom')
37
+ Liquid.cache_classes = original_cache_setting
38
+ end
39
+
40
+ def test_without_cache_classes_tags_reloads_the_class
41
+ original_cache_setting = Liquid.cache_classes
42
+ Liquid.cache_classes = false
43
+
44
+ original_klass = Class.new
45
+ Object.send(:const_set, :CustomTag, original_klass)
46
+ Template.register_tag('custom', CustomTag)
47
+
48
+ Object.send(:remove_const, :CustomTag)
49
+
50
+ new_klass = Class.new
51
+ Object.send(:const_set, :CustomTag, new_klass)
52
+
53
+ assert Template.tags['custom'].equal?(new_klass)
54
+ ensure
55
+ Object.send(:remove_const, :CustomTag)
56
+ Template.tags.delete('custom')
57
+ Liquid.cache_classes = original_cache_setting
58
+ end
59
+
60
+ class FakeTag; end
61
+
62
+ def test_tags_delete
63
+ Template.register_tag('fake', FakeTag)
64
+ assert_equal FakeTag, Template.tags['fake']
65
+
66
+ Template.tags.delete('fake')
67
+ assert_nil Template.tags['fake']
68
+ end
69
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ class TokenizerTest < Test::Unit::TestCase
4
+ def test_tokenize_strings
5
+ assert_equal [' '], tokenize(' ')
6
+ assert_equal ['hello world'], tokenize('hello world')
7
+ end
8
+
9
+ def test_tokenize_variables
10
+ assert_equal ['{{funk}}'], tokenize('{{funk}}')
11
+ assert_equal [' ', '{{funk}}', ' '], tokenize(' {{funk}} ')
12
+ assert_equal [' ', '{{funk}}', ' ', '{{so}}', ' ', '{{brother}}', ' '], tokenize(' {{funk}} {{so}} {{brother}} ')
13
+ assert_equal [' ', '{{ funk }}', ' '], tokenize(' {{ funk }} ')
14
+ end
15
+
16
+ def test_tokenize_blocks
17
+ assert_equal ['{%comment%}'], tokenize('{%comment%}')
18
+ assert_equal [' ', '{%comment%}', ' '], tokenize(' {%comment%} ')
19
+
20
+ assert_equal [' ', '{%comment%}', ' ', '{%endcomment%}', ' '], tokenize(' {%comment%} {%endcomment%} ')
21
+ assert_equal [' ', '{% comment %}', ' ', '{% endcomment %}', ' '], tokenize(" {% comment %} {% endcomment %} ")
22
+ end
23
+
24
+ private
25
+
26
+ def tokenize(source)
27
+ Liquid::Template.new.send(:tokenize, source)
28
+ end
29
+ end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class VariableTest < Test::Unit::TestCase
3
+ class VariableUnitTest < Test::Unit::TestCase
4
4
  include Liquid
5
5
 
6
6
  def test_variable
@@ -73,8 +73,14 @@ class VariableTest < Test::Unit::TestCase
73
73
  end
74
74
 
75
75
  def test_symbol
76
- var = Variable.new("http://disney.com/logo.gif | image: 'med' ")
77
- assert_equal 'http://disney.com/logo.gif', var.name
76
+ var = Variable.new("http://disney.com/logo.gif | image: 'med' ", :error_mode => :lax)
77
+ assert_equal "http://disney.com/logo.gif", var.name
78
+ assert_equal [["image",["'med'"]]], var.filters
79
+ end
80
+
81
+ def test_string_to_filter
82
+ var = Variable.new("'http://disney.com/logo.gif' | image: 'med' ")
83
+ assert_equal "'http://disney.com/logo.gif'", var.name
78
84
  assert_equal [["image",["'med'"]]], var.filters
79
85
  end
80
86
 
@@ -115,72 +121,16 @@ class VariableTest < Test::Unit::TestCase
115
121
  end
116
122
 
117
123
  def test_lax_filter_argument_parsing
118
- var = Variable.new(%! number_of_comments | pluralize: 'comment': 'comments' !)
124
+ var = Variable.new(%! number_of_comments | pluralize: 'comment': 'comments' !, :error_mode => :lax)
119
125
  assert_equal 'number_of_comments', var.name
120
126
  assert_equal [['pluralize',["'comment'","'comments'"]]], var.filters
121
127
  end
122
- end
123
-
124
-
125
- class VariableResolutionTest < Test::Unit::TestCase
126
- include Liquid
127
-
128
- def test_simple_variable
129
- template = Template.parse(%|{{test}}|)
130
- assert_equal 'worked', template.render('test' => 'worked')
131
- assert_equal 'worked wonderfully', template.render('test' => 'worked wonderfully')
132
- end
133
-
134
- def test_simple_with_whitespaces
135
- template = Template.parse(%| {{ test }} |)
136
- assert_equal ' worked ', template.render('test' => 'worked')
137
- assert_equal ' worked wonderfully ', template.render('test' => 'worked wonderfully')
138
- end
139
128
 
140
- def test_ignore_unknown
141
- template = Template.parse(%|{{ test }}|)
142
- assert_equal '', template.render
129
+ def test_strict_filter_argument_parsing
130
+ with_error_mode(:strict) do
131
+ assert_raises(SyntaxError) do
132
+ Variable.new(%! number_of_comments | pluralize: 'comment': 'comments' !)
133
+ end
134
+ end
143
135
  end
144
-
145
- def test_hash_scoping
146
- template = Template.parse(%|{{ test.test }}|)
147
- assert_equal 'worked', template.render('test' => {'test' => 'worked'})
148
- end
149
-
150
- def test_preset_assigns
151
- template = Template.parse(%|{{ test }}|)
152
- template.assigns['test'] = 'worked'
153
- assert_equal 'worked', template.render
154
- end
155
-
156
- def test_reuse_parsed_template
157
- template = Template.parse(%|{{ greeting }} {{ name }}|)
158
- template.assigns['greeting'] = 'Goodbye'
159
- assert_equal 'Hello Tobi', template.render('greeting' => 'Hello', 'name' => 'Tobi')
160
- assert_equal 'Hello ', template.render('greeting' => 'Hello', 'unknown' => 'Tobi')
161
- assert_equal 'Hello Brian', template.render('greeting' => 'Hello', 'name' => 'Brian')
162
- assert_equal 'Goodbye Brian', template.render('name' => 'Brian')
163
- assert_equal({'greeting'=>'Goodbye'}, template.assigns)
164
- end
165
-
166
- def test_assigns_not_polluted_from_template
167
- template = Template.parse(%|{{ test }}{% assign test = 'bar' %}{{ test }}|)
168
- template.assigns['test'] = 'baz'
169
- assert_equal 'bazbar', template.render
170
- assert_equal 'bazbar', template.render
171
- assert_equal 'foobar', template.render('test' => 'foo')
172
- assert_equal 'bazbar', template.render
173
- end
174
-
175
- def test_hash_with_default_proc
176
- template = Template.parse(%|Hello {{ test }}|)
177
- assigns = Hash.new { |h,k| raise "Unknown variable '#{k}'" }
178
- assigns['test'] = 'Tobi'
179
- assert_equal 'Hello Tobi', template.render!(assigns)
180
- assigns.delete('test')
181
- e = assert_raises(RuntimeError) {
182
- template.render!(assigns)
183
- }
184
- assert_equal "Unknown variable 'test'", e.message
185
- end
186
- end # VariableTest
136
+ end