# -*- coding: utf-8; -*-
require 'spec_helper'
require 'tdiary'
require 'misc/style/rd/rd_style'
describe TDiary::RdDiary do
before do
@diary = TDiary::RdDiary.new(Time::at( 1041346800 ), "TITLE", "")
end
describe '#append' do
before do
source = <<-'EOF'
= subTitle
honbun
== subTitleH4
honbun
EOF
@diary.append(source)
end
context 'HTML' do
before do
@html = <<-'EOF'
<%=section_enter_proc( Time::at( 1041346800 ))%>
<%= subtitle_proc( Time::at( 1041346800 ), "subTitle" ) %>
honbun
subTitleH4
honbun
<%=section_leave_proc( Time::at( 1041346800 ))%>
EOF
end
it { @diary.to_html.should eq @html }
end
end
describe '#replace' do
before do
source = <<-'EOF'
= subTitle
honbun
== subTitleH4
honbun
EOF
@diary.append(source)
replaced = <<-'EOF'
= replaceTitle
replace
== replaceTitleH4
replace
EOF
@diary.replace(Time::at( 1041346800 ), "TITLE", replaced)
@html = <<-'EOF'
<%=section_enter_proc( Time::at( 1041346800 ))%>
<%= subtitle_proc( Time::at( 1041346800 ), "replaceTitle" ) %>
replace
replaceTitleH4
replace
<%=section_leave_proc( Time::at( 1041346800 ))%>
EOF
end
it { @diary.to_html.should eq @html }
end
describe '#add_section' do
before do
source = <<-'EOF'
= subTitle
honbun
== subTitleH4
honbun
EOF
@diary.append(source)
@diary.add_section('subTitle2', 'honbun')
@html = <<-'EOF'
<%=section_enter_proc( Time::at( 1041346800 ))%>
<%= subtitle_proc( Time::at( 1041346800 ), "subTitle" ) %>
honbun
subTitleH4
honbun
<%=section_leave_proc( Time::at( 1041346800 ))%>
<%=section_enter_proc( Time::at( 1041346800 ))%>
<%= subtitle_proc( Time::at( 1041346800 ), "subTitle2" ) %>
honbun
<%=section_leave_proc( Time::at( 1041346800 ))%>
EOF
end
it { @diary.to_html.should eq @html }
end
describe '#delete_section' do
before do
source = <<-'EOF'
= subTitle
honbun
= subTitle2
honbun
EOF
@diary.append(source)
@diary.delete_section(1)
@html = <<-'EOF'
<%=section_enter_proc( Time::at( 1041346800 ))%>
<%= subtitle_proc( Time::at( 1041346800 ), "subTitle2" ) %>
honbun
<%=section_leave_proc( Time::at( 1041346800 ))%>
EOF
end
it { @diary.to_html.should eq @html }
end
describe 'test_rd_style_plugin' do
before do
source = <<-'EOF'
= subTitle
((%plugin%))
((%plugin%))
aaa
((%plugin%))
a((%ho
ge%))b
((%ho
ge%))
EOF
@diary.append(source)
end
context 'HTML' do
before do
@html = <<-'EOF'
<%=section_enter_proc( Time::at( 1041346800 ))%>
<%= subtitle_proc( Time::at( 1041346800 ), "subTitle" ) %>
<%=plugin %>
<%=plugin %>
aaa
<%=plugin %>
a<%=ho ge%>b
<%=ho ge%>
<%=section_leave_proc( Time::at( 1041346800 ))%>
EOF
end
it { @diary.to_html.should eq @html }
end
end
describe 'test_rd_on_error' do
context 'link' do
before do
source = <<-'EOF'
(())
EOF
@diary.append(source)
@exception_message = <<-'EOF'
RD syntax error: line 1:
...(()) ...
^
EOF
end
it {
lambda{ @diary.to_html }.should raise_error(SyntaxError){ |e|
e.message.should eq @exception_message
}
}
end
end
end
# Local Variables:
# mode: ruby
# indent-tabs-mode: t
# tab-width: 3
# ruby-indent-level: 3
# End: