mirror of
https://github.com/kemko/liquid.git
synced 2026-01-04 17:25:41 +03:00
Compare commits
1 Commits
pz-float-v
...
pz-test-in
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8493f95acb |
2
Gemfile
2
Gemfile
@@ -22,6 +22,6 @@ group :test do
|
|||||||
gem 'rubocop-performance', require: false
|
gem 'rubocop-performance', require: false
|
||||||
|
|
||||||
platform :mri, :truffleruby do
|
platform :mri, :truffleruby do
|
||||||
gem 'liquid-c', github: 'Shopify/liquid-c', ref: 'pz-range-var-float'
|
gem 'liquid-c', github: 'Shopify/liquid-c', ref: 'pz-fix-invalid-float'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -77,9 +77,6 @@ module Liquid
|
|||||||
body.parse(tokens, parse_context) do |end_tag_name, end_tag_params|
|
body.parse(tokens, parse_context) do |end_tag_name, end_tag_params|
|
||||||
@blank &&= body.blank?
|
@blank &&= body.blank?
|
||||||
|
|
||||||
# Instrument for bug 1346
|
|
||||||
Usage.increment("end_tag_params") if end_tag_params && !end_tag_params.empty?
|
|
||||||
|
|
||||||
return false if end_tag_name == block_delimiter
|
return false if end_tag_name == block_delimiter
|
||||||
raise_tag_never_closed(block_name) unless end_tag_name
|
raise_tag_never_closed(block_name) unless end_tag_name
|
||||||
|
|
||||||
|
|||||||
@@ -9,12 +9,7 @@ module Liquid
|
|||||||
@index = 0
|
@index = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :length, :parentloop
|
attr_reader :name, :length, :parentloop
|
||||||
|
|
||||||
def name
|
|
||||||
Usage.increment('forloop_drop_name')
|
|
||||||
@name
|
|
||||||
end
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@index + 1
|
@index + 1
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
tag_termination: "Tag '%{token}' was not properly terminated with regexp: %{tag_end}"
|
tag_termination: "Tag '%{token}' was not properly terminated with regexp: %{tag_end}"
|
||||||
variable_termination: "Variable '%{token}' was not properly terminated with regexp: %{tag_end}"
|
variable_termination: "Variable '%{token}' was not properly terminated with regexp: %{tag_end}"
|
||||||
tag_never_closed: "'%{block_name}' tag was never closed"
|
tag_never_closed: "'%{block_name}' tag was never closed"
|
||||||
|
meta_syntax_error: "Liquid syntax error: #{e.message}"
|
||||||
table_row: "Syntax Error in 'table_row loop' - Valid syntax: table_row [item] in [collection] cols=3"
|
table_row: "Syntax Error in 'table_row loop' - Valid syntax: table_row [item] in [collection] cols=3"
|
||||||
render: "Syntax error in tag 'render' - Template name must be a quoted string"
|
render: "Syntax error in tag 'render' - Template name must be a quoted string"
|
||||||
argument:
|
argument:
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ module Liquid
|
|||||||
case input
|
case input
|
||||||
when Integer
|
when Integer
|
||||||
input
|
input
|
||||||
when NilClass, String, Float
|
when NilClass, String
|
||||||
input.to_i
|
input.to_i
|
||||||
else
|
else
|
||||||
Utils.to_integer(input)
|
Utils.to_integer(input)
|
||||||
|
|||||||
@@ -198,7 +198,6 @@ module Liquid
|
|||||||
case key
|
case key
|
||||||
when 'offset'
|
when 'offset'
|
||||||
@from = if expr == 'continue'
|
@from = if expr == 'continue'
|
||||||
Usage.increment('for_offset_continue')
|
|
||||||
:continue
|
:continue
|
||||||
else
|
else
|
||||||
parse_expression(expr)
|
parse_expression(expr)
|
||||||
|
|||||||
@@ -55,24 +55,4 @@ class BlockTest < Minitest::Test
|
|||||||
assert_equal buf.object_id, output.object_id
|
assert_equal buf.object_id, output.object_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_instrument_for_bug_1346
|
|
||||||
calls = []
|
|
||||||
Liquid::Usage.stub(:increment, ->(name) { calls << name }) do
|
|
||||||
Liquid::Template.parse("{% for i in (1..2) %}{{ i }}{% endfor {% foo %}")
|
|
||||||
end
|
|
||||||
assert_equal(["end_tag_params"], calls)
|
|
||||||
|
|
||||||
calls = []
|
|
||||||
Liquid::Usage.stub(:increment, ->(name) { calls << name }) do
|
|
||||||
Liquid::Template.parse("{% for i in (1..2) %}{{ i }}{% endfor test %}")
|
|
||||||
end
|
|
||||||
assert_equal(["end_tag_params"], calls)
|
|
||||||
|
|
||||||
calls = []
|
|
||||||
Liquid::Usage.stub(:increment, ->(name) { calls << name }) do
|
|
||||||
Liquid::Template.parse("{% for i in (1..2) %}{{ i }}{% endfor %}")
|
|
||||||
end
|
|
||||||
assert_equal([], calls)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ class ExpressionTest < Minitest::Test
|
|||||||
def test_range
|
def test_range
|
||||||
assert_equal(1..2, parse_and_eval("(1..2)"))
|
assert_equal(1..2, parse_and_eval("(1..2)"))
|
||||||
assert_equal(3..4, parse_and_eval(" ( 3 .. 4 ) "))
|
assert_equal(3..4, parse_and_eval(" ( 3 .. 4 ) "))
|
||||||
assert_equal(1..2, parse_and_eval("(1.1..2.2)"))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -131,4 +131,16 @@ class ParsingQuirksTest < Minitest::Test
|
|||||||
def test_contains_in_id
|
def test_contains_in_id
|
||||||
assert_template_result(' YES ', '{% if containsallshipments == true %} YES {% endif %}', 'containsallshipments' => true)
|
assert_template_result(' YES ', '{% if containsallshipments == true %} YES {% endif %}', 'containsallshipments' => true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_invalid_float_with_no_leading_integer
|
||||||
|
with_error_mode(:lax) do
|
||||||
|
assert_template_result("", "{{ -.1 }}")
|
||||||
|
assert_template_result("", "{{ .1 }}")
|
||||||
|
end
|
||||||
|
|
||||||
|
with_error_mode(:strict) do
|
||||||
|
assert_raises(SyntaxError) { Template.parse("{{ -.1 }}") }
|
||||||
|
assert_raises(SyntaxError) { Template.parse("{{ .1 }}") }
|
||||||
|
end
|
||||||
|
end
|
||||||
end # ParsingQuirksTest
|
end # ParsingQuirksTest
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ HERE
|
|||||||
|
|
||||||
def test_for_with_variable_range
|
def test_for_with_variable_range
|
||||||
assert_template_result(' 1 2 3 ', '{%for item in (1..foobar) %} {{item}} {%endfor%}', "foobar" => 3)
|
assert_template_result(' 1 2 3 ', '{%for item in (1..foobar) %} {{item}} {%endfor%}', "foobar" => 3)
|
||||||
assert_template_result(' 1 2 3 ', '{%for item in (x..y) %} {{item}} {%endfor%}', "x" => 1.1, "y" => 3.3)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_for_with_hash_value_range
|
def test_for_with_hash_value_range
|
||||||
@@ -438,30 +437,4 @@ HERE
|
|||||||
|
|
||||||
assert(context.registers[:for_stack].empty?)
|
assert(context.registers[:for_stack].empty?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_instrument_for_offset_continue
|
|
||||||
assert_usage_increment('for_offset_continue') do
|
|
||||||
Template.parse('{% for item in items offset:continue %}{{item}}{% endfor %}')
|
|
||||||
end
|
|
||||||
|
|
||||||
assert_usage_increment('for_offset_continue', times: 0) do
|
|
||||||
Template.parse('{% for item in items offset:2 %}{{item}}{% endfor %}')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_instrument_forloop_drop_name
|
|
||||||
assigns = { 'items' => [1, 2, 3, 4, 5] }
|
|
||||||
|
|
||||||
assert_usage_increment('forloop_drop_name', times: 5) do
|
|
||||||
Template.parse('{% for item in items %}{{forloop.name}}{% endfor %}').render!(assigns)
|
|
||||||
end
|
|
||||||
|
|
||||||
assert_usage_increment('forloop_drop_name', times: 0) do
|
|
||||||
Template.parse('{% for item in items %}{{forloop.index}}{% endfor %}').render!(assigns)
|
|
||||||
end
|
|
||||||
|
|
||||||
assert_usage_increment('forloop_drop_name', times: 0) do
|
|
||||||
Template.parse('{% for item in items %}{{item}}{% endfor %}').render!(assigns)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -556,8 +556,4 @@ class TrimModeTest < Minitest::Test
|
|||||||
template = Liquid::Template.parse("B\n {%- if true %}{% endif %}", bug_compatible_whitespace_trimming: true)
|
template = Liquid::Template.parse("B\n {%- if true %}{% endif %}", bug_compatible_whitespace_trimming: true)
|
||||||
assert_equal("B", template.render)
|
assert_equal("B", template.render)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_trim_blank
|
|
||||||
assert_template_result('foobar', 'foo {{-}} bar')
|
|
||||||
end
|
|
||||||
end # TrimModeTest
|
end # TrimModeTest
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ class VariableTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_hash_scoping
|
def test_hash_scoping
|
||||||
assert_template_result('worked', "{{ test.test }}", 'test' => { 'test' => 'worked' })
|
template = Template.parse(%({{ test.test }}))
|
||||||
assert_template_result('worked', "{{ test . test }}", 'test' => { 'test' => 'worked' })
|
assert_equal('worked', template.render!('test' => { 'test' => 'worked' }))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_false_renders_as_false
|
def test_false_renders_as_false
|
||||||
|
|||||||
Reference in New Issue
Block a user