mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 09:05:13 -07:00
Merge pull request #1359 from Shopify/pz-instrument-range-floats
Instrument usage of floats in ranges
This commit is contained in:
@@ -8,6 +8,8 @@ module Liquid
|
|||||||
if start_obj.respond_to?(:evaluate) || end_obj.respond_to?(:evaluate)
|
if start_obj.respond_to?(:evaluate) || end_obj.respond_to?(:evaluate)
|
||||||
new(start_obj, end_obj)
|
new(start_obj, end_obj)
|
||||||
else
|
else
|
||||||
|
Usage.increment('range_float') if start_obj.is_a?(Float) || end_obj.is_a?(Float)
|
||||||
|
|
||||||
start_obj.to_i..end_obj.to_i
|
start_obj.to_i..end_obj.to_i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -31,15 +31,33 @@ class ExpressionTest < Minitest::Test
|
|||||||
assert_equal(3..4, parse_and_eval(" ( 3 .. 4 ) "))
|
assert_equal(3..4, parse_and_eval(" ( 3 .. 4 ) "))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_instrument_range_float
|
||||||
|
assert_usage_increment('range_float') do
|
||||||
|
parse("(1.0..2.0)")
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_usage_increment('range_float') do
|
||||||
|
parse("(1.0..2)")
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_usage_increment('range_float', times: 0) do
|
||||||
|
parse("(1..2)")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def parse_and_eval(markup, **assigns)
|
def parse(markup)
|
||||||
if Liquid::Template.error_mode == :strict
|
if Liquid::Template.error_mode == :strict
|
||||||
p = Liquid::Parser.new(markup)
|
p = Liquid::Parser.new(markup)
|
||||||
markup = p.expression
|
markup = p.expression
|
||||||
p.consume(:end_of_string)
|
p.consume(:end_of_string)
|
||||||
end
|
end
|
||||||
expression = Liquid::Expression.parse(markup)
|
Liquid::Expression.parse(markup)
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_and_eval(markup, **assigns)
|
||||||
|
expression = parse(markup)
|
||||||
context = Liquid::Context.new(assigns)
|
context = Liquid::Context.new(assigns)
|
||||||
context.evaluate(expression)
|
context.evaluate(expression)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user