review 5.6.0 → 5.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) 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 +22 -0
  8. data/NEWS.md +21 -0
  9. data/README.md +1 -1
  10. data/lib/review/book/base.rb +1 -1
  11. data/lib/review/builder.rb +4 -8
  12. data/lib/review/epubmaker/epubcommon.rb +13 -7
  13. data/lib/review/epubmaker/epubv2.rb +0 -5
  14. data/lib/review/epubmaker/epubv3.rb +9 -1
  15. data/lib/review/epubmaker/producer.rb +2 -3
  16. data/lib/review/epubmaker.rb +2 -4
  17. data/lib/review/htmlbuilder.rb +2 -2
  18. data/lib/review/idgxmlbuilder.rb +4 -3
  19. data/lib/review/img_math.rb +9 -2
  20. data/lib/review/init.rb +3 -3
  21. data/lib/review/latexbuilder.rb +1 -1
  22. data/lib/review/lineinput.rb +2 -2
  23. data/lib/review/makerhelper.rb +2 -2
  24. data/lib/review/pdfmaker.rb +3 -5
  25. data/lib/review/update.rb +3 -7
  26. data/lib/review/version.rb +1 -1
  27. data/lib/review/yamlloader.rb +0 -3
  28. data/review.gemspec +2 -3
  29. data/samples/syntax-book/Gemfile +1 -1
  30. data/templates/opf/epubv2.opf.erb +2 -0
  31. data/templates/opf/epubv3.opf.erb +2 -0
  32. data/templates/opf/opf_manifest_epubv2.opf.erb +2 -0
  33. data/templates/opf/opf_manifest_epubv3.opf.erb +2 -0
  34. data/templates/opf/opf_tocx_epubv3.opf.erb +2 -0
  35. metadata +10 -139
  36. data/test/assets/black.eps +0 -280
  37. data/test/assets/fit.png +0 -0
  38. data/test/assets/header_listener.html +0 -35
  39. data/test/assets/img_math/img1.png +0 -0
  40. data/test/assets/img_math/img2.png +0 -0
  41. data/test/assets/img_math/img3.png +0 -0
  42. data/test/assets/large.gif +0 -0
  43. data/test/assets/large.jpg +0 -0
  44. data/test/assets/large.png +0 -0
  45. data/test/assets/large.svg +0 -65
  46. data/test/assets/syntax_book_index_detail.txt +0 -60
  47. data/test/assets/test.xml.erb +0 -3
  48. data/test/assets/test_template.tex +0 -189
  49. data/test/assets/test_template_backmatter.tex +0 -200
  50. data/test/book_test_helper.rb +0 -44
  51. data/test/run_test.rb +0 -12
  52. data/test/test_book.rb +0 -588
  53. data/test/test_book_chapter.rb +0 -329
  54. data/test/test_book_part.rb +0 -53
  55. data/test/test_builder.rb +0 -128
  56. data/test/test_catalog.rb +0 -174
  57. data/test/test_catalog_converter_cmd.rb +0 -73
  58. data/test/test_compiler.rb +0 -52
  59. data/test/test_configure.rb +0 -91
  60. data/test/test_converter.rb +0 -21
  61. data/test/test_epub3maker.rb +0 -733
  62. data/test/test_epubmaker.rb +0 -931
  63. data/test/test_epubmaker_cmd.rb +0 -56
  64. data/test/test_extentions_hash.rb +0 -66
  65. data/test/test_helper.rb +0 -62
  66. data/test/test_htmlbuilder.rb +0 -3315
  67. data/test/test_htmltoc.rb +0 -29
  68. data/test/test_htmlutils.rb +0 -43
  69. data/test/test_i18n.rb +0 -300
  70. data/test/test_idgxmlbuilder.rb +0 -1529
  71. data/test/test_idgxmlmaker_cmd.rb +0 -50
  72. data/test/test_image_finder.rb +0 -81
  73. data/test/test_img_math.rb +0 -120
  74. data/test/test_index.rb +0 -287
  75. data/test/test_indexbuilder.rb +0 -52
  76. data/test/test_latexbuilder.rb +0 -2972
  77. data/test/test_latexbuilder_v2.rb +0 -1654
  78. data/test/test_lineinput.rb +0 -104
  79. data/test/test_location.rb +0 -30
  80. data/test/test_logger.rb +0 -33
  81. data/test/test_makerhelper.rb +0 -44
  82. data/test/test_markdownbuilder.rb +0 -371
  83. data/test/test_md2inaobuilder.rb +0 -90
  84. data/test/test_pdfmaker.rb +0 -354
  85. data/test/test_pdfmaker_cmd.rb +0 -130
  86. data/test/test_plaintextbuilder.rb +0 -1214
  87. data/test/test_preprocessor.rb +0 -196
  88. data/test/test_review_ext.rb +0 -30
  89. data/test/test_reviewheaderlistener.rb +0 -49
  90. data/test/test_rstbuilder.rb +0 -619
  91. data/test/test_sec_counter.rb +0 -156
  92. data/test/test_template.rb +0 -33
  93. data/test/test_textmaker_cmd.rb +0 -58
  94. data/test/test_textutils.rb +0 -187
  95. data/test/test_tocprinter.rb +0 -46
  96. data/test/test_topbuilder.rb +0 -1301
  97. data/test/test_update.rb +0 -473
  98. data/test/test_webtocprinter.rb +0 -195
  99. data/test/test_yamlloader.rb +0 -186
  100. data/test/test_zip_exporter.rb +0 -106
@@ -1,329 +0,0 @@
1
- require 'book_test_helper'
2
-
3
- class ChapterTest < Test::Unit::TestCase
4
- include BookTestHelper
5
-
6
- def setup
7
- I18n.setup
8
- end
9
-
10
- def test_initialize
11
- ch = Book::Chapter.new(:book, :number, :name, '/foo/bar', :io)
12
- assert_equal :book, ch.book
13
- assert_equal :number, ch.number
14
- assert_equal '/foo/bar', ch.path
15
- assert_equal '#<ReVIEW::Book::Chapter number /foo/bar>', ch.inspect
16
- end
17
-
18
- def test_dirname_and_basename
19
- ch = Book::Chapter.new(nil, nil, nil, nil, nil)
20
- assert_equal nil, ch.dirname
21
- assert_equal nil, ch.basename
22
-
23
- ch = Book::Chapter.new(nil, nil, nil, '/foo/bar', nil)
24
- assert_equal '/foo', ch.dirname
25
- assert_equal 'bar', ch.basename
26
-
27
- ch = Book::Chapter.new(nil, nil, nil, 'bar', nil)
28
- assert_equal '.', ch.dirname
29
- assert_equal 'bar', ch.basename
30
- end
31
-
32
- def test_name
33
- ch = Book::Chapter.new(nil, nil, 'foo', nil)
34
- assert_equal 'foo', ch.name
35
-
36
- ch = Book::Chapter.new(nil, nil, 'foo.bar', nil)
37
- assert_equal 'foo', ch.name
38
-
39
- # ch = Book::Chapter.new(nil, nil, nil, nil)
40
- # assert_raises(TypeError) { ch.name } # XXX: OK?
41
- end
42
-
43
- def test_size
44
- ch = Book::Chapter.new(nil, nil, nil, __FILE__, :io)
45
- filesize = File.read(__FILE__, mode: 'rt:BOM|utf-8').size
46
- assert_equal filesize, ch.size
47
-
48
- File.open(__FILE__, 'r') do |i|
49
- ch = Book::Chapter.new(nil, nil, nil, nil, i)
50
- filesize = File.read(__FILE__, mode: 'rt:BOM|utf-8').size
51
- assert_equal filesize, ch.size
52
- end
53
- end
54
-
55
- def test_title
56
- io = StringIO.new
57
- book = Book::Base.new
58
- ch = Book::Chapter.new(book, nil, nil, nil, io)
59
- assert_equal '', ch.title
60
-
61
- io = StringIO.new("=1\n=2\n")
62
- ch = Book::Chapter.new(book, nil, nil, nil, io)
63
- assert_equal '1', ch.title
64
- end
65
-
66
- def test_lines
67
- lines = ["1\n", "2\n", '3']
68
- tf = Tempfile.new('chapter_test')
69
- tf.print lines.join
70
- tf.close
71
-
72
- book = Book::Base.new
73
- ch = Book::Chapter.new(book, nil, nil, tf.path)
74
- ch.generate_indexes
75
- assert_equal lines, ch.lines
76
-
77
- lines = ["1\n", "2\n", '3']
78
- tf1 = Tempfile.new('chapter_test1')
79
- tf1.print lines.join
80
- tf1.close
81
- tf2 = Tempfile.new('chapter_test2')
82
- tf2.puts lines.join
83
- tf2.puts lines.join
84
- tf2.close
85
-
86
- ch = Book::Chapter.new(book, nil, nil, tf1.path, tf2.path)
87
- ch.generate_indexes
88
- assert_equal lines, ch.lines # XXX: OK?
89
- end
90
-
91
- def test_volume
92
- content = "abc\ndef"
93
- tf1 = Tempfile.new('chapter_test1')
94
- tf1.print content
95
- tf1.close
96
- tf2 = Tempfile.new('chapter_test2')
97
- tf2.print content
98
- tf2.print content
99
- tf2.close
100
-
101
- book = Book::Base.new
102
- ch = Book::Chapter.new(book, nil, nil, tf1.path)
103
- assert ch.volume
104
- assert_equal content.gsub(/\s/, '').size, ch.volume.bytes
105
-
106
- book = Book::Base.new
107
- ch = Book::Chapter.new(book, nil, nil, tf1.path, tf2)
108
- assert ch.volume
109
- assert_equal content.gsub(/\s/, '').size, ch.volume.bytes # XXX: OK?
110
- end
111
-
112
- def test_on_chaps?
113
- mktmpbookdir('CHAPS' => "chapter1.re\nchapter2.re",
114
- 'chapter1.re' => '12345', 'preface.re' => 'abcde') do |dir, book, files|
115
- ch1 = Book::Chapter.new(book, 1, 'chapter1', files['chapter1.re'])
116
- pre = Book::Chapter.new(book, nil, 'preface', files['preface.re'])
117
-
118
- assert ch1.on_chaps?
119
- assert !pre.on_chaps?
120
-
121
- ch2_path = File.join(dir, 'chapter2.re')
122
- FileUtils.touch(ch2_path)
123
- ch2 = Book::Chapter.new(book, 2, 'chapter2', ch2_path)
124
-
125
- ch3_path = File.join(dir, 'chapter3.re')
126
- FileUtils.touch(ch3_path)
127
- ch3 = Book::Chapter.new(book, 3, 'chapter3', ch3_path)
128
-
129
- assert ch2.on_chaps?
130
- assert !ch3.on_chaps?
131
- end
132
- end
133
-
134
- def test_invalid_encoding
135
- mktmpbookdir('CHAPS' => 'chapter1.re',
136
- 'chapter1.re' => "= 日本語UTF-8\n") do |_dir, book, files|
137
- assert Book::Chapter.new(book, 1, 'chapter1', files['chapter1.re'])
138
- end
139
-
140
- # UTF-16LE UTF-16BE UTF-32LE UTF-32BE cause error on Windows
141
- %w[CP932 SHIFT_JIS EUC-JP].each do |enc|
142
- mktmpbookdir('CHAPS' => 'chapter1.re',
143
- 'chapter1.re' => "= 日本語UTF-8\n".encode(enc)) do |_dir, book, files|
144
- e = assert_raises(ReVIEW::CompileError) { Book::Chapter.new(book, 1, 'chapter1', files['chapter1.re']) }
145
- assert_equal 'chapter1: invalid byte sequence in UTF-8', e.message
146
- end
147
- end
148
- end
149
-
150
- def test_list_index
151
- do_test_index(<<E, Book::ListIndex, :list_index, :list)
152
- //listnum[abc][abc-listnum]{
153
- //}
154
- //list[def][def-list]{
155
- //}
156
- //table[def]{
157
- //}
158
- //table[others]{
159
- //}
160
- E
161
- end
162
-
163
- def test_table_index
164
- do_test_index(<<E, Book::TableIndex, :table_index, :table)
165
- //table[abc]{
166
- //}
167
- //table[def]{
168
- //}
169
- //list[def][def-list]{
170
- //}
171
- //list[others][other-list]{
172
- //}
173
- E
174
- end
175
-
176
- def test_footnote_index
177
- content = <<E
178
- @<fn>{abc}@<fn>{def}@<fn>{xyz}
179
- //footnote[abc][textabc...]
180
- //footnote[def][textdef...]
181
- //footnote[xyz][textxyz...]
182
- //list[def][def-list]{
183
- //}
184
- //list[others][others-list]{
185
- //}
186
- E
187
- do_test_index(content, Book::FootnoteIndex, :footnote_index, :footnote) do |ch|
188
- assert_raises ReVIEW::KeyError do
189
- ch.footnote('xyz2')
190
- end
191
- end
192
- end
193
-
194
- def test_endnote_index
195
- content = <<E
196
- @<fn>{abc}@<fn>{def}@<fn>{xyz}@<endnote>{abc}@<endnote>{def}@<endnote>{xyz}
197
- //footnote[abc][textabc...]
198
- //footnote[def][textdef...]
199
- //footnote[xyz][textxyz...]
200
- //endnote[abc][textabc...]
201
- //endnote[def][textdef...]
202
- //endnote[xyz][textxyz...]
203
- //list[def][def-list]{
204
- //}
205
- //list[others][others-list]{
206
- //}
207
- E
208
- do_test_index(content, Book::EndnoteIndex, :endnote_index, :endnote) do |ch|
209
- assert_raises ReVIEW::KeyError do
210
- ch.endnote('xyz2')
211
- end
212
- end
213
- end
214
-
215
- def test_bibpaper
216
- do_test_index(<<E, Book::BibpaperIndex, :bibpaper_index, :bibpaper, filename: 'bib.re')
217
- //bibpaper[abc][text...]
218
- //bibpaper[def][text...]
219
- //bibpaper[xyz][text...]
220
- E
221
- assert_raises FileNotFound do
222
- do_test_index('', Book::BibpaperIndex, :bibpaper_index, :bibpaper, filename: 'bib')
223
- end
224
- end
225
-
226
- def test_headline_index
227
- do_test_index(<<E, Book::HeadlineIndex, :headline_index, :headline, propagate: false)
228
- == x
229
- == abc
230
- == def
231
- === def
232
- //table[others]{
233
- //}
234
- E
235
- end
236
-
237
- def test_headline_index_nullsection
238
- do_test_index(<<E, Book::HeadlineIndex, :headline_index, :headline, propagate: false)
239
- == abc
240
- ==== dummy
241
- == def
242
- E
243
- end
244
-
245
- def test_column_index
246
- do_test_index(<<E, Book::ColumnIndex, :column_index, :column, propagate: false)
247
- = dummy1
248
- ===[column]{abc} aaaa
249
- = dummy2
250
- ===[column] def
251
- == dummy3
252
- E
253
- end
254
-
255
- def test_image
256
- do_test_index(<<E, Book::ImageIndex, :image_index, :image)
257
- //image[abc][abc-image]{
258
- //}
259
- //image[def][abc-image]{
260
- //}
261
- //list[def][def-list]{
262
- //}
263
- //list[others][others-list]{
264
- //}
265
- E
266
-
267
- do_test_index(<<E, Book::NumberlessImageIndex, :numberless_image_index, :image, propagate: false)
268
- //numberlessimage[abc]{
269
- //}
270
- //numberlessimage[def]{
271
- //}
272
- //list[def][def-list]{
273
- //}
274
- //list[others][others-list]{
275
- //}
276
- E
277
-
278
- do_test_index(<<E, Book::ImageIndex, :image_index, :image)
279
- //numberlessimage[abc]{
280
- //}
281
- //image[def][def-image]{
282
- //}
283
- //list[def][def-list]{
284
- //}
285
- //list[others][others-list]{
286
- //}
287
- E
288
-
289
- do_test_index(<<E, Book::NumberlessImageIndex, :numberless_image_index, :image, propagate: false)
290
- //numberlessimage[abc]{
291
- //}
292
- //image[def][def-image]{
293
- //}
294
- //list[def][def-list]{
295
- //}
296
- //list[others][others-list]{
297
- //}
298
- E
299
- end
300
-
301
- def do_test_index(content, _klass, _list_method, ref_method, opts = {})
302
- Dir.mktmpdir do |dir|
303
- path = File.join(dir, opts[:filename] || 'chapter.re')
304
-
305
- File.open(path, 'w') do |o|
306
- o.print content
307
- end
308
-
309
- book = Book::Base.new(dir)
310
-
311
- ch = Book::Chapter.new(book, 1, 'chapter', path)
312
- book.generate_indexes
313
- ch.generate_indexes
314
- assert ch.__send__(ref_method, 'abc')
315
- assert ch.__send__(ref_method, 'def')
316
- assert_raises ReVIEW::KeyError do
317
- ch.__send__(ref_method, nil)
318
- end
319
- assert_raises ReVIEW::KeyError do
320
- ch.__send__(ref_method, 'others')
321
- end
322
- assert_raises ReVIEW::KeyError do
323
- ch.__send__(ref_method, 'not exist id')
324
- end
325
-
326
- yield(ch) if block_given?
327
- end
328
- end
329
- end
@@ -1,53 +0,0 @@
1
- require 'book_test_helper'
2
- class PartTest < Test::Unit::TestCase
3
- include BookTestHelper
4
-
5
- def test_initialize
6
- book = Book::Base.new
7
- part = Book::Part.new(book, nil, nil)
8
- assert_equal nil, part.number
9
- assert_equal nil, part.chapters
10
- assert_equal '', part.name
11
-
12
- part = Book::Part.new(book, 123, [], 'name')
13
- assert_equal 123, part.number
14
- assert_equal [], part.chapters
15
- assert_equal 'name', part.name
16
- end
17
-
18
- def test_each_chapter
19
- part = Book::Part.new(nil, nil, [1, 2, 3])
20
-
21
- tmp = []
22
- part.each_chapter { |ch| tmp << ch }
23
- assert_equal [1, 2, 3], tmp
24
- end
25
-
26
- def test_volume
27
- book = Book::Base.new
28
- part = Book::Part.new(book, nil, [])
29
- assert part.volume
30
- assert_equal 0, part.volume.bytes
31
- assert_equal 0, part.volume.chars
32
- assert_equal 0, part.volume.lines
33
-
34
- chs = []
35
- tfs = [] ## prevent from removing Tempfile
36
- Tempfile.open('part_test') do |o|
37
- o.print '12345'
38
- chs << Book::Chapter.new(book, nil, nil, o.path)
39
- tfs << o
40
- end
41
- Tempfile.open('part_test') do |o|
42
- o.print '67890'
43
- chs << Book::Chapter.new(book, nil, nil, o.path)
44
- tfs << o
45
- end
46
-
47
- part = Book::Part.new(book, nil, chs)
48
- assert part.volume
49
- assert part.volume.bytes == 0
50
- assert part.volume.chars == 0
51
- assert part.volume.lines == 0
52
- end
53
- end
data/test/test_builder.rb DELETED
@@ -1,128 +0,0 @@
1
- require 'test_helper'
2
- require 'review/builder'
3
-
4
- require 'review/book'
5
-
6
- class MockCompiler
7
- def text(s)
8
- [:text, s]
9
- end
10
- end
11
-
12
- class BuidlerTest < Test::Unit::TestCase
13
- include ReVIEW
14
-
15
- def setup
16
- @b = Builder.new
17
- chap = ReVIEW::Book::Chapter.new(nil, nil, '-', nil)
18
- @b.bind(MockCompiler.new, chap, nil)
19
- end
20
-
21
- def test_initialize
22
- assert Builder.new
23
- end
24
-
25
- def test_bind
26
- b = Builder.new
27
- chap = ReVIEW::Book::Chapter.new(ReVIEW::Book::Base.new, nil, '-', nil)
28
- assert_nothing_raised do
29
- b.bind(nil, chap, nil)
30
- end
31
- end
32
-
33
- def test_result
34
- b = Builder.new
35
- assert_raises(NoMethodError) do # XXX: OK?
36
- b.result
37
- end
38
-
39
- b = Builder.new
40
- chapter = ReVIEW::Book::Chapter.new(ReVIEW::Book::Base.new, nil, '-', nil)
41
- b.bind(nil, chapter, nil)
42
- assert_equal '', b.result
43
- end
44
-
45
- def test_print_and_puts
46
- b = Builder.new
47
- assert_raises(NoMethodError) do # XXX: OK?
48
- b.print ''
49
- end
50
- assert_raises(NoMethodError) do # XXX: OK?
51
- b.puts ''
52
- end
53
- end
54
-
55
- def test_not_implemented_methods
56
- ex = NoMethodError # XXX: OK?
57
- %i[list_header list_body listnum_body source_header source_body image_image image_dummy table_header table_begin tr th table_end compile_ruby compile_kw compile_href bibpaper_header bibpaper_bibpaper inline_hd_chap].each do |m|
58
- b = Builder.new
59
- assert_raises(ex) { b.__send__(m) }
60
- end
61
- end
62
-
63
- def test_compile_inline
64
- text = 'abc'
65
- assert_equal [:text, text], @b.compile_inline(text)
66
- end
67
-
68
- def test_inline_ruby
69
- def @b.compile_ruby(base, ruby)
70
- [base, ruby]
71
- end
72
- str = @b.inline_ruby('foo,bar')
73
- assert_equal str, ['foo', 'bar']
74
- str = @b.inline_ruby(' foo , bar ')
75
- assert_equal str, ['foo', 'bar']
76
- str = @b.inline_ruby('foo\\,\\,,\\,bar,buz')
77
- assert_equal str, ['foo,,', ',bar,buz']
78
- end
79
-
80
- def test_compile_inline_backslash
81
- text = 'abc\\d\\#a'
82
- assert_equal [:text, text], @b.compile_inline(text)
83
- end
84
-
85
- def test_inline_missing_ref
86
- b = Builder.new
87
- chapter = ReVIEW::Book::Chapter.new(ReVIEW::Book::Base.new, 1, 'chap1', nil, StringIO.new)
88
- b.bind(nil, chapter, nil)
89
- e = assert_raises(ReVIEW::ApplicationError) { b.inline_list('unknown|list1') }
90
- assert_equal 'unknown list: unknown|list1', e.message
91
- e = assert_raises(ReVIEW::ApplicationError) { b.inline_table('unknown|table1') }
92
- assert_equal 'unknown table: unknown|table1', e.message
93
- e = assert_raises(ReVIEW::ApplicationError) { b.inline_img('unknown|img1') }
94
- assert_equal 'unknown image: unknown|img1', e.message
95
- e = assert_raises(ReVIEW::ApplicationError) { b.inline_column('unknown|column1') }
96
- assert_equal 'unknown column: unknown|column1', e.message
97
- e = assert_raises(ReVIEW::ApplicationError) { b.inline_fn('unknown|footnote1') }
98
- assert_equal 'unknown footnote: unknown|footnote1', e.message
99
- e = assert_raises(ReVIEW::ApplicationError) { b.inline_endnote('endnote1') }
100
- assert_equal 'unknown endnote: endnote1', e.message
101
- end
102
-
103
- def test_nest_error
104
- b = XBuilder.new
105
- b.children = nil
106
- assert_equal '', b.solve_nest('')
107
- b.children = ['dl']
108
- e = assert_raises(ReVIEW::ApplicationError) { b.solve_nest('') }
109
- assert_equal ': //beginchild of dl misses //endchild', e.message
110
- b.children = ['ul', 'dl', 'ol']
111
- e = assert_raises(ReVIEW::ApplicationError) { b.solve_nest('') }
112
- assert_equal ': //beginchild of ol,dl,ul misses //endchild', e.message
113
-
114
- assert_equal "\u0001→/ol←\u0001", b.endchild
115
- assert_equal "\u0001→/dl←\u0001", b.endchild
116
- assert_equal "\u0001→/ul←\u0001", b.endchild
117
- e = assert_raises(ReVIEW::ApplicationError) { b.endchild }
118
- assert_equal ": //endchild is shown, but any opened //beginchild doesn't exist", e.message
119
- end
120
-
121
- class XBuilder < Builder
122
- attr_accessor :children
123
-
124
- def puts(s)
125
- s
126
- end
127
- end
128
- end
data/test/test_catalog.rb DELETED
@@ -1,174 +0,0 @@
1
- require 'test_helper'
2
- require 'book_test_helper'
3
- require 'review/catalog'
4
-
5
- class CatalogTest < Test::Unit::TestCase
6
- include ReVIEW
7
- include BookTestHelper
8
-
9
- def test_predef
10
- sut = Catalog.new(yaml)
11
- exp = %w[pre01.re pre02.re]
12
- assert_equal(exp, sut.predef)
13
- end
14
-
15
- def test_chaps
16
- sut = Catalog.new(yaml)
17
- exp = %w[ch01.re ch02.re]
18
- assert_equal(exp, sut.chaps)
19
- end
20
-
21
- def test_chaps_empty
22
- yaml = StringIO.new
23
- sut = Catalog.new(yaml)
24
- assert_equal([], sut.chaps)
25
- end
26
-
27
- def test_appendix
28
- sut = Catalog.new(yaml)
29
- exp = %w[post01.re post02.re]
30
- assert_equal(exp, sut.appendix)
31
- end
32
-
33
- def test_chaps_with_parts
34
- sut = Catalog.new(yaml_with_parts)
35
- exp = %w[ch01.re ch02.re ch03.re ch04.re ch05.re]
36
- assert_equal(exp, sut.chaps)
37
- end
38
-
39
- def test_parts
40
- sut = Catalog.new(yaml_with_parts)
41
- exp = %w[part1.re part2.re]
42
- assert_equal(exp, sut.parts)
43
- end
44
-
45
- def test_parts_with_empty
46
- sut = Catalog.new(yaml)
47
- assert_equal([], sut.parts)
48
- end
49
-
50
- def test_empty_parts
51
- sut = Catalog.new(StringIO.new)
52
- assert_equal([], sut.parts_with_chaps)
53
- end
54
-
55
- def test_parts2
56
- sut = Catalog.new(yaml_with_parts)
57
- assert_equal(['ch01.re',
58
- { 'part1.re' => ['ch02.re'] },
59
- 'ch03.re',
60
- { 'part2.re' => ['ch04.re', 'ch05.re'] }],
61
- sut.parts_with_chaps)
62
- end
63
-
64
- def test_postdef
65
- sut = Catalog.new(yaml)
66
- exp = %w[back01.re back02.re]
67
- assert_equal(exp, sut.postdef)
68
- end
69
-
70
- def test_from_object
71
- sut = Catalog.new(yaml_hash)
72
- exp = %w[ch01.re ch02.re]
73
- assert_equal(exp, sut.chaps)
74
- end
75
-
76
- def test_validate
77
- mktmpbookdir do |dir, _book, _files|
78
- %w[pre01.re pre02.re ch01.re ch02.re post01.re post02.re back01.re back02.re].each do |file|
79
- FileUtils.touch(file)
80
- end
81
- cat = Catalog.new(yaml_hash)
82
- cat.validate!({ 'contentdir' => '.' }, dir)
83
- end
84
- end
85
-
86
- def test_validate_with_parts
87
- mktmpbookdir do |dir, _book, _files|
88
- %w[ch01.re part1.re ch02.re ch03.re part2.re ch04.re ch05.re].each do |file|
89
- FileUtils.touch(file)
90
- end
91
- cat = Catalog.new(yaml_with_parts)
92
- cat.validate!({ 'contentdir' => '.' }, dir)
93
- end
94
- end
95
-
96
- def test_validate_fail_ch02
97
- assert_raise FileNotFound do
98
- mktmpbookdir do |dir, _book, _files|
99
- %w[pre01.re pre02.re ch01.re].each do |file|
100
- FileUtils.touch(file)
101
- end
102
- cat = Catalog.new(yaml_hash)
103
- cat.validate!({ 'contentdir' => '.' }, dir)
104
- end
105
- end
106
- end
107
-
108
- def test_validate_fail_back02
109
- assert_raise FileNotFound do
110
- mktmpbookdir do |dir, _book, _files|
111
- %w[pre01.re pre02.re ch01.re ch02.re post01.re post02.re back01.re back03.re].each do |file|
112
- FileUtils.touch(file)
113
- end
114
- cat = Catalog.new(yaml_hash)
115
- cat.validate!({ 'contentdir' => '.' }, dir)
116
- end
117
- end
118
- end
119
-
120
- def test_validate_contentdir
121
- mktmpbookdir do |dir, _book, _files|
122
- Dir.mkdir('content')
123
- %w[content/pre01.re content/pre02.re content/ch01.re content/ch02.re content/post01.re content/post02.re content/back01.re content/back02.re].each do |file|
124
- FileUtils.touch(file)
125
- end
126
- cat = Catalog.new(yaml_hash)
127
- cat.validate!({ 'contentdir' => 'content' }, dir)
128
- end
129
- end
130
-
131
- private
132
-
133
- def yaml
134
- StringIO.new(<<-EOS)
135
-
136
- PREDEF:
137
- - pre01.re
138
- - pre02.re
139
-
140
- CHAPS:
141
- - ch01.re
142
- - ch02.re
143
-
144
- APPENDIX:
145
- - post01.re
146
- - post02.re
147
-
148
- POSTDEF:
149
- - back01.re
150
- - back02.re
151
- EOS
152
- end
153
-
154
- def yaml_hash
155
- { 'PREDEF' => %w[pre01.re pre02.re],
156
- 'CHAPS' => %w[ch01.re ch02.re],
157
- 'APPENDIX' => %w[post01.re post02.re],
158
- 'POSTDEF' => %w[back01.re back02.re] }
159
- end
160
-
161
- def yaml_with_parts
162
- StringIO.new(<<-EOS)
163
- CHAPS:
164
- - ch01.re
165
- - part1.re:
166
- - ch02.re
167
- - ch03.re
168
- - part2.re:
169
- - ch04.re
170
- - ch05.re
171
-
172
- EOS
173
- end
174
- end