review-peg 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +36 -0
- data/.rubocop.yml +47 -0
- data/.rubocop_todo.yml +605 -0
- data/.travis.yml +18 -0
- data/COPYING +515 -0
- data/ChangeLog +2449 -0
- data/Dockerfile +22 -0
- data/Gemfile +6 -0
- data/README.rdoc +81 -0
- data/Rakefile +51 -0
- data/bin/review-catalog-converter-peg +129 -0
- data/bin/review-check-peg +169 -0
- data/bin/review-checkdep-peg +63 -0
- data/bin/review-compile-peg +202 -0
- data/bin/review-epubmaker-legacy-peg +1024 -0
- data/bin/review-epubmaker-peg +44 -0
- data/bin/review-index-peg +110 -0
- data/bin/review-init-peg +151 -0
- data/bin/review-pdfmaker-peg +18 -0
- data/bin/review-preproc-peg +131 -0
- data/bin/review-validate-peg +51 -0
- data/bin/review-vol-peg +100 -0
- data/debian/README.Debian +12 -0
- data/debian/README.source +5 -0
- data/debian/changelog +5 -0
- data/debian/compat +1 -0
- data/debian/control +22 -0
- data/debian/copyright +62 -0
- data/debian/docs +6 -0
- data/debian/manpage.1.ex +59 -0
- data/debian/patches/path.diff +91 -0
- data/debian/patches/series +1 -0
- data/debian/review.install +13 -0
- data/debian/review.links +4 -0
- data/debian/rules +13 -0
- data/debian/source/format +1 -0
- data/doc/NEWS.ja.md +350 -0
- data/doc/NEWS.md +354 -0
- data/doc/catalog.ja.md +53 -0
- data/doc/catalog.md +52 -0
- data/doc/format.ja.md +734 -0
- data/doc/format.md +746 -0
- data/doc/format_idg.ja.md +203 -0
- data/doc/quickstart.ja.md +222 -0
- data/doc/quickstart.md +252 -0
- data/doc/ruby-uuid/README +11 -0
- data/doc/ruby-uuid/README.ja +34 -0
- data/doc/sample.css +108 -0
- data/doc/sample.yml +238 -0
- data/lib/epubmaker.rb +24 -0
- data/lib/epubmaker/content.rb +93 -0
- data/lib/epubmaker/epubcommon.rb +424 -0
- data/lib/epubmaker/epubv2.rb +139 -0
- data/lib/epubmaker/epubv3.rb +222 -0
- data/lib/epubmaker/producer.rb +330 -0
- data/lib/lineinput.rb +107 -0
- data/lib/review.rb +3 -0
- data/lib/review/book.rb +43 -0
- data/lib/review/book/base.rb +401 -0
- data/lib/review/book/chapter.rb +100 -0
- data/lib/review/book/compilable.rb +184 -0
- data/lib/review/book/image_finder.rb +71 -0
- data/lib/review/book/index.rb +413 -0
- data/lib/review/book/page_metric.rb +47 -0
- data/lib/review/book/part.rb +54 -0
- data/lib/review/book/volume.rb +67 -0
- data/lib/review/builder.rb +452 -0
- data/lib/review/catalog.rb +52 -0
- data/lib/review/compiler.rb +5183 -0
- data/lib/review/compiler/literals_1_9.kpeg +22 -0
- data/lib/review/compiler/literals_1_9.rb +435 -0
- data/lib/review/configure.rb +64 -0
- data/lib/review/epubbuilder.rb +18 -0
- data/lib/review/epubmaker.rb +480 -0
- data/lib/review/ewbbuilder.rb +381 -0
- data/lib/review/exception.rb +21 -0
- data/lib/review/extentions.rb +4 -0
- data/lib/review/extentions/array.rb +25 -0
- data/lib/review/extentions/object.rb +9 -0
- data/lib/review/extentions/string.rb +33 -0
- data/lib/review/htmlbuilder.rb +1166 -0
- data/lib/review/htmllayout.rb +41 -0
- data/lib/review/htmltoc.rb +45 -0
- data/lib/review/htmlutils.rb +90 -0
- data/lib/review/i18n.rb +96 -0
- data/lib/review/i18n.yml +169 -0
- data/lib/review/idgxmlbuilder.rb +1233 -0
- data/lib/review/inaobuilder.rb +357 -0
- data/lib/review/latexbuilder.rb +941 -0
- data/lib/review/latexindex.rb +35 -0
- data/lib/review/latexutils.rb +95 -0
- data/lib/review/layout.tex.erb +340 -0
- data/lib/review/lineinput.rb +17 -0
- data/lib/review/location.rb +24 -0
- data/lib/review/makerhelper.rb +67 -0
- data/lib/review/markdownbuilder.rb +339 -0
- data/lib/review/node.rb +288 -0
- data/lib/review/pdfmaker.rb +332 -0
- data/lib/review/preprocessor.rb +530 -0
- data/lib/review/review.kpeg +745 -0
- data/lib/review/sec_counter.rb +69 -0
- data/lib/review/template.rb +21 -0
- data/lib/review/textbuilder.rb +17 -0
- data/lib/review/textutils.rb +16 -0
- data/lib/review/tocparser.rb +348 -0
- data/lib/review/tocprinter.rb +205 -0
- data/lib/review/topbuilder.rb +796 -0
- data/lib/review/unfold.rb +138 -0
- data/lib/review/version.rb +3 -0
- data/lib/uuid.rb +312 -0
- data/review.gemspec +32 -0
- data/templates/html/layout-html5.html.erb +17 -0
- data/templates/html/layout-xhtml1.html.erb +20 -0
- data/templates/ncx/epubv2.ncx.erb +11 -0
- data/templates/opf/epubv2.opf.erb +21 -0
- data/templates/opf/epubv3.opf.erb +18 -0
- data/templates/xml/container.xml.erb +6 -0
- data/test/CHAPS +2 -0
- data/test/assets/test.xml.erb +3 -0
- data/test/assets/test_template.tex +255 -0
- data/test/assets/test_template_backmatter.tex +32 -0
- data/test/bib.re +13 -0
- data/test/book_test_helper.rb +35 -0
- data/test/sample-book/README.md +7 -0
- data/test/sample-book/src/Rakefile +58 -0
- data/test/sample-book/src/_cover.html +3 -0
- data/test/sample-book/src/catalog.yml +10 -0
- data/test/sample-book/src/ch01.re +71 -0
- data/test/sample-book/src/ch02.re +3 -0
- data/test/sample-book/src/config.yml +186 -0
- data/test/sample-book/src/images/ch01-imgsample.jpg +0 -0
- data/test/sample-book/src/images/cover.jpg +0 -0
- data/test/sample-book/src/preface.re +15 -0
- data/test/sample-book/src/sty/jumoline.sty +310 -0
- data/test/sample-book/src/sty/reviewmacro.sty +39 -0
- data/test/sample-book/src/style.css +251 -0
- data/test/sample-book/src/vendor/jumoline/README +29 -0
- data/test/sample-book/src/vendor/jumoline/jumoline.dtx +2988 -0
- data/test/sample-book/src/vendor/jumoline/jumoline.ins +6 -0
- data/test/test.re +43 -0
- data/test/test_book.rb +556 -0
- data/test/test_book_chapter.rb +280 -0
- data/test/test_book_part.rb +54 -0
- data/test/test_builder.rb +80 -0
- data/test/test_catalog.rb +119 -0
- data/test/test_catalog_converter_cmd.rb +73 -0
- data/test/test_compiler.rb +92 -0
- data/test/test_configure.rb +50 -0
- data/test/test_epub3maker.rb +529 -0
- data/test/test_epubmaker.rb +569 -0
- data/test/test_epubmaker_cmd.rb +40 -0
- data/test/test_helper.rb +92 -0
- data/test/test_htmlbuilder.rb +1114 -0
- data/test/test_htmltoc.rb +32 -0
- data/test/test_htmlutils.rb +50 -0
- data/test/test_i18n.rb +180 -0
- data/test/test_idgxmlbuilder.rb +608 -0
- data/test/test_image_finder.rb +82 -0
- data/test/test_inaobuilder.rb +245 -0
- data/test/test_index.rb +174 -0
- data/test/test_latexbuilder.rb +732 -0
- data/test/test_lineinput.rb +182 -0
- data/test/test_makerhelper.rb +66 -0
- data/test/test_markdownbuilder.rb +125 -0
- data/test/test_pdfmaker.rb +171 -0
- data/test/test_pdfmaker_cmd.rb +40 -0
- data/test/test_preprocessor.rb +23 -0
- data/test/test_review_ext.rb +31 -0
- data/test/test_template.rb +26 -0
- data/test/test_textutils.rb +32 -0
- data/test/test_topbuilder.rb +291 -0
- data/test/test_uuid.rb +157 -0
- metadata +357 -0
@@ -0,0 +1,280 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'book_test_helper'
|
3
|
+
class ChapterTest < Test::Unit::TestCase
|
4
|
+
include BookTestHelper
|
5
|
+
|
6
|
+
def test_initialize
|
7
|
+
ch = Book::Chapter.new(:book, :number, :name, '/foo/bar', :io)
|
8
|
+
assert_equal :book, ch.book
|
9
|
+
assert_equal :number, ch.number
|
10
|
+
assert_equal '/foo/bar', ch.path
|
11
|
+
assert_equal "#<ReVIEW::Book::Chapter number /foo/bar>", ch.inspect
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_dirname_and_basename
|
15
|
+
ch = Book::Chapter.new(nil, nil, nil, nil, nil)
|
16
|
+
assert_equal nil, ch.dirname
|
17
|
+
assert_equal nil, ch.basename
|
18
|
+
|
19
|
+
ch = Book::Chapter.new(nil, nil, nil, '/foo/bar', nil)
|
20
|
+
assert_equal '/foo', ch.dirname
|
21
|
+
assert_equal 'bar', ch.basename
|
22
|
+
|
23
|
+
ch = Book::Chapter.new(nil, nil, nil, 'bar', nil)
|
24
|
+
assert_equal '.', ch.dirname
|
25
|
+
assert_equal 'bar', ch.basename
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_name
|
29
|
+
ch = Book::Chapter.new(nil, nil, 'foo', nil)
|
30
|
+
assert_equal 'foo', ch.name
|
31
|
+
|
32
|
+
ch = Book::Chapter.new(nil, nil, 'foo.bar', nil)
|
33
|
+
assert_equal 'foo', ch.name
|
34
|
+
|
35
|
+
# ch = Book::Chapter.new(nil, nil, nil, nil)
|
36
|
+
# assert_raises(TypeError) { ch.name } # XXX: OK?
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_open
|
40
|
+
ch = Book::Chapter.new(nil, nil, nil, __FILE__, :io)
|
41
|
+
assert_equal :io, ch.open
|
42
|
+
assert_equal [:io], ch.open {|io| [io] }
|
43
|
+
|
44
|
+
ch = Book::Chapter.new(nil, nil, nil, __FILE__)
|
45
|
+
assert_equal __FILE__, ch.open.path
|
46
|
+
assert_equal [__FILE__], ch.open {|io| [io.path] }
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_size
|
50
|
+
ch = Book::Chapter.new(nil, nil, nil, __FILE__, :io)
|
51
|
+
assert_equal File.size(__FILE__), ch.size
|
52
|
+
|
53
|
+
File.open(__FILE__, 'r') do |i|
|
54
|
+
ch = Book::Chapter.new(nil, nil, nil, nil, i)
|
55
|
+
assert_raises(TypeError) do # XXX: OK?
|
56
|
+
ch.size
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_title
|
62
|
+
io = StringIO.new
|
63
|
+
book = Book::Base.new(nil)
|
64
|
+
ch = Book::Chapter.new(book, nil, nil, nil, io)
|
65
|
+
assert_equal '', ch.title
|
66
|
+
|
67
|
+
io = StringIO.new("=1\n=2\n")
|
68
|
+
ch = Book::Chapter.new(book, nil, nil, nil, io)
|
69
|
+
assert_equal '1', ch.title
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_lines
|
73
|
+
lines = ["1\n", "2\n", "3"]
|
74
|
+
tf = Tempfile.new('chapter_test')
|
75
|
+
tf.print lines.join('')
|
76
|
+
tf.close
|
77
|
+
|
78
|
+
book = Book::Base.new(nil)
|
79
|
+
ch = Book::Chapter.new(book, nil, nil, tf.path)
|
80
|
+
assert_equal lines, ch.lines
|
81
|
+
|
82
|
+
lines = ["1\n", "2\n", "3"]
|
83
|
+
tf1 = Tempfile.new('chapter_test1')
|
84
|
+
tf1.print lines.join('')
|
85
|
+
tf1.close
|
86
|
+
tf2 = Tempfile.new('chapter_test2')
|
87
|
+
tf2.puts lines.join('')
|
88
|
+
tf2.puts lines.join('')
|
89
|
+
tf2.close
|
90
|
+
|
91
|
+
ch = Book::Chapter.new(book, nil, nil, tf1.path, tf2.path)
|
92
|
+
assert_equal lines, ch.lines # XXX: OK?
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_volume
|
96
|
+
content = "abc\ndef"
|
97
|
+
tf1 = Tempfile.new('chapter_test1')
|
98
|
+
tf1.print content
|
99
|
+
tf1.close
|
100
|
+
tf2 = Tempfile.new('chapter_test2')
|
101
|
+
tf2.print content
|
102
|
+
tf2.print content
|
103
|
+
tf2.close
|
104
|
+
|
105
|
+
book = Book::Base.new(nil)
|
106
|
+
ch = Book::Chapter.new(book, nil, nil, tf1.path)
|
107
|
+
assert ch.volume
|
108
|
+
assert_equal content.gsub(/\s/, '').size, ch.volume.bytes
|
109
|
+
|
110
|
+
book = Book::Base.new(nil)
|
111
|
+
ch = Book::Chapter.new(book, nil, nil, tf1.path, tf2)
|
112
|
+
assert ch.volume
|
113
|
+
assert_equal content.gsub(/\s/, '').size, ch.volume.bytes # XXX: OK?
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_on_CHAPS?
|
117
|
+
mktmpbookdir 'CHAPS' => "chapter1.re\nchapter2.re",
|
118
|
+
'chapter1.re' => '12345', 'preface.re' => 'abcde' do |dir, book, files|
|
119
|
+
ch1 = Book::Chapter.new(book, 1, 'chapter1', files['chapter1.re'])
|
120
|
+
pre = Book::Chapter.new(book, nil, 'preface', files['preface.re'])
|
121
|
+
|
122
|
+
assert ch1.on_CHAPS?
|
123
|
+
assert !pre.on_CHAPS?
|
124
|
+
|
125
|
+
ch2_path = File.join(dir, 'chapter2.er')
|
126
|
+
File.open(ch2_path, 'w') {}
|
127
|
+
ch2 = Book::Chapter.new(book, 2, 'chapter2', ch2_path)
|
128
|
+
|
129
|
+
ch3_path = File.join(dir, 'chapter3.er')
|
130
|
+
File.open(ch3_path, 'w') {}
|
131
|
+
ch3 = Book::Chapter.new(book, 3, 'chapter3', ch3_path)
|
132
|
+
|
133
|
+
assert ch2.on_CHAPS?
|
134
|
+
assert !ch3.on_CHAPS?
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_list_index
|
139
|
+
do_test_index(<<E, Book::ListIndex, :list_index, :list)
|
140
|
+
//list
|
141
|
+
//listnum [abc]
|
142
|
+
//list [def]
|
143
|
+
//table [def]
|
144
|
+
//table [others]
|
145
|
+
E
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_table_index
|
149
|
+
do_test_index(<<E, Book::TableIndex, :table_index, :table)
|
150
|
+
//table
|
151
|
+
//table [abc]
|
152
|
+
//table [def]
|
153
|
+
//list [def]
|
154
|
+
//list [others]
|
155
|
+
E
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_footnote_index
|
159
|
+
content = <<E
|
160
|
+
//footnote
|
161
|
+
//footnote [abc][text...]
|
162
|
+
//footnote [def][text...]
|
163
|
+
//footnote [xyz]
|
164
|
+
//list [def]
|
165
|
+
//list [others]
|
166
|
+
E
|
167
|
+
do_test_index(content, Book::FootnoteIndex, :footnote_index, :footnote) do |ch|
|
168
|
+
assert_raises ReVIEW::KeyError do
|
169
|
+
ch.footnote('xyz')
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_bibpaper
|
175
|
+
do_test_index(<<E, Book::BibpaperIndex, :bibpaper_index, :bibpaper, :filename => 'bib.re')
|
176
|
+
//bibpaper
|
177
|
+
//bibpaper [abc][text...]
|
178
|
+
//bibpaper [def][text...]
|
179
|
+
//bibpaper [xyz]
|
180
|
+
//list [def]
|
181
|
+
//list [others]
|
182
|
+
E
|
183
|
+
assert_raises FileNotFound do
|
184
|
+
do_test_index('', Book::BibpaperIndex, :bibpaper_index, :bibpaper, :filename => 'bib')
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_headline_index
|
189
|
+
do_test_index(<<E, Book::HeadlineIndex, :headline_index, :headline, :propagate => false)
|
190
|
+
==
|
191
|
+
== abc
|
192
|
+
== def
|
193
|
+
=== def
|
194
|
+
//table others
|
195
|
+
E
|
196
|
+
end
|
197
|
+
|
198
|
+
|
199
|
+
def test_headline_index_nullsection
|
200
|
+
do_test_index(<<E, Book::HeadlineIndex, :headline_index, :headline, :propagate => false)
|
201
|
+
== abc
|
202
|
+
==== dummy
|
203
|
+
== def
|
204
|
+
E
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
def test_column_index
|
209
|
+
book = Book::Base.new(nil)
|
210
|
+
do_test_index(<<E, Book::ColumnIndex, :column_index, :column, :propagate => false)
|
211
|
+
= dummy1
|
212
|
+
===[column]{abc} aaaa
|
213
|
+
= dummy2
|
214
|
+
===[column] def
|
215
|
+
== dummy3
|
216
|
+
E
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_image
|
220
|
+
do_test_index(<<E, Book::ImageIndex, :image_index, :image)
|
221
|
+
//image
|
222
|
+
//image [abc]
|
223
|
+
//image [def]
|
224
|
+
//list [def]
|
225
|
+
//list [others]
|
226
|
+
E
|
227
|
+
|
228
|
+
do_test_index(<<E, Book::NumberlessImageIndex, :numberless_image_index, :image, :propagate => false)
|
229
|
+
//numberlessimage
|
230
|
+
//numberlessimage [abc]
|
231
|
+
//numberlessimage [def]
|
232
|
+
//list [def]
|
233
|
+
//list [others]
|
234
|
+
E
|
235
|
+
|
236
|
+
do_test_index(<<E, Book::ImageIndex, :image_index, :image)
|
237
|
+
//image
|
238
|
+
//numberlessimage [abc]
|
239
|
+
//image [def]
|
240
|
+
//list [def]
|
241
|
+
//list [others]
|
242
|
+
E
|
243
|
+
|
244
|
+
do_test_index(<<E, Book::NumberlessImageIndex, :numberless_image_index, :image, :propagate => false)
|
245
|
+
//image
|
246
|
+
//numberlessimage [abc]
|
247
|
+
//image [def]
|
248
|
+
//list [def]
|
249
|
+
//list [others]
|
250
|
+
E
|
251
|
+
end
|
252
|
+
|
253
|
+
def do_test_index(content, klass, list_method, ref_method, opts = {})
|
254
|
+
Dir.mktmpdir do |dir|
|
255
|
+
path = File.join(dir, opts[:filename] || 'chapter.re')
|
256
|
+
|
257
|
+
book = Book::Base.new(dir)
|
258
|
+
|
259
|
+
ch = nil
|
260
|
+
File.open(path, 'w') do |o|
|
261
|
+
o.print content
|
262
|
+
ch = Book::Chapter.new(book, 1, 'chapter', o.path)
|
263
|
+
end
|
264
|
+
|
265
|
+
assert ch.__send__(ref_method, 'abc')
|
266
|
+
assert ch.__send__(ref_method, 'def')
|
267
|
+
assert_raises ReVIEW::KeyError do
|
268
|
+
ch.__send__(ref_method, nil)
|
269
|
+
end
|
270
|
+
assert_raises ReVIEW::KeyError do
|
271
|
+
ch.__send__(ref_method, 'others')
|
272
|
+
end
|
273
|
+
assert_raises ReVIEW::KeyError do
|
274
|
+
ch.__send__(ref_method, 'not exist id')
|
275
|
+
end
|
276
|
+
|
277
|
+
yield(ch) if block_given?
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'book_test_helper'
|
2
|
+
class PartTest < Test::Unit::TestCase
|
3
|
+
include BookTestHelper
|
4
|
+
|
5
|
+
def test_initialize
|
6
|
+
part = Book::Part.new(nil, nil, nil)
|
7
|
+
assert_equal nil, part.number
|
8
|
+
assert_equal nil, part.chapters
|
9
|
+
assert_equal '', part.name
|
10
|
+
|
11
|
+
part = Book::Part.new(nil, 123, [], 'name')
|
12
|
+
assert_equal 123, part.number
|
13
|
+
assert_equal [], part.chapters
|
14
|
+
assert_equal 'name', part.name
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_each_chapter
|
18
|
+
part = Book::Part.new(nil, nil, [1, 2, 3])
|
19
|
+
|
20
|
+
tmp = []
|
21
|
+
part.each_chapter do |ch|
|
22
|
+
tmp << ch
|
23
|
+
end
|
24
|
+
assert_equal [1, 2, 3], tmp
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_volume
|
28
|
+
book = Book::Base.new(nil)
|
29
|
+
part = Book::Part.new(book, nil, [])
|
30
|
+
assert part.volume
|
31
|
+
assert_equal 0, part.volume.bytes
|
32
|
+
assert_equal 0, part.volume.chars
|
33
|
+
assert_equal 0, part.volume.lines
|
34
|
+
|
35
|
+
chs = []
|
36
|
+
tfs = [] ## prevent from removing Tempfile
|
37
|
+
Tempfile.open('part_test') do |o|
|
38
|
+
o.print "12345"
|
39
|
+
chs << Book::Chapter.new(book, nil, nil, o.path)
|
40
|
+
tfs << o
|
41
|
+
end
|
42
|
+
Tempfile.open('part_test') do |o|
|
43
|
+
o.print "67890"
|
44
|
+
chs << Book::Chapter.new(book, nil, nil, o.path)
|
45
|
+
tfs << o
|
46
|
+
end
|
47
|
+
|
48
|
+
part = Book::Part.new(book, nil, chs)
|
49
|
+
assert part.volume
|
50
|
+
assert part.volume.bytes > 0
|
51
|
+
assert part.volume.chars > 0
|
52
|
+
assert part.volume.lines > 0
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'review/builder'
|
5
|
+
|
6
|
+
require 'review/book'
|
7
|
+
|
8
|
+
class MockCompiler
|
9
|
+
def text(s)
|
10
|
+
[:text, s]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class BuidlerTest < Test::Unit::TestCase
|
15
|
+
include ReVIEW
|
16
|
+
|
17
|
+
def setup
|
18
|
+
@b = Builder.new
|
19
|
+
chap = ReVIEW::Book::Chapter.new(nil, nil, '-', nil)
|
20
|
+
@b.bind(MockCompiler.new, chap, nil)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_initialize
|
24
|
+
assert Builder.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_bind
|
28
|
+
b = Builder.new
|
29
|
+
chap = ReVIEW::Book::Chapter.new(ReVIEW::Book::Base.load, nil, '-', nil)
|
30
|
+
assert_nothing_raised do
|
31
|
+
b.bind(nil, chap, nil)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_result
|
36
|
+
b = Builder.new
|
37
|
+
assert_raises(NoMethodError) do # XXX: OK?
|
38
|
+
b.result
|
39
|
+
end
|
40
|
+
|
41
|
+
b = Builder.new
|
42
|
+
chapter = ReVIEW::Book::Chapter.new(ReVIEW::Book::Base.load, nil, '-', nil)
|
43
|
+
b.bind(nil, chapter, nil)
|
44
|
+
assert_equal '', b.result
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_not_implemented_methods
|
48
|
+
ex = NoMethodError # XXX: OK?
|
49
|
+
[
|
50
|
+
:list_header, :list_body, :listnum_body,
|
51
|
+
:source_header, :source_body,
|
52
|
+
:image_image, :image_dummy,
|
53
|
+
:table_header, :table_begin, :tr, :th, :table_end,
|
54
|
+
:compile_ruby, :compile_kw, :compile_href,
|
55
|
+
:bibpaper_header, :bibpaper_bibpaper,
|
56
|
+
:inline_hd_chap,
|
57
|
+
].each do |m|
|
58
|
+
b = Builder.new
|
59
|
+
assert_raises(ex) { b.__send__(m) }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class XBuilder < Builder
|
64
|
+
def list_header(id, caption)
|
65
|
+
end
|
66
|
+
|
67
|
+
def list_body(lines)
|
68
|
+
end
|
69
|
+
|
70
|
+
def listnum_body(lines)
|
71
|
+
end
|
72
|
+
|
73
|
+
def source_header(caption)
|
74
|
+
end
|
75
|
+
|
76
|
+
def source_body(lines)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'review/catalog'
|
3
|
+
|
4
|
+
class CatalogTest < Test::Unit::TestCase
|
5
|
+
include ReVIEW
|
6
|
+
|
7
|
+
def test_predef
|
8
|
+
sut = Catalog.new(yaml)
|
9
|
+
exp =<<-EOS
|
10
|
+
pre01.re
|
11
|
+
pre02.re
|
12
|
+
EOS
|
13
|
+
assert_equal(exp.chomp, sut.predef)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_chaps
|
17
|
+
sut = Catalog.new(yaml)
|
18
|
+
exp =<<-EOS
|
19
|
+
ch01.re
|
20
|
+
ch02.re
|
21
|
+
EOS
|
22
|
+
assert_equal(exp.chomp, sut.chaps)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_chaps_empty
|
26
|
+
yaml = StringIO.new
|
27
|
+
sut = Catalog.new(yaml)
|
28
|
+
assert_equal("", sut.chaps)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_appendix
|
32
|
+
sut = Catalog.new(yaml)
|
33
|
+
exp =<<-EOS
|
34
|
+
post01.re
|
35
|
+
post02.re
|
36
|
+
EOS
|
37
|
+
assert_equal(exp.chomp, sut.appendix)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_chaps_with_parts
|
41
|
+
sut = Catalog.new(yaml_with_parts)
|
42
|
+
exp =<<-EOS
|
43
|
+
ch01.re
|
44
|
+
ch02.re
|
45
|
+
ch03.re
|
46
|
+
ch04.re
|
47
|
+
ch05.re
|
48
|
+
EOS
|
49
|
+
assert_equal(exp.chomp, sut.chaps)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_parts
|
53
|
+
sut = Catalog.new(yaml_with_parts)
|
54
|
+
exp =<<-EOS
|
55
|
+
part1.re
|
56
|
+
part2.re
|
57
|
+
EOS
|
58
|
+
assert_equal(exp.chomp, sut.parts)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_parts_with_empty
|
62
|
+
sut = Catalog.new(yaml)
|
63
|
+
assert_equal("", sut.parts)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_parts2
|
67
|
+
sut = Catalog.new(yaml_with_parts)
|
68
|
+
assert_equal(["ch01.re",
|
69
|
+
{"part1.re" => ["ch02.re"]},
|
70
|
+
"ch03.re",
|
71
|
+
{"part2.re" => ["ch04.re", "ch05.re"]}],
|
72
|
+
sut.parts_with_chaps)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_postdef
|
76
|
+
sut = Catalog.new(yaml)
|
77
|
+
exp =<<-EOS
|
78
|
+
back01.re
|
79
|
+
back02.re
|
80
|
+
EOS
|
81
|
+
assert_equal(exp.chomp, sut.postdef)
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
def yaml
|
86
|
+
StringIO.new <<-EOS
|
87
|
+
|
88
|
+
PREDEF:
|
89
|
+
- pre01.re
|
90
|
+
- pre02.re
|
91
|
+
|
92
|
+
CHAPS:
|
93
|
+
- ch01.re
|
94
|
+
- ch02.re
|
95
|
+
|
96
|
+
APPENDIX:
|
97
|
+
- post01.re
|
98
|
+
- post02.re
|
99
|
+
|
100
|
+
POSTDEF:
|
101
|
+
- back01.re
|
102
|
+
- back02.re
|
103
|
+
EOS
|
104
|
+
end
|
105
|
+
|
106
|
+
def yaml_with_parts
|
107
|
+
StringIO.new <<-EOS
|
108
|
+
CHAPS:
|
109
|
+
- ch01.re
|
110
|
+
- part1.re:
|
111
|
+
- ch02.re
|
112
|
+
- ch03.re
|
113
|
+
- part2.re:
|
114
|
+
- ch04.re
|
115
|
+
- ch05.re
|
116
|
+
|
117
|
+
EOS
|
118
|
+
end
|
119
|
+
end
|