review 5.5.0 → 5.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +31 -0
  3. data/.github/workflows/ruby-tex.yml +1 -1
  4. data/.github/workflows/ruby-win.yml +1 -1
  5. data/.github/workflows/ruby.yml +2 -2
  6. data/.rubocop.yml +13 -2
  7. data/NEWS.ja.md +40 -0
  8. data/NEWS.md +39 -0
  9. data/README.md +1 -1
  10. data/doc/format.ja.md +70 -33
  11. data/doc/format.md +69 -34
  12. data/doc/quickstart.ja.md +7 -1
  13. data/doc/quickstart.md +7 -1
  14. data/lib/review/book/base.rb +1 -1
  15. data/lib/review/builder.rb +6 -10
  16. data/lib/review/epubmaker/epubcommon.rb +13 -7
  17. data/lib/review/epubmaker/epubv2.rb +0 -5
  18. data/lib/review/epubmaker/epubv3.rb +9 -1
  19. data/lib/review/epubmaker/producer.rb +2 -3
  20. data/lib/review/epubmaker.rb +2 -4
  21. data/lib/review/htmlbuilder.rb +2 -2
  22. data/lib/review/i18n.yml +24 -2
  23. data/lib/review/idgxmlbuilder.rb +29 -10
  24. data/lib/review/idgxmlmaker.rb +11 -1
  25. data/lib/review/img_math.rb +9 -2
  26. data/lib/review/init.rb +10 -5
  27. data/lib/review/latexbuilder.rb +2 -2
  28. data/lib/review/lineinput.rb +2 -2
  29. data/lib/review/makerhelper.rb +2 -2
  30. data/lib/review/pdfmaker.rb +3 -5
  31. data/lib/review/update.rb +3 -7
  32. data/lib/review/version.rb +1 -1
  33. data/lib/review/yamlloader.rb +0 -3
  34. data/review.gemspec +3 -3
  35. data/samples/syntax-book/Gemfile +1 -1
  36. data/templates/latex/config.erb +6 -1
  37. data/templates/latex/review-jlreq/review-base.sty +11 -8
  38. data/templates/latex/review-jsbook/review-base.sty +15 -11
  39. data/templates/opf/epubv2.opf.erb +2 -0
  40. data/templates/opf/epubv3.opf.erb +2 -0
  41. data/templates/opf/opf_manifest_epubv2.opf.erb +2 -0
  42. data/templates/opf/opf_manifest_epubv3.opf.erb +2 -0
  43. data/templates/opf/opf_tocx_epubv3.opf.erb +2 -0
  44. metadata +24 -139
  45. data/test/assets/black.eps +0 -280
  46. data/test/assets/fit.png +0 -0
  47. data/test/assets/header_listener.html +0 -35
  48. data/test/assets/img_math/img1.png +0 -0
  49. data/test/assets/img_math/img2.png +0 -0
  50. data/test/assets/img_math/img3.png +0 -0
  51. data/test/assets/large.gif +0 -0
  52. data/test/assets/large.jpg +0 -0
  53. data/test/assets/large.png +0 -0
  54. data/test/assets/large.svg +0 -65
  55. data/test/assets/syntax_book_index_detail.txt +0 -60
  56. data/test/assets/test.xml.erb +0 -3
  57. data/test/assets/test_template.tex +0 -179
  58. data/test/assets/test_template_backmatter.tex +0 -190
  59. data/test/book_test_helper.rb +0 -44
  60. data/test/run_test.rb +0 -12
  61. data/test/test_book.rb +0 -588
  62. data/test/test_book_chapter.rb +0 -329
  63. data/test/test_book_part.rb +0 -53
  64. data/test/test_builder.rb +0 -126
  65. data/test/test_catalog.rb +0 -174
  66. data/test/test_catalog_converter_cmd.rb +0 -73
  67. data/test/test_compiler.rb +0 -52
  68. data/test/test_configure.rb +0 -91
  69. data/test/test_converter.rb +0 -21
  70. data/test/test_epub3maker.rb +0 -733
  71. data/test/test_epubmaker.rb +0 -931
  72. data/test/test_epubmaker_cmd.rb +0 -56
  73. data/test/test_extentions_hash.rb +0 -66
  74. data/test/test_helper.rb +0 -62
  75. data/test/test_htmlbuilder.rb +0 -3312
  76. data/test/test_htmltoc.rb +0 -29
  77. data/test/test_htmlutils.rb +0 -43
  78. data/test/test_i18n.rb +0 -300
  79. data/test/test_idgxmlbuilder.rb +0 -1487
  80. data/test/test_idgxmlmaker_cmd.rb +0 -50
  81. data/test/test_image_finder.rb +0 -81
  82. data/test/test_img_math.rb +0 -120
  83. data/test/test_index.rb +0 -287
  84. data/test/test_indexbuilder.rb +0 -52
  85. data/test/test_latexbuilder.rb +0 -2964
  86. data/test/test_latexbuilder_v2.rb +0 -1654
  87. data/test/test_lineinput.rb +0 -104
  88. data/test/test_location.rb +0 -30
  89. data/test/test_logger.rb +0 -33
  90. data/test/test_makerhelper.rb +0 -44
  91. data/test/test_markdownbuilder.rb +0 -371
  92. data/test/test_md2inaobuilder.rb +0 -90
  93. data/test/test_pdfmaker.rb +0 -354
  94. data/test/test_pdfmaker_cmd.rb +0 -130
  95. data/test/test_plaintextbuilder.rb +0 -1211
  96. data/test/test_preprocessor.rb +0 -196
  97. data/test/test_review_ext.rb +0 -30
  98. data/test/test_reviewheaderlistener.rb +0 -49
  99. data/test/test_rstbuilder.rb +0 -616
  100. data/test/test_sec_counter.rb +0 -156
  101. data/test/test_template.rb +0 -33
  102. data/test/test_textmaker_cmd.rb +0 -58
  103. data/test/test_textutils.rb +0 -187
  104. data/test/test_tocprinter.rb +0 -46
  105. data/test/test_topbuilder.rb +0 -1298
  106. data/test/test_update.rb +0 -473
  107. data/test/test_webtocprinter.rb +0 -195
  108. data/test/test_yamlloader.rb +0 -186
  109. data/test/test_zip_exporter.rb +0 -106
data/test/test_book.rb DELETED
@@ -1,588 +0,0 @@
1
- require 'book_test_helper'
2
- require 'fileutils'
3
-
4
- class BookTest < Test::Unit::TestCase
5
- include BookTestHelper
6
-
7
- def setup
8
- if ENV['GITHUB_WORKSPACE']
9
- ENV['TMPDIR'] = File.join(ENV['GITHUB_WORKSPACE'], 'tmp_review')
10
- FileUtils.mkdir_p(ENV['TMPDIR'])
11
- end
12
- end
13
-
14
- def assert_same_path(expected, result, *options)
15
- require 'pathname'
16
- ex_path = Pathname(expected).realpath
17
- re_path = Pathname(result).realpath
18
- assert_equal ex_path, re_path, *options
19
- end
20
-
21
- def test_update_rubyenv
22
- num = rand(99999)
23
- test_const = "ReVIEW__BOOK__TEST__#{num}"
24
- begin
25
- Dir.mktmpdir do |dir|
26
- File.write(File.join(dir, 'review-ext.rb'), "#{test_const} = #{num}")
27
- Book::Base.new(dir)
28
- assert_equal num, (Object.class_eval { const_get(test_const) })
29
- end
30
- ensure
31
- Object.class_eval { remove_const(test_const) }
32
- end
33
- end
34
-
35
- def test_ext
36
- book = Book::Base.new(File.dirname(__FILE__))
37
- assert_equal '.re', book.ext
38
- end
39
-
40
- def test_read_chaps
41
- Dir.mktmpdir do |dir|
42
- book = Book::Base.new(dir)
43
- assert_equal [], book.read_chaps
44
-
45
- chaps_path = File.join(dir, 'CHAPS')
46
- re1_path = File.join(dir, "123#{book.ext}")
47
- re2_path = File.join(dir, "456#{book.ext}")
48
-
49
- File.open(chaps_path, 'w') { |o| o.print "abc\n" }
50
- File.open(re1_path, 'w') { |o| o.print "123\n" }
51
- File.open(re2_path, 'w') { |o| o.print "456\n" }
52
-
53
- assert_equal ['abc'], book.read_chaps
54
-
55
- File.unlink(chaps_path)
56
- assert_equal [re1_path, re2_path], book.read_chaps
57
-
58
- File.unlink(re1_path)
59
- assert_equal [re2_path], book.read_chaps
60
-
61
- File.unlink(re2_path)
62
- assert_equal [], book.read_chaps
63
- end
64
- end
65
-
66
- def test_read_part
67
- Dir.mktmpdir do |dir|
68
- book = Book::Base.new(dir)
69
- assert !book.part_exist?
70
- assert_raises Errno::ENOENT do # XXX: OK?
71
- book.read_part
72
- end
73
-
74
- chaps_path = File.join(dir, 'PART')
75
- chaps_content = "abc\n"
76
- File.open(chaps_path, 'w') { |o| o.print chaps_content }
77
-
78
- assert book.part_exist?
79
- assert_equal %w[abc], book.read_part
80
-
81
- ## do not cache PART data
82
- File.open(chaps_path, 'w') { |o| o.print "XYZ\n" }
83
- assert_equal %w[XYZ], book.read_part
84
- end
85
- end
86
-
87
- def test_read_appendix
88
- Dir.mktmpdir do |dir|
89
- book = Book::Base.new(dir)
90
- assert_equal [], book.read_appendix
91
-
92
- post_path = File.join(dir, 'POSTDEF')
93
- re1_path = File.join(dir, "123#{book.ext}")
94
- re2_path = File.join(dir, "456#{book.ext}")
95
-
96
- File.open(post_path, 'w') { |o| o.print "abc\n" }
97
- File.open(re1_path, 'w') { |o| o.print "123\n" }
98
- File.open(re2_path, 'w') { |o| o.print "456\n" }
99
-
100
- assert_equal ['abc'], book.read_appendix
101
-
102
- File.unlink(post_path)
103
- assert_equal [re1_path, re2_path], book.read_appendix
104
-
105
- File.unlink(re1_path)
106
- assert_equal [re2_path], book.read_appendix
107
-
108
- File.unlink(re2_path)
109
- assert_equal [], book.read_appendix
110
- end
111
- end
112
-
113
- def test_read_postdef
114
- Dir.mktmpdir do |dir|
115
- book = Book::Base.new(dir)
116
- assert_equal [], book.read_postdef
117
-
118
- post_path = File.join(dir, 'POSTDEF')
119
- re1_path = File.join(dir, "123#{book.ext}")
120
- re2_path = File.join(dir, "456#{book.ext}")
121
-
122
- File.open(post_path, 'w') { |o| o.print "abc\n" }
123
- File.open(re1_path, 'w') { |o| o.print "123\n" }
124
- File.open(re2_path, 'w') { |o| o.print "456\n" }
125
-
126
- assert_equal [], book.read_postdef
127
-
128
- File.unlink(post_path)
129
- assert_equal [], book.read_postdef
130
- end
131
- end
132
-
133
- def test_read_bib
134
- Dir.mktmpdir do |dir|
135
- book = Book::Base.new(dir)
136
- assert !book.bib_exist?
137
- assert_raises Errno::ENOENT do # XXX: OK?
138
- book.read_bib
139
- end
140
- bib_path = File.join(dir, "bib#{book.ext}")
141
- File.open(bib_path, 'w') { |o| o.print "abc\n" }
142
-
143
- assert book.bib_exist?
144
- assert_equal "abc\n", book.read_bib
145
- end
146
- end
147
-
148
- # backward compatible
149
- def test_set_parameter
150
- book = Book::Base.new(File.dirname(__FILE__))
151
- book.config = :test
152
- assert_equal :test, book.config
153
- end
154
-
155
- def test_set_config
156
- book = Book::Base.new(File.dirname(__FILE__))
157
- book.config = :test
158
- assert_equal :test, book.config
159
- end
160
-
161
- def test_parse_chapters
162
- mktmpbookdir('CHAPS' => '') do |_dir, book, _files|
163
- parts = book.instance_eval { parse_chapters }
164
- assert_equal 0, parts.size
165
- end
166
-
167
- mktmpbookdir('CHAPS' => "chapter1.re\nchapter2\n") do |dir, book, _files|
168
- parts = book.instance_eval { parse_chapters }
169
- assert_equal 1, parts.size
170
-
171
- assert_equal nil, parts[0].number
172
- assert_equal 2, parts[0].chapters.size
173
- chaps = parts[0].chapters.map { |ch| [ch.number, ch.name, ch.path] }
174
- expect = [
175
- [1, 'chapter1', File.join(dir, 'chapter1.re')],
176
- [2, 'chapter2', File.join(dir, 'chapter2')]
177
- ]
178
- assert_equal expect, chaps
179
- end
180
-
181
- mktmpbookdir('CHAPS' => <<EOC) do |dir, book, _files|
182
- part1_chapter1.re
183
- part1_chapter2.re
184
-
185
-
186
- part2_chapter1.re
187
- part2_chapter2.re
188
- part2_chapter3.re
189
-
190
- part3_chapter1.re
191
- EOC
192
- parts = book.instance_eval { parse_chapters }
193
- assert_equal 3, parts.size
194
-
195
- assert_equal nil, parts[0].number
196
- assert_equal 2, parts[0].chapters.size
197
- chaps = parts[0].chapters.map { |ch| [ch.number, ch.name, ch.path] }
198
- expect = [
199
- [1, 'part1_chapter1', File.join(dir, 'part1_chapter1.re')],
200
- [2, 'part1_chapter2', File.join(dir, 'part1_chapter2.re')]
201
- ]
202
- assert_equal expect, chaps
203
-
204
- assert_equal nil, parts[1].number
205
- assert_equal 3, parts[1].chapters.size
206
- chaps = parts[1].chapters.map { |ch| [ch.number, ch.name, ch.path] }
207
- expect = [
208
- [3, 'part2_chapter1', File.join(dir, 'part2_chapter1.re')],
209
- [4, 'part2_chapter2', File.join(dir, 'part2_chapter2.re')],
210
- [5, 'part2_chapter3', File.join(dir, 'part2_chapter3.re')]
211
- ]
212
- assert_equal expect, chaps
213
-
214
- assert_equal nil, parts[2].number
215
- assert_equal 1, parts[2].chapters.size
216
- chaps = parts[2].chapters.map { |ch| [ch.number, ch.name, ch.path] }
217
- expect = [
218
- [6, 'part3_chapter1', File.join(dir, 'part3_chapter1.re')]
219
- ]
220
- assert_equal expect, chaps
221
- end
222
- end
223
-
224
- def test_parse_chpaters_with_parts_file
225
- n_test = 0
226
- [
227
- [
228
- # 期待されるパートの数, :chapter_fileの内容, :part_fileの内容, 期待されるパートタイトルのリスト
229
- 2,
230
- "part1_chapter1.re\n\npart2_chpater1.re\n",
231
- "part1\npart2\npart3\n",
232
- %w[part1 part2]
233
- ],
234
- [
235
- 3,
236
- "part1_chapter1.re\n\npart2_chapter1.re\n\npart3_chapter1.re",
237
- "part1\n",
238
- [
239
- 'part1',
240
- '', # XXX: OK?
241
- ''
242
- ]
243
- ],
244
- [
245
- 1,
246
- "part1_chapter1.re\n",
247
- '',
248
- [
249
- '' # XXX: OK?
250
- ]
251
- ],
252
- [
253
- 1,
254
- "part1_chapter1.re\n",
255
- nil,
256
- [
257
- ''
258
- ]
259
- ]
260
- ].each do |n_parts, chaps, parts, part_names|
261
- n_test += 1
262
- Dir.mktmpdir do |dir|
263
- book = Book::Base.new(dir)
264
- chaps_path = File.join(dir, 'CHAPS')
265
- File.open(chaps_path, 'w') { |o| o.print chaps }
266
- if parts
267
- parts_path = File.join(dir, 'PART')
268
- File.open(parts_path, 'w') { |o| o.print parts }
269
- end
270
-
271
- parts = book.instance_eval { parse_chapters }
272
- assert_equal n_parts, parts.size, "##{n_test}"
273
- assert_equal part_names, parts.map(&:name), "##{n_test}"
274
- end
275
- end
276
- end
277
-
278
- def test_prefaces
279
- mktmpbookdir do |_dir, book, _files|
280
- assert_equal nil, book.prefaces
281
- end
282
-
283
- mktmpbookdir('PREDEF' => '') do |_dir, book, _files|
284
- assert_equal nil, book.prefaces # XXX: OK?
285
- end
286
-
287
- mktmpbookdir('PREDEF' => 'chapter1',
288
- 'chapter1.re' => '') do |_dir, book, files|
289
- assert_kind_of(Book::Part, book.prefaces)
290
- assert_equal '', book.prefaces.name
291
- assert_equal 1, book.prefaces.chapters.size
292
- assert_equal 'chapter1', book.prefaces.chapters.first.name
293
- assert_equal files['chapter1.re'], book.prefaces.chapters.first.path
294
- end
295
-
296
- mktmpbookdir('PREDEF' => "chapter1\n\nchapter2",
297
- 'chapter1.re' => '', 'chapter2.re' => '') do |_dir, book, files|
298
- assert_kind_of(Book::Part, book.prefaces)
299
- assert_equal '', book.prefaces.name
300
- assert_equal 2, book.prefaces.chapters.size
301
- assert_equal 'chapter1', book.prefaces.chapters.first.name
302
- assert_equal files['chapter1.re'], book.prefaces.chapters.first.path
303
- assert_equal 'chapter2', book.prefaces.chapters.last.name
304
- assert_equal files['chapter2.re'], book.prefaces.chapters.last.path
305
- end
306
-
307
- mktmpbookdir('PREDEF' => 'chapter1 chapter2',
308
- 'chapter1.re' => '', 'chapter2.re' => '') do |_dir, book, _files|
309
- assert_kind_of(Book::Part, book.prefaces)
310
- assert_equal '', book.prefaces.name
311
- assert_equal 2, book.prefaces.chapters.size # XXX: OK?
312
- end
313
-
314
- mktmpbookdir('PREDEF' => 'not_exist') do |_dir, book, _files|
315
- assert_raises FileNotFound do
316
- assert_equal nil, book.prefaces
317
- end
318
- end
319
-
320
- mktmpbookdir('PREDEF' => 'chapter1.re',
321
- 'chapter1.re' => '') do |_dir, book, _files|
322
- assert_kind_of(Book::Part, book.prefaces)
323
- assert_equal '', book.prefaces.name
324
- assert_equal 1, book.prefaces.chapters.size
325
- end
326
-
327
- mktmpbookdir('PREDEF' => 'chapter1.txt',
328
- 'chapter1.txt' => '') do |_dir, book, _files|
329
- assert_kind_of(Book::Part, book.prefaces)
330
- assert_equal '', book.prefaces.name
331
- assert_equal 1, book.prefaces.chapters.size
332
- end
333
- end
334
-
335
- def test_appendix
336
- mktmpbookdir do |_dir, book, _files|
337
- assert_equal nil, book.appendix
338
- end
339
-
340
- mktmpbookdir('POSTDEF' => '') do |_dir, book, _files|
341
- assert_equal nil, book.appendix
342
- end
343
-
344
- mktmpbookdir('POSTDEF' => 'chapter1',
345
- 'chapter1.re' => '') do |_dir, book, files|
346
- assert_kind_of(Book::Part, book.appendix)
347
- assert_equal '', book.appendix.name
348
- assert_equal 1, book.appendix.chapters.size
349
- assert_equal 'chapter1', book.appendix.chapters.first.name
350
- assert_equal files['chapter1.re'], book.appendix.chapters.first.path
351
- assert_equal 1, book.appendix.chapters.first.number
352
- end
353
-
354
- mktmpbookdir('POSTDEF' => "chapter1\n\nchapter2",
355
- 'chapter1.re' => '', 'chapter2.re' => '') do |_dir, book, files|
356
- assert_kind_of(Book::Part, book.appendix)
357
- assert_equal '', book.appendix.name
358
- assert_equal 2, book.appendix.chapters.size
359
- assert_equal 'chapter1', book.appendix.chapters.first.name
360
- assert_equal files['chapter1.re'], book.appendix.chapters.first.path
361
- assert_equal 'chapter2', book.appendix.chapters.last.name
362
- assert_equal files['chapter2.re'], book.appendix.chapters.last.path
363
- assert_equal 1, book.appendix.chapters.first.number
364
- assert_equal 2, book.appendix.chapters.last.number
365
- end
366
-
367
- mktmpbookdir('POSTDEF' => 'chapter1 chapter2',
368
- 'chapter1.re' => '', 'chapter2.re' => '') do |_dir, book, _files|
369
- assert_kind_of(Book::Part, book.appendix)
370
- assert_equal '', book.appendix.name
371
- assert_equal 2, book.appendix.chapters.size # XXX: OK?
372
- assert_equal 1, book.appendix.chapters.first.number
373
- assert_equal 2, book.appendix.chapters.last.number
374
- end
375
-
376
- mktmpbookdir('POSTDEF' => 'not_exist') do |_dir, book, _files|
377
- assert_raises FileNotFound do
378
- assert_equal nil, book.appendix
379
- end
380
- end
381
-
382
- mktmpbookdir('catalog.yml' => "APPENDIX:\n - p01.re",
383
- 'p01.re' => '= appendix') do |_dir, book, _files|
384
- assert_equal 'appendix', book.appendix.chapters.first.title
385
- assert_equal 1, book.appendix.chapters.first.number
386
- end
387
- end
388
-
389
- def test_postscripts
390
- mktmpbookdir('catalog.yml' => "POSTDEF:\n - b01.re",
391
- 'b01.re' => '= back') do |_dir, book, _files|
392
- assert_kind_of(Book::Part, book.postscripts)
393
- assert_equal 1, book.postscripts.chapters.size
394
- assert_equal 'back', book.postscripts.chapters.first.title
395
- assert_equal nil, book.postscripts.chapters.first.number
396
- end
397
- end
398
-
399
- def test_parts
400
- mktmpbookdir do |_dir, book, _files|
401
- assert book.parts.empty?
402
- assert !book.part(0)
403
- assert !book.part(1)
404
-
405
- tmp = []
406
- book.each_part { tmp << true }
407
- assert tmp.empty?
408
- end
409
-
410
- mktmpbookdir('CHAPS' => "ch1\nch2\n\nch3", 'PART' => "foo\nbar\n") do |_dir, book, _files|
411
- parts = book.parts
412
- assert_equal 2, parts.size
413
- assert !book.part(0)
414
- assert_equal 'foo', book.part(1).name
415
- assert_equal 'bar', book.part(2).name
416
- assert !book.part(3)
417
-
418
- tmp = []
419
- book.each_part { |p| tmp << p.number }
420
- assert_equal [1, 2], tmp
421
- end
422
- end
423
-
424
- def test_parts_in_file
425
- mktmpbookdir do |_dir, book, _files|
426
- assert book.parts_in_file.empty?
427
- assert !book.part(0)
428
- assert !book.part(1)
429
-
430
- tmp = []
431
- book.each_part { tmp << true }
432
- assert tmp.empty?
433
- end
434
-
435
- mktmpbookdir('CHAPS' => "ch1.re\nch2.re\n\nch3.re\n",
436
- 'PART' => "foo\nbar\n",
437
- 'ch1.re' => "= ch1\n\n", 'ch2.re' => "= ch2\n\n",
438
- 'ch3.re' => "= ch3\n\n") do |_dir, book, _files|
439
- parts = book.parts_in_file
440
- assert_equal 0, parts.size
441
- assert !book.part(0)
442
- assert_equal 'foo', book.part(1).name
443
- assert_equal 'bar', book.part(2).name
444
- assert !book.part(3)
445
-
446
- tmp = []
447
- book.each_part { |p| tmp << p.number }
448
- assert_equal [1, 2], tmp
449
- end
450
-
451
- mktmpbookdir('CHAPS' => "ch1.re\nch2.re\n\nch3.re\n",
452
- 'PART' => "foo.re\nbar.re\n",
453
- 'foo.re' => "= part1\n\n", 'bar.re' => "= part2\n\n",
454
- 'ch1.re' => "= ch1\n\n", 'ch2.re' => "= ch2\n\n",
455
- 'ch3.re' => "= ch3\n\n") do |_dir, book, _files|
456
- parts = book.parts_in_file
457
- assert_equal 2, parts.size
458
- assert !book.part(0)
459
- assert_equal 'foo', book.part(1).name
460
- assert_equal 'bar', book.part(2).name
461
- assert !book.part(3)
462
-
463
- tmp = []
464
- book.each_part { |p| tmp << p.number }
465
- assert_equal [1, 2], tmp
466
- end
467
- end
468
-
469
- def test_chapters
470
- mktmpbookdir('CHAPS' => "ch1\nch2\n\nch3") do |_dir, book, _files|
471
- chapters = book.chapters
472
- assert_equal 3, chapters.size
473
-
474
- ch_names = %w[ch1 ch2 ch3]
475
- tmp = []
476
- book.each_chapter { |ch| tmp << ch.name }
477
- assert_equal ch_names, tmp
478
-
479
- ch_names.each do |name|
480
- assert book.chapter(name)
481
- assert_equal name, book.chapter(name).name
482
- end
483
-
484
- assert_raises ReVIEW::KeyError do
485
- book.chapter('not exist')
486
- end
487
- end
488
-
489
- mktmpbookdir('CHAPS' => "ch1.txt\nch2.txt\n\nch3.txt") do |_dir, book, _files|
490
- chapters = book.chapters
491
- assert_equal 3, chapters.size
492
-
493
- ch_names = %w[ch1 ch2 ch3]
494
- tmp = []
495
- book.each_chapter { |ch| tmp << ch.name }
496
- assert_equal ch_names, tmp
497
-
498
- ch_names.each do |name|
499
- assert book.chapter(name)
500
- assert_equal name, book.chapter(name).name
501
- end
502
-
503
- assert_raises ReVIEW::KeyError do
504
- book.chapter('not exist')
505
- end
506
- end
507
- end
508
-
509
- def test_next_chapter
510
- mktmpbookdir('CHAPS' => "ch1\nch2") do |_dir, book, _files|
511
- chapter = book.chapter('ch1')
512
- assert_equal book.chapter('ch2'), book.next_chapter(chapter)
513
-
514
- chapter = book.chapter('ch2')
515
- assert_equal nil, book.next_chapter(chapter)
516
- end
517
- end
518
-
519
- def test_prev_chapter
520
- mktmpbookdir('CHAPS' => "ch1\nch2") do |_dir, book, _files|
521
- chapter = book.chapter('ch2')
522
- assert_equal book.chapter('ch1'), book.prev_chapter(chapter)
523
-
524
- chapter = book.chapter('ch1')
525
- assert_equal nil, book.prev_chapter(chapter)
526
- end
527
- end
528
-
529
- def test_volume
530
- mktmpbookdir do |_dir, book, _files|
531
- assert book.volume
532
- assert_equal 0, book.volume.bytes
533
- assert_equal 0, book.volume.chars
534
- assert_equal 0, book.volume.lines
535
- end
536
-
537
- mktmpbookdir('CHAPS' => 'chapter1.re', 'chapter1.re' => '12345') do |_dir, book, _files|
538
- assert book.volume
539
- assert book.volume.bytes > 0
540
- assert book.volume.chars > 0
541
- assert book.volume.lines > 0
542
- end
543
-
544
- mktmpbookdir('preface.re' => '12345') do |dir, _book, _files|
545
- Dir.chdir(dir) do
546
- book2 = Book::Base.new('.')
547
- assert book2.volume
548
- assert book2.volume.bytes > 0
549
- assert book2.volume.chars > 0
550
- assert book2.volume.lines > 0
551
- end
552
- end
553
- end
554
-
555
- def test_basedir
556
- Dir.mktmpdir do |dir|
557
- book = Book::Base.new(dir)
558
- assert_equal dir, book.basedir
559
- end
560
- end
561
-
562
- def test_contentdir
563
- mktmpbookdir('config.yml' => "contentdir: content\n",
564
- 'catalog.yml' => "CHAPS:\n - ch01.re\n",
565
- 'content/ch01.re' => "foo\n") do |_dir, book, _files|
566
- assert_equal "foo\n", book.chapters[0].content
567
- end
568
- end
569
-
570
- def test_page_metric
571
- Dir.mktmpdir do |dir|
572
- book = Book::Base.new(dir)
573
- assert_equal ReVIEW::Book::PageMetric::A5, book.page_metric
574
- end
575
- end
576
-
577
- def test_page_metric_config
578
- mktmpbookdir('config.yml' => "bookname: book\npage_metric: B5\n") do |_dir, book, _files|
579
- assert_equal ReVIEW::Book::PageMetric::B5, book.page_metric
580
- end
581
- end
582
-
583
- def test_page_metric_config_array
584
- mktmpbookdir('config.yml' => "bookname: book\npage_metric: [50, 40, 36, 40, 1]\n") do |_dir, book, _files|
585
- assert_equal ReVIEW::Book::PageMetric::B5, book.page_metric
586
- end
587
- end
588
- end