-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1656 from kmuto/review-header-listener
Extract EPUBMaker#parse_headlines to add a test
- Loading branch information
Showing
4 changed files
with
105 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
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE html> | ||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="ja"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="stylesheet" type="text/css" href="style.css" /> | ||
<meta name="generator" content="Re:VIEW" /> | ||
<title>first chapter</title> | ||
</head> | ||
<body> | ||
<h1><a id="h1"></a><span class="secno">第1章 </span>first chapter</h1> | ||
|
||
<h2><a id="h1-1"></a><span class="secno">1.1 </span>first section</h2> | ||
|
||
<h3><a id="h1-1-1"></a>first <img src="images/icon1.jpg" alt="subsection" /></h3> | ||
|
||
<h2><a id="h1-2"></a><span class="secno">1.2 </span>second section</h2> | ||
|
||
<h3 id="dummy1"><a id="h1-2-1"></a>dummy subsection</h3> | ||
|
||
<h2><a id="h1-3"></a><span class="secno">1.3 </span>third section</h2> | ||
|
||
<h2 id="ch01_nonum1" notoc="true">notoc section</h2> | ||
|
||
<h2 id="dummy2" notoc="true">notoc section</h2> | ||
|
||
<a id="ch01_nonum3" /><h2 id="ch01_nonum3" hidden="true">nodisp section</h2> | ||
|
||
<a id="dummy3" /><h2 id="dummy3" hidden="true">nodisp section</h2> | ||
|
||
<h2 id="ch01_nonum5">nonum section</h2> | ||
|
||
<h2 id="dummy4">nonum section</h2> | ||
</body> | ||
</html> |
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,49 @@ | ||
require 'test_helper' | ||
require 'rexml/document' | ||
require 'rexml/streamlistener' | ||
require 'review/epubmaker' | ||
|
||
class ReVIEWHeaderListenerTest < Test::Unit::TestCase | ||
def setup | ||
@epubmaker = ReVIEW::EPUBMaker.new | ||
end | ||
|
||
def teardown | ||
end | ||
|
||
def test_epubmaker_parse_headlines | ||
# original Re:VIEW source: | ||
# | ||
# = first chapter | ||
# == first section | ||
# === first @<embed>{<img src="images/icon1.jpg" alt="subsection" />} | ||
# == second section | ||
# ==={dummy1} dummy subsection | ||
# == third section | ||
# ==[notoc] notoc section | ||
# ==[notoc]{dummy2} notoc section | ||
# ==[nodisp] nodisp section | ||
# ==[nodisp]{dummy3} nodisp section | ||
# ==[nonum] nonum section | ||
# ==[nonum]{dummy4} nonum section | ||
Dir.mktmpdir do |_dir| | ||
path = File.join(assets_dir, 'header_listener.html') | ||
headlines = @epubmaker.parse_headlines(path) | ||
|
||
expected = [{ 'id' => 'h1', 'level' => 1, 'notoc' => nil, 'title' => '第1章 first chapter' }, | ||
{ 'id' => 'h1-1', 'level' => 2, 'notoc' => nil, 'title' => '1.1 first section' }, | ||
{ 'id' => 'h1-1-1', 'level' => 3, 'notoc' => nil, 'title' => 'first subsection' }, | ||
{ 'id' => 'h1-2', 'level' => 2, 'notoc' => nil, 'title' => '1.2 second section' }, | ||
{ 'id' => 'h1-2-1', 'level' => 3, 'notoc' => nil, 'title' => 'dummy subsection' }, | ||
{ 'id' => 'h1-3', 'level' => 2, 'notoc' => nil, 'title' => '1.3 third section' }, | ||
{ 'id' => 'ch01_nonum1', 'level' => 2, 'notoc' => 'true', 'title' => 'notoc section' }, | ||
{ 'id' => 'dummy2', 'level' => 2, 'notoc' => 'true', 'title' => 'notoc section' }, | ||
{ 'id' => 'ch01_nonum3', 'level' => 2, 'notoc' => nil, 'title' => 'nodisp section' }, | ||
{ 'id' => 'dummy3', 'level' => 2, 'notoc' => nil, 'title' => 'nodisp section' }, | ||
{ 'id' => 'ch01_nonum5', 'level' => 2, 'notoc' => nil, 'title' => 'nonum section' }, | ||
{ 'id' => 'dummy4', 'level' => 2, 'notoc' => nil, 'title' => 'nonum section' }] | ||
|
||
assert_equal expected, headlines | ||
end | ||
end | ||
end |