tmtms-review 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +9 -0
  3. data/COPYING +515 -0
  4. data/ChangeLog +2083 -0
  5. data/README.rdoc +50 -0
  6. data/Rakefile +56 -0
  7. data/VERSION +1 -0
  8. data/bin/review-check +178 -0
  9. data/bin/review-checkdep +63 -0
  10. data/bin/review-compile +205 -0
  11. data/bin/review-epubmaker +661 -0
  12. data/bin/review-epubmaker-ng +176 -0
  13. data/bin/review-index +118 -0
  14. data/bin/review-pdfmaker +208 -0
  15. data/bin/review-preproc +142 -0
  16. data/bin/review-validate +51 -0
  17. data/bin/review-vol +102 -0
  18. data/debian/README.Debian +12 -0
  19. data/debian/README.source +5 -0
  20. data/debian/changelog +5 -0
  21. data/debian/compat +1 -0
  22. data/debian/control +22 -0
  23. data/debian/copyright +62 -0
  24. data/debian/docs +6 -0
  25. data/debian/manpage.1.ex +59 -0
  26. data/debian/patches/path.diff +91 -0
  27. data/debian/patches/series +1 -0
  28. data/debian/review.install +13 -0
  29. data/debian/review.links +4 -0
  30. data/debian/rules +13 -0
  31. data/debian/source/format +1 -0
  32. data/doc/format.rdoc +582 -0
  33. data/doc/format_idg.rdoc +180 -0
  34. data/doc/libepubmaker/sample.yaml +90 -0
  35. data/doc/quickstart.rdoc +188 -0
  36. data/doc/ruby-uuid/README +11 -0
  37. data/doc/ruby-uuid/README.ja +34 -0
  38. data/doc/sample.css +108 -0
  39. data/doc/sample.yaml +62 -0
  40. data/lib/epubmaker.rb +28 -0
  41. data/lib/epubmaker/content.rb +82 -0
  42. data/lib/epubmaker/epubv2.rb +418 -0
  43. data/lib/epubmaker/epubv3.rb +249 -0
  44. data/lib/epubmaker/producer.rb +204 -0
  45. data/lib/epubmaker/resource.rb +66 -0
  46. data/lib/lineinput.rb +155 -0
  47. data/lib/review.rb +3 -0
  48. data/lib/review/book.rb +46 -0
  49. data/lib/review/book/base.rb +235 -0
  50. data/lib/review/book/chapter.rb +81 -0
  51. data/lib/review/book/compilable.rb +159 -0
  52. data/lib/review/book/index.rb +339 -0
  53. data/lib/review/book/page_metric.rb +38 -0
  54. data/lib/review/book/parameters.rb +97 -0
  55. data/lib/review/book/part.rb +44 -0
  56. data/lib/review/book/volume.rb +65 -0
  57. data/lib/review/builder.rb +444 -0
  58. data/lib/review/compiler.rb +550 -0
  59. data/lib/review/configure.rb +38 -0
  60. data/lib/review/epubbuilder.rb +18 -0
  61. data/lib/review/exception.rb +21 -0
  62. data/lib/review/extentions.rb +3 -0
  63. data/lib/review/extentions/object.rb +9 -0
  64. data/lib/review/extentions/string.rb +33 -0
  65. data/lib/review/htmlbuilder.rb +1097 -0
  66. data/lib/review/htmllayout.rb +19 -0
  67. data/lib/review/htmlutils.rb +36 -0
  68. data/lib/review/i18n.rb +30 -0
  69. data/lib/review/i18n.yaml +34 -0
  70. data/lib/review/idgxmlbuilder.rb +1145 -0
  71. data/lib/review/latexbuilder.rb +815 -0
  72. data/lib/review/latexindex.rb +35 -0
  73. data/lib/review/latexutils.rb +79 -0
  74. data/lib/review/preprocessor.rb +563 -0
  75. data/lib/review/review.tex.erb +232 -0
  76. data/lib/review/textbuilder.rb +17 -0
  77. data/lib/review/textutils.rb +66 -0
  78. data/lib/review/tocparser.rb +342 -0
  79. data/lib/review/tocprinter.rb +221 -0
  80. data/lib/review/topbuilder.rb +785 -0
  81. data/lib/review/unfold.rb +138 -0
  82. data/lib/uuid.rb +312 -0
  83. data/review.gemspec +141 -0
  84. data/test/CHAPS +2 -0
  85. data/test/bib.re +13 -0
  86. data/test/book_test_helper.rb +35 -0
  87. data/test/test.re +43 -0
  88. data/test/test_book.rb +598 -0
  89. data/test/test_book_chapter.rb +418 -0
  90. data/test/test_book_parameter.rb +42 -0
  91. data/test/test_book_part.rb +50 -0
  92. data/test/test_builder.rb +144 -0
  93. data/test/test_compiler.rb +44 -0
  94. data/test/test_epubmaker.rb +507 -0
  95. data/test/test_helper.rb +27 -0
  96. data/test/test_htmlbuilder.rb +554 -0
  97. data/test/test_htmlutils.rb +28 -0
  98. data/test/test_i18n.rb +64 -0
  99. data/test/test_idgxmlbuilder.rb +589 -0
  100. data/test/test_index.rb +31 -0
  101. data/test/test_latexbuilder.rb +656 -0
  102. data/test/test_lineinput.rb +198 -0
  103. data/test/test_preprocessor.rb +23 -0
  104. data/test/test_textutils.rb +68 -0
  105. data/test/test_topbuilder.rb +244 -0
  106. data/test/test_uuid.rb +156 -0
  107. metadata +161 -0
@@ -0,0 +1,2 @@
1
+ test.re
2
+ bib.re
@@ -0,0 +1,13 @@
1
+
2
+ //bibpaper[lins][Lins, 1991]{
3
+ Refael D. Lins. A shared memory architecture for parallel study of
4
+ algorithums for cyclic reference_counting. Technical Report 92,
5
+ Computing Laboratory, The University of Kent at Canterbury , August
6
+ 1991
7
+ //}
8
+
9
+ //bibpaper[nari][nari, 1991]{
10
+ nari paper
11
+ //}
12
+
13
+ //bibpaper[nari][Hogefuge]
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+ require 'review/book'
3
+
4
+ require 'stringio'
5
+ require 'tempfile'
6
+ require 'tmpdir'
7
+
8
+ include ReVIEW
9
+
10
+ module BookTestHelper
11
+ def mktmpbookdir(files = {})
12
+ created_files = {}
13
+ Dir.mktmpdir do |dir|
14
+ files.each_pair do |basename, content|
15
+ path = File.join(dir, basename)
16
+ File.open(path, 'w') {|o| o.print content }
17
+ created_files[basename] = path
18
+ end
19
+ book = Book::Base.new(dir)
20
+ yield(dir, book, created_files)
21
+ end
22
+ end
23
+
24
+ def get_instance_variables(obj)
25
+ obj.instance_variables.inject({}) do |memo, name|
26
+ value = obj.instance_variable_get(name)
27
+ if value.instance_variables.empty?
28
+ memo[name] = value
29
+ else
30
+ memo[name] = get_instance_variables(value)
31
+ end
32
+ memo
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,43 @@
1
+ = 見出し
2
+ 以下を実行
3
+ //emlist{
4
+ ./bin/review-compile --inencoding=UTF-8 --outencoding=UTF-8 --hdnumberingmode test.re --target=html
5
+ }
6
+ == 節1
7
+
8
+ == 節2
9
+
10
+ ==[column]コラム
11
+
12
+ == 節3
13
+
14
+ ソースコードの引用
15
+
16
+ //source[/hello/world.rb]{
17
+ puts "hello world!"
18
+ //}
19
+
20
+ ■行番号付きキャプションなしリスト
21
+ //emlistnum{
22
+ hoge
23
+ fuge
24
+ //}
25
+
26
+ ■行番号付きキャプションありリスト
27
+ //listnum[hoge][ほげ]{
28
+ hoge
29
+ fuge
30
+ //}
31
+
32
+ ほげは@<list>{hoge}でもわかるとおり
33
+
34
+ ■本文中でのソースコード引用
35
+ 擬似コード内のの@<code>{p = obj.ref_cnt}では…
36
+
37
+ ■参考文献の参照方法
38
+ …がしられています( @<bib>{lins} )
39
+
40
+
41
+ //emlist{
42
+ hoge
43
+ //}
@@ -0,0 +1,598 @@
1
+ # encoding: utf-8
2
+ require 'book_test_helper'
3
+
4
+ class BookTest < Test::Unit::TestCase
5
+ include BookTestHelper
6
+
7
+ def assert_same_path(expected, result, *options)
8
+ require 'pathname'
9
+ ex_path = Pathname(expected).realpath
10
+ re_path = Pathname(result).realpath
11
+ assert_equal ex_path, re_path, *options
12
+ end
13
+
14
+ def test_s_load_default
15
+ Dir.mktmpdir do |dir|
16
+ File.open(File.join(dir, 'CHAPS'), 'w') {}
17
+ Dir.chdir(dir) do
18
+ assert_same_path dir, File.expand_path(Book.load_default.basedir), "error in dir CHAPS"
19
+ end
20
+
21
+ subdir = File.join(dir, 'sub')
22
+ Dir.mkdir(subdir)
23
+ Dir.chdir(subdir) do
24
+ assert_same_path dir, File.expand_path(Book.load_default.basedir), "error in dir sub"
25
+ end
26
+
27
+ sub2dir = File.join(dir, 'sub', 'sub')
28
+ Dir.mkdir(sub2dir)
29
+ Dir.chdir(sub2dir) do
30
+ assert_same_path dir, File.expand_path(Book.load_default.basedir), "error in dir sub sub"
31
+ end
32
+
33
+ sub3dir = File.join(dir, 'sub', 'sub', 'sub')
34
+ Dir.mkdir(sub3dir)
35
+ Dir.chdir(sub3dir) do
36
+ assert_same_path sub3dir, File.expand_path(Book.load_default.basedir), "error in dir sub sub sub"
37
+ end
38
+ end
39
+
40
+ # tests for ReVIEW.book
41
+ default_book = nil
42
+ Dir.mktmpdir do |dir|
43
+ Dir.chdir(dir) do
44
+ default_book = ReVIEW.book
45
+ assert default_book
46
+ end
47
+ end
48
+ Dir.mktmpdir do |dir|
49
+ Dir.chdir(dir) do
50
+ assert_equal default_book, ReVIEW.book, "chdir mktmpdir"
51
+ end
52
+ end
53
+ end
54
+
55
+ def test_s_load
56
+ Dir.mktmpdir do |dir|
57
+ book = Book.load(dir)
58
+ defs = get_instance_variables(Book::Parameters.default)
59
+ pars = get_instance_variables(book.instance_eval { @parameters })
60
+ assert_equal defs, pars
61
+ end
62
+ end
63
+
64
+ def test_s_update_rubyenv
65
+ save_load_path = $LOAD_PATH.dup
66
+
67
+ Dir.mktmpdir do |dir|
68
+ Book.update_rubyenv(dir)
69
+ assert_equal save_load_path, $LOAD_PATH
70
+ end
71
+
72
+ Dir.mktmpdir do |dir|
73
+ local_lib_path = File.join(dir, 'lib')
74
+ Dir.mkdir(local_lib_path)
75
+ Book.update_rubyenv(dir)
76
+ assert_equal save_load_path, $LOAD_PATH
77
+ end
78
+
79
+ begin
80
+ Dir.mktmpdir do |dir|
81
+ local_lib_path = File.join(dir, 'lib')
82
+ Dir.mkdir(local_lib_path)
83
+ Dir.mkdir(File.join(local_lib_path, 'review'))
84
+ Book.update_rubyenv(dir)
85
+ assert save_load_path != $LOAD_PATH
86
+ assert $LOAD_PATH.index(local_lib_path)
87
+ end
88
+ ensure
89
+ $LOAD_PATH.replace save_load_path
90
+ end
91
+
92
+ num = rand(99999)
93
+ test_const = "ReVIEW__BOOK__TEST__#{num}"
94
+ begin
95
+ Dir.mktmpdir do |dir|
96
+ File.open(File.join(dir, 'review-ext.rb'), 'w') do |o|
97
+ o.puts "#{test_const} = #{num}"
98
+ end
99
+ Book.update_rubyenv(dir)
100
+ assert_equal num, Object.class_eval { const_get(test_const) }
101
+ end
102
+ ensure
103
+ Object.class_eval { remove_const(test_const) }
104
+ end
105
+ end
106
+
107
+ def test_ext
108
+ book = Book::Base.new(File.dirname(__FILE__))
109
+ assert_equal '.re', book.ext
110
+ end
111
+
112
+ def test_read_CHAPS
113
+ Dir.mktmpdir do |dir|
114
+ book = Book::Base.new(dir)
115
+ assert_equal "", book.read_CHAPS
116
+
117
+ chaps_path = File.join(dir, 'CHAPS')
118
+ re1_path = File.join(dir, "123#{book.ext}")
119
+ re2_path = File.join(dir, "456#{book.ext}")
120
+
121
+ File.open(chaps_path, 'w') {|o| o.print "abc\n" }
122
+ File.open(re1_path, 'w') {|o| o.print "123\n" }
123
+ File.open(re2_path, 'w') {|o| o.print "456\n" }
124
+
125
+ assert_equal "abc\n", book.read_CHAPS
126
+
127
+ File.unlink(chaps_path)
128
+ assert_equal "#{re1_path}\n#{re2_path}", book.read_CHAPS
129
+
130
+ File.unlink(re1_path)
131
+ assert_equal "#{re2_path}", book.read_CHAPS
132
+
133
+ File.unlink(re2_path)
134
+ assert_equal "", book.read_CHAPS
135
+ end
136
+ end
137
+
138
+ def test_read_PART
139
+ Dir.mktmpdir do |dir|
140
+ book = Book::Base.new(dir)
141
+ assert !book.part_exist?
142
+ assert_raises Errno::ENOENT do # XXX: OK?
143
+ book.read_PART
144
+ end
145
+
146
+ chaps_path = File.join(dir, 'PART')
147
+ chaps_content = "abc\n"
148
+ File.open(chaps_path, 'w') {|o| o.print chaps_content }
149
+
150
+ assert book.part_exist?
151
+ assert_equal chaps_content, book.read_PART
152
+
153
+ File.open(chaps_path, 'w') {|o| o.print "XYZ\n" }
154
+ assert_equal chaps_content, book.read_PART
155
+ end
156
+ end
157
+
158
+ def test_read_bib
159
+ Dir.mktmpdir do |dir|
160
+ book = Book::Base.new(dir)
161
+ assert !book.bib_exist?
162
+ assert_raises Errno::ENOENT do # XXX: OK?
163
+ book.read_bib
164
+ end
165
+
166
+ bib_path = File.join(dir, "bib#{book.ext}")
167
+ File.open(bib_path, 'w') {|o| o.print "abc\n" }
168
+
169
+ assert book.bib_exist?
170
+ assert_equal "abc\n", book.read_bib
171
+ end
172
+ end
173
+
174
+ def test_setParameter
175
+ book = Book::Base.new(File.dirname(__FILE__))
176
+ book.param = :test
177
+ assert_equal :test, book.instance_eval {@param}
178
+ end
179
+
180
+ def test_parse_chapters
181
+ mktmpbookdir 'CHAPS' => '' do |dir, book, files|
182
+ parts = book.instance_eval { parse_chapters }
183
+ assert_equal 0, parts.size
184
+ end
185
+
186
+ mktmpbookdir 'CHAPS' => "chapter1.re\nchapter2\n" do |dir, book, files|
187
+ parts = book.instance_eval { parse_chapters }
188
+ assert_equal 1, parts.size
189
+
190
+ assert_equal 1, parts[0].number
191
+ assert_equal 2, parts[0].chapters.size
192
+ chaps = parts[0].chapters.map {|ch| [ch.number, ch.name, ch.path] }
193
+ expect = [
194
+ [1, 'chapter1', File.join(dir, 'chapter1.re')],
195
+ [2, 'chapter2', File.join(dir, 'chapter2')],
196
+ ]
197
+ assert_equal expect, chaps
198
+ end
199
+
200
+ mktmpbookdir 'CHAPS' => <<EOC do |dir, book, files|
201
+ part1_chapter1.re
202
+ part1_chapter2.re
203
+
204
+
205
+ part2_chapter1.re
206
+ part2_chapter2.re
207
+ part2_chapter3.re
208
+
209
+ part3_chapter1.re
210
+ EOC
211
+ parts = book.instance_eval { parse_chapters }
212
+ assert_equal 3, parts.size
213
+
214
+ assert_equal 1, parts[0].number
215
+ assert_equal 2, parts[0].chapters.size
216
+ chaps = parts[0].chapters.map {|ch| [ch.number, ch.name, ch.path] }
217
+ expect = [
218
+ [1, 'part1_chapter1', File.join(dir, 'part1_chapter1.re')],
219
+ [2, 'part1_chapter2', File.join(dir, 'part1_chapter2.re')],
220
+ ]
221
+ assert_equal expect, chaps
222
+
223
+ assert_equal 2, parts[1].number
224
+ assert_equal 3, parts[1].chapters.size
225
+ chaps = parts[1].chapters.map {|ch| [ch.number, ch.name, ch.path] }
226
+ expect = [
227
+ [3, 'part2_chapter1', File.join(dir, 'part2_chapter1.re')],
228
+ [4, 'part2_chapter2', File.join(dir, 'part2_chapter2.re')],
229
+ [5, 'part2_chapter3', File.join(dir, 'part2_chapter3.re')],
230
+ ]
231
+ assert_equal expect, chaps
232
+
233
+ assert_equal 3, parts[2].number
234
+ assert_equal 1, parts[2].chapters.size
235
+ chaps = parts[2].chapters.map {|ch| [ch.number, ch.name, ch.path] }
236
+ expect = [
237
+ [6, 'part3_chapter1', File.join(dir, 'part3_chapter1.re')],
238
+ ]
239
+ assert_equal expect, chaps
240
+ end
241
+ end
242
+
243
+ def test_parse_chpaters_with_parts_file
244
+ n_test = 0
245
+ [
246
+ [
247
+ # 期待されるパートの数, :chapter_fileの内容, :part_fileの内容, 期待されるパートタイトルのリスト
248
+ 2,
249
+ "part1_chapter1.re\n\npart2_chpater1.re\n",
250
+ "part1\npart2\npart3\n",
251
+ %w(part1 part2),
252
+ ],
253
+ [
254
+ 3,
255
+ "part1_chapter1.re\n\npart2_chapter1.re\n\npart3_chapter1.re",
256
+ "part1\n",
257
+ [
258
+ "part1",
259
+ nil, # XXX: OK?
260
+ ""
261
+ ],
262
+ ],
263
+ [
264
+ 1,
265
+ "part1_chapter1.re\n",
266
+ "",
267
+ [
268
+ nil, # XXX: OK?
269
+ ],
270
+ ],
271
+ [
272
+ 1,
273
+ "part1_chapter1.re\n",
274
+ nil,
275
+ [
276
+ "",
277
+ ],
278
+ ],
279
+ ].each do |n_parts, chaps_text, parts_text, part_names|
280
+ n_test += 1
281
+ Dir.mktmpdir do |dir|
282
+ params = Book::Parameters.new(:part_file => 'PARTS')
283
+ book = Book::Base.new(dir, params)
284
+ chaps_path = File.join(dir, 'CHAPS')
285
+ File.open(chaps_path, 'w') {|o| o.print chaps_text }
286
+ unless parts_text.nil?
287
+ parts_path = File.join(dir, 'PARTS')
288
+ File.open(parts_path, 'w') {|o| o.print parts_text }
289
+ end
290
+
291
+ parts = book.instance_eval { parse_chapters }
292
+ assert_equal n_parts, parts.size, "\##{n_test}"
293
+ assert_equal part_names, parts.map {|p| p.name }, "\##{n_test}"
294
+ end
295
+ end
296
+ end
297
+
298
+ def test_prefaces
299
+ mktmpbookdir do |dir, book, files|
300
+ assert_equal nil, book.prefaces
301
+ end
302
+
303
+ mktmpbookdir 'preface.re' => '' do |dir, book, files|
304
+ assert_kind_of Book::Part, book.prefaces
305
+ assert_equal '', book.prefaces.name
306
+ assert_equal 1, book.prefaces.chapters.size
307
+ assert_equal "preface", book.prefaces.chapters.first.name
308
+ assert_equal files['preface.re'], book.prefaces.chapters.first.path
309
+ assert_equal nil, book.prefaces.chapters.first.number
310
+ end
311
+
312
+ mktmpbookdir 'preface.re' => '',
313
+ 'PREDEF' => '' do |dir, book, files|
314
+ assert_equal nil, book.prefaces # XXX: OK?
315
+ end
316
+
317
+ mktmpbookdir 'PREDEF' => '' do |dir, book, files|
318
+ assert_equal nil, book.prefaces
319
+ end
320
+
321
+ mktmpbookdir 'PREDEF' => 'chapter1',
322
+ 'chapter1.re' => '' do |dir, book, files|
323
+ assert_kind_of Book::Part, book.prefaces
324
+ assert_equal '', book.prefaces.name
325
+ assert_equal 1, book.prefaces.chapters.size
326
+ assert_equal "chapter1", book.prefaces.chapters.first.name
327
+ assert_equal files['chapter1.re'], book.prefaces.chapters.first.path
328
+ end
329
+
330
+ mktmpbookdir 'PREDEF' => "chapter1\n\nchapter2",
331
+ 'chapter1.re' => '', 'chapter2.re' => '' do |dir, book, files|
332
+ assert_kind_of Book::Part, book.prefaces
333
+ assert_equal '', book.prefaces.name
334
+ assert_equal 2, book.prefaces.chapters.size
335
+ assert_equal "chapter1", book.prefaces.chapters.first.name
336
+ assert_equal files['chapter1.re'], book.prefaces.chapters.first.path
337
+ assert_equal "chapter2", book.prefaces.chapters.last.name
338
+ assert_equal files['chapter2.re'], book.prefaces.chapters.last.path
339
+ end
340
+
341
+ mktmpbookdir 'PREDEF' => "chapter1 chapter2",
342
+ 'chapter1.re' => '', 'chapter2.re' => '' do |dir, book, files|
343
+ assert_kind_of Book::Part, book.prefaces
344
+ assert_equal '', book.prefaces.name
345
+ assert_equal 2, book.prefaces.chapters.size # XXX: OK?
346
+ end
347
+
348
+ mktmpbookdir 'PREDEF' => 'not_exist' do |dir, book, files|
349
+ assert_raises FileNotFound do
350
+ assert_equal nil, book.prefaces
351
+ end
352
+ end
353
+
354
+ mktmpbookdir 'PREDEF' => 'chapter1.re',
355
+ 'chapter1.re' => '' do |dir, book, files|
356
+ assert_kind_of Book::Part, book.prefaces
357
+ assert_equal '', book.prefaces.name
358
+ assert_equal 1, book.prefaces.chapters.size
359
+ end
360
+
361
+ mktmpbookdir 'PREDEF' => 'chapter1.txt',
362
+ 'chapter1.txt' => '' do |dir, book, files|
363
+ assert_kind_of Book::Part, book.prefaces
364
+ assert_equal '', book.prefaces.name
365
+ assert_equal 1, book.prefaces.chapters.size
366
+ end
367
+ end
368
+
369
+ def test_postscripts
370
+ mktmpbookdir do |dir, book, files|
371
+ assert_equal nil, book.postscripts
372
+ end
373
+
374
+ mktmpbookdir 'appendix.re' => '' do |dir, book, files|
375
+ assert_kind_of Book::Part, book.postscripts
376
+ assert_equal '', book.postscripts.name
377
+ assert_equal 1, book.postscripts.chapters.size
378
+ assert_equal "appendix", book.postscripts.chapters.first.name
379
+ assert_equal files['appendix.re'], book.postscripts.chapters.first.path
380
+ assert_equal nil, book.postscripts.chapters.first.number
381
+ end
382
+
383
+ mktmpbookdir 'postscript.re' => '' do |dir, book, files|
384
+ assert_kind_of Book::Part, book.postscripts
385
+ assert_equal '', book.postscripts.name
386
+ assert_equal 1, book.postscripts.chapters.size
387
+ assert_equal "postscript", book.postscripts.chapters.first.name
388
+ assert_equal files['postscript.re'], book.postscripts.chapters.first.path
389
+ assert_equal nil, book.postscripts.chapters.first.number
390
+ end
391
+
392
+ mktmpbookdir 'appendix.re' => '',
393
+ 'postscript.re' => '' do |dir, book, files|
394
+ assert_kind_of Book::Part, book.postscripts
395
+ assert_equal '', book.postscripts.name
396
+ assert_equal 2, book.postscripts.chapters.size
397
+ assert_equal "appendix", book.postscripts.chapters.first.name
398
+ assert_equal files['appendix.re'], book.postscripts.chapters.first.path
399
+ assert_equal nil, book.postscripts.chapters.first.number
400
+ assert_equal "postscript", book.postscripts.chapters.last.name
401
+ assert_equal files['postscript.re'], book.postscripts.chapters.last.path
402
+ assert_equal nil, book.postscripts.chapters.last.number
403
+ end
404
+
405
+ mktmpbookdir 'preface.re' => '',
406
+ 'POSTDEF' => '' do |dir, book, files|
407
+ assert_equal nil, book.postscripts # XXX: OK?
408
+ end
409
+
410
+ mktmpbookdir 'POSTDEF' => '' do |dir, book, files|
411
+ assert_equal nil, book.postscripts
412
+ end
413
+
414
+ mktmpbookdir 'POSTDEF' => 'chapter1',
415
+ 'chapter1.re' => '' do |dir, book, files|
416
+ assert_kind_of Book::Part, book.postscripts
417
+ assert_equal '', book.postscripts.name
418
+ assert_equal 1, book.postscripts.chapters.size
419
+ assert_equal "chapter1", book.postscripts.chapters.first.name
420
+ assert_equal files['chapter1.re'], book.postscripts.chapters.first.path
421
+ end
422
+
423
+ mktmpbookdir 'POSTDEF' => "chapter1\n\nchapter2",
424
+ 'chapter1.re' => '', 'chapter2.re' => '' do |dir, book, files|
425
+ assert_kind_of Book::Part, book.postscripts
426
+ assert_equal '', book.postscripts.name
427
+ assert_equal 2, book.postscripts.chapters.size
428
+ assert_equal "chapter1", book.postscripts.chapters.first.name
429
+ assert_equal files['chapter1.re'], book.postscripts.chapters.first.path
430
+ assert_equal "chapter2", book.postscripts.chapters.last.name
431
+ assert_equal files['chapter2.re'], book.postscripts.chapters.last.path
432
+ end
433
+
434
+ mktmpbookdir 'POSTDEF' => "chapter1 chapter2",
435
+ 'chapter1.re' => '', 'chapter2.re' => '' do |dir, book, files|
436
+ assert_kind_of Book::Part, book.postscripts
437
+ assert_equal '', book.postscripts.name
438
+ assert_equal 2, book.postscripts.chapters.size # XXX: OK?
439
+ end
440
+
441
+ mktmpbookdir 'POSTDEF' => 'not_exist' do |dir, book, files|
442
+ assert_raises FileNotFound do
443
+ assert_equal nil, book.postscripts
444
+ end
445
+ end
446
+ end
447
+
448
+ def test_parts
449
+ mktmpbookdir do |dir, book, files|
450
+ assert book.parts.empty?
451
+ assert !book.part(0)
452
+ assert !book.part(1)
453
+
454
+ tmp = []
455
+ book.each_part { tmp << true }
456
+ assert tmp.empty?
457
+ end
458
+
459
+ mktmpbookdir 'CHAPS' => "ch1\nch2\n\nch3" do |dir, book, files|
460
+ parts = book.parts
461
+ assert_equal 2, parts.size
462
+ assert !book.part(0)
463
+ assert book.part(1)
464
+ assert book.part(2)
465
+ assert !book.part(3)
466
+
467
+ tmp = []
468
+ book.each_part {|p| tmp << p.number }
469
+ assert_equal [1, 2], tmp
470
+ end
471
+
472
+ mktmpbookdir 'CHAPS' => "ch1\nch2\n\nch3",
473
+ 'preface.re' => '' do |dir, book, files|
474
+ parts = book.parts
475
+ assert_equal 3, parts.size
476
+ assert book.part(1)
477
+ assert book.part(2)
478
+ assert !book.part(3)
479
+ assert book.part(nil) # XXX: OK?
480
+ assert_equal 'preface', parts.first.chapters.first.name
481
+
482
+ tmp = []
483
+ book.each_part {|p| tmp << p.number }
484
+ assert_equal [nil, 1, 2], tmp
485
+ end
486
+
487
+ mktmpbookdir 'CHAPS' => "ch1\nch2\n\nch3",
488
+ 'postscript.re' => '' do |dir, book, files|
489
+ parts = book.parts
490
+ assert_equal 3, parts.size
491
+ assert book.part(1)
492
+ assert book.part(2)
493
+ assert !book.part(3)
494
+ assert book.part(nil) # XXX: OK?
495
+ assert_equal 'postscript', parts.last.chapters.last.name
496
+
497
+ tmp = []
498
+ book.each_part {|p| tmp << p.number }
499
+ assert_equal [1, 2, nil], tmp
500
+ end
501
+
502
+ mktmpbookdir 'CHAPS' => "ch1\nch2\n\nch3",
503
+ 'preface.re' => '', 'postscript.re' => '' do |dir, book, files|
504
+ parts = book.parts
505
+ assert_equal 4, parts.size
506
+ assert book.part(1)
507
+ assert book.part(2)
508
+ assert !book.part(3)
509
+ assert !book.part(4)
510
+ assert book.part(nil) # XXX: OK?
511
+ assert_equal 'preface', parts.first.chapters.first.name
512
+ assert_equal 'postscript', parts.last.chapters.last.name
513
+
514
+ tmp = []
515
+ book.each_part {|p| tmp << p.number }
516
+ assert_equal [nil, 1, 2, nil], tmp
517
+ end
518
+ end
519
+
520
+ def test_chapters
521
+ mktmpbookdir 'CHAPS' => "ch1\nch2\n\nch3",
522
+ 'preface.re' => '', 'postscript.re' => '' do |dir, book, files|
523
+ chapters = book.chapters
524
+ assert_equal 5, chapters.size
525
+
526
+ ch_names = %w(preface ch1 ch2 ch3 postscript)
527
+ tmp = []
528
+ book.each_chapter {|ch| tmp << ch.name }
529
+ assert_equal ch_names, tmp
530
+
531
+ ch_names.each do |name|
532
+ assert book.chapter(name)
533
+ assert_equal name, book.chapter(name).name
534
+ end
535
+
536
+ assert_raises ReVIEW::KeyError do
537
+ book.chapter('not exist')
538
+ end
539
+ end
540
+
541
+ mktmpbookdir 'CHAPS' => "ch1.txt\nch2.txt\n\nch3.txt",
542
+ 'preface.re' => '', 'postscript.re' => '' do |dir, book, files|
543
+ chapters = book.chapters
544
+ assert_equal 5, chapters.size
545
+
546
+ ch_names = %w(preface ch1 ch2 ch3 postscript)
547
+ tmp = []
548
+ book.each_chapter {|ch| tmp << ch.name }
549
+ assert_equal ch_names, tmp
550
+
551
+ ch_names.each do |name|
552
+ assert book.chapter(name)
553
+ assert_equal name, book.chapter(name).name
554
+ end
555
+
556
+ assert_raises ReVIEW::KeyError do
557
+ book.chapter('not exist')
558
+ end
559
+ end
560
+ end
561
+
562
+ def test_volume
563
+ mktmpbookdir do |dir, book, files|
564
+ assert book.volume
565
+ assert_equal 0, book.volume.bytes
566
+ assert_equal 0, book.volume.chars
567
+ assert_equal 0, book.volume.lines
568
+ end
569
+
570
+ mktmpbookdir 'CHAPS' => 'chapter1.re', 'chapter1.re' => '12345' do |dir, book, files|
571
+ assert book.volume
572
+ assert book.volume.bytes > 0
573
+ assert book.volume.chars > 0
574
+ assert book.volume.lines > 0
575
+ end
576
+
577
+ mktmpbookdir 'preface.re' => '12345' do |dir, book, files|
578
+ assert_raises Errno::ENOENT do # XXX: OK?
579
+ book.volume
580
+ end
581
+
582
+ Dir.chdir(dir) do
583
+ book2 = Book::Base.new('.')
584
+ assert book2.volume
585
+ assert book2.volume.bytes > 0
586
+ assert book2.volume.chars > 0
587
+ assert book2.volume.lines > 0
588
+ end
589
+ end
590
+ end
591
+
592
+ def test_basedir
593
+ Dir.mktmpdir do |dir|
594
+ book = Book::Base.new(dir)
595
+ assert_equal dir, book.basedir
596
+ end
597
+ end
598
+ end