liquid 4.0.3 → 5.0.1
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.
- checksums.yaml +4 -4
- data/History.md +43 -0
- data/README.md +6 -0
- data/lib/liquid.rb +17 -5
- data/lib/liquid/block.rb +31 -14
- data/lib/liquid/block_body.rb +166 -54
- data/lib/liquid/condition.rb +39 -18
- data/lib/liquid/context.rb +106 -51
- data/lib/liquid/document.rb +47 -9
- data/lib/liquid/drop.rb +4 -2
- data/lib/liquid/errors.rb +20 -18
- data/lib/liquid/expression.rb +29 -34
- data/lib/liquid/extensions.rb +2 -0
- data/lib/liquid/file_system.rb +6 -4
- data/lib/liquid/forloop_drop.rb +11 -4
- data/lib/liquid/i18n.rb +5 -3
- data/lib/liquid/interrupts.rb +3 -1
- data/lib/liquid/lexer.rb +30 -23
- data/lib/liquid/locales/en.yml +3 -1
- data/lib/liquid/parse_context.rb +20 -4
- data/lib/liquid/parse_tree_visitor.rb +2 -2
- data/lib/liquid/parser.rb +30 -18
- data/lib/liquid/parser_switching.rb +17 -3
- data/lib/liquid/partial_cache.rb +24 -0
- data/lib/liquid/profiler.rb +67 -86
- data/lib/liquid/profiler/hooks.rb +26 -14
- data/lib/liquid/range_lookup.rb +5 -3
- data/lib/liquid/register.rb +6 -0
- data/lib/liquid/resource_limits.rb +47 -8
- data/lib/liquid/standardfilters.rb +67 -46
- data/lib/liquid/static_registers.rb +44 -0
- data/lib/liquid/strainer_factory.rb +36 -0
- data/lib/liquid/strainer_template.rb +53 -0
- data/lib/liquid/tablerowloop_drop.rb +6 -4
- data/lib/liquid/tag.rb +28 -6
- data/lib/liquid/tag/disableable.rb +22 -0
- data/lib/liquid/tag/disabler.rb +21 -0
- data/lib/liquid/tags/assign.rb +24 -10
- data/lib/liquid/tags/break.rb +8 -3
- data/lib/liquid/tags/capture.rb +11 -8
- data/lib/liquid/tags/case.rb +33 -27
- data/lib/liquid/tags/comment.rb +5 -3
- data/lib/liquid/tags/continue.rb +8 -3
- data/lib/liquid/tags/cycle.rb +25 -14
- data/lib/liquid/tags/decrement.rb +6 -3
- data/lib/liquid/tags/echo.rb +34 -0
- data/lib/liquid/tags/for.rb +68 -44
- data/lib/liquid/tags/if.rb +35 -23
- data/lib/liquid/tags/ifchanged.rb +11 -10
- data/lib/liquid/tags/include.rb +34 -47
- data/lib/liquid/tags/increment.rb +7 -3
- data/lib/liquid/tags/raw.rb +14 -11
- data/lib/liquid/tags/render.rb +84 -0
- data/lib/liquid/tags/table_row.rb +23 -19
- data/lib/liquid/tags/unless.rb +15 -15
- data/lib/liquid/template.rb +53 -72
- data/lib/liquid/template_factory.rb +9 -0
- data/lib/liquid/tokenizer.rb +17 -9
- data/lib/liquid/usage.rb +8 -0
- data/lib/liquid/utils.rb +5 -3
- data/lib/liquid/variable.rb +46 -41
- data/lib/liquid/variable_lookup.rb +8 -6
- data/lib/liquid/version.rb +2 -1
- data/test/integration/assign_test.rb +74 -5
- data/test/integration/blank_test.rb +11 -8
- data/test/integration/block_test.rb +47 -1
- data/test/integration/capture_test.rb +18 -10
- data/test/integration/context_test.rb +609 -5
- data/test/integration/document_test.rb +4 -2
- data/test/integration/drop_test.rb +67 -83
- data/test/integration/error_handling_test.rb +73 -61
- data/test/integration/expression_test.rb +46 -0
- data/test/integration/filter_test.rb +53 -42
- data/test/integration/hash_ordering_test.rb +5 -3
- data/test/integration/output_test.rb +26 -24
- data/test/integration/parsing_quirks_test.rb +19 -7
- data/test/integration/{render_profiling_test.rb → profiler_test.rb} +84 -25
- data/test/integration/security_test.rb +30 -21
- data/test/integration/standard_filter_test.rb +343 -281
- data/test/integration/tag/disableable_test.rb +59 -0
- data/test/integration/tag_test.rb +45 -0
- data/test/integration/tags/break_tag_test.rb +4 -2
- data/test/integration/tags/continue_tag_test.rb +4 -2
- data/test/integration/tags/echo_test.rb +13 -0
- data/test/integration/tags/for_tag_test.rb +107 -51
- data/test/integration/tags/if_else_tag_test.rb +5 -3
- data/test/integration/tags/include_tag_test.rb +70 -54
- data/test/integration/tags/increment_tag_test.rb +4 -2
- data/test/integration/tags/liquid_tag_test.rb +116 -0
- data/test/integration/tags/raw_tag_test.rb +14 -11
- data/test/integration/tags/render_tag_test.rb +213 -0
- data/test/integration/tags/standard_tag_test.rb +38 -31
- data/test/integration/tags/statements_test.rb +23 -21
- data/test/integration/tags/table_row_test.rb +2 -0
- data/test/integration/tags/unless_else_tag_test.rb +4 -2
- data/test/integration/template_test.rb +118 -124
- data/test/integration/trim_mode_test.rb +78 -44
- data/test/integration/variable_test.rb +43 -32
- data/test/test_helper.rb +75 -22
- data/test/unit/block_unit_test.rb +19 -24
- data/test/unit/condition_unit_test.rb +79 -77
- data/test/unit/file_system_unit_test.rb +6 -4
- data/test/unit/i18n_unit_test.rb +7 -5
- data/test/unit/lexer_unit_test.rb +11 -9
- data/test/{integration → unit}/parse_tree_visitor_test.rb +9 -2
- data/test/unit/parser_unit_test.rb +37 -35
- data/test/unit/partial_cache_unit_test.rb +128 -0
- data/test/unit/regexp_unit_test.rb +17 -15
- data/test/unit/static_registers_unit_test.rb +156 -0
- data/test/unit/strainer_factory_unit_test.rb +100 -0
- data/test/unit/strainer_template_unit_test.rb +82 -0
- data/test/unit/tag_unit_test.rb +5 -3
- data/test/unit/tags/case_tag_unit_test.rb +3 -1
- data/test/unit/tags/for_tag_unit_test.rb +4 -2
- data/test/unit/tags/if_tag_unit_test.rb +3 -1
- data/test/unit/template_factory_unit_test.rb +12 -0
- data/test/unit/template_unit_test.rb +19 -10
- data/test/unit/tokenizer_unit_test.rb +26 -19
- data/test/unit/variable_unit_test.rb +51 -49
- metadata +73 -47
- data/lib/liquid/strainer.rb +0 -66
- data/lib/liquid/truffle.rb +0 -5
- data/test/truffle/truffle_test.rb +0 -9
- data/test/unit/context_unit_test.rb +0 -489
- data/test/unit/strainer_unit_test.rb +0 -164
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class FileSystemUnitTest < Minitest::Test
|
@@ -11,8 +13,8 @@ class FileSystemUnitTest < Minitest::Test
|
|
11
13
|
|
12
14
|
def test_local
|
13
15
|
file_system = Liquid::LocalFileSystem.new("/some/path")
|
14
|
-
assert_equal
|
15
|
-
assert_equal
|
16
|
+
assert_equal("/some/path/_mypartial.liquid", file_system.full_path("mypartial"))
|
17
|
+
assert_equal("/some/path/dir/_mypartial.liquid", file_system.full_path("dir/mypartial"))
|
16
18
|
|
17
19
|
assert_raises(FileSystemError) do
|
18
20
|
file_system.full_path("../dir/mypartial")
|
@@ -29,7 +31,7 @@ class FileSystemUnitTest < Minitest::Test
|
|
29
31
|
|
30
32
|
def test_custom_template_filename_patterns
|
31
33
|
file_system = Liquid::LocalFileSystem.new("/some/path", "%s.html")
|
32
|
-
assert_equal
|
33
|
-
assert_equal
|
34
|
+
assert_equal("/some/path/mypartial.html", file_system.full_path("mypartial"))
|
35
|
+
assert_equal("/some/path/dir/mypartial.html", file_system.full_path("dir/mypartial"))
|
34
36
|
end
|
35
37
|
end # FileSystemTest
|
data/test/unit/i18n_unit_test.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class I18nUnitTest < Minitest::Test
|
@@ -8,15 +10,15 @@ class I18nUnitTest < Minitest::Test
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def test_simple_translate_string
|
11
|
-
assert_equal
|
13
|
+
assert_equal("less is more", @i18n.translate("simple"))
|
12
14
|
end
|
13
15
|
|
14
16
|
def test_nested_translate_string
|
15
|
-
assert_equal
|
17
|
+
assert_equal("something wasn't right", @i18n.translate("errors.syntax.oops"))
|
16
18
|
end
|
17
19
|
|
18
20
|
def test_single_string_interpolation
|
19
|
-
assert_equal
|
21
|
+
assert_equal("something different", @i18n.translate("whatever", something: "different"))
|
20
22
|
end
|
21
23
|
|
22
24
|
# def test_raises_translation_error_on_undefined_interpolation_key
|
@@ -26,12 +28,12 @@ class I18nUnitTest < Minitest::Test
|
|
26
28
|
# end
|
27
29
|
|
28
30
|
def test_raises_unknown_translation
|
29
|
-
assert_raises
|
31
|
+
assert_raises(I18n::TranslationError) do
|
30
32
|
@i18n.translate("doesnt_exist")
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
36
|
def test_sets_default_path_to_en
|
35
|
-
assert_equal
|
37
|
+
assert_equal(I18n::DEFAULT_LOCALE, I18n.new.path)
|
36
38
|
end
|
37
39
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class LexerUnitTest < Minitest::Test
|
@@ -5,42 +7,42 @@ class LexerUnitTest < Minitest::Test
|
|
5
7
|
|
6
8
|
def test_strings
|
7
9
|
tokens = Lexer.new(%( 'this is a test""' "wat 'lol'")).tokenize
|
8
|
-
assert_equal
|
10
|
+
assert_equal([[:string, %('this is a test""')], [:string, %("wat 'lol'")], [:end_of_string]], tokens)
|
9
11
|
end
|
10
12
|
|
11
13
|
def test_integer
|
12
14
|
tokens = Lexer.new('hi 50').tokenize
|
13
|
-
assert_equal
|
15
|
+
assert_equal([[:id, 'hi'], [:number, '50'], [:end_of_string]], tokens)
|
14
16
|
end
|
15
17
|
|
16
18
|
def test_float
|
17
19
|
tokens = Lexer.new('hi 5.0').tokenize
|
18
|
-
assert_equal
|
20
|
+
assert_equal([[:id, 'hi'], [:number, '5.0'], [:end_of_string]], tokens)
|
19
21
|
end
|
20
22
|
|
21
23
|
def test_comparison
|
22
24
|
tokens = Lexer.new('== <> contains ').tokenize
|
23
|
-
assert_equal
|
25
|
+
assert_equal([[:comparison, '=='], [:comparison, '<>'], [:comparison, 'contains'], [:end_of_string]], tokens)
|
24
26
|
end
|
25
27
|
|
26
28
|
def test_specials
|
27
29
|
tokens = Lexer.new('| .:').tokenize
|
28
|
-
assert_equal
|
30
|
+
assert_equal([[:pipe, '|'], [:dot, '.'], [:colon, ':'], [:end_of_string]], tokens)
|
29
31
|
tokens = Lexer.new('[,]').tokenize
|
30
|
-
assert_equal
|
32
|
+
assert_equal([[:open_square, '['], [:comma, ','], [:close_square, ']'], [:end_of_string]], tokens)
|
31
33
|
end
|
32
34
|
|
33
35
|
def test_fancy_identifiers
|
34
36
|
tokens = Lexer.new('hi five?').tokenize
|
35
|
-
assert_equal
|
37
|
+
assert_equal([[:id, 'hi'], [:id, 'five?'], [:end_of_string]], tokens)
|
36
38
|
|
37
39
|
tokens = Lexer.new('2foo').tokenize
|
38
|
-
assert_equal
|
40
|
+
assert_equal([[:number, '2'], [:id, 'foo'], [:end_of_string]], tokens)
|
39
41
|
end
|
40
42
|
|
41
43
|
def test_whitespace
|
42
44
|
tokens = Lexer.new("five|\n\t ==").tokenize
|
43
|
-
assert_equal
|
45
|
+
assert_equal([[:id, 'five'], [:pipe, '|'], [:comparison, '=='], [:end_of_string]], tokens)
|
44
46
|
end
|
45
47
|
|
46
48
|
def test_unexpected_character
|
@@ -26,6 +26,13 @@ class ParseTreeVisitorTest < Minitest::Test
|
|
26
26
|
)
|
27
27
|
end
|
28
28
|
|
29
|
+
def test_echo
|
30
|
+
assert_equal(
|
31
|
+
["test"],
|
32
|
+
visit(%({% echo test %}))
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
29
36
|
def test_if_condition
|
30
37
|
assert_equal(
|
31
38
|
["test"],
|
@@ -227,7 +234,7 @@ class ParseTreeVisitorTest < Minitest::Test
|
|
227
234
|
[[nil, [
|
228
235
|
[nil, [[nil, [["other", []]]]]],
|
229
236
|
["test", []],
|
230
|
-
["xs", []]
|
237
|
+
["xs", []],
|
231
238
|
]]],
|
232
239
|
traversal(%({% for x in xs offset: test %}{{ other }}{% endfor %})).visit
|
233
240
|
)
|
@@ -238,7 +245,7 @@ class ParseTreeVisitorTest < Minitest::Test
|
|
238
245
|
def traversal(template)
|
239
246
|
ParseTreeVisitor
|
240
247
|
.for(Template.parse(template).root)
|
241
|
-
.add_callback_for(VariableLookup
|
248
|
+
.add_callback_for(VariableLookup) { |node| node.name } # rubocop:disable Style/SymbolProc
|
242
249
|
end
|
243
250
|
|
244
251
|
def visit(template)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class ParserUnitTest < Minitest::Test
|
@@ -5,72 +7,72 @@ class ParserUnitTest < Minitest::Test
|
|
5
7
|
|
6
8
|
def test_consume
|
7
9
|
p = Parser.new("wat: 7")
|
8
|
-
assert_equal
|
9
|
-
assert_equal
|
10
|
-
assert_equal
|
10
|
+
assert_equal('wat', p.consume(:id))
|
11
|
+
assert_equal(':', p.consume(:colon))
|
12
|
+
assert_equal('7', p.consume(:number))
|
11
13
|
end
|
12
14
|
|
13
15
|
def test_jump
|
14
16
|
p = Parser.new("wat: 7")
|
15
17
|
p.jump(2)
|
16
|
-
assert_equal
|
18
|
+
assert_equal('7', p.consume(:number))
|
17
19
|
end
|
18
20
|
|
19
21
|
def test_consume?
|
20
22
|
p = Parser.new("wat: 7")
|
21
|
-
assert_equal
|
22
|
-
assert_equal
|
23
|
-
assert_equal
|
24
|
-
assert_equal
|
23
|
+
assert_equal('wat', p.consume?(:id))
|
24
|
+
assert_equal(false, p.consume?(:dot))
|
25
|
+
assert_equal(':', p.consume(:colon))
|
26
|
+
assert_equal('7', p.consume?(:number))
|
25
27
|
end
|
26
28
|
|
27
29
|
def test_id?
|
28
30
|
p = Parser.new("wat 6 Peter Hegemon")
|
29
|
-
assert_equal
|
30
|
-
assert_equal
|
31
|
-
assert_equal
|
32
|
-
assert_equal
|
33
|
-
assert_equal
|
31
|
+
assert_equal('wat', p.id?('wat'))
|
32
|
+
assert_equal(false, p.id?('endgame'))
|
33
|
+
assert_equal('6', p.consume(:number))
|
34
|
+
assert_equal('Peter', p.id?('Peter'))
|
35
|
+
assert_equal(false, p.id?('Achilles'))
|
34
36
|
end
|
35
37
|
|
36
38
|
def test_look
|
37
39
|
p = Parser.new("wat 6 Peter Hegemon")
|
38
|
-
assert_equal
|
39
|
-
assert_equal
|
40
|
-
assert_equal
|
41
|
-
assert_equal
|
42
|
-
assert_equal
|
43
|
-
assert_equal
|
40
|
+
assert_equal(true, p.look(:id))
|
41
|
+
assert_equal('wat', p.consume(:id))
|
42
|
+
assert_equal(false, p.look(:comparison))
|
43
|
+
assert_equal(true, p.look(:number))
|
44
|
+
assert_equal(true, p.look(:id, 1))
|
45
|
+
assert_equal(false, p.look(:number, 1))
|
44
46
|
end
|
45
47
|
|
46
48
|
def test_expressions
|
47
49
|
p = Parser.new("hi.there hi?[5].there? hi.there.bob")
|
48
|
-
assert_equal
|
49
|
-
assert_equal
|
50
|
-
assert_equal
|
50
|
+
assert_equal('hi.there', p.expression)
|
51
|
+
assert_equal('hi?[5].there?', p.expression)
|
52
|
+
assert_equal('hi.there.bob', p.expression)
|
51
53
|
|
52
54
|
p = Parser.new("567 6.0 'lol' \"wut\"")
|
53
|
-
assert_equal
|
54
|
-
assert_equal
|
55
|
-
assert_equal
|
56
|
-
assert_equal
|
55
|
+
assert_equal('567', p.expression)
|
56
|
+
assert_equal('6.0', p.expression)
|
57
|
+
assert_equal("'lol'", p.expression)
|
58
|
+
assert_equal('"wut"', p.expression)
|
57
59
|
end
|
58
60
|
|
59
61
|
def test_ranges
|
60
62
|
p = Parser.new("(5..7) (1.5..9.6) (young..old) (hi[5].wat..old)")
|
61
|
-
assert_equal
|
62
|
-
assert_equal
|
63
|
-
assert_equal
|
64
|
-
assert_equal
|
63
|
+
assert_equal('(5..7)', p.expression)
|
64
|
+
assert_equal('(1.5..9.6)', p.expression)
|
65
|
+
assert_equal('(young..old)', p.expression)
|
66
|
+
assert_equal('(hi[5].wat..old)', p.expression)
|
65
67
|
end
|
66
68
|
|
67
69
|
def test_arguments
|
68
70
|
p = Parser.new("filter: hi.there[5], keyarg: 7")
|
69
|
-
assert_equal
|
70
|
-
assert_equal
|
71
|
-
assert_equal
|
72
|
-
assert_equal
|
73
|
-
assert_equal
|
71
|
+
assert_equal('filter', p.consume(:id))
|
72
|
+
assert_equal(':', p.consume(:colon))
|
73
|
+
assert_equal('hi.there[5]', p.argument)
|
74
|
+
assert_equal(',', p.consume(:comma))
|
75
|
+
assert_equal('keyarg: 7', p.argument)
|
74
76
|
end
|
75
77
|
|
76
78
|
def test_invalid_expression
|
@@ -0,0 +1,128 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class PartialCacheUnitTest < Minitest::Test
|
6
|
+
def test_uses_the_file_system_register_if_present
|
7
|
+
context = Liquid::Context.build(
|
8
|
+
registers: {
|
9
|
+
file_system: StubFileSystem.new('my_partial' => 'my partial body'),
|
10
|
+
}
|
11
|
+
)
|
12
|
+
|
13
|
+
partial = Liquid::PartialCache.load(
|
14
|
+
'my_partial',
|
15
|
+
context: context,
|
16
|
+
parse_context: Liquid::ParseContext.new
|
17
|
+
)
|
18
|
+
|
19
|
+
assert_equal('my partial body', partial.render)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_reads_from_the_file_system_only_once_per_file
|
23
|
+
file_system = StubFileSystem.new('my_partial' => 'some partial body')
|
24
|
+
context = Liquid::Context.build(
|
25
|
+
registers: { file_system: file_system }
|
26
|
+
)
|
27
|
+
|
28
|
+
2.times do
|
29
|
+
Liquid::PartialCache.load(
|
30
|
+
'my_partial',
|
31
|
+
context: context,
|
32
|
+
parse_context: Liquid::ParseContext.new
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
assert_equal(1, file_system.file_read_count)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_cache_state_is_stored_per_context
|
40
|
+
parse_context = Liquid::ParseContext.new
|
41
|
+
shared_file_system = StubFileSystem.new(
|
42
|
+
'my_partial' => 'my shared value'
|
43
|
+
)
|
44
|
+
context_one = Liquid::Context.build(
|
45
|
+
registers: {
|
46
|
+
file_system: shared_file_system,
|
47
|
+
}
|
48
|
+
)
|
49
|
+
context_two = Liquid::Context.build(
|
50
|
+
registers: {
|
51
|
+
file_system: shared_file_system,
|
52
|
+
}
|
53
|
+
)
|
54
|
+
|
55
|
+
2.times do
|
56
|
+
Liquid::PartialCache.load(
|
57
|
+
'my_partial',
|
58
|
+
context: context_one,
|
59
|
+
parse_context: parse_context
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
Liquid::PartialCache.load(
|
64
|
+
'my_partial',
|
65
|
+
context: context_two,
|
66
|
+
parse_context: parse_context
|
67
|
+
)
|
68
|
+
|
69
|
+
assert_equal(2, shared_file_system.file_read_count)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_cache_is_not_broken_when_a_different_parse_context_is_used
|
73
|
+
file_system = StubFileSystem.new('my_partial' => 'some partial body')
|
74
|
+
context = Liquid::Context.build(
|
75
|
+
registers: { file_system: file_system }
|
76
|
+
)
|
77
|
+
|
78
|
+
Liquid::PartialCache.load(
|
79
|
+
'my_partial',
|
80
|
+
context: context,
|
81
|
+
parse_context: Liquid::ParseContext.new(my_key: 'value one')
|
82
|
+
)
|
83
|
+
Liquid::PartialCache.load(
|
84
|
+
'my_partial',
|
85
|
+
context: context,
|
86
|
+
parse_context: Liquid::ParseContext.new(my_key: 'value two')
|
87
|
+
)
|
88
|
+
|
89
|
+
# Technically what we care about is that the file was parsed twice,
|
90
|
+
# but measuring file reads is an OK proxy for this.
|
91
|
+
assert_equal(1, file_system.file_read_count)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_uses_default_template_factory_when_no_template_factory_found_in_register
|
95
|
+
context = Liquid::Context.build(
|
96
|
+
registers: {
|
97
|
+
file_system: StubFileSystem.new('my_partial' => 'my partial body'),
|
98
|
+
}
|
99
|
+
)
|
100
|
+
|
101
|
+
partial = Liquid::PartialCache.load(
|
102
|
+
'my_partial',
|
103
|
+
context: context,
|
104
|
+
parse_context: Liquid::ParseContext.new
|
105
|
+
)
|
106
|
+
|
107
|
+
assert_equal('my partial body', partial.render)
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_uses_template_factory_register_if_present
|
111
|
+
template_factory = StubTemplateFactory.new
|
112
|
+
context = Liquid::Context.build(
|
113
|
+
registers: {
|
114
|
+
file_system: StubFileSystem.new('my_partial' => 'my partial body'),
|
115
|
+
template_factory: template_factory,
|
116
|
+
}
|
117
|
+
)
|
118
|
+
|
119
|
+
partial = Liquid::PartialCache.load(
|
120
|
+
'my_partial',
|
121
|
+
context: context,
|
122
|
+
parse_context: Liquid::ParseContext.new
|
123
|
+
)
|
124
|
+
|
125
|
+
assert_equal('my partial body', partial.render)
|
126
|
+
assert_equal(1, template_factory.count)
|
127
|
+
end
|
128
|
+
end
|
@@ -1,44 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class RegexpUnitTest < Minitest::Test
|
4
6
|
include Liquid
|
5
7
|
|
6
8
|
def test_empty
|
7
|
-
assert_equal
|
9
|
+
assert_equal([], ''.scan(QuotedFragment))
|
8
10
|
end
|
9
11
|
|
10
12
|
def test_quote
|
11
|
-
assert_equal
|
13
|
+
assert_equal(['"arg 1"'], '"arg 1"'.scan(QuotedFragment))
|
12
14
|
end
|
13
15
|
|
14
16
|
def test_words
|
15
|
-
assert_equal
|
17
|
+
assert_equal(['arg1', 'arg2'], 'arg1 arg2'.scan(QuotedFragment))
|
16
18
|
end
|
17
19
|
|
18
20
|
def test_tags
|
19
|
-
assert_equal
|
20
|
-
assert_equal
|
21
|
-
assert_equal
|
21
|
+
assert_equal(['<tr>', '</tr>'], '<tr> </tr>'.scan(QuotedFragment))
|
22
|
+
assert_equal(['<tr></tr>'], '<tr></tr>'.scan(QuotedFragment))
|
23
|
+
assert_equal(['<style', 'class="hello">', '</style>'], %(<style class="hello">' </style>).scan(QuotedFragment))
|
22
24
|
end
|
23
25
|
|
24
26
|
def test_double_quoted_words
|
25
|
-
assert_equal
|
27
|
+
assert_equal(['arg1', 'arg2', '"arg 3"'], 'arg1 arg2 "arg 3"'.scan(QuotedFragment))
|
26
28
|
end
|
27
29
|
|
28
30
|
def test_single_quoted_words
|
29
|
-
assert_equal
|
31
|
+
assert_equal(['arg1', 'arg2', "'arg 3'"], 'arg1 arg2 \'arg 3\''.scan(QuotedFragment))
|
30
32
|
end
|
31
33
|
|
32
34
|
def test_quoted_words_in_the_middle
|
33
|
-
assert_equal
|
35
|
+
assert_equal(['arg1', 'arg2', '"arg 3"', 'arg4'], 'arg1 arg2 "arg 3" arg4 '.scan(QuotedFragment))
|
34
36
|
end
|
35
37
|
|
36
38
|
def test_variable_parser
|
37
|
-
assert_equal
|
38
|
-
assert_equal
|
39
|
-
assert_equal
|
40
|
-
assert_equal
|
41
|
-
assert_equal
|
42
|
-
assert_equal
|
39
|
+
assert_equal(['var'], 'var'.scan(VariableParser))
|
40
|
+
assert_equal(['var', 'method'], 'var.method'.scan(VariableParser))
|
41
|
+
assert_equal(['var', '[method]'], 'var[method]'.scan(VariableParser))
|
42
|
+
assert_equal(['var', '[method]', '[0]'], 'var[method][0]'.scan(VariableParser))
|
43
|
+
assert_equal(['var', '["method"]', '[0]'], 'var["method"][0]'.scan(VariableParser))
|
44
|
+
assert_equal(['var', '[method]', '[0]', 'method'], 'var[method][0].method'.scan(VariableParser))
|
43
45
|
end
|
44
46
|
end # RegexpTest
|