-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
106 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<div id="__brokendiv"> | ||
Preface | ||
|
||
<div> | ||
<h1>Section 1</h1> | ||
|
||
Hello! | ||
</div> | ||
|
||
<div> | ||
<div> | ||
<h1>Section 2</h1> | ||
</div> | ||
<div> | ||
This document describes something. | ||
</div> | ||
<div> | ||
<h2>Section 2.1</h2> | ||
|
||
Content | ||
|
||
<h2>Section 2.2</h2> | ||
|
||
<div class="nastydiv"> | ||
<h3>Section 2.2.1</h3><h4>Section 2.2.1.1</h4><h2>Section 2.3</h2> | ||
</div> | ||
|
||
Hey! | ||
</div> | ||
</div> | ||
|
||
<h1>Section 3</h1><h2>Section 3.1</h2> | ||
|
||
Goodbye! | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
require "spec_helper" | ||
|
||
describe Coradoc::ReverseAdoc do | ||
let(:input) { File.read("spec/reverse_adoc/assets/sections.html") } | ||
let(:document) { Nokogiri::HTML(input) } | ||
let(:level) { 1 } | ||
subject { Coradoc::ReverseAdoc.convert(input, split_sections: level) } | ||
let(:l1sections) { | ||
%w[sections/section-01.adoc | ||
sections/section-02.adoc | ||
sections/section-03.adoc | ||
] + [nil] } | ||
let(:l2sections) { | ||
%w[sections/section-01.adoc | ||
sections/section-02/section-01.adoc | ||
sections/section-02/section-02.adoc | ||
sections/section-02/section-03.adoc | ||
sections/section-02.adoc | ||
sections/section-03/section-01.adoc | ||
sections/section-03.adoc | ||
] + [nil] } | ||
|
||
context "splitting in level nil" do | ||
let(:level) { nil } | ||
|
||
it { should_not be_a Hash } | ||
end | ||
|
||
shared_examples "can split and generate correct index" do | ||
it { should be_a Hash } | ||
it "should have a correct keys" do | ||
subject.keys.should be == expected_sections | ||
end | ||
|
||
it "should have a correct index" do | ||
section_content = l1sections.compact.map { |i| "include::#{i}[]\n\n" }.join | ||
subject[nil].should be == "[[__brokendiv]]\nPreface\n#{section_content}" | ||
end | ||
end | ||
|
||
context "splitting in level 1" do | ||
let(:level) { 1 } | ||
let(:expected_sections) { l1sections } | ||
|
||
include_examples "can split and generate correct index" | ||
end | ||
|
||
context "splitting in level 2" do | ||
let(:level) { 2 } | ||
let(:expected_sections) { l2sections } | ||
|
||
include_examples "can split and generate correct index" | ||
|
||
it "should have a correct level2 index" do | ||
subject["sections/section-02.adoc"].should be == | ||
"== Section 2\n" + | ||
"\n" + | ||
"This document describes something.\n" + | ||
"\n" + | ||
"include::../sections/section-02/section-01.adoc[]\n" + | ||
"\n" + | ||
"include::../sections/section-02/section-02.adoc[]\n" + | ||
"\n" + | ||
"include::../sections/section-02/section-03.adoc[]\n" + | ||
"\n" | ||
end | ||
end | ||
end |