# -*- coding: utf-8; -*- require 'spec_helper' require 'tdiary' require 'misc/style/etdiary/etdiary_style' describe TDiary::EtdiaryDiary do before do @diary = TDiary::EtdiaryDiary.new(Time::at( 1041346800 ), "TITLE", "") end describe '#append' do before do @source = <<-'EOF' hogehoge fugafuga fugahoge hogera <> honbun <<<>subTitleH4>> honbun

notParagraph

Content of block element with blank line.
hogehoge
Paragraph begin with tag.
In 
, < and > are automatically escaped.
<<>> Section without title and anchor. <<<>>> Section without title. EOF @diary.append(@source) end context 'HTML' do before do @html = <<-'EOF'
<%=section_enter_proc( Time::at( 1041346800 ) )%>

hogehoge fugafuga

fugahoge hogera

<%=section_leave_proc( Time::at( 1041346800 ) )%>
<%=section_enter_proc( Time::at( 1041346800 ) )%>

<%= subtitle_proc( Time::at( 1041346800 ), "subTitle" ) %>

honbun

<%= subtitle_proc( Time::at( 1041346800 ), "subTitleH4" ) %>:

honbun

notParagraph

Content of block element with blank line.
hogehoge

Paragraph begin with tag.

In <pre>, < and > are automatically escaped.

<%= subtitle_proc( Time::at( 1041346800 ), nil ) %> Section without title and anchor.

Section without title.

<%=section_leave_proc( Time::at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end context 'CHTML' do before do @html = <<-'EOF' <%=section_enter_proc( Time::at( 1041346800 ) )%>

hogehoge fugafuga

fugahoge hogera

<%=section_leave_proc( Time::at( 1041346800 ) )%> <%=section_enter_proc( Time::at( 1041346800 ) )%>

<%= subtitle_proc( Time::at( 1041346800 ), "subTitle" ) %>

honbun

<%= subtitle_proc( Time::at( 1041346800 ), "subTitleH4" ) %>: honbun

notParagraph

Content of block element with blank line.
hogehoge

Paragraph begin with tag.

In <pre>, < and > are automatically escaped.

<%= subtitle_proc( Time::at( 1041346800 ), nil ) %> Section without title and anchor.

Section without title.

<%=section_leave_proc( Time::at( 1041346800 ) )%> EOF end it { @diary.to_html({'anchor' => true, 'index' => true}, :CHTML).should eq @html } end context 'to_src' do it { @diary.to_src.should eq @source } end end describe '#add_section' do before do source = <<-'EOF' <> 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

<%= subtitle_proc( Time::at( 1041346800 ), "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' <> honbun <> 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 '#replace' do before do source = <<-'EOF' <> honbun <<<>subTitleH4>> honbun EOF @diary.append(source) replaced = <<-'EOF' <> 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

<%= subtitle_proc( Time::at( 1041346800 ), "replaceTitleH4" ) %>:

replace

<%=section_leave_proc( Time::at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end describe 'test_etdiary_unterminated_tag' do before do source = <<-'EOF'

paragraph EOF @diary.append(source) end context 'HTML' do before do @html = <<-'EOF'

<%=section_enter_proc( Time::at( 1041346800 ) )%>

paragraph

(tDiary warning: tag <p> is not terminated.) <%=section_leave_proc( Time::at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end context 'CHTML' do before do @html = <<-'EOF' <%=section_enter_proc( Time::at( 1041346800 ) )%>

paragraph

(tDiary warning: tag <p> is not terminated.) <%=section_leave_proc( Time::at( 1041346800 ) )%> EOF end it { @diary.to_html({'anchor' => true, 'index' => true}, :CHTML).should eq @html } end end describe 'test_etdiary_null' do before do source = <<-'EOF' EOF @diary.append(source) end context 'HTML' do before do @html = <<-'EOF'
<%=section_enter_proc( Time::at( 1041346800 ) )%>

<%=section_leave_proc( Time::at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end context 'CHTML' do before do @html = <<-'EOF' <%=section_enter_proc( Time::at( 1041346800 ) )%>

<%=section_leave_proc( Time::at( 1041346800 ) )%> EOF end it { @diary.to_html({'anchor' => true, 'index' => true}, :CHTML).should eq @html } end end describe 'test_etdiary_sectionAtBeginning' do before do source = <<-'EOF' <> fuga EOF @diary.append(source) end context 'HTML' do before do @html = <<-'EOF'
<%=section_enter_proc( Time::at( 1041346800 ) )%>

<%= subtitle_proc( Time::at( 1041346800 ), "hoge" ) %>

fuga

<%=section_leave_proc( Time::at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end context 'CHTML' do before do @html = <<-'EOF' <%=section_enter_proc( Time::at( 1041346800 ) )%>

<%= subtitle_proc( Time::at( 1041346800 ), "hoge" ) %>

fuga

<%=section_leave_proc( Time::at( 1041346800 ) )%> EOF end it { @diary.to_html({'anchor' => true, 'index' => true}, :CHTML).should eq @html } end end describe 'test_etdiary_appending' do before do source = <<-'EOF'

para1

EOF sourceAppended = <<-'EOF'

para2

EOF @diary.append(source) @diary.append(sourceAppended) end context 'HTML' do before do @html = <<-'EOF'
<%=section_enter_proc( Time::at( 1041346800 ) )%>

para1

para2

<%=section_leave_proc( Time::at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end context 'CHTML' do before do @html = <<-'EOF' <%=section_enter_proc( Time::at( 1041346800 ) )%>

para1

para2

<%=section_leave_proc( Time::at( 1041346800 ) )%> EOF end it { @diary.to_html({'anchor' => true, 'index' => true}, :CHTML).should eq @html } end end # 2004.08.12 Reported by Shun-ichi TAHARA, thanks! describe 'test_etdiary_subsequentPREtoSectionTitle' do before do source = <<-'EOF' <>
hoge

fuga
EOF @diary.append(source) end context 'HTML' do before do @html = <<-'EOF'
<%=section_enter_proc( Time::at( 1041346800 ) )%>

<%= subtitle_proc( Time::at( 1041346800 ), "hoge" ) %>

hoge

fuga
<%=section_leave_proc( Time::at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end context 'CHTML' do before do @html = <<-'EOF' <%=section_enter_proc( Time::at( 1041346800 ) )%>

<%= subtitle_proc( Time::at( 1041346800 ), "hoge" ) %>

hoge

fuga
<%=section_leave_proc( Time::at( 1041346800 ) )%> EOF end it { @diary.to_html({'anchor' => true, 'index' => true}, :CHTML).should eq @html } end end # 2004.08.19 Reported by Shun-ichi TAHARA, thanks! describe 'test_etdiary_badAnchorNumber' do before do source = <<-'EOF' sect0-para0 <> sect1-para0 sect1-para1 sect1-para2 <> sect2-para0 EOF @diary.append(source) sections = [] @diary.each_section { |sect| sections << sect } @anchorNumber = 0 @section = sections.find do |sect| @anchorNumber += 1 (sect.subtitle == "sect2") end end it { @section.should_not be_nil } it { @anchorNumber.should eq 2 } # github issue #271 it { @section.body_to_html.should eq "

sect2-para0\n

\n" } end end # Local Variables: # mode: ruby # indent-tabs-mode: t # tab-width: 3 # ruby-indent-level: 3 # End: