require 'spec_helper' RSpec.describe 'Element rendering', type: :render do it 'parses one-line element' do expect(render_string('%span hello')).to eq("hello\n") end it 'parses multi-line element' do expect(render_string(<\nhello\n\n") %span hello HAML end it 'parses nested elements' do expect(render_string(<\n\nhello\n\n\nworld\n\n\n") %span %b hello %i %small world HAML end it 'parses multi-line texts' do expect(render_string(<\n\nhello\nworld\n\n\n") %span %b hello world HAML end it 'skips empty lines' do expect(render_string(<\n\nhello\n\n\n") %span %b hello HAML end it 'raises error if indent is wrong' do expect { render_string(<hello\n}) end it 'parses id' do expect(render_string('%span#foo-bar hello')).to eq(%Q{hello\n}) end it 'parses classes and id' do expect(render_string('%span.foo#foo-bar.bar hello')).to eq(%Q{hello\n}) end it "doesn't skip spaces before attribute list" do expect(render_string('%span {hello}')).to eq("{hello}\n") expect(render_string('%span (hello)')).to eq("(hello)\n") end context 'with invalid tag name' do it 'raises error' do expect { render_string('%.foo') }.to raise_error(Faml::SyntaxError) end end it 'parses #' do expect(render_string('#main')).to eq(%Q{
\n}) end it 'parses .' do expect(render_string('.wrapper.main')).to eq(%Q{
\n}) end it 'parses Ruby multiline' do expect(render_string(<\n2+3i\n\n") %div %span= Complex(2, 3) HAML end it 'parses string interpolation' do expect(render_string(%q|%span hello #{''} |)).to eq("hello </span> \n") expect(render_string(<<'HAML')).to eq("\nhello </span> \n\n") %span hello #{{text: ''}[:text]} HAML expect(render_string(<<'HAML')).to eq("\nhello </span> \n\n") - @var = '' %span hello #@var HAML end it 'parses string interpolation with multibyte characters' do expect(render_string(%q|#{'日本語'} にほんご|)).to eq("日本語 にほんご\n") end it 'recognized escaped string interpolation' do expect(render_string(%q|%p hello \#{1 + 2}|)).to eq("

hello \#{1 + 2}

\n") end it 'parses self-closing tag' do expect(render_string('%p/')).to eq("

\n") end it 'renders some attributes as self-closing by default' do expect(render_string('%meta{"http-equiv" => "Content-Type", :content => "text/html"}')).to eq("\n") end it 'parses == syntax' do expect(render_string('%p== =#{1+2}hello')).to eq("

=3hello

\n") end it 'raises error if self-closing tag have text' do expect { render_string('%p/ hello') }.to raise_error(Faml::SyntaxError) end it 'raises error if self-closing tag have children' do expect { render_string(<