2015-03-12 09:07:49 +09:00
|
|
|
describe Hamlit::Engine do
|
2015-03-11 21:26:46 +09:00
|
|
|
describe 'silent script' do
|
2015-03-15 00:28:03 +09:00
|
|
|
it 'renders silent script' do
|
2015-03-11 21:26:46 +09:00
|
|
|
assert_render(<<-HAML, <<-HTML)
|
|
|
|
- foo = 3
|
|
|
|
- bar = 2
|
|
|
|
= foo + bar
|
|
|
|
HAML
|
|
|
|
5
|
|
|
|
HTML
|
|
|
|
end
|
2015-03-11 21:49:28 +09:00
|
|
|
|
2015-03-15 00:28:03 +09:00
|
|
|
it 'renders nested block' do
|
2015-03-11 21:49:28 +09:00
|
|
|
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
|
|
|
|
|
2015-03-15 00:28:03 +09:00
|
|
|
it 'renders if' do
|
2015-03-11 21:49:28 +09:00
|
|
|
assert_render(<<-HAML, <<-HTML)
|
|
|
|
- if true
|
|
|
|
ok
|
|
|
|
HAML
|
|
|
|
ok
|
|
|
|
HTML
|
|
|
|
end
|
2015-03-11 22:16:50 +09:00
|
|
|
|
2015-03-15 00:28:03 +09:00
|
|
|
it 'renders if-else' do
|
2015-03-11 22:16:50 +09:00
|
|
|
assert_render(<<-HAML, <<-HTML)
|
|
|
|
- if true
|
|
|
|
ok
|
|
|
|
- else
|
|
|
|
ng
|
|
|
|
|
|
|
|
- if false
|
|
|
|
ng
|
|
|
|
|
|
|
|
- else
|
|
|
|
ok
|
|
|
|
HAML
|
|
|
|
ok
|
|
|
|
ok
|
|
|
|
HTML
|
|
|
|
end
|
2015-03-11 22:20:06 +09:00
|
|
|
|
2015-03-15 18:49:59 +09:00
|
|
|
it 'renders nested if-else' do
|
|
|
|
assert_render(<<-'HAML', <<-HTML)
|
|
|
|
%span
|
|
|
|
- if false
|
|
|
|
ng
|
|
|
|
- else
|
|
|
|
ok
|
|
|
|
HAML
|
|
|
|
<span>
|
|
|
|
ok
|
|
|
|
</span>
|
|
|
|
HTML
|
|
|
|
end
|
|
|
|
|
2015-03-16 00:08:08 +09:00
|
|
|
it 'accept if inside if-else' do
|
|
|
|
assert_render(<<-'HAML', <<-HTML)
|
|
|
|
- if false
|
|
|
|
- if true
|
|
|
|
ng
|
|
|
|
- else
|
|
|
|
ok
|
|
|
|
HAML
|
|
|
|
ok
|
|
|
|
HTML
|
|
|
|
end
|
|
|
|
|
2015-03-15 00:28:03 +09:00
|
|
|
it 'renders if-elsif' do
|
2015-03-11 22:20:06 +09:00
|
|
|
assert_render(<<-HAML, <<-HTML)
|
|
|
|
- if false
|
|
|
|
- elsif true
|
|
|
|
ok
|
2015-03-11 22:35:33 +09:00
|
|
|
|
|
|
|
- if false
|
|
|
|
- elsif false
|
|
|
|
- else
|
|
|
|
ok
|
|
|
|
HAML
|
|
|
|
ok
|
|
|
|
ok
|
|
|
|
HTML
|
|
|
|
end
|
|
|
|
|
2015-03-15 00:28:03 +09:00
|
|
|
it 'renders case-when' do
|
2015-03-11 22:35:33 +09:00
|
|
|
assert_render(<<-'HAML', <<-HTML)
|
|
|
|
- case 'foo'
|
|
|
|
- when /\Ao/
|
|
|
|
ng
|
|
|
|
- when /\Af/
|
|
|
|
ok
|
|
|
|
- else
|
|
|
|
ng
|
2015-03-11 22:20:06 +09:00
|
|
|
HAML
|
|
|
|
ok
|
|
|
|
HTML
|
|
|
|
end
|
2015-03-16 13:46:35 +09:00
|
|
|
|
|
|
|
it 'joins a next line if a current line ends with ","' do
|
|
|
|
assert_render("- foo = [', \n ']\n= foo", <<-HTML)
|
|
|
|
[", "]
|
|
|
|
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
|
2015-03-11 21:26:46 +09:00
|
|
|
end
|
|
|
|
end
|