review 5.0.0 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby-tex.yml +35 -0
  3. data/.github/workflows/ruby-win.yml +8 -4
  4. data/.github/workflows/ruby.yml +6 -2
  5. data/.rubocop.yml +24 -9
  6. data/NEWS.ja.md +215 -0
  7. data/NEWS.md +215 -1
  8. data/README.md +7 -6
  9. data/Rakefile +7 -2
  10. data/bin/review +2 -4
  11. data/bin/review-catalog-converter +3 -3
  12. data/bin/review-check +6 -8
  13. data/bin/review-checkdep +1 -4
  14. data/bin/review-compile +10 -20
  15. data/bin/review-epub2html +1 -4
  16. data/bin/review-epubmaker +3 -4
  17. data/bin/review-idgxmlmaker +1 -3
  18. data/bin/review-index +11 -5
  19. data/bin/review-init +1 -4
  20. data/bin/review-pdfmaker +1 -3
  21. data/bin/review-preproc +30 -38
  22. data/bin/review-textmaker +1 -3
  23. data/bin/review-update +1 -4
  24. data/bin/review-validate +3 -3
  25. data/bin/review-vol +1 -4
  26. data/bin/review-webmaker +1 -3
  27. data/doc/config.yml.sample +23 -5
  28. data/doc/config.yml.sample-simple +1 -1
  29. data/doc/format.ja.md +49 -12
  30. data/doc/format.md +52 -12
  31. data/doc/quickstart.ja.md +11 -1
  32. data/doc/quickstart.md +11 -2
  33. data/doc/writing_vertical.ja.md +6 -0
  34. data/lib/review/book/base.rb +4 -0
  35. data/lib/review/book/book_unit.rb +15 -2
  36. data/lib/review/book/chapter.rb +3 -0
  37. data/lib/review/book/index.rb +5 -1
  38. data/lib/review/book/volume.rb +1 -0
  39. data/lib/review/builder.rb +90 -54
  40. data/lib/review/call_hook.rb +20 -0
  41. data/lib/review/catalog.rb +2 -0
  42. data/lib/review/compiler.rb +88 -52
  43. data/lib/review/configure.rb +64 -7
  44. data/lib/review/epubmaker/content.rb +113 -0
  45. data/lib/review/epubmaker/epubcommon.rb +372 -0
  46. data/lib/review/epubmaker/epubv2.rb +178 -0
  47. data/lib/review/epubmaker/epubv3.rb +231 -0
  48. data/lib/review/epubmaker/producer.rb +167 -0
  49. data/lib/review/epubmaker/reviewheaderlistener.rb +12 -2
  50. data/lib/review/epubmaker/zip_exporter.rb +84 -0
  51. data/lib/review/epubmaker.rb +114 -129
  52. data/lib/review/exception.rb +13 -0
  53. data/lib/review/htmlbuilder.rb +109 -67
  54. data/lib/review/htmlutils.rb +1 -1
  55. data/lib/review/i18n.rb +1 -0
  56. data/lib/review/i18n.yml +6 -0
  57. data/lib/review/idgxmlbuilder.rb +72 -48
  58. data/lib/review/idgxmlmaker.rb +15 -14
  59. data/lib/review/img_math.rb +239 -0
  60. data/lib/review/index_builder.rb +90 -32
  61. data/lib/review/init.rb +4 -4
  62. data/lib/review/latexbox.rb +58 -0
  63. data/lib/review/latexbuilder.rb +79 -58
  64. data/lib/review/latexutils.rb +9 -1
  65. data/lib/review/lineinput.rb +112 -2
  66. data/lib/review/loggable.rb +27 -0
  67. data/lib/review/logger.rb +89 -2
  68. data/lib/review/makerhelper.rb +7 -206
  69. data/lib/review/markdownbuilder.rb +44 -4
  70. data/lib/review/pdfmaker.rb +70 -51
  71. data/lib/review/plaintextbuilder.rb +20 -11
  72. data/lib/review/preprocessor/directive.rb +35 -0
  73. data/lib/review/preprocessor/line.rb +34 -0
  74. data/lib/review/preprocessor/repository.rb +177 -0
  75. data/lib/review/preprocessor.rb +105 -301
  76. data/lib/review/rstbuilder.rb +13 -4
  77. data/lib/review/sec_counter.rb +1 -0
  78. data/lib/review/template.rb +11 -1
  79. data/lib/review/textmaker.rb +23 -20
  80. data/lib/review/textutils.rb +10 -17
  81. data/lib/review/tocprinter.rb +93 -71
  82. data/lib/review/topbuilder.rb +44 -19
  83. data/lib/review/update.rb +5 -6
  84. data/lib/review/version.rb +1 -1
  85. data/lib/review/volumeprinter.rb +11 -12
  86. data/lib/review/webmaker.rb +31 -27
  87. data/lib/review/webtocprinter.rb +10 -9
  88. data/lib/review/yamlloader.rb +2 -1
  89. data/lib/review.rb +1 -1
  90. data/review.gemspec +5 -3
  91. data/samples/sample-book/src/config-epub2.yml +1 -1
  92. data/samples/sample-book/src/config.yml +1 -1
  93. data/samples/sample-book/src/lib/tasks/review.rake +19 -1
  94. data/samples/sample-book/src/lib/tasks/z01_copy_sty.rake +2 -1
  95. data/samples/syntax-book/ch01.re +1 -1
  96. data/samples/syntax-book/ch02.re +30 -6
  97. data/samples/syntax-book/ch03.re +1 -1
  98. data/samples/syntax-book/images/img3-2.png +0 -0
  99. data/samples/syntax-book/lib/tasks/z01_copy_sty.rake +2 -1
  100. data/templates/html/_colophon.html.erb +23 -0
  101. data/templates/html/_colophon_history.html.erb +9 -0
  102. data/templates/html/_cover.html.erb +10 -0
  103. data/templates/html/_part_body.html.erb +6 -0
  104. data/templates/html/_titlepage.html.erb +20 -0
  105. data/templates/html/layout-html5.html.erb +6 -0
  106. data/templates/html/layout-xhtml1.html.erb +6 -0
  107. data/templates/latex/config.erb +11 -0
  108. data/templates/latex/review-jlreq/review-base.sty +7 -9
  109. data/templates/latex/review-jlreq/review-jlreq.cls +48 -6
  110. data/templates/latex/review-jlreq/review-style.sty +6 -1
  111. data/templates/latex/review-jlreq/review-tcbox.sty +348 -0
  112. data/templates/latex/review-jlreq/reviewmacro.sty +5 -0
  113. data/templates/latex/review-jsbook/review-base.sty +13 -9
  114. data/templates/latex/review-jsbook/review-jsbook.cls +41 -6
  115. data/templates/latex/review-jsbook/review-style.sty +6 -1
  116. data/templates/latex/review-jsbook/review-tcbox.sty +348 -0
  117. data/templates/latex/review-jsbook/reviewmacro.sty +5 -0
  118. data/templates/opf/epubv2.opf.erb +7 -7
  119. data/templates/opf/epubv3.opf.erb +7 -7
  120. data/templates/opf/opf_manifest_epubv2.opf.erb +10 -0
  121. data/templates/opf/opf_manifest_epubv3.opf.erb +10 -0
  122. data/templates/opf/opf_metainfo_epubv2.opf.erb +17 -0
  123. data/templates/opf/opf_metainfo_epubv3.opf.erb +49 -0
  124. data/templates/opf/opf_tocx_epubv2.opf.erb +9 -0
  125. data/templates/opf/opf_tocx_epubv3.opf.erb +17 -0
  126. data/templates/web/html/layout-html5.html.erb +6 -5
  127. data/templates/web/html/layout-xhtml1.html.erb +6 -0
  128. data/test/assets/header_listener.html +35 -0
  129. data/test/assets/img_math/img1.png +0 -0
  130. data/test/assets/img_math/img2.png +0 -0
  131. data/test/assets/img_math/img3.png +0 -0
  132. data/test/assets/syntax_book_index_detail.txt +60 -0
  133. data/test/assets/test_template.tex +7 -1
  134. data/test/assets/test_template_backmatter.tex +7 -1
  135. data/test/run_test.rb +1 -1
  136. data/test/test_book_chapter.rb +27 -4
  137. data/test/test_builder.rb +10 -8
  138. data/test/test_catalog_converter_cmd.rb +1 -1
  139. data/test/test_epub3maker.rb +168 -124
  140. data/test/test_epubmaker.rb +248 -131
  141. data/test/test_epubmaker_cmd.rb +15 -4
  142. data/test/test_helper.rb +5 -4
  143. data/test/test_htmlbuilder.rb +170 -31
  144. data/test/test_idgxmlbuilder.rb +44 -23
  145. data/test/test_idgxmlmaker_cmd.rb +7 -3
  146. data/test/test_img_math.rb +111 -0
  147. data/test/test_index.rb +30 -4
  148. data/test/test_indexbuilder.rb +5 -5
  149. data/test/test_latexbuilder.rb +151 -26
  150. data/test/test_latexbuilder_v2.rb +18 -10
  151. data/test/test_lineinput.rb +20 -93
  152. data/test/test_markdownbuilder.rb +42 -0
  153. data/test/test_pdfmaker.rb +90 -0
  154. data/test/test_pdfmaker_cmd.rb +2 -2
  155. data/test/test_plaintextbuilder.rb +56 -40
  156. data/test/test_preprocessor.rb +188 -1
  157. data/test/test_reviewheaderlistener.rb +49 -0
  158. data/test/test_rstbuilder.rb +13 -0
  159. data/test/test_template.rb +12 -2
  160. data/test/test_textmaker_cmd.rb +5 -1
  161. data/test/test_tocprinter.rb +46 -0
  162. data/test/test_topbuilder.rb +50 -19
  163. data/test/test_update.rb +34 -34
  164. data/test/test_zip_exporter.rb +5 -6
  165. metadata +95 -17
  166. data/lib/epubmaker/content.rb +0 -111
  167. data/lib/epubmaker/epubcommon.rb +0 -449
  168. data/lib/epubmaker/epubv2.rb +0 -142
  169. data/lib/epubmaker/epubv3.rb +0 -235
  170. data/lib/epubmaker/producer.rb +0 -375
  171. data/lib/epubmaker/zip_exporter.rb +0 -81
  172. data/lib/epubmaker.rb +0 -23
  173. data/lib/lineinput.rb +0 -155
@@ -0,0 +1,111 @@
1
+ require 'test_helper'
2
+ require 'review/htmlbuilder'
3
+ require 'review/img_math'
4
+ require 'mini_magick'
5
+
6
+ class ImgMathTest < Test::Unit::TestCase
7
+ def setup
8
+ @config = ReVIEW::Configure.values
9
+ @tmpdir = Dir.mktmpdir
10
+ @config.merge!(
11
+ 'math_format' => 'imgmath',
12
+ 'texcommand' => 'uplatex',
13
+ 'imagedir' => @tmpdir
14
+ )
15
+ @config['imgmath_options']['fontsize'] = 24
16
+ @img_math = ReVIEW::ImgMath.new(@config)
17
+ end
18
+
19
+ def teardown
20
+ @img_math.cleanup_mathimg
21
+ FileUtils.rm_rf(@tmpdir)
22
+ end
23
+
24
+ def test_defer_math_image_pathname
25
+ str1 = '$A > B \\gg C$'
26
+ key1 = Digest::SHA256.hexdigest(str1)
27
+ img_path1 = @img_math.defer_math_image(str1, key1)
28
+
29
+ assert_equal "_gen_#{key1}.png", File.basename(img_path1)
30
+ end
31
+
32
+ def test_defer_math_image
33
+ unless support_latex_in_tests?
34
+ $stderr.puts 'skip test_defer_math_image'
35
+ return true
36
+ end
37
+
38
+ str1 = '$\\sum_{i=1}^nf_n(x) \\in \\mathbb{R}$'
39
+ key1 = Digest::SHA256.hexdigest(str1)
40
+ img_path1 = @img_math.defer_math_image(str1, key1)
41
+ str2 = '$\\sum_{i=1}^nf_n(X) \\in \\mathbb{R}$'
42
+ key2 = Digest::SHA256.hexdigest(str2)
43
+ img_path2 = @img_math.defer_math_image(str2, key2)
44
+ @img_math.make_math_images
45
+
46
+ assert File.exist?(img_path1)
47
+ assert File.exist?(img_path2)
48
+
49
+ val1 = compare_images(img_path1, File.join(assets_dir, 'img_math/img1.png'))
50
+ assert_equal 0, val1
51
+
52
+ val2 = compare_images(img_path2, File.join(assets_dir, 'img_math/img2.png'))
53
+ assert_equal 0, val2
54
+
55
+ val3 = compare_images(img_path1, img_path2)
56
+ assert val3 > 100
57
+ end
58
+
59
+ def test_make_math_image_pathname
60
+ unless support_latex_in_tests?
61
+ $stderr.puts 'skip test_make_math_image_pathname'
62
+ return true
63
+ end
64
+
65
+ str1 = '$A > B \\gg C$'
66
+ key1 = Digest::SHA256.hexdigest(str1)
67
+ img_path1 = @img_math.make_math_image(str1, key1)
68
+
69
+ assert_equal "_gen_#{key1}.png", File.basename(img_path1)
70
+ end
71
+
72
+ def test_make_math_image
73
+ unless support_latex_in_tests?
74
+ $stderr.puts 'skip test_make_math_image'
75
+ return true
76
+ end
77
+ str1 = '$A > B \\gg C$'
78
+ key1 = Digest::SHA256.hexdigest(str1)
79
+ img_path1 = @img_math.make_math_image(str1, key1)
80
+
81
+ assert File.exist?(img_path1)
82
+
83
+ val1 = compare_images(img_path1, File.join(assets_dir, 'img_math/img3.png'))
84
+ assert val1 < 10
85
+ end
86
+
87
+ private
88
+
89
+ def compare_images(image1, image2)
90
+ compare = MiniMagick::Tool::Compare.new(whiny: false)
91
+ compare << '-fuzz'
92
+ compare << '10%'
93
+ compare.metric('AE')
94
+ compare << image1
95
+ compare << image2
96
+ compare << File.join(@tmpdir, 'diff.jpg')
97
+
98
+ compare.call do |_, dist, _|
99
+ return dist.to_i
100
+ end
101
+ end
102
+
103
+ def support_latex_in_tests?
104
+ begin
105
+ `uplatex -v`
106
+ true
107
+ rescue
108
+ false
109
+ end
110
+ end
111
+ end
data/test/test_index.rb CHANGED
@@ -12,6 +12,8 @@ class IndexTest < Test::Unit::TestCase
12
12
  @builder = TOPBuilder.new
13
13
  @config = ReVIEW::Configure.create(config: { 'secnolevel' => 2, 'language' => 'ja' })
14
14
  @book = Book::Base.new(config: @config)
15
+ @log_io = StringIO.new
16
+ ReVIEW.logger = ReVIEW::Logger.new(@log_io)
15
17
  @compiler = ReVIEW::Compiler.new(@builder)
16
18
  @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
17
19
  location = Location.new(nil, nil)
@@ -21,16 +23,19 @@ class IndexTest < Test::Unit::TestCase
21
23
  end
22
24
 
23
25
  def test_footnote_index
24
- compile_block("//footnote[foo][bar]\n")
26
+ compile_block("@<fn>{foo}\n//footnote[foo][bar]\n")
25
27
  fn = @chapter.footnote_index
26
28
  items = fn.to_a
27
29
  item = items[0]
28
30
  assert_equal 'foo', item.id
29
31
  assert_equal 'bar', item.content
32
+
33
+ compile_block("//footnote[foo][bar]\n")
34
+ assert_match(/ID foo is not referred/, @log_io.string)
30
35
  end
31
36
 
32
37
  def test_footnote_index_with_escape
33
- compile_block('//footnote[foo][bar[\]buz]' + "\n")
38
+ compile_block("@<fn>{foo}\n" + '//footnote[foo][bar[\]buz]' + "\n")
34
39
  fn = @chapter.footnote_index
35
40
  items = fn.to_a
36
41
  item = items[0]
@@ -39,7 +44,7 @@ class IndexTest < Test::Unit::TestCase
39
44
  end
40
45
 
41
46
  def test_footnote_index_with_escape2
42
- compile_block('//footnote[foo][bar\\a\\$buz]' + "\n")
47
+ compile_block("@<fn>{foo}\n" + '//footnote[foo][bar\\a\\$buz]' + "\n")
43
48
  fn = @chapter.footnote_index
44
49
  items = fn.to_a
45
50
  item = items[0]
@@ -48,7 +53,7 @@ class IndexTest < Test::Unit::TestCase
48
53
  end
49
54
 
50
55
  def test_footnote_index_key?
51
- compile_block('//footnote[foo][bar]' + "\n")
56
+ compile_block("@<fn>{foo}\n" + '//footnote[foo][bar]' + "\n")
52
57
  fn = @chapter.footnote_index
53
58
  assert_equal true, fn.key?('foo')
54
59
 
@@ -58,6 +63,27 @@ class IndexTest < Test::Unit::TestCase
58
63
  # rubocop:enable Style/PreferredHashMethods
59
64
  end
60
65
 
66
+ def test_endnote_index
67
+ compile_block("@<endnote>{foo}\n//endnote[foo][bar]\n//printendnotes\n")
68
+ endnote = @chapter.endnote_index
69
+ items = endnote.to_a
70
+ item = items[0]
71
+ assert_equal 'foo', item.id
72
+ assert_equal 'bar', item.content
73
+ assert_equal true, endnote.key?('foo')
74
+ # rubocop:disable Style/PreferredHashMethods
75
+ assert_equal true, endnote.has_key?('foo')
76
+ # rubocop:enable Style/PreferredHashMethods
77
+
78
+ e = assert_raises(ReVIEW::ApplicationError) do
79
+ compile_block("@<endnote>{foo}\n//endnote[foo][bar]\n")
80
+ end
81
+ assert_equal ':3: //endnote is found but //printendnotes is not found.', e.message
82
+
83
+ compile_block("//endnote[foo][bar]\n//printendnotes\n")
84
+ assert_match(/ID foo is not referred/, @log_io.string)
85
+ end
86
+
61
87
  def test_headline_index
62
88
  src = <<-EOB
63
89
  = chap1
@@ -24,28 +24,28 @@ class IndexBuidlerTest < Test::Unit::TestCase
24
24
 
25
25
  def test_check_id
26
26
  io = StringIO.new
27
- @b.instance_eval{ @logger = ReVIEW::Logger.new(io) }
27
+ @b.instance_eval { @logger = ReVIEW::Logger.new(io) }
28
28
  @b.check_id('ABC')
29
29
  assert_match('', io.string)
30
30
 
31
31
  %w(# % \\ { } [ ] ~ / $ ' " | * ? & < > `).each do |c|
32
32
  io = StringIO.new
33
- @b.instance_eval{ @logger = ReVIEW::Logger.new(io) }
33
+ @b.instance_eval { @logger = ReVIEW::Logger.new(io) }
34
34
  @b.check_id("id#{c}")
35
35
  assert_match(/deprecated ID: `#{Regexp.escape(c)}` in `id#{Regexp.escape(c)}`/, io.string)
36
36
  end
37
37
  io = StringIO.new
38
- @b.instance_eval{ @logger = ReVIEW::Logger.new(io) }
38
+ @b.instance_eval { @logger = ReVIEW::Logger.new(io) }
39
39
  @b.check_id('A B C#')
40
40
  assert_match(/deprecated ID: ` ` in `A B C#`/, io.string)
41
41
 
42
42
  io = StringIO.new
43
- @b.instance_eval{ @logger = ReVIEW::Logger.new(io) }
43
+ @b.instance_eval { @logger = ReVIEW::Logger.new(io) }
44
44
  @b.check_id("A\tB")
45
45
  assert_match(/deprecated ID: `\t` in `A\tB`/, io.string)
46
46
 
47
47
  io = StringIO.new
48
- @b.instance_eval{ @logger = ReVIEW::Logger.new(io) }
48
+ @b.instance_eval { @logger = ReVIEW::Logger.new(io) }
49
49
  @b.check_id('.ABC')
50
50
  assert_match(/deprecated ID: `.ABC` begins from `.`/, io.string)
51
51
  end
@@ -20,6 +20,8 @@ class LATEXBuidlerTest < Test::Unit::TestCase
20
20
  @config['pdfmaker']['image_scale2width'] = nil
21
21
  @book = Book::Base.new
22
22
  @book.config = @config
23
+ @log_io = StringIO.new
24
+ ReVIEW.logger = ReVIEW::Logger.new(@log_io)
23
25
  @compiler = ReVIEW::Compiler.new(@builder)
24
26
  @chapter = Book::Chapter.new(@book, 1, 'chap1', nil, StringIO.new)
25
27
  location = Location.new(nil, nil)
@@ -197,6 +199,16 @@ EOS
197
199
  assert_equal 'abc\\reviewunderline{def}ghi', actual
198
200
  end
199
201
 
202
+ def test_inline_ins
203
+ actual = compile_inline('abc@<ins>{def}ghi')
204
+ assert_equal 'abc\\reviewinsert{def}ghi', actual
205
+ end
206
+
207
+ def test_inline_del
208
+ actual = compile_inline('abc@<del>{def}ghi')
209
+ assert_equal 'abc\\reviewstrike{def}ghi', actual
210
+ end
211
+
200
212
  def test_inline_bou
201
213
  actual = compile_inline('傍点の@<bou>{テスト}です。')
202
214
  assert_equal '傍点の\\reviewbou{テスト}です。', actual
@@ -245,6 +257,20 @@ EOS
245
257
  assert_equal 'test \\reviewttb{inline test} test2', actual
246
258
  end
247
259
 
260
+ def test_endnote
261
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block("//endnote[foo][bar]\n\n@<endnote>{foo}\n") }
262
+ assert_equal ':4: //endnote is found but //printendnotes is not found.', e.message
263
+
264
+ actual = compile_block("@<endnote>{foo}\n//endnote[foo][bar]\n//printendnotes\n")
265
+ expected = <<-'EOS'
266
+
267
+ \endnote{bar}
268
+
269
+ \theendnotes
270
+ EOS
271
+ assert_equal expected, actual
272
+ end
273
+
248
274
  def test_inline_hd_chap
249
275
  def @chapter.headline_index
250
276
  item = Book::Index::Item.new('chap1|test', [1, 1], 'te_st')
@@ -296,13 +322,65 @@ EOS
296
322
  return true
297
323
  end
298
324
  tmpdir = Dir.mktmpdir
299
- File.write(File.join(tmpdir, 'sample.dic'), "強運\tはーどらっく\n")
325
+ File.write(File.join(tmpdir, 'sample.dic'), "強運\tはーどらっく\nmain(ブロック)\tmain{|}\n")
300
326
  @book.config['pdfmaker']['makeindex'] = true
301
327
  @book.config['pdfmaker']['makeindex_dic'] = "#{tmpdir}/sample.dic"
302
328
  @builder.setup_index
303
329
  actual = compile_inline('@<hidx>{漢字}@<hidx>{強運}@<hidx>{項目@1<<>>項目@2}')
304
- FileUtils.remove_entry_secure(tmpdir)
305
330
  assert_equal %Q(\\index{かんじ@漢字}\\index{はーどらっく@強運}\\index{こうもく"@1@項目"@1!こうもく"@2@項目"@2}), actual
331
+ actual = compile_inline('@<hidx>{main(ブロック)}@<hidx>{あいうえお{\}}')
332
+ FileUtils.remove_entry_secure(tmpdir)
333
+ assert_equal %Q(\\index{main{|}@main(ブロック)}\\index{あいうえお{}@あいうえお\\reviewleftcurlybrace{}\\reviewrightcurlybrace{}}), actual
334
+ end
335
+
336
+ def test_inline_idx_escape
337
+ # as is
338
+ %w[a あ ' ( ) = ` + ; * : , . ? /].each do |c|
339
+ actual = @builder.index(c)
340
+ assert_equal %Q(\\index{#{c}}), actual
341
+ end
342
+ actual = @builder.index('[')
343
+ assert_equal %Q(\\index{[}), actual
344
+ actual = @builder.index(']')
345
+ assert_equal %Q(\\index{]}), actual
346
+
347
+ # escape display string by "
348
+ %w[! " @].each do |c|
349
+ actual = @builder.index(c)
350
+ assert_equal %Q(\\index{"#{c}@"#{c}}), actual
351
+ end
352
+
353
+ # escape display string by \
354
+ %w[# % &].each do |c|
355
+ actual = @builder.index(c)
356
+ assert_equal %Q(\\index{#{c}@\\#{c}}), actual
357
+ end
358
+
359
+ # escape display string by macro
360
+ actual = @builder.index('$')
361
+ assert_equal %Q(\\index{$@\\textdollar{}}), actual
362
+ actual = @builder.index('-')
363
+ assert_equal %Q(\\index{-@{-}}), actual
364
+ actual = @builder.index('~')
365
+ assert_equal %Q(\\index{~@\\textasciitilde{}}), actual
366
+ actual = @builder.index('^')
367
+ assert_equal %Q(\\index{^@\\textasciicircum{}}), actual
368
+ actual = @builder.index('\\')
369
+ assert_equal %Q(\\index{\\@\\reviewbackslash{}}), actual
370
+ actual = @builder.index('<')
371
+ assert_equal %Q(\\index{<@\\textless{}}), actual
372
+ actual = @builder.index('>')
373
+ assert_equal %Q(\\index{>@\\textgreater{}}), actual
374
+ actual = @builder.index('_')
375
+ assert_equal %Q(\\index{_@\\textunderscore{}}), actual
376
+
377
+ # escape both sort key and display string
378
+ actual = @builder.index('{')
379
+ assert_equal %Q(\\index{{@\\reviewleftcurlybrace{}}), actual
380
+ actual = @builder.index('|')
381
+ assert_equal %Q(\\index{|@\\textbar{}}), actual
382
+ actual = @builder.index('}')
383
+ assert_equal %Q(\\index{}@\\reviewrightcurlybrace{}}), actual
306
384
  end
307
385
 
308
386
  def test_jis_x_0201_kana
@@ -1039,6 +1117,19 @@ EOS
1039
1117
  \\end{reviewimage}
1040
1118
  EOS
1041
1119
  assert_equal expected, actual
1120
+
1121
+ actual = compile_block("//image[sampleimg][]{\n//}\n")
1122
+ expected = <<-EOS
1123
+ \\begin{reviewimage}%%sampleimg
1124
+ \\reviewimagecaption{}
1125
+ \\label{image:chap1:sampleimg}
1126
+ \\reviewincludegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}
1127
+ \\end{reviewimage}
1128
+ EOS
1129
+ assert_equal expected, actual
1130
+
1131
+ actual = compile_block("//image[sampleimg][][]{\n//}\n")
1132
+ assert_equal expected, actual
1042
1133
  end
1043
1134
 
1044
1135
  def test_image_with_metric
@@ -1187,6 +1278,12 @@ EOS
1187
1278
  \\end{reviewimage}
1188
1279
  EOS
1189
1280
  assert_equal expected, actual
1281
+
1282
+ actual = compile_block("//indepimage[sampleimg][]\n")
1283
+ assert_equal expected, actual
1284
+
1285
+ actual = compile_block("//indepimage[sampleimg][][]\n")
1286
+ assert_equal expected, actual
1190
1287
  end
1191
1288
 
1192
1289
  def test_indepimage_with_metric
@@ -1286,12 +1383,12 @@ EOS
1286
1383
  end
1287
1384
 
1288
1385
  io = StringIO.new
1289
- @builder.instance_eval{ @logger = ReVIEW::Logger.new(io) }
1386
+ @builder.instance_eval { @logger = ReVIEW::Logger.new(io) }
1290
1387
 
1291
1388
  actual = compile_block("//indepimage[sample_img_nofile_][sample photo]\n")
1292
1389
  expected = <<-EOS
1293
1390
  \\begin{reviewdummyimage}
1294
- --[[path = sample\\textunderscore{}img\\textunderscore{}nofile\\textunderscore{} (not exist)]]--
1391
+ {-}{-}[[path = sample\\reviewbackslash{}textunderscore\\{\\}img\\reviewbackslash{}textunderscore\\{\\}nofile\\reviewbackslash{}textunderscore\\{\\} (not exist)]]{-}{-}
1295
1392
  \\reviewindepimagecaption{図: sample photo}
1296
1393
  \\end{reviewdummyimage}
1297
1394
  EOS
@@ -1324,6 +1421,16 @@ ccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline
1324
1421
  EOS
1325
1422
  assert_equal expected, actual
1326
1423
 
1424
+ actual = compile_block("//table[foo][]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
1425
+ expected = <<-EOS
1426
+ \\begin{reviewtable}{|l|l|}
1427
+ \\hline
1428
+ \\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline
1429
+ ccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline
1430
+ \\end{reviewtable}
1431
+ EOS
1432
+ assert_equal expected, actual
1433
+
1327
1434
  @config['caption_position']['table'] = 'bottom'
1328
1435
  actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
1329
1436
  expected = <<-EOS
@@ -1342,10 +1449,10 @@ EOS
1342
1449
 
1343
1450
  def test_empty_table
1344
1451
  e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n//}\n") }
1345
- assert_equal ':2: error: no rows in the table', e.message
1452
+ assert_equal 'no rows in the table', e.message
1346
1453
 
1347
1454
  e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n------------\n//}\n") }
1348
- assert_equal ':3: error: no rows in the table', e.message
1455
+ assert_equal 'no rows in the table', e.message
1349
1456
  end
1350
1457
 
1351
1458
  def test_customize_cellwidth
@@ -1491,6 +1598,18 @@ EOS
1491
1598
  EOS
1492
1599
  assert_equal expected, actual
1493
1600
 
1601
+ actual = compile_block("//imgtable[sampleimg][]{\n//}\n")
1602
+ expected = <<-EOS
1603
+ \\label{table:chap1:sampleimg}
1604
+ \\begin{reviewimage}%%sampleimg
1605
+ \\reviewincludegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}
1606
+ \\end{reviewimage}
1607
+ EOS
1608
+ assert_equal expected, actual
1609
+
1610
+ actual = compile_block("//imgtable[sampleimg][][]{\n//}\n")
1611
+ assert_equal expected, actual
1612
+
1494
1613
  @book.config['pdfmaker']['use_original_image_size'] = true
1495
1614
  actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n")
1496
1615
 
@@ -2149,8 +2268,8 @@ EOS
2149
2268
 
2150
2269
  //}
2151
2270
  EOS
2152
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2153
- assert_match(/minicolumn cannot be nested:/, e.message)
2271
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2272
+ assert_match(/minicolumn cannot be nested:/, @log_io.string)
2154
2273
  end
2155
2274
  end
2156
2275
 
@@ -2166,8 +2285,8 @@ EOS
2166
2285
 
2167
2286
  //}
2168
2287
  EOS
2169
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2170
- assert_match(/minicolumn cannot be nested:/, e.message)
2288
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2289
+ assert_match(/minicolumn cannot be nested:/, @log_io.string)
2171
2290
  end
2172
2291
  end
2173
2292
 
@@ -2182,8 +2301,8 @@ EOS
2182
2301
 
2183
2302
  //}
2184
2303
  EOS
2185
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2186
- assert_match(/minicolumn cannot be nested:/, e.message)
2304
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2305
+ assert_match(/minicolumn cannot be nested:/, @log_io.string)
2187
2306
  end
2188
2307
  end
2189
2308
 
@@ -2312,7 +2431,7 @@ EOB
2312
2431
  @book.config['words_file'] = File.join(dir, 'words.csv')
2313
2432
 
2314
2433
  io = StringIO.new
2315
- @builder.instance_eval{ @logger = ReVIEW::Logger.new(io) }
2434
+ @builder.instance_eval { @logger = ReVIEW::Logger.new(io) }
2316
2435
  actual = compile_block('@<w>{F} @<w>{B} @<wb>{B} @<w>{N}')
2317
2436
  expected = <<-EOS
2318
2437
 
@@ -2324,19 +2443,25 @@ EOS
2324
2443
  end
2325
2444
 
2326
2445
  def test_inline_unknown
2327
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
2328
- assert_equal ':1: error: unknown image: n', e.message
2329
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
2330
- assert_equal ':1: error: unknown footnote: n', e.message
2331
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
2332
- assert_equal ':1: error: unknown headline: n', e.message
2446
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
2447
+ assert_match(/unknown image: n/, @log_io.string)
2448
+
2449
+ @log_io.string = ''
2450
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
2451
+ assert_match(/unknown footnote: n/, @log_io.string)
2452
+
2453
+ @log_io.string = ''
2454
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
2455
+ assert_match(/unknown headline: n/, @log_io.string)
2333
2456
  %w[list table column].each do |name|
2334
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
2335
- assert_equal ":1: error: unknown #{name}: n", e.message
2457
+ @log_io.string = ''
2458
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
2459
+ assert_match(/unknown #{name}: n/, @log_io.string)
2336
2460
  end
2337
2461
  %w[chap chapref title].each do |name|
2338
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
2339
- assert_equal ':1: error: key not found: "n"', e.message
2462
+ @log_io.string = ''
2463
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
2464
+ assert_match(/key not found: "n"/, @log_io.string)
2340
2465
  end
2341
2466
  end
2342
2467
 
@@ -2485,7 +2610,7 @@ EOS
2485
2610
  //beginchild
2486
2611
  EOS
2487
2612
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2488
- assert_equal ":1: error: //beginchild is shown, but previous element isn't ul, ol, or dl", e.message
2613
+ assert_equal ":1: //beginchild is shown, but previous element isn't ul, ol, or dl", e.message
2489
2614
  end
2490
2615
 
2491
2616
  def test_nest_error_close2
@@ -2503,7 +2628,7 @@ EOS
2503
2628
  //beginchild
2504
2629
  EOS
2505
2630
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2506
- assert_equal ':12: error: //beginchild of dl,ol,ul misses //endchild', e.message
2631
+ assert_equal ':12: //beginchild of dl,ol,ul misses //endchild', e.message
2507
2632
  end
2508
2633
 
2509
2634
  def test_nest_error_close3
@@ -2523,7 +2648,7 @@ EOS
2523
2648
  //endchild
2524
2649
  EOS
2525
2650
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2526
- assert_equal ':14: error: //beginchild of ol,ul misses //endchild', e.message
2651
+ assert_equal ':14: //beginchild of ol,ul misses //endchild', e.message
2527
2652
  end
2528
2653
 
2529
2654
  def test_nest_ul
@@ -20,6 +20,8 @@ class LATEXBuidlerV2Test < Test::Unit::TestCase
20
20
  @config['pdfmaker']['image_scale2width'] = nil
21
21
  @book = Book::Base.new
22
22
  @book.config = @config
23
+ @log_io = StringIO.new
24
+ ReVIEW.logger = ReVIEW::Logger.new(@log_io)
23
25
  @compiler = ReVIEW::Compiler.new(@builder)
24
26
  @chapter = Book::Chapter.new(@book, 1, 'chap1', nil, StringIO.new)
25
27
  location = Location.new(nil, nil)
@@ -1544,19 +1546,25 @@ EOS
1544
1546
  end
1545
1547
 
1546
1548
  def test_inline_unknown
1547
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
1548
- assert_equal ':1: error: unknown image: n', e.message
1549
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
1550
- assert_equal ':1: error: unknown footnote: n', e.message
1551
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
1552
- assert_equal ':1: error: unknown headline: n', e.message
1549
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
1550
+ assert_match(/unknown image: n/, @log_io.string)
1551
+
1552
+ @log_io.string = ''
1553
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
1554
+ assert_match(/unknown footnote: n/, @log_io.string)
1555
+
1556
+ @log_io.string = ''
1557
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
1558
+ assert_match(/unknown headline: n/, @log_io.string)
1553
1559
  %w[list table column].each do |name|
1554
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1555
- assert_equal ":1: error: unknown #{name}: n", e.message
1560
+ @log_io.string = ''
1561
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1562
+ assert_match(/unknown #{name}: n/, @log_io.string)
1556
1563
  end
1557
1564
  %w[chap chapref title].each do |name|
1558
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1559
- assert_equal ':1: error: key not found: "n"', e.message
1565
+ @log_io.string = ''
1566
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1567
+ assert_match(/key not found: "n"/, @log_io.string)
1560
1568
  end
1561
1569
  end
1562
1570