Files
liquid/test/unit/optimizer_test.rb
Marc-André Cournoyer 0de722968c Introduce the AST Optimizer
... that can only optimize one thing: combine `| append: 'a' | append: 'b'` into a single `| append_all: ['a', 'b']` filter call.

This avoids all the intermediate allocations caused by several `append`.

Also introduce a new filter `append_all: [*items]`.
2020-10-07 13:47:42 -04:00

17 lines
390 B
Ruby

# frozen_string_literal: true
require 'test_helper'
class OptimizerUnitTest < Minitest::Test
include Liquid
def test_combines_append_filters
optimizer = Optimizer.new
var = Variable.new('hello | append: "a" | append: b', ParseContext.new)
var = optimizer.optimize(var)
assert_equal([
['append_all', ["a", VariableLookup.new("b")]]
], var.filters)
end
end