1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
require_relative '../test_helper'
describe 'optimization' do
def compiled_code(haml)
Hamlit::Engine.new.call(haml)
end
describe 'static analysis' do
it 'renders static value for href statically' do
haml = %|%a{ href: 1 }|
assert_equal true, compiled_code(haml).include?(%|href='1'|)
end
it 'renders static script statically' do
haml = <<-HAML.unindent
%span
1
HAML
assert_equal true, compiled_code(haml).include?(%q|<span>\n1\n</span>|)
end
it 'renders inline static script statically' do
haml = %|%span= 1|
assert_equal true, compiled_code(haml).include?(%|<span>1</span>|)
end
end
describe 'string interpolation' do
it 'renders a static part of string literal statically' do
haml = %q|%input{ value: "jruby#{9000}#{dynamic}" }|
assert_equal true, compiled_code(haml).include?(%|value='jruby9000|)
haml = %q|%span= "jruby#{9000}#{dynamic}"|
assert_equal true, compiled_code(haml).include?(%|<span>jruby9000|)
end
it 'optimizes script' do
haml = %q|= "jruby#{ "#{9000}" }#{dynamic}"|
assert_equal true, compiled_code(haml).include?(%|jruby9000|)
end
it 'detects a static part recursively' do
haml = %q|%input{ value: "#{ "hello#{ hello }" }" }|
assert_equal true, compiled_code(haml).include?(%|value='hello|)
end
end
end if RUBY_ENGINE != 'truffleruby' # truffleruby does not implement major Ripper features
|