locomotivecms-liquid 2.6.0 → 4.0.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +62 -5
- data/README.md +4 -4
- data/lib/liquid.rb +16 -12
- data/lib/liquid/block.rb +37 -118
- data/lib/liquid/block_body.rb +131 -0
- data/lib/liquid/condition.rb +28 -17
- data/lib/liquid/context.rb +94 -146
- data/lib/liquid/document.rb +16 -10
- data/lib/liquid/drop.rb +8 -5
- data/lib/liquid/drops/inherited_block_drop.rb +24 -0
- data/lib/liquid/errors.rb +44 -5
- data/lib/liquid/expression.rb +33 -0
- data/lib/liquid/file_system.rb +17 -6
- data/lib/liquid/i18n.rb +2 -2
- data/lib/liquid/interrupts.rb +1 -1
- data/lib/liquid/lexer.rb +11 -9
- data/lib/liquid/locales/en.yml +2 -4
- data/lib/liquid/parser.rb +2 -1
- data/lib/liquid/parser_switching.rb +31 -0
- data/lib/liquid/profiler.rb +162 -0
- data/lib/liquid/profiler/hooks.rb +23 -0
- data/lib/liquid/range_lookup.rb +22 -0
- data/lib/liquid/resource_limits.rb +23 -0
- data/lib/liquid/standardfilters.rb +142 -67
- data/lib/liquid/strainer.rb +14 -4
- data/lib/liquid/tag.rb +22 -41
- data/lib/liquid/tags/assign.rb +15 -10
- data/lib/liquid/tags/break.rb +1 -1
- data/lib/liquid/tags/capture.rb +7 -9
- data/lib/liquid/tags/case.rb +28 -19
- data/lib/liquid/tags/comment.rb +2 -2
- data/lib/liquid/tags/continue.rb +1 -4
- data/lib/liquid/tags/cycle.rb +10 -14
- data/lib/liquid/tags/decrement.rb +3 -4
- data/lib/liquid/tags/extends.rb +28 -44
- data/lib/liquid/tags/for.rb +64 -42
- data/lib/liquid/tags/if.rb +30 -19
- data/lib/liquid/tags/ifchanged.rb +4 -4
- data/lib/liquid/tags/include.rb +30 -20
- data/lib/liquid/tags/increment.rb +3 -8
- data/lib/liquid/tags/inherited_block.rb +54 -56
- data/lib/liquid/tags/raw.rb +18 -10
- data/lib/liquid/tags/table_row.rb +72 -0
- data/lib/liquid/tags/unless.rb +5 -7
- data/lib/liquid/template.rb +113 -53
- data/lib/liquid/token.rb +18 -0
- data/lib/liquid/utils.rb +13 -4
- data/lib/liquid/variable.rb +68 -50
- data/lib/liquid/variable_lookup.rb +78 -0
- data/lib/liquid/version.rb +1 -1
- data/test/fixtures/en_locale.yml +9 -0
- data/test/integration/assign_test.rb +48 -0
- data/test/integration/blank_test.rb +106 -0
- data/test/integration/capture_test.rb +50 -0
- data/test/integration/context_test.rb +32 -0
- data/test/integration/document_test.rb +19 -0
- data/test/integration/drop_test.rb +271 -0
- data/test/integration/error_handling_test.rb +207 -0
- data/test/integration/filter_test.rb +125 -0
- data/test/integration/hash_ordering_test.rb +23 -0
- data/test/integration/output_test.rb +116 -0
- data/test/integration/parsing_quirks_test.rb +119 -0
- data/test/integration/render_profiling_test.rb +154 -0
- data/test/integration/security_test.rb +64 -0
- data/test/integration/standard_filter_test.rb +379 -0
- data/test/integration/tags/break_tag_test.rb +16 -0
- data/test/integration/tags/continue_tag_test.rb +16 -0
- data/test/integration/tags/extends_tag_test.rb +104 -0
- data/test/integration/tags/for_tag_test.rb +375 -0
- data/test/integration/tags/if_else_tag_test.rb +169 -0
- data/test/integration/tags/include_tag_test.rb +234 -0
- data/test/integration/tags/increment_tag_test.rb +24 -0
- data/test/integration/tags/raw_tag_test.rb +25 -0
- data/test/integration/tags/standard_tag_test.rb +297 -0
- data/test/integration/tags/statements_test.rb +113 -0
- data/test/integration/tags/table_row_test.rb +63 -0
- data/test/integration/tags/unless_else_tag_test.rb +26 -0
- data/test/integration/template_test.rb +216 -0
- data/test/integration/variable_test.rb +82 -0
- data/test/test_helper.rb +83 -0
- data/test/unit/block_unit_test.rb +55 -0
- data/test/unit/condition_unit_test.rb +149 -0
- data/test/unit/context_unit_test.rb +482 -0
- data/test/unit/file_system_unit_test.rb +35 -0
- data/test/unit/i18n_unit_test.rb +37 -0
- data/test/unit/lexer_unit_test.rb +51 -0
- data/test/unit/module_ex_unit_test.rb +87 -0
- data/test/unit/parser_unit_test.rb +82 -0
- data/test/unit/regexp_unit_test.rb +44 -0
- data/test/unit/strainer_unit_test.rb +71 -0
- data/test/unit/tag_unit_test.rb +16 -0
- data/test/unit/tags/case_tag_unit_test.rb +10 -0
- data/test/unit/tags/for_tag_unit_test.rb +13 -0
- data/test/unit/tags/if_tag_unit_test.rb +8 -0
- data/test/unit/template_unit_test.rb +70 -0
- data/test/unit/tokenizer_unit_test.rb +38 -0
- data/test/unit/variable_unit_test.rb +150 -0
- metadata +144 -15
- data/lib/extras/liquid_view.rb +0 -51
- data/lib/liquid/htmltags.rb +0 -74
- data/lib/liquid/tags/default_content.rb +0 -21
- data/lib/locomotivecms-liquid.rb +0 -1
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class FileSystemUnitTest < Minitest::Test
|
4
|
+
include Liquid
|
5
|
+
|
6
|
+
def test_default
|
7
|
+
assert_raises(FileSystemError) do
|
8
|
+
BlankFileSystem.new.read_template_file("dummy", {'dummy'=>'smarty'})
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_local
|
13
|
+
file_system = Liquid::LocalFileSystem.new("/some/path")
|
14
|
+
assert_equal "/some/path/_mypartial.liquid" , file_system.full_path("mypartial")
|
15
|
+
assert_equal "/some/path/dir/_mypartial.liquid", file_system.full_path("dir/mypartial")
|
16
|
+
|
17
|
+
assert_raises(FileSystemError) do
|
18
|
+
file_system.full_path("../dir/mypartial")
|
19
|
+
end
|
20
|
+
|
21
|
+
assert_raises(FileSystemError) do
|
22
|
+
file_system.full_path("/dir/../../dir/mypartial")
|
23
|
+
end
|
24
|
+
|
25
|
+
assert_raises(FileSystemError) do
|
26
|
+
file_system.full_path("/etc/passwd")
|
27
|
+
end
|
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
|
35
|
+
end # FileSystemTest
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class I18nUnitTest < Minitest::Test
|
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_raises I18n::TranslationError do
|
24
|
+
# @i18n.translate("whatever", :oopstypos => "yes")
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
|
28
|
+
def test_raises_unknown_translation
|
29
|
+
assert_raises 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,51 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LexerUnitTest < Minitest::Test
|
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
|
+
|
37
|
+
tokens = Lexer.new('2foo').tokenize
|
38
|
+
assert_equal [[:number, '2'], [:id, 'foo'], [:end_of_string]], tokens
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_whitespace
|
42
|
+
tokens = Lexer.new("five|\n\t ==").tokenize
|
43
|
+
assert_equal [[:id,'five'], [:pipe, '|'], [:comparison, '=='], [:end_of_string]], tokens
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_unexpected_character
|
47
|
+
assert_raises(SyntaxError) do
|
48
|
+
Lexer.new("%").tokenize
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestClassA
|
4
|
+
liquid_methods :allowedA, :chainedB
|
5
|
+
def allowedA
|
6
|
+
'allowedA'
|
7
|
+
end
|
8
|
+
def restrictedA
|
9
|
+
'restrictedA'
|
10
|
+
end
|
11
|
+
def chainedB
|
12
|
+
TestClassB.new
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class TestClassB
|
17
|
+
liquid_methods :allowedB, :chainedC
|
18
|
+
def allowedB
|
19
|
+
'allowedB'
|
20
|
+
end
|
21
|
+
def chainedC
|
22
|
+
TestClassC.new
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class TestClassC
|
27
|
+
liquid_methods :allowedC
|
28
|
+
def allowedC
|
29
|
+
'allowedC'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class TestClassC::LiquidDropClass
|
34
|
+
def another_allowedC
|
35
|
+
'another_allowedC'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class ModuleExUnitTest < Minitest::Test
|
40
|
+
include Liquid
|
41
|
+
|
42
|
+
def setup
|
43
|
+
@a = TestClassA.new
|
44
|
+
@b = TestClassB.new
|
45
|
+
@c = TestClassC.new
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_should_create_LiquidDropClass
|
49
|
+
assert TestClassA::LiquidDropClass
|
50
|
+
assert TestClassB::LiquidDropClass
|
51
|
+
assert TestClassC::LiquidDropClass
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_should_respond_to_liquid
|
55
|
+
assert @a.respond_to?(:to_liquid)
|
56
|
+
assert @b.respond_to?(:to_liquid)
|
57
|
+
assert @c.respond_to?(:to_liquid)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_should_return_LiquidDropClass_object
|
61
|
+
assert @a.to_liquid.is_a?(TestClassA::LiquidDropClass)
|
62
|
+
assert @b.to_liquid.is_a?(TestClassB::LiquidDropClass)
|
63
|
+
assert @c.to_liquid.is_a?(TestClassC::LiquidDropClass)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_should_respond_to_liquid_methods
|
67
|
+
assert @a.to_liquid.respond_to?(:allowedA)
|
68
|
+
assert @a.to_liquid.respond_to?(:chainedB)
|
69
|
+
assert @b.to_liquid.respond_to?(:allowedB)
|
70
|
+
assert @b.to_liquid.respond_to?(:chainedC)
|
71
|
+
assert @c.to_liquid.respond_to?(:allowedC)
|
72
|
+
assert @c.to_liquid.respond_to?(:another_allowedC)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_should_not_respond_to_restricted_methods
|
76
|
+
assert ! @a.to_liquid.respond_to?(:restricted)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_should_use_regular_objects_as_drops
|
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
|
+
end
|
87
|
+
end # ModuleExTest
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ParserUnitTest < Minitest::Test
|
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].there? hi.there.bob")
|
48
|
+
assert_equal 'hi.there', p.expression
|
49
|
+
assert_equal 'hi?[5].there?', 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
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RegexpUnitTest < Minitest::Test
|
4
|
+
include Liquid
|
5
|
+
|
6
|
+
def test_empty
|
7
|
+
assert_equal [], ''.scan(QuotedFragment)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_quote
|
11
|
+
assert_equal ['"arg 1"'], '"arg 1"'.scan(QuotedFragment)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_words
|
15
|
+
assert_equal ['arg1', 'arg2'], 'arg1 arg2'.scan(QuotedFragment)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_tags
|
19
|
+
assert_equal ['<tr>', '</tr>'], '<tr> </tr>'.scan(QuotedFragment)
|
20
|
+
assert_equal ['<tr></tr>'], '<tr></tr>'.scan(QuotedFragment)
|
21
|
+
assert_equal ['<style', 'class="hello">', '</style>'], %|<style class="hello">' </style>|.scan(QuotedFragment)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_double_quoted_words
|
25
|
+
assert_equal ['arg1', 'arg2', '"arg 3"'], 'arg1 arg2 "arg 3"'.scan(QuotedFragment)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_single_quoted_words
|
29
|
+
assert_equal ['arg1', 'arg2', "'arg 3'"], 'arg1 arg2 \'arg 3\''.scan(QuotedFragment)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_quoted_words_in_the_middle
|
33
|
+
assert_equal ['arg1', 'arg2', '"arg 3"', 'arg4'], 'arg1 arg2 "arg 3" arg4 '.scan(QuotedFragment)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_variable_parser
|
37
|
+
assert_equal ['var'], 'var'.scan(VariableParser)
|
38
|
+
assert_equal ['var', 'method'], 'var.method'.scan(VariableParser)
|
39
|
+
assert_equal ['var', '[method]'], 'var[method]'.scan(VariableParser)
|
40
|
+
assert_equal ['var', '[method]', '[0]'], 'var[method][0]'.scan(VariableParser)
|
41
|
+
assert_equal ['var', '["method"]', '[0]'], 'var["method"][0]'.scan(VariableParser)
|
42
|
+
assert_equal ['var', '[method]', '[0]', 'method'], 'var[method][0].method'.scan(VariableParser)
|
43
|
+
end
|
44
|
+
end # RegexpTest
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class StrainerUnitTest < Minitest::Test
|
4
|
+
include Liquid
|
5
|
+
|
6
|
+
module AccessScopeFilters
|
7
|
+
def public_filter
|
8
|
+
"public"
|
9
|
+
end
|
10
|
+
|
11
|
+
def private_filter
|
12
|
+
"private"
|
13
|
+
end
|
14
|
+
private :private_filter
|
15
|
+
end
|
16
|
+
|
17
|
+
Strainer.global_filter(AccessScopeFilters)
|
18
|
+
|
19
|
+
def test_strainer
|
20
|
+
strainer = Strainer.create(nil)
|
21
|
+
assert_equal 5, strainer.invoke('size', 'input')
|
22
|
+
assert_equal "public", strainer.invoke("public_filter")
|
23
|
+
end
|
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
|
+
|
32
|
+
def test_strainer_only_invokes_public_filter_methods
|
33
|
+
strainer = Strainer.create(nil)
|
34
|
+
assert_equal false, strainer.invokable?('__test__')
|
35
|
+
assert_equal false, strainer.invokable?('test')
|
36
|
+
assert_equal false, strainer.invokable?('instance_eval')
|
37
|
+
assert_equal false, strainer.invokable?('__send__')
|
38
|
+
assert_equal true, strainer.invokable?('size') # from the standard lib
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_strainer_returns_nil_if_no_filter_method_found
|
42
|
+
strainer = Strainer.create(nil)
|
43
|
+
assert_nil strainer.invoke("private_filter")
|
44
|
+
assert_nil strainer.invoke("undef_the_filter")
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_strainer_returns_first_argument_if_no_method_and_arguments_given
|
48
|
+
strainer = Strainer.create(nil)
|
49
|
+
assert_equal "password", strainer.invoke("undef_the_method", "password")
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_strainer_only_allows_methods_defined_in_filters
|
53
|
+
strainer = Strainer.create(nil)
|
54
|
+
assert_equal "1 + 1", strainer.invoke("instance_eval", "1 + 1")
|
55
|
+
assert_equal "puts", strainer.invoke("__send__", "puts", "Hi Mom")
|
56
|
+
assert_equal "has_method?", strainer.invoke("invoke", "has_method?", "invoke")
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_strainer_uses_a_class_cache_to_avoid_method_cache_invalidation
|
60
|
+
a = Module.new
|
61
|
+
b = Module.new
|
62
|
+
strainer = Strainer.create(nil, [a,b])
|
63
|
+
assert_kind_of Strainer, strainer
|
64
|
+
assert_kind_of a, strainer
|
65
|
+
assert_kind_of b, strainer
|
66
|
+
Strainer.class_variable_get(:@@filters).each do |m|
|
67
|
+
assert_kind_of m, strainer
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end # StrainerTest
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TagUnitTest < Minitest::Test
|
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
|
+
|
12
|
+
def test_return_raw_text_of_tag
|
13
|
+
tag = Tag.parse("long_tag", "param1, param2, param3", [], {})
|
14
|
+
assert_equal("long_tag param1, param2, param3", tag.raw)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CaseTagUnitTest < Minitest::Test
|
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.map(&:nodelist).flatten
|
9
|
+
end
|
10
|
+
end
|