mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Resurrect all specs
This commit is contained in:
parent
9d287aea54
commit
a2bb715d8d
15 changed files with 1696 additions and 0 deletions
399
test/hamlit/engine/old_attribute_test.rb
Normal file
399
test/hamlit/engine/old_attribute_test.rb
Normal file
|
@ -0,0 +1,399 @@
|
|||
describe Hamlit::Engine do
|
||||
include RenderAssertion
|
||||
|
||||
describe 'old attributes' do
|
||||
it 'renders attributes' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span{class: 'foo'} bar
|
||||
HAML
|
||||
<span class='foo'>bar</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders attributes' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span{ data: 2 } bar
|
||||
HAML
|
||||
<span data='2'>bar</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders attributes' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
%span{ :class => 'foo' } bar
|
||||
HAML
|
||||
<span class='foo'>bar</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders attributes' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
%span{ :class => 'foo', id: 'bar' } bar
|
||||
HAML
|
||||
<span class='foo' id='bar'>bar</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders attributes' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
%span{ :'data-disable' => true } bar
|
||||
HAML
|
||||
<span data-disable>bar</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'accepts method call including comma' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
%body{ class: "#{"ab".gsub(/a/, 'b')}", data: { confirm: 'really?', disable: true }, id: 'c'.gsub(/c/, 'a') }
|
||||
HAML
|
||||
<body class='bb' data-confirm='really?' data-disable id='a'></body>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'accepts tag content' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
%span{ class: 'foo' } <b>bar</b>
|
||||
HAML
|
||||
<span class='foo'><b>bar</b></span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders multi-byte chars as static attribute value' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
%img{ alt: 'こんにちは' }
|
||||
HAML
|
||||
<img alt='こんにちは'>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'sorts static attributes by name' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span{ :foo => "bar", :hoge => "piyo"}
|
||||
%span{ :hoge => "piyo", :foo => "bar"}
|
||||
HAML
|
||||
<span foo='bar' hoge='piyo'></span>
|
||||
<span foo='bar' hoge='piyo'></span>
|
||||
HTML
|
||||
end
|
||||
|
||||
describe 'runtime attributes' do
|
||||
it 'renders runtime hash attribute' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
- hash = { foo: 'bar' }
|
||||
%span{ hash }
|
||||
HAML
|
||||
<span foo='bar'></span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders multiples hashes' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
- h1 = { a: 'b' }
|
||||
- h2 = { c: 'd' }
|
||||
- h3 = { e: 'f' }
|
||||
%span{ h1, h2, h3 }
|
||||
HAML
|
||||
<span a='b' c='d' e='f'></span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders multiples hashes and literal hash' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
- h1 = { a: 'b' }
|
||||
- h2 = { c: 'd' }
|
||||
- h3 = { e: 'f' }
|
||||
%span{ h1, h2, h3, g: 'h', i: 'j' }
|
||||
HAML
|
||||
<span a='b' c='d' e='f' g='h' i='j'></span>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
|
||||
describe 'joinable attributes' do
|
||||
it 'joins class with a space' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
- val = ['a', 'b', 'c']
|
||||
%p{ class: val }
|
||||
%p{ class: %w[a b c] }
|
||||
%p{ class: ['a', 'b', 'c'] }
|
||||
HAML
|
||||
<p class='a b c'></p>
|
||||
<p class='a b c'></p>
|
||||
<p class='a b c'></p>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'joins attribute class and element class' do
|
||||
assert_render(<<-HAML, <<-HTML, compatible_only: :haml)
|
||||
.foo{ class: ['bar'] }
|
||||
.foo{ class: ['bar', 'foo'] }
|
||||
.foo{ class: ['bar', nil] }
|
||||
.foo{ class: ['bar', 'baz'] }
|
||||
HAML
|
||||
<div class='bar foo'></div>
|
||||
<div class='bar foo'></div>
|
||||
<div class='bar foo'></div>
|
||||
<div class='bar baz foo'></div>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'joins id with an underscore' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
- val = ['a', 'b', 'c']
|
||||
%p{ id: val }
|
||||
%p{ id: %w[a b c] }
|
||||
%p{ id: ['a', 'b', 'c'] }
|
||||
HAML
|
||||
<p id='a_b_c'></p>
|
||||
<p id='a_b_c'></p>
|
||||
<p id='a_b_c'></p>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'does not join others' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
%a{ data: { value: [count: 1] } }
|
||||
HAML
|
||||
<a data-value='[{:count=>1}]'></a>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
|
||||
describe 'deletable attributes' do
|
||||
it 'deletes attributes whose value is nil or false' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
- hash = { checked: false }
|
||||
%input{ hash }
|
||||
%input{ checked: false }
|
||||
%input{ checked: nil }
|
||||
- checked = nil
|
||||
%input{ checked: checked }
|
||||
- checked = false
|
||||
%input{ checked: checked }
|
||||
HAML
|
||||
<input>
|
||||
<input>
|
||||
<input>
|
||||
<input>
|
||||
<input>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'deletes some limited attributes with dynamic value' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
- val = false
|
||||
#foo.bar{ autofocus: val }
|
||||
#foo.bar{ checked: val }
|
||||
#foo.bar{ data: { disabled: val } }
|
||||
#foo.bar{ disabled: val }
|
||||
#foo.bar{ formnovalidate: val }
|
||||
#foo.bar{ multiple: val }
|
||||
#foo.bar{ readonly: val }
|
||||
#foo.bar{ required: val }
|
||||
HAML
|
||||
<div class='bar' id='foo'></div>
|
||||
<div class='bar' id='foo'></div>
|
||||
<div class='bar' id='foo'></div>
|
||||
<div class='bar' id='foo'></div>
|
||||
<div class='bar' id='foo'></div>
|
||||
<div class='bar' id='foo'></div>
|
||||
<div class='bar' id='foo'></div>
|
||||
<div class='bar' id='foo'></div>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'does not delete non-boolean attributes, for optimization' do
|
||||
skip
|
||||
assert_render(<<-'HAML', <<-HTML, compatible_only: [])
|
||||
/ wontfix: Non-boolean attributes are not escaped for optimization.
|
||||
- val = false
|
||||
%a{ href: val }
|
||||
- val = nil
|
||||
%a{ href: val }
|
||||
|
||||
/ Boolean attributes are escaped correctly.
|
||||
- val = false
|
||||
%a{ disabled: val }
|
||||
- val = nil
|
||||
%a{ disabled: val }
|
||||
HAML
|
||||
<!-- wontfix: Non-boolean attributes are not escaped for optimization. -->
|
||||
<a href='false'></a>
|
||||
<a href=''></a>
|
||||
<!-- Boolean attributes are escaped correctly. -->
|
||||
<a></a>
|
||||
<a></a>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
|
||||
describe 'html escape' do
|
||||
it 'escapes attribute values on static attributes' do
|
||||
assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
|
||||
%a{title: "'"}
|
||||
%a{title: "'\""}
|
||||
%a{href: '/search?foo=bar&hoge=<fuga>'}
|
||||
HAML
|
||||
<a title='''></a>
|
||||
<a title=''"'></a>
|
||||
<a href='/search?foo=bar&hoge=<fuga>'></a>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'escapes attribute values on dynamic attributes' do
|
||||
assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
|
||||
- title = "'\""
|
||||
- href = '/search?foo=bar&hoge=<fuga>'
|
||||
%a{title: title}
|
||||
%a{href: href}
|
||||
HAML
|
||||
<a title=''"'></a>
|
||||
<a href='/search?foo=bar&hoge=<fuga>'></a>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'escapes attribute values on hash attributes' do
|
||||
assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
|
||||
- title = { title: "'\"" }
|
||||
- href = { href: '/search?foo=bar&hoge=<fuga>' }
|
||||
%a{ title }
|
||||
%a{ href }
|
||||
HAML
|
||||
<a title=''"'></a>
|
||||
<a href='/search?foo=bar&hoge=<fuga>'></a>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
|
||||
describe 'nested attributes' do
|
||||
it 'renders data attribute by hash' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
- hash = { bar: 'baz' }
|
||||
%span.foo{ data: hash }
|
||||
HAML
|
||||
<span class='foo' data-bar='baz'></span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders true attributes' do
|
||||
assert_render(<<-'HAML', <<-HTML, compatible_only: :haml)
|
||||
%span{ data: { disable: true } } bar
|
||||
HAML
|
||||
<span data-disable>bar</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders nested hash whose value is variable' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
- hash = { disable: true }
|
||||
%span{ data: hash } bar
|
||||
HAML
|
||||
<span data-disable>bar</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'changes an underscore in a nested key to a hyphen' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
%div{ data: { raw_src: 'foo' } }
|
||||
HAML
|
||||
<div data-raw-src='foo'></div>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'changes an underscore in a nested dynamic attribute' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
- hash = { raw_src: 'foo' }
|
||||
%div{ data: hash }
|
||||
HAML
|
||||
<div data-raw-src='foo'></div>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
|
||||
describe 'element class with attribute class' do
|
||||
it 'does not generate double classes' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
.item{ class: 'first' }
|
||||
HAML
|
||||
<div class='first item'></div>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'does not generate double classes for a variable' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
- val = 'val'
|
||||
.element{ class: val }
|
||||
HAML
|
||||
<div class='element val'></div>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'does not generate double classes for hash attributes' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
- hash = { class: 'val' }
|
||||
.element{ hash }
|
||||
HAML
|
||||
<div class='element val'></div>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
|
||||
describe 'element id with attribute id' do
|
||||
it 'does not generate double ids' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
#item{ id: 'first' }
|
||||
HAML
|
||||
<div id='item_first'></div>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'does not generate double ids for a variable' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
- val = 'first'
|
||||
#item{ id: val }
|
||||
HAML
|
||||
<div id='item_first'></div>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'does not generate double ids for hash attributes' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
- hash = { id: 'first' }
|
||||
#item{ hash }
|
||||
HAML
|
||||
<div id='item_first'></div>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'does not generate double ids and classes for hash attributes' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
- hash = { id: 'first', class: 'foo' }
|
||||
#item.bar{ hash }
|
||||
HAML
|
||||
<div class='bar foo' id='item_first'></div>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
|
||||
if RUBY_VERSION >= "2.2.0"
|
||||
describe 'Ruby 2.2 syntax' do
|
||||
it 'renders static attributes' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%meta{ content: 'IE=edge', 'http-equiv': 'X-UA-Compatible' }
|
||||
HAML
|
||||
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders dynamic attributes' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
- hash = { content: 'IE=edge' }
|
||||
%meta{ hash, 'http-equiv': 'X-UA-Compatible' }
|
||||
HAML
|
||||
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
124
test/hamlit/engine/script_test.rb
Normal file
124
test/hamlit/engine/script_test.rb
Normal file
|
@ -0,0 +1,124 @@
|
|||
describe Hamlit::Engine do
|
||||
include RenderAssertion
|
||||
|
||||
describe 'script' do
|
||||
it 'renders one-line script' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
= 1 + 2
|
||||
%span= 3 * 4
|
||||
HAML
|
||||
3
|
||||
<span>12</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders one-line script with comment' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
= # comment_only
|
||||
= '#' + "#" # = 3 #
|
||||
= ['#',
|
||||
"#"] # comment
|
||||
HAML
|
||||
|
||||
##
|
||||
["#", "#"]
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders multi-lines script' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span
|
||||
= 1 + 2
|
||||
4 / 2
|
||||
%a= 3 - 4
|
||||
HAML
|
||||
<span>
|
||||
3
|
||||
4 / 2
|
||||
<a>-1</a>
|
||||
</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders block script' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
= 3.times do |i|
|
||||
= i
|
||||
4
|
||||
HAML
|
||||
0
|
||||
1
|
||||
2
|
||||
34
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders tag internal block script' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span
|
||||
= 1.times do |i|
|
||||
= i
|
||||
HAML
|
||||
<span>
|
||||
0
|
||||
1</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders block and a variable with spaces' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
- 1.times do | i |
|
||||
= i
|
||||
HAML
|
||||
0
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'accepts a continuing script' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
- def foo(a, b); a + b; end
|
||||
= foo(1,
|
||||
2)
|
||||
HAML
|
||||
3
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders !=' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML.rstrip, escape_html: true)
|
||||
!= '<"&>'
|
||||
!= '<"&>'.tap do |str|
|
||||
-# no operation
|
||||
HAML
|
||||
<"&>
|
||||
<"&>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders &=' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML.rstrip, escape_html: false)
|
||||
&= '<"&>'
|
||||
&= '<"&>'.tap do |str|
|
||||
-# no operation
|
||||
HAML
|
||||
<"&>
|
||||
<"&>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'regards ~ operator as =' do
|
||||
skip
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
~ "<code>hello\nworld</code>"
|
||||
HAML
|
||||
<code>hello
|
||||
world</code>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
end
|
216
test/hamlit/engine/silent_script_test.rb
Normal file
216
test/hamlit/engine/silent_script_test.rb
Normal file
|
@ -0,0 +1,216 @@
|
|||
describe Hamlit::Engine do
|
||||
include RenderAssertion
|
||||
|
||||
describe 'silent script' do
|
||||
it 'renders nothing' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
- nil
|
||||
- 3
|
||||
- 'foo'
|
||||
HAML
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders silent script' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
- foo = 3
|
||||
- bar = 2
|
||||
= foo + bar
|
||||
HAML
|
||||
5
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders nested block' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
- 2.times do |i|
|
||||
= i
|
||||
2
|
||||
- 3.upto(4).each do |i|
|
||||
= i
|
||||
HAML
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders if' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
- if true
|
||||
ok
|
||||
HAML
|
||||
ok
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders if-else' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
- if true
|
||||
ok
|
||||
- else
|
||||
ng
|
||||
|
||||
- if false
|
||||
ng
|
||||
|
||||
- else
|
||||
ok
|
||||
HAML
|
||||
ok
|
||||
ok
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders nested if-else' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
%span
|
||||
- if false
|
||||
ng
|
||||
- else
|
||||
ok
|
||||
HAML
|
||||
<span>
|
||||
ok
|
||||
</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders empty elsif statement' do
|
||||
assert_render(<<-'HAML', <<-HTML, compatible_only: :haml, error_with: :faml)
|
||||
%span
|
||||
- if false
|
||||
- elsif false
|
||||
HAML
|
||||
<span>
|
||||
</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders empty else statement' do
|
||||
assert_render(<<-'HAML', <<-HTML, compatible_only: :haml, error_with: :faml)
|
||||
%span
|
||||
- if false
|
||||
ng
|
||||
- else
|
||||
HAML
|
||||
<span>
|
||||
</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders empty when statement' do
|
||||
assert_render(<<-'HAML', <<-HTML, compatible_only: :haml, error_with: :faml)
|
||||
%span
|
||||
- case
|
||||
- when false
|
||||
HAML
|
||||
<span>
|
||||
</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'accept if inside if-else' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
- if false
|
||||
- if true
|
||||
ng
|
||||
- else
|
||||
ok
|
||||
HAML
|
||||
ok
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders if-elsif' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
- if false
|
||||
- elsif true
|
||||
ok
|
||||
|
||||
- if false
|
||||
- elsif false
|
||||
- else
|
||||
ok
|
||||
HAML
|
||||
ok
|
||||
ok
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders case-when' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
- case 'foo'
|
||||
- when /\Ao/
|
||||
ng
|
||||
- when /\Af/
|
||||
ok
|
||||
- else
|
||||
ng
|
||||
HAML
|
||||
ok
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders case-when with multiple candidates' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
- case 'a'
|
||||
- when 'a', 'b'
|
||||
ok
|
||||
HAML
|
||||
ok
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders begin-rescue' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
- begin
|
||||
- raise 'error'
|
||||
- rescue
|
||||
hello
|
||||
- ensure
|
||||
world
|
||||
HAML
|
||||
hello
|
||||
world
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders rescue with error' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
- begin
|
||||
- raise 'error'
|
||||
- rescue RuntimeError => e
|
||||
hello
|
||||
HAML
|
||||
hello
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'joins a next line if a current line ends with ","' do
|
||||
skip
|
||||
assert_render("- foo = [', \n ']\n= foo", <<-HTML, compatible_only: :haml)
|
||||
[", "]
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'accepts illegal indent in continuing code' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span
|
||||
%div
|
||||
- def foo(a, b); a + b; end
|
||||
- num = foo(1,
|
||||
2)
|
||||
= num
|
||||
HAML
|
||||
<span>
|
||||
<div>
|
||||
3
|
||||
</div>
|
||||
</span>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
end
|
303
test/hamlit/engine/tag_test.rb
Normal file
303
test/hamlit/engine/tag_test.rb
Normal file
|
@ -0,0 +1,303 @@
|
|||
describe Hamlit::Engine do
|
||||
include RenderAssertion
|
||||
|
||||
describe 'tag' do
|
||||
it 'renders one-line tag' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span hello
|
||||
HAML
|
||||
<span>hello</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'accepts multi-line =' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span= 'hello'.gsub('hell',
|
||||
'')
|
||||
HAML
|
||||
<span>o</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders multi-line tag' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span
|
||||
hello
|
||||
HAML
|
||||
<span>
|
||||
hello
|
||||
</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders a nested tag' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span
|
||||
%b
|
||||
hello
|
||||
%i
|
||||
%small world
|
||||
HAML
|
||||
<span>
|
||||
<b>
|
||||
hello
|
||||
</b>
|
||||
<i>
|
||||
<small>world</small>
|
||||
</i>
|
||||
</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders multi-line texts' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span
|
||||
%b
|
||||
hello
|
||||
world
|
||||
HAML
|
||||
<span>
|
||||
<b>
|
||||
hello
|
||||
world
|
||||
</b>
|
||||
</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'skips empty lines' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span
|
||||
|
||||
%b
|
||||
|
||||
hello
|
||||
|
||||
HAML
|
||||
<span>
|
||||
<b>
|
||||
hello
|
||||
</b>
|
||||
</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders classes' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span.foo-1.bar_A hello
|
||||
HAML
|
||||
<span class='foo-1 bar_A'>hello</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders ids only last one' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span#Bar_0#bar-
|
||||
hello
|
||||
HAML
|
||||
<span id='bar-'>
|
||||
hello
|
||||
</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders ids and classes' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span#a.b#c.d hello
|
||||
HAML
|
||||
<span class='b d' id='c'>hello</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders implicit div tag starting with id' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
#hello.world
|
||||
HAML
|
||||
<div class='world' id='hello'></div>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders implicit div tag starting with class' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
.world#hello
|
||||
foo
|
||||
HAML
|
||||
<div class='world' id='hello'>
|
||||
foo
|
||||
</div>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders large-case tag' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%SPAN
|
||||
foo
|
||||
HAML
|
||||
<SPAN>
|
||||
foo
|
||||
</SPAN>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders h1 tag' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%h1 foo
|
||||
HAML
|
||||
<h1>foo</h1>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders tag including hyphen or underscore' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%-_ foo
|
||||
HAML
|
||||
<-_>foo</-_>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'does not render silent script just after a tag' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span- raise 'a'
|
||||
HAML
|
||||
<span->raise 'a'</span->
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders a text just after attributes' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span{a: 2}a
|
||||
HAML
|
||||
<span a='2'>a</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'strips a text' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span foo
|
||||
HAML
|
||||
<span>foo</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'ignores spaces after tag' do
|
||||
assert_render("%span \n a", <<-HTML)
|
||||
<span>
|
||||
a
|
||||
</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'parses self-closing tag' do
|
||||
assert_render(<<-HAML, <<-HTML, format: :xhtml)
|
||||
%div/
|
||||
%div
|
||||
HAML
|
||||
<div />
|
||||
<div></div>
|
||||
HTML
|
||||
end
|
||||
|
||||
describe 'whitespace removal' do
|
||||
it 'removes outer whitespace by >' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span> a
|
||||
%span b
|
||||
%span c
|
||||
%span>
|
||||
d
|
||||
%span
|
||||
e
|
||||
%span f
|
||||
HAML
|
||||
<span>a</span><span>b</span>
|
||||
<span>c</span><span>
|
||||
d
|
||||
</span><span>
|
||||
e
|
||||
</span>
|
||||
<span>f</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'removes outer whitespace by > from inside of block' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span a
|
||||
- if true
|
||||
%span>
|
||||
b
|
||||
%span
|
||||
c
|
||||
HAML
|
||||
<span>a</span><span>
|
||||
b
|
||||
</span><span>
|
||||
c
|
||||
</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'removes whitespaces inside block script' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span<
|
||||
= 2.times do
|
||||
= 'foo'
|
||||
%span> bar
|
||||
HAML
|
||||
<span>foofoo2<span>bar</span></span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'removes whitespace inside script inside silent script' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
.bar<
|
||||
- 3.times do
|
||||
= 'foo'
|
||||
HAML
|
||||
<div class='bar'>foofoofoo</div>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'removes whitespace inside script recursively' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
.foo<
|
||||
- 1.times do
|
||||
= 2.times do
|
||||
- 2.times do
|
||||
= 1.times do
|
||||
= 'bar'
|
||||
HAML
|
||||
<div class='foo'>bar1bar1bar1bar12</div>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'does not remove whitespace after string interpolation' do
|
||||
assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
|
||||
%div<
|
||||
#{'hello'}
|
||||
world
|
||||
HAML
|
||||
<div>hello
|
||||
world</div>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'removes whitespace inside script inside silent script' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML, compatible_only: :faml)
|
||||
.bar<
|
||||
- 1.times do
|
||||
= '1'
|
||||
= '2'
|
||||
HAML
|
||||
<div class='bar'>1
|
||||
2</div>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
249
test/hamlit/engine/text_test.rb
Normal file
249
test/hamlit/engine/text_test.rb
Normal file
|
@ -0,0 +1,249 @@
|
|||
describe Hamlit::Engine do
|
||||
include RenderAssertion
|
||||
|
||||
describe 'text' do
|
||||
it 'renders string interpolation' do
|
||||
skip
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
#{ "a#{3}a" }a" #{["1", 2]} b " !
|
||||
a#{{ a: 3 }}
|
||||
<ht#{2}ml>
|
||||
HAML
|
||||
a3aa" ["1", 2] b " !
|
||||
a{:a=>3}
|
||||
<ht2ml>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders . or # which is not continued by tag name' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML, error_with: [:haml, :faml])
|
||||
.
|
||||
.*
|
||||
..
|
||||
#
|
||||
#+
|
||||
##
|
||||
HAML
|
||||
.
|
||||
.*
|
||||
..
|
||||
#
|
||||
#+
|
||||
##
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'escapes all operators by backslash' do
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
= 'a'
|
||||
-
|
||||
\= 'a'
|
||||
\-
|
||||
HAML
|
||||
a
|
||||
= 'a'
|
||||
-
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders == operator' do
|
||||
skip
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
===
|
||||
== =
|
||||
== <a>
|
||||
== #{'<a>'}
|
||||
HAML
|
||||
=
|
||||
=
|
||||
<a>
|
||||
<a>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders !== operator' do
|
||||
skip
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
== #{'<a>'}
|
||||
!== #{'<a>'}
|
||||
!===
|
||||
!== =
|
||||
HAML
|
||||
<a>
|
||||
<a>
|
||||
=
|
||||
=
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'leaves empty spaces after backslash' do
|
||||
skip
|
||||
expect(render_string('\ a')).to eq(" a\n")
|
||||
end
|
||||
|
||||
it 'renders spaced - properly' do
|
||||
assert_render(<<-HAML, <<-'HTML')
|
||||
%div
|
||||
foo
|
||||
.test - bar
|
||||
.test - baz
|
||||
HAML
|
||||
<div>
|
||||
foo
|
||||
<div class='test'>- bar</div>
|
||||
<div class='test'>- baz</div>
|
||||
</div>
|
||||
HTML
|
||||
end
|
||||
|
||||
describe 'inline operator' do
|
||||
it 'renders ! operator' do
|
||||
assert_render(<<-'HAML', <<-'HTML')
|
||||
%span!#{'<nyaa>'}
|
||||
%span! #{'<nyaa>'}
|
||||
! #{'<nyaa>'}
|
||||
HAML
|
||||
<span><nyaa></span>
|
||||
<span><nyaa></span>
|
||||
<nyaa>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders & operator' do
|
||||
assert_render(<<-'HAML', <<-'HTML')
|
||||
%span& #{'<nyaa>'}
|
||||
%span&#{'<nyaa>'}
|
||||
& #{'<nyaa>'}
|
||||
HAML
|
||||
<span><nyaa></span>
|
||||
<span><nyaa></span>
|
||||
<nyaa>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders !, & operator right before a non-space character' do
|
||||
assert_render(<<-'HAML', <<-'HTML', compatible_only: :haml)
|
||||
|
||||
\
|
||||
!hello
|
||||
\!hello
|
||||
HAML
|
||||
|
||||
|
||||
!hello
|
||||
!hello
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders &, ! operator inside a tag' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
%span
|
||||
%span
|
||||
%span& nbsp;
|
||||
%span !hello
|
||||
%span!hello
|
||||
%span! hello
|
||||
HAML
|
||||
<span> </span>
|
||||
<span>nbsp;</span>
|
||||
<span>nbsp;</span>
|
||||
<span>!hello</span>
|
||||
<span>hello</span>
|
||||
<span>hello</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'does not accept backslash operator' do
|
||||
assert_render(<<-'HAML', <<-'HTML')
|
||||
%span\ foo
|
||||
HAML
|
||||
<span>\ foo</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders != operator' do
|
||||
assert_render(<<-'HAML', <<-'HTML')
|
||||
%span!= '<nyaa>'
|
||||
HAML
|
||||
<span><nyaa></span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders !== operator' do
|
||||
assert_render(<<-'HAML', <<-'HTML')
|
||||
%span!==#{'<nyaa>'}
|
||||
%span!== #{'<nyaa>'}
|
||||
!==#{'<nyaa>'}
|
||||
!== #{'<nyaa>'}
|
||||
HAML
|
||||
<span><nyaa></span>
|
||||
<span><nyaa></span>
|
||||
<nyaa>
|
||||
<nyaa>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders &= operator' do
|
||||
skip
|
||||
assert_render(<<-'HAML', <<-'HTML', escape_html: false)
|
||||
%span&= '<nyaa>'
|
||||
HAML
|
||||
<span><nyaa></span>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders &== operator' do
|
||||
assert_render(<<-'HAML', <<-'HTML')
|
||||
&===
|
||||
&== =
|
||||
&== #{'<p>'}
|
||||
HAML
|
||||
=
|
||||
=
|
||||
<p>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders ~ operator' do
|
||||
assert_render(<<-HAML, <<-HTML, escape_html: false)
|
||||
%span~ 1
|
||||
HAML
|
||||
<span>1</span>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
|
||||
describe 'string interpolation' do
|
||||
specify { assert_render('#{}', "\n") }
|
||||
specify { assert_render('1#{}', "1\n") }
|
||||
specify { assert_render('1#{2}', "12\n") }
|
||||
specify { assert_render('}#{1}', "}1\n") }
|
||||
specify { assert_render('#{1}2', "12\n") }
|
||||
specify { assert_render('1#{ "2#{3}4" }5', "12345\n") }
|
||||
specify { assert_render('#{1}2#{3}4#{5}6#{7}8#{9}', "123456789\n") }
|
||||
specify { assert_render(%q{'"!@$%^&*|=#{1}1#{1}2}, %Q{'"!@$%^&*|=1112\n}) }
|
||||
specify { assert_render('あ#{1}', "あ1\n") }
|
||||
specify { assert_render('あ#{"い"}う', "あいう\n") }
|
||||
specify { skip; assert_render('a#{"<b>"}c', "a<b>c\n") }
|
||||
end
|
||||
|
||||
describe 'illegal inputs' do
|
||||
it 'rejects an invalid tag' do
|
||||
skip
|
||||
expect { render_string(<<-HAML.unindent) }.
|
||||
% a
|
||||
HAML
|
||||
to raise_error(Hamlit::SyntaxError, 'Invalid tag: "% a".')
|
||||
end
|
||||
|
||||
it 'rejects an invalid tag' do
|
||||
skip
|
||||
expect { render_string(<<-HAML.unindent) }.
|
||||
%.foo
|
||||
HAML
|
||||
to raise_error(Hamlit::SyntaxError, 'Invalid tag: "%.foo".')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
65
test/hamlit/filters/coffee_test.rb
Normal file
65
test/hamlit/filters/coffee_test.rb
Normal file
|
@ -0,0 +1,65 @@
|
|||
describe Hamlit::Filters do
|
||||
include RenderAssertion
|
||||
|
||||
describe '#compile' do
|
||||
it 'renders coffee filter' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
:coffee
|
||||
foo = ->
|
||||
alert('hello')
|
||||
HAML
|
||||
<script>
|
||||
(function() {
|
||||
var foo;
|
||||
|
||||
foo = function() {
|
||||
return alert('hello');
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
</script>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders coffeescript filter' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
:coffee
|
||||
foo = ->
|
||||
alert('hello')
|
||||
HAML
|
||||
<script>
|
||||
(function() {
|
||||
var foo;
|
||||
|
||||
foo = function() {
|
||||
return alert('hello');
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
</script>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders coffeescript filter' do
|
||||
skip
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
:coffee
|
||||
foo = ->
|
||||
alert("#{'<&>'}")
|
||||
HAML
|
||||
<script>
|
||||
(function() {
|
||||
var foo;
|
||||
|
||||
foo = function() {
|
||||
return alert("<&>");
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
</script>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
end
|
37
test/hamlit/filters/css_test.rb
Normal file
37
test/hamlit/filters/css_test.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
describe Hamlit::Filters do
|
||||
include RenderAssertion
|
||||
|
||||
describe '#compile' do
|
||||
it 'renders css' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
:css
|
||||
.foo {
|
||||
width: 100px;
|
||||
}
|
||||
HAML
|
||||
<style>
|
||||
.foo {
|
||||
width: 100px;
|
||||
}
|
||||
</style>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'parses string interpolation' do
|
||||
skip
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
:css
|
||||
.foo {
|
||||
content: "#{'<&>'}";
|
||||
}
|
||||
HAML
|
||||
<style>
|
||||
.foo {
|
||||
content: "<&>";
|
||||
}
|
||||
</style>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
end
|
19
test/hamlit/filters/erb_test.rb
Normal file
19
test/hamlit/filters/erb_test.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
describe Hamlit::Filters do
|
||||
include RenderAssertion
|
||||
|
||||
describe '#compile' do
|
||||
it 'renders erb filter' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML, compatible_only: [], error_with: :faml)
|
||||
:erb
|
||||
<% if true %>
|
||||
ok
|
||||
<% else %>
|
||||
ng
|
||||
<% end %>
|
||||
HAML
|
||||
ok
|
||||
HTML
|
||||
end
|
||||
end
|
||||
end
|
88
test/hamlit/filters/javascript_test.rb
Normal file
88
test/hamlit/filters/javascript_test.rb
Normal file
|
@ -0,0 +1,88 @@
|
|||
describe Hamlit::Filters do
|
||||
include RenderAssertion
|
||||
|
||||
describe '#compile' do
|
||||
it 'just renders script tag for empty filter' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML, compatible_only: [])
|
||||
before
|
||||
:javascript
|
||||
after
|
||||
HAML
|
||||
before
|
||||
<script>
|
||||
|
||||
</script>
|
||||
after
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'compiles javascript filter' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
before
|
||||
:javascript
|
||||
alert('hello');
|
||||
after
|
||||
HAML
|
||||
before
|
||||
<script>
|
||||
alert('hello');
|
||||
</script>
|
||||
after
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'accepts illegal indentation' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML, compatible_only: :faml)
|
||||
:javascript
|
||||
if {
|
||||
alert('hello');
|
||||
}
|
||||
:javascript
|
||||
if {
|
||||
alert('hello');
|
||||
}
|
||||
HAML
|
||||
<script>
|
||||
if {
|
||||
alert('hello');
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
if {
|
||||
alert('hello');
|
||||
}
|
||||
</script>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'accepts illegal indentation' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
:javascript
|
||||
if {
|
||||
alert('a');
|
||||
}
|
||||
HAML
|
||||
<script>
|
||||
if {
|
||||
alert('a');
|
||||
}
|
||||
</script>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'parses string interpolation' do
|
||||
skip
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
:javascript
|
||||
var a = "#{'<&>'}";
|
||||
HAML
|
||||
<script>
|
||||
var a = "<&>";
|
||||
</script>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
end
|
41
test/hamlit/filters/less_test.rb
Normal file
41
test/hamlit/filters/less_test.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
describe Hamlit::Filters do
|
||||
include RenderAssertion
|
||||
|
||||
describe '#compile' do
|
||||
it 'renders less filter' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML, compatible_only: :haml, error_with: :faml)
|
||||
:less
|
||||
.users_controller {
|
||||
.show_action {
|
||||
margin: 10px;
|
||||
padding: 20px;
|
||||
}
|
||||
}
|
||||
HAML
|
||||
<style>
|
||||
.users_controller .show_action {
|
||||
margin: 10px;
|
||||
padding: 20px;
|
||||
}
|
||||
</style>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'parses string interpolation' do
|
||||
skip
|
||||
assert_render(<<-'HAML', <<-HTML, compatible_only: :haml, error_with: :faml)
|
||||
:less
|
||||
.foo {
|
||||
content: "#{'<&>'}";
|
||||
}
|
||||
HAML
|
||||
<style>
|
||||
.foo {
|
||||
content: "<&>";
|
||||
}
|
||||
</style>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
end
|
34
test/hamlit/filters/markdown_test.rb
Normal file
34
test/hamlit/filters/markdown_test.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
describe Hamlit::Filters do
|
||||
include RenderAssertion
|
||||
|
||||
describe '#compile' do
|
||||
it 'renders markdown filter' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
:markdown
|
||||
# Hamlit
|
||||
Yet another haml implementation
|
||||
HAML
|
||||
<h1>Hamlit</h1>
|
||||
|
||||
<p>Yet another haml implementation</p>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders markdown filter with string interpolation' do
|
||||
skip
|
||||
assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
|
||||
- project = '<Hamlit>'
|
||||
:markdown
|
||||
# #{project}
|
||||
#{'<&>'}
|
||||
Yet another haml implementation
|
||||
HAML
|
||||
<h1><Hamlit></h1>
|
||||
|
||||
<p><&>
|
||||
Yet another haml implementation</p>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
end
|
17
test/hamlit/filters/plain_test.rb
Normal file
17
test/hamlit/filters/plain_test.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
describe Hamlit::Filters do
|
||||
include RenderAssertion
|
||||
|
||||
describe '#compile' do
|
||||
it 'renders plain filter' do
|
||||
assert_render(<<-'HAML', <<-HTML, compatible_only: :haml)
|
||||
:plain
|
||||
あ
|
||||
#{'い'}
|
||||
HAML
|
||||
あ
|
||||
い
|
||||
|
||||
HTML
|
||||
end
|
||||
end
|
||||
end
|
26
test/hamlit/filters/ruby_test.rb
Normal file
26
test/hamlit/filters/ruby_test.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
describe Hamlit::Filters do
|
||||
include RenderAssertion
|
||||
|
||||
it 'renders ruby filter' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
:ruby
|
||||
hello
|
||||
HAML
|
||||
hello
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders ruby filter' do
|
||||
skip
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
:ruby
|
||||
hash = {
|
||||
a: "#{'<&>'}",
|
||||
}
|
||||
= hash[:a]
|
||||
HAML
|
||||
<&>
|
||||
HTML
|
||||
end
|
||||
end
|
37
test/hamlit/filters/sass_test.rb
Normal file
37
test/hamlit/filters/sass_test.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
describe Hamlit::Filters do
|
||||
include RenderAssertion
|
||||
|
||||
describe '#compile' do
|
||||
it 'renders sass filter' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
:sass
|
||||
.users_controller
|
||||
.show_action
|
||||
margin: 10px
|
||||
padding: 20px
|
||||
HAML
|
||||
<style>
|
||||
.users_controller .show_action {
|
||||
margin: 10px;
|
||||
padding: 20px; }
|
||||
</style>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders sass filter with string interpolation' do
|
||||
skip
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
:sass
|
||||
.users_controller
|
||||
.show_action
|
||||
content: "#{'<&>'}"
|
||||
HAML
|
||||
<style>
|
||||
.users_controller .show_action {
|
||||
content: "<&>"; }
|
||||
</style>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
end
|
41
test/hamlit/filters/scss_test.rb
Normal file
41
test/hamlit/filters/scss_test.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
describe Hamlit::Filters do
|
||||
include RenderAssertion
|
||||
|
||||
describe '#compile' do
|
||||
it 'renders scss filter' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
:scss
|
||||
.users_controller {
|
||||
.show_action {
|
||||
margin: 10px;
|
||||
padding: 20px;
|
||||
}
|
||||
}
|
||||
HAML
|
||||
<style>
|
||||
.users_controller .show_action {
|
||||
margin: 10px;
|
||||
padding: 20px; }
|
||||
</style>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'parses string interpolation' do
|
||||
skip
|
||||
assert_render(<<-'HAML', <<-HTML)
|
||||
:scss
|
||||
.users_controller {
|
||||
.show_action {
|
||||
content: "#{'<&>'}";
|
||||
}
|
||||
}
|
||||
HAML
|
||||
<style>
|
||||
.users_controller .show_action {
|
||||
content: "<&>"; }
|
||||
</style>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue