liquid 2.6.3 → 3.0.0

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 (102) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +46 -13
  3. data/README.md +27 -2
  4. data/lib/liquid/block.rb +85 -51
  5. data/lib/liquid/block_body.rb +123 -0
  6. data/lib/liquid/condition.rb +26 -15
  7. data/lib/liquid/context.rb +106 -140
  8. data/lib/liquid/document.rb +3 -3
  9. data/lib/liquid/drop.rb +17 -1
  10. data/lib/liquid/errors.rb +50 -2
  11. data/lib/liquid/expression.rb +33 -0
  12. data/lib/liquid/file_system.rb +17 -6
  13. data/lib/liquid/i18n.rb +39 -0
  14. data/lib/liquid/interrupts.rb +1 -1
  15. data/lib/liquid/lexer.rb +51 -0
  16. data/lib/liquid/locales/en.yml +22 -0
  17. data/lib/liquid/parser.rb +90 -0
  18. data/lib/liquid/parser_switching.rb +31 -0
  19. data/lib/liquid/profiler/hooks.rb +23 -0
  20. data/lib/liquid/profiler.rb +159 -0
  21. data/lib/liquid/range_lookup.rb +22 -0
  22. data/lib/liquid/standardfilters.rb +143 -55
  23. data/lib/liquid/strainer.rb +14 -4
  24. data/lib/liquid/tag.rb +25 -9
  25. data/lib/liquid/tags/assign.rb +12 -9
  26. data/lib/liquid/tags/break.rb +1 -1
  27. data/lib/liquid/tags/capture.rb +10 -8
  28. data/lib/liquid/tags/case.rb +13 -13
  29. data/lib/liquid/tags/comment.rb +9 -2
  30. data/lib/liquid/tags/continue.rb +1 -4
  31. data/lib/liquid/tags/cycle.rb +5 -7
  32. data/lib/liquid/tags/decrement.rb +3 -4
  33. data/lib/liquid/tags/for.rb +69 -36
  34. data/lib/liquid/tags/if.rb +52 -25
  35. data/lib/liquid/tags/ifchanged.rb +3 -3
  36. data/lib/liquid/tags/include.rb +19 -8
  37. data/lib/liquid/tags/increment.rb +4 -8
  38. data/lib/liquid/tags/raw.rb +4 -7
  39. data/lib/liquid/tags/table_row.rb +73 -0
  40. data/lib/liquid/tags/unless.rb +2 -4
  41. data/lib/liquid/template.rb +124 -14
  42. data/lib/liquid/token.rb +18 -0
  43. data/lib/liquid/utils.rb +13 -4
  44. data/lib/liquid/variable.rb +103 -25
  45. data/lib/liquid/variable_lookup.rb +78 -0
  46. data/lib/liquid/version.rb +1 -1
  47. data/lib/liquid.rb +19 -11
  48. data/test/fixtures/en_locale.yml +9 -0
  49. data/test/{liquid → integration}/assign_test.rb +18 -1
  50. data/test/integration/blank_test.rb +106 -0
  51. data/test/{liquid → integration}/capture_test.rb +3 -3
  52. data/test/integration/context_test.rb +32 -0
  53. data/test/integration/drop_test.rb +271 -0
  54. data/test/integration/error_handling_test.rb +207 -0
  55. data/test/{liquid → integration}/filter_test.rb +11 -11
  56. data/test/integration/hash_ordering_test.rb +23 -0
  57. data/test/{liquid → integration}/output_test.rb +13 -13
  58. data/test/integration/parsing_quirks_test.rb +116 -0
  59. data/test/integration/render_profiling_test.rb +154 -0
  60. data/test/{liquid → integration}/security_test.rb +10 -10
  61. data/test/{liquid → integration}/standard_filter_test.rb +148 -32
  62. data/test/{liquid → integration}/tags/break_tag_test.rb +1 -1
  63. data/test/{liquid → integration}/tags/continue_tag_test.rb +1 -1
  64. data/test/{liquid → integration}/tags/for_tag_test.rb +80 -2
  65. data/test/{liquid → integration}/tags/if_else_tag_test.rb +24 -21
  66. data/test/integration/tags/include_tag_test.rb +234 -0
  67. data/test/{liquid → integration}/tags/increment_tag_test.rb +1 -1
  68. data/test/{liquid → integration}/tags/raw_tag_test.rb +2 -1
  69. data/test/{liquid → integration}/tags/standard_tag_test.rb +28 -26
  70. data/test/integration/tags/statements_test.rb +113 -0
  71. data/test/{liquid/tags/html_tag_test.rb → integration/tags/table_row_test.rb} +5 -5
  72. data/test/{liquid → integration}/tags/unless_else_tag_test.rb +1 -1
  73. data/test/{liquid → integration}/template_test.rb +81 -45
  74. data/test/integration/variable_test.rb +82 -0
  75. data/test/test_helper.rb +73 -20
  76. data/test/{liquid/block_test.rb → unit/block_unit_test.rb} +2 -5
  77. data/test/{liquid/condition_test.rb → unit/condition_unit_test.rb} +23 -1
  78. data/test/{liquid/context_test.rb → unit/context_unit_test.rb} +39 -25
  79. data/test/{liquid/file_system_test.rb → unit/file_system_unit_test.rb} +11 -5
  80. data/test/unit/i18n_unit_test.rb +37 -0
  81. data/test/unit/lexer_unit_test.rb +48 -0
  82. data/test/{liquid/module_ex_test.rb → unit/module_ex_unit_test.rb} +7 -7
  83. data/test/unit/parser_unit_test.rb +82 -0
  84. data/test/{liquid/regexp_test.rb → unit/regexp_unit_test.rb} +3 -3
  85. data/test/{liquid/strainer_test.rb → unit/strainer_unit_test.rb} +20 -1
  86. data/test/unit/tag_unit_test.rb +16 -0
  87. data/test/unit/tags/case_tag_unit_test.rb +10 -0
  88. data/test/unit/tags/for_tag_unit_test.rb +13 -0
  89. data/test/unit/tags/if_tag_unit_test.rb +8 -0
  90. data/test/unit/template_unit_test.rb +69 -0
  91. data/test/unit/tokenizer_unit_test.rb +38 -0
  92. data/test/unit/variable_unit_test.rb +139 -0
  93. metadata +135 -67
  94. data/lib/extras/liquid_view.rb +0 -51
  95. data/lib/liquid/htmltags.rb +0 -73
  96. data/test/liquid/drop_test.rb +0 -180
  97. data/test/liquid/error_handling_test.rb +0 -81
  98. data/test/liquid/hash_ordering_test.rb +0 -25
  99. data/test/liquid/parsing_quirks_test.rb +0 -52
  100. data/test/liquid/tags/include_tag_test.rb +0 -166
  101. data/test/liquid/tags/statements_test.rb +0 -134
  102. data/test/liquid/variable_test.rb +0 -186
@@ -1,52 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ParsingQuirksTest < Test::Unit::TestCase
4
- include Liquid
5
-
6
- def test_error_with_css
7
- text = %| div { font-weight: bold; } |
8
- template = Template.parse(text)
9
-
10
- assert_equal text, template.render
11
- assert_equal [String], template.root.nodelist.collect {|i| i.class}
12
- end
13
-
14
- def test_raise_on_single_close_bracet
15
- assert_raise(SyntaxError) do
16
- Template.parse("text {{method} oh nos!")
17
- end
18
- end
19
-
20
- def test_raise_on_label_and_no_close_bracets
21
- assert_raise(SyntaxError) do
22
- Template.parse("TEST {{ ")
23
- end
24
- end
25
-
26
- def test_raise_on_label_and_no_close_bracets_percent
27
- assert_raise(SyntaxError) do
28
- Template.parse("TEST {% ")
29
- end
30
- end
31
-
32
- def test_error_on_empty_filter
33
- assert_nothing_raised do
34
- Template.parse("{{test |a|b|}}")
35
- Template.parse("{{test}}")
36
- Template.parse("{{|test|}}")
37
- end
38
- end
39
-
40
- def test_meaningless_parens
41
- assigns = {'b' => 'bar', 'c' => 'baz'}
42
- markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false"
43
- assert_template_result(' YES ',"{% if #{markup} %} YES {% endif %}", assigns)
44
- end
45
-
46
- def test_unexpected_characters_silently_eat_logic
47
- markup = "true && false"
48
- assert_template_result(' YES ',"{% if #{markup} %} YES {% endif %}")
49
- markup = "false || true"
50
- assert_template_result('',"{% if #{markup} %} YES {% endif %}")
51
- end
52
- end # ParsingQuirksTest
@@ -1,166 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestFileSystem
4
- def read_template_file(template_path, context)
5
- case template_path
6
- when "product"
7
- "Product: {{ product.title }} "
8
-
9
- when "locale_variables"
10
- "Locale: {{echo1}} {{echo2}}"
11
-
12
- when "variant"
13
- "Variant: {{ variant.title }}"
14
-
15
- when "nested_template"
16
- "{% include 'header' %} {% include 'body' %} {% include 'footer' %}"
17
-
18
- when "body"
19
- "body {% include 'body_detail' %}"
20
-
21
- when "nested_product_template"
22
- "Product: {{ nested_product_template.title }} {%include 'details'%} "
23
-
24
- when "recursively_nested_template"
25
- "-{% include 'recursively_nested_template' %}"
26
-
27
- when "pick_a_source"
28
- "from TestFileSystem"
29
-
30
- else
31
- template_path
32
- end
33
- end
34
- end
35
-
36
- class OtherFileSystem
37
- def read_template_file(template_path, context)
38
- 'from OtherFileSystem'
39
- end
40
- end
41
-
42
- class CountingFileSystem
43
- attr_reader :count
44
- def read_template_file(template_path, context)
45
- @count ||= 0
46
- @count += 1
47
- 'from CountingFileSystem'
48
- end
49
- end
50
-
51
- class IncludeTagTest < Test::Unit::TestCase
52
- include Liquid
53
-
54
- def setup
55
- Liquid::Template.file_system = TestFileSystem.new
56
- end
57
-
58
- def test_include_tag_looks_for_file_system_in_registers_first
59
- assert_equal 'from OtherFileSystem',
60
- Template.parse("{% include 'pick_a_source' %}").render({}, :registers => {:file_system => OtherFileSystem.new})
61
- end
62
-
63
-
64
- def test_include_tag_with
65
- assert_equal "Product: Draft 151cm ",
66
- Template.parse("{% include 'product' with products[0] %}").render( "products" => [ {'title' => 'Draft 151cm'}, {'title' => 'Element 155cm'} ] )
67
- end
68
-
69
- def test_include_tag_with_default_name
70
- assert_equal "Product: Draft 151cm ",
71
- Template.parse("{% include 'product' %}").render( "product" => {'title' => 'Draft 151cm'} )
72
- end
73
-
74
- def test_include_tag_for
75
-
76
- assert_equal "Product: Draft 151cm Product: Element 155cm ",
77
- Template.parse("{% include 'product' for products %}").render( "products" => [ {'title' => 'Draft 151cm'}, {'title' => 'Element 155cm'} ] )
78
- end
79
-
80
- def test_include_tag_with_local_variables
81
- assert_equal "Locale: test123 ",
82
- Template.parse("{% include 'locale_variables' echo1: 'test123' %}").render
83
- end
84
-
85
- def test_include_tag_with_multiple_local_variables
86
- assert_equal "Locale: test123 test321",
87
- Template.parse("{% include 'locale_variables' echo1: 'test123', echo2: 'test321' %}").render
88
- end
89
-
90
- def test_include_tag_with_multiple_local_variables_from_context
91
- assert_equal "Locale: test123 test321",
92
- Template.parse("{% include 'locale_variables' echo1: echo1, echo2: more_echos.echo2 %}").render('echo1' => 'test123', 'more_echos' => { "echo2" => 'test321'})
93
- end
94
-
95
- def test_nested_include_tag
96
- assert_equal "body body_detail",
97
- Template.parse("{% include 'body' %}").render
98
-
99
- assert_equal "header body body_detail footer",
100
- Template.parse("{% include 'nested_template' %}").render
101
- end
102
-
103
- def test_nested_include_with_variable
104
-
105
- assert_equal "Product: Draft 151cm details ",
106
- Template.parse("{% include 'nested_product_template' with product %}").render("product" => {"title" => 'Draft 151cm'})
107
-
108
- assert_equal "Product: Draft 151cm details Product: Element 155cm details ",
109
- Template.parse("{% include 'nested_product_template' for products %}").render("products" => [{"title" => 'Draft 151cm'}, {"title" => 'Element 155cm'}])
110
-
111
- end
112
-
113
- def test_recursively_included_template_does_not_produce_endless_loop
114
-
115
- infinite_file_system = Class.new do
116
- def read_template_file(template_path, context)
117
- "-{% include 'loop' %}"
118
- end
119
- end
120
-
121
- Liquid::Template.file_system = infinite_file_system.new
122
-
123
- assert_raise(Liquid::StackLevelError) do
124
- Template.parse("{% include 'loop' %}").render!
125
- end
126
-
127
- end
128
-
129
- def test_backwards_compatability_support_for_overridden_read_template_file
130
- infinite_file_system = Class.new do
131
- def read_template_file(template_path) # testing only one argument here.
132
- "- hi mom"
133
- end
134
- end
135
-
136
- Liquid::Template.file_system = infinite_file_system.new
137
-
138
- Template.parse("{% include 'hi_mom' %}").render!
139
- end
140
-
141
- def test_dynamically_choosen_template
142
-
143
- assert_equal "Test123", Template.parse("{% include template %}").render("template" => 'Test123')
144
- assert_equal "Test321", Template.parse("{% include template %}").render("template" => 'Test321')
145
-
146
- assert_equal "Product: Draft 151cm ", Template.parse("{% include template for product %}").render("template" => 'product', 'product' => { 'title' => 'Draft 151cm'})
147
- end
148
-
149
- def test_include_tag_caches_second_read_of_same_partial
150
- file_system = CountingFileSystem.new
151
- assert_equal 'from CountingFileSystemfrom CountingFileSystem',
152
- Template.parse("{% include 'pick_a_source' %}{% include 'pick_a_source' %}").render({}, :registers => {:file_system => file_system})
153
- assert_equal 1, file_system.count
154
- end
155
-
156
- def test_include_tag_doesnt_cache_partials_across_renders
157
- file_system = CountingFileSystem.new
158
- assert_equal 'from CountingFileSystem',
159
- Template.parse("{% include 'pick_a_source' %}").render({}, :registers => {:file_system => file_system})
160
- assert_equal 1, file_system.count
161
-
162
- assert_equal 'from CountingFileSystem',
163
- Template.parse("{% include 'pick_a_source' %}").render({}, :registers => {:file_system => file_system})
164
- assert_equal 2, file_system.count
165
- end
166
- end # IncludeTagTest
@@ -1,134 +0,0 @@
1
- require 'test_helper'
2
-
3
- class StatementsTest < Test::Unit::TestCase
4
- include Liquid
5
-
6
- def test_true_eql_true
7
- text = %| {% if true == true %} true {% else %} false {% endif %} |
8
- expected = %| true |
9
- assert_equal expected, Template.parse(text).render
10
- end
11
-
12
- def test_true_not_eql_true
13
- text = %| {% if true != true %} true {% else %} false {% endif %} |
14
- expected = %| false |
15
- assert_equal expected, Template.parse(text).render
16
- end
17
-
18
- def test_true_lq_true
19
- text = %| {% if 0 > 0 %} true {% else %} false {% endif %} |
20
- expected = %| false |
21
- assert_equal expected, Template.parse(text).render
22
- end
23
-
24
- def test_one_lq_zero
25
- text = %| {% if 1 > 0 %} true {% else %} false {% endif %} |
26
- expected = %| true |
27
- assert_equal expected, Template.parse(text).render
28
- end
29
-
30
- def test_zero_lq_one
31
- text = %| {% if 0 < 1 %} true {% else %} false {% endif %} |
32
- expected = %| true |
33
- assert_equal expected, Template.parse(text).render
34
- end
35
-
36
- def test_zero_lq_or_equal_one
37
- text = %| {% if 0 <= 0 %} true {% else %} false {% endif %} |
38
- expected = %| true |
39
- assert_equal expected, Template.parse(text).render
40
- end
41
-
42
- def test_zero_lq_or_equal_one_involving_nil
43
- text = %| {% if null <= 0 %} true {% else %} false {% endif %} |
44
- expected = %| false |
45
- assert_equal expected, Template.parse(text).render
46
-
47
-
48
- text = %| {% if 0 <= null %} true {% else %} false {% endif %} |
49
- expected = %| false |
50
- assert_equal expected, Template.parse(text).render
51
- end
52
-
53
- def test_zero_lqq_or_equal_one
54
- text = %| {% if 0 >= 0 %} true {% else %} false {% endif %} |
55
- expected = %| true |
56
- assert_equal expected, Template.parse(text).render
57
- end
58
-
59
- def test_strings
60
- text = %| {% if 'test' == 'test' %} true {% else %} false {% endif %} |
61
- expected = %| true |
62
- assert_equal expected, Template.parse(text).render
63
- end
64
-
65
- def test_strings_not_equal
66
- text = %| {% if 'test' != 'test' %} true {% else %} false {% endif %} |
67
- expected = %| false |
68
- assert_equal expected, Template.parse(text).render
69
- end
70
-
71
- def test_var_strings_equal
72
- text = %| {% if var == "hello there!" %} true {% else %} false {% endif %} |
73
- expected = %| true |
74
- assert_equal expected, Template.parse(text).render('var' => 'hello there!')
75
- end
76
-
77
- def test_var_strings_are_not_equal
78
- text = %| {% if "hello there!" == var %} true {% else %} false {% endif %} |
79
- expected = %| true |
80
- assert_equal expected, Template.parse(text).render('var' => 'hello there!')
81
- end
82
-
83
- def test_var_and_long_string_are_equal
84
- text = %| {% if var == 'hello there!' %} true {% else %} false {% endif %} |
85
- expected = %| true |
86
- assert_equal expected, Template.parse(text).render('var' => 'hello there!')
87
- end
88
-
89
-
90
- def test_var_and_long_string_are_equal_backwards
91
- text = %| {% if 'hello there!' == var %} true {% else %} false {% endif %} |
92
- expected = %| true |
93
- assert_equal expected, Template.parse(text).render('var' => 'hello there!')
94
- end
95
-
96
- #def test_is_nil
97
- # text = %| {% if var != nil %} true {% else %} false {% end %} |
98
- # @template.assigns = { 'var' => 'hello there!'}
99
- # expected = %| true |
100
- # assert_equal expected, @template.parse(text)
101
- #end
102
-
103
- def test_is_collection_empty
104
- text = %| {% if array == empty %} true {% else %} false {% endif %} |
105
- expected = %| true |
106
- assert_equal expected, Template.parse(text).render('array' => [])
107
- end
108
-
109
- def test_is_not_collection_empty
110
- text = %| {% if array == empty %} true {% else %} false {% endif %} |
111
- expected = %| false |
112
- assert_equal expected, Template.parse(text).render('array' => [1,2,3])
113
- end
114
-
115
- def test_nil
116
- text = %| {% if var == nil %} true {% else %} false {% endif %} |
117
- expected = %| true |
118
- assert_equal expected, Template.parse(text).render('var' => nil)
119
-
120
- text = %| {% if var == null %} true {% else %} false {% endif %} |
121
- expected = %| true |
122
- assert_equal expected, Template.parse(text).render('var' => nil)
123
- end
124
-
125
- def test_not_nil
126
- text = %| {% if var != nil %} true {% else %} false {% endif %} |
127
- expected = %| true |
128
- assert_equal expected, Template.parse(text).render('var' => 1 )
129
-
130
- text = %| {% if var != null %} true {% else %} false {% endif %} |
131
- expected = %| true |
132
- assert_equal expected, Template.parse(text).render('var' => 1 )
133
- end
134
- end # StatementsTest
@@ -1,186 +0,0 @@
1
- require 'test_helper'
2
-
3
- class VariableTest < Test::Unit::TestCase
4
- include Liquid
5
-
6
- def test_variable
7
- var = Variable.new('hello')
8
- assert_equal 'hello', var.name
9
- end
10
-
11
- def test_filters
12
- var = Variable.new('hello | textileze')
13
- assert_equal 'hello', var.name
14
- assert_equal [["textileze",[]]], var.filters
15
-
16
- var = Variable.new('hello | textileze | paragraph')
17
- assert_equal 'hello', var.name
18
- assert_equal [["textileze",[]], ["paragraph",[]]], var.filters
19
-
20
- var = Variable.new(%! hello | strftime: '%Y'!)
21
- assert_equal 'hello', var.name
22
- assert_equal [["strftime",["'%Y'"]]], var.filters
23
-
24
- var = Variable.new(%! 'typo' | link_to: 'Typo', true !)
25
- assert_equal %!'typo'!, var.name
26
- assert_equal [["link_to",["'Typo'", "true"]]], var.filters
27
-
28
- var = Variable.new(%! 'typo' | link_to: 'Typo', false !)
29
- assert_equal %!'typo'!, var.name
30
- assert_equal [["link_to",["'Typo'", "false"]]], var.filters
31
-
32
- var = Variable.new(%! 'foo' | repeat: 3 !)
33
- assert_equal %!'foo'!, var.name
34
- assert_equal [["repeat",["3"]]], var.filters
35
-
36
- var = Variable.new(%! 'foo' | repeat: 3, 3 !)
37
- assert_equal %!'foo'!, var.name
38
- assert_equal [["repeat",["3","3"]]], var.filters
39
-
40
- var = Variable.new(%! 'foo' | repeat: 3, 3, 3 !)
41
- assert_equal %!'foo'!, var.name
42
- assert_equal [["repeat",["3","3","3"]]], var.filters
43
-
44
- var = Variable.new(%! hello | strftime: '%Y, okay?'!)
45
- assert_equal 'hello', var.name
46
- assert_equal [["strftime",["'%Y, okay?'"]]], var.filters
47
-
48
- var = Variable.new(%! hello | things: "%Y, okay?", 'the other one'!)
49
- assert_equal 'hello', var.name
50
- assert_equal [["things",["\"%Y, okay?\"","'the other one'"]]], var.filters
51
- end
52
-
53
- def test_filter_with_date_parameter
54
-
55
- var = Variable.new(%! '2006-06-06' | date: "%m/%d/%Y"!)
56
- assert_equal "'2006-06-06'", var.name
57
- assert_equal [["date",["\"%m/%d/%Y\""]]], var.filters
58
-
59
- end
60
-
61
- def test_filters_without_whitespace
62
- var = Variable.new('hello | textileze | paragraph')
63
- assert_equal 'hello', var.name
64
- assert_equal [["textileze",[]], ["paragraph",[]]], var.filters
65
-
66
- var = Variable.new('hello|textileze|paragraph')
67
- assert_equal 'hello', var.name
68
- assert_equal [["textileze",[]], ["paragraph",[]]], var.filters
69
-
70
- var = Variable.new("hello|replace:'foo','bar'|textileze")
71
- assert_equal 'hello', var.name
72
- assert_equal [["replace", ["'foo'", "'bar'"]], ["textileze", []]], var.filters
73
- end
74
-
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
78
- assert_equal [["image",["'med'"]]], var.filters
79
- end
80
-
81
- def test_string_single_quoted
82
- var = Variable.new(%| "hello" |)
83
- assert_equal '"hello"', var.name
84
- end
85
-
86
- def test_string_double_quoted
87
- var = Variable.new(%| 'hello' |)
88
- assert_equal "'hello'", var.name
89
- end
90
-
91
- def test_integer
92
- var = Variable.new(%| 1000 |)
93
- assert_equal "1000", var.name
94
- end
95
-
96
- def test_float
97
- var = Variable.new(%| 1000.01 |)
98
- assert_equal "1000.01", var.name
99
- end
100
-
101
- def test_string_with_special_chars
102
- var = Variable.new(%| 'hello! $!@.;"ddasd" ' |)
103
- assert_equal %|'hello! $!@.;"ddasd" '|, var.name
104
- end
105
-
106
- def test_string_dot
107
- var = Variable.new(%| test.test |)
108
- assert_equal 'test.test', var.name
109
- end
110
-
111
- def test_filter_with_keyword_arguments
112
- var = Variable.new(%! hello | things: greeting: "world", farewell: 'goodbye'!)
113
- assert_equal 'hello', var.name
114
- assert_equal [['things',["greeting: \"world\"","farewell: 'goodbye'"]]], var.filters
115
- end
116
-
117
- def test_lax_filter_argument_parsing
118
- var = Variable.new(%! number_of_comments | pluralize: 'comment': 'comments' !)
119
- assert_equal 'number_of_comments', var.name
120
- assert_equal [['pluralize',["'comment'","'comments'"]]], var.filters
121
- 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
-
140
- def test_ignore_unknown
141
- template = Template.parse(%|{{ test }}|)
142
- assert_equal '', template.render
143
- 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