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
@@ -1,2964 +0,0 @@
1
- require 'test_helper'
2
- require 'review/compiler'
3
- require 'review/book'
4
- require 'review/latexbuilder'
5
- require 'review/i18n'
6
-
7
- class LATEXBuidlerTest < Test::Unit::TestCase
8
- include ReVIEW
9
-
10
- def setup
11
- @builder = LATEXBuilder.new
12
- @config = ReVIEW::Configure.values
13
- @config.merge!(
14
- 'secnolevel' => 2, # for IDGXMLBuilder, EPUBBuilder
15
- 'toclevel' => 2,
16
- 'stylesheet' => nil, # for EPUBBuilder
17
- 'texcommand' => 'uplatex',
18
- 'review_version' => '4'
19
- )
20
- @config['pdfmaker']['image_scale2width'] = nil
21
- @book = Book::Base.new
22
- @book.config = @config
23
- @log_io = StringIO.new
24
- ReVIEW.logger = ReVIEW::Logger.new(@log_io)
25
- @compiler = ReVIEW::Compiler.new(@builder)
26
- @chapter = Book::Chapter.new(@book, 1, 'chap1', nil, StringIO.new)
27
- location = Location.new(nil, nil)
28
- @builder.bind(@compiler, @chapter, location)
29
- I18n.setup('ja')
30
- end
31
-
32
- def test_escape
33
- actual = @builder.escape('<>&_')
34
- assert_equal %Q(\\textless{}\\textgreater{}\\&\\textunderscore{}), actual
35
- end
36
-
37
- def test_unescape
38
- actual = @builder.unescape(%Q(\\textless{}\\textgreater{}\\&\\textunderscore{}))
39
- assert_equal '<>&_', actual
40
- end
41
-
42
- def test_headline_level1
43
- actual = compile_block("={test} this is test.\n")
44
- expected = <<-EOS
45
- \\chapter{this is test.}
46
- \\label{chap:chap1}
47
- EOS
48
- assert_equal expected, actual
49
- end
50
-
51
- def test_headline_level1_without_secno
52
- @config['secnolevel'] = 0
53
- actual = compile_block("={test} this is test.\n")
54
- expected = <<-EOS
55
- \\chapter*{this is test.}
56
- \\addcontentsline{toc}{chapter}{this is test.}
57
- \\label{chap:chap1}
58
- EOS
59
- assert_equal expected, actual
60
- end
61
-
62
- def test_headline_level1_with_inlinetag
63
- actual = compile_block(%Q(={test} this @<b>{is} test.<&"_>\n))
64
- expected = <<-EOS
65
- \\chapter{this \\reviewbold{is} test.\\textless{}\\&"\\textunderscore{}\\textgreater{}}
66
- \\label{chap:chap1}
67
- EOS
68
- assert_equal expected, actual
69
- end
70
-
71
- def test_headline_level2
72
- actual = compile_block("=={test} this is test.\n")
73
- expected = <<-EOS
74
- \\section{this is test.}
75
- \\label{sec:1-1}
76
- \\label{test}
77
- EOS
78
- assert_equal expected, actual
79
- end
80
-
81
- def test_headline_level3
82
- actual = compile_block("==={test} this is test.\n")
83
- expected = <<-EOS
84
- \\subsection*{this is test.}
85
- \\label{sec:1-0-1}
86
- \\label{test}
87
- EOS
88
- assert_equal expected, actual
89
- end
90
-
91
- def test_headline_level3_with_secno
92
- @config['secnolevel'] = 3
93
- actual = compile_block("==={test} this is test.\n")
94
- expected = <<-EOS
95
- \\subsection{this is test.}
96
- \\label{sec:1-0-1}
97
- \\label{test}
98
- EOS
99
- assert_equal expected, actual
100
- end
101
-
102
- def test_label
103
- actual = compile_block("//label[label_test]\n")
104
- assert_equal %Q(\\label{label_test}\n), actual
105
- end
106
-
107
- def test_href
108
- actual = compile_inline('@<href>{http://github.com,GitHub}')
109
- assert_equal '\\href{http://github.com}{GitHub}', actual
110
- end
111
-
112
- def test_inline_href
113
- actual = compile_inline('@<href>{http://github.com,Git\\,Hub}')
114
- assert_equal '\\href{http://github.com}{Git,Hub}', actual
115
- end
116
-
117
- def test_href_without_label
118
- actual = compile_inline('@<href>{http://github.com}')
119
- assert_equal '\\url{http://github.com}', actual
120
- end
121
-
122
- def test_href_with_underscore
123
- actual = compile_inline('@<href>{http://example.com/aaa/bbb, AAA_BBB}')
124
- assert_equal '\\href{http://example.com/aaa/bbb}{AAA\\textunderscore{}BBB}', actual
125
- end
126
-
127
- def test_href_mailto
128
- actual = compile_inline('@<href>{mailto:takahashim@example.com, takahashim@example.com}')
129
- assert_equal '\\href{mailto:takahashim@example.com}{takahashim@example.com}', actual
130
- end
131
-
132
- def test_inline_br
133
- actual = compile_inline('@<br>{}')
134
- assert_equal %Q(\\\\\n), actual
135
- end
136
-
137
- def test_inline_br_with_other_strings
138
- actual = compile_inline('abc@<br>{}def')
139
- assert_equal %Q(abc\\\\\ndef), actual
140
- end
141
-
142
- def test_inline_i
143
- actual = compile_inline('abc@<i>{def}ghi')
144
- assert_equal 'abc\\reviewit{def}ghi', actual
145
- end
146
-
147
- def test_inline_i_and_escape
148
- actual = compile_inline('test @<i>{inline<&;\\ test} test2')
149
- assert_equal 'test \\reviewit{inline\\textless{}\\&;\\reviewbackslash{} test} test2', actual
150
- end
151
-
152
- def test_inline_dtp
153
- actual = compile_inline('abc@<dtp>{def}ghi')
154
- assert_equal 'abcghi', actual
155
- end
156
-
157
- def test_inline_code
158
- actual = compile_inline('abc@<code>{def}ghi')
159
- assert_equal 'abc\\reviewcode{def}ghi', actual
160
- end
161
-
162
- def test_inline_raw
163
- actual = compile_inline('@<raw>{@<tt>{inline!$%\\}}')
164
- assert_equal '@<tt>{inline!$%}', actual
165
- end
166
-
167
- def test_inline_sup
168
- actual = compile_inline('abc@<sup>{def}')
169
- assert_equal 'abc\\textsuperscript{def}', actual
170
- end
171
-
172
- def test_inline_sub
173
- actual = compile_inline('abc@<sub>{def}')
174
- assert_equal 'abc\\textsubscript{def}', actual
175
- end
176
-
177
- def test_inline_b
178
- actual = compile_inline('abc@<b>{def}')
179
- assert_equal 'abc\\reviewbold{def}', actual
180
- end
181
-
182
- def test_inline_b_and_escape
183
- actual = compile_inline('test @<b>{inline<&;\\ test} test2')
184
- assert_equal 'test \\reviewbold{inline\\textless{}\\&;\\reviewbackslash{} test} test2', actual
185
- end
186
-
187
- def test_inline_em
188
- actual = compile_inline('abc@<em>{def}')
189
- assert_equal 'abc\\reviewem{def}', actual
190
- end
191
-
192
- def test_inline_strong
193
- actual = compile_inline('abc@<strong>{def}')
194
- assert_equal 'abc\\reviewstrong{def}', actual
195
- end
196
-
197
- def test_inline_u
198
- actual = compile_inline('abc@<u>{def}ghi')
199
- assert_equal 'abc\\reviewunderline{def}ghi', actual
200
- end
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
-
212
- def test_inline_bou
213
- actual = compile_inline('傍点の@<bou>{テスト}です。')
214
- assert_equal '傍点の\\reviewbou{テスト}です。', actual
215
- end
216
-
217
- def test_inline_m
218
- @config['review_version'] = '3.0'
219
- actual = compile_inline('abc@<m>{\\alpha^n = \\inf < 2}ghi')
220
- assert_equal 'abc$\\alpha^n = \\inf < 2$ghi', actual
221
-
222
- @config['review_version'] = '2.0'
223
- actual = compile_inline('abc@<m>{\\alpha^n = \\inf < 2}ghi')
224
- assert_equal 'abc $\\alpha^n = \\inf < 2$ ghi', actual
225
- end
226
-
227
- def test_inline_m2
228
- @config['review_version'] = '3.0'
229
- ## target text: @<m>{X = \{ {x_1\},{x_2\}, \cdots ,{x_n\} \\\}}
230
- actual = compile_inline('@<m>{X = \\{ {x_1\\},{x_2\\}, \\cdots ,{x_n\\} \\\\\\}}')
231
- ## expected text: $X = \{ {x_1},{x_2}, \cdots ,{x_n} \}$
232
- assert_equal '$X = \\{ {x_1},{x_2}, \\cdots ,{x_n} \\}$', actual
233
-
234
- @config['review_version'] = '2.0'
235
- actual = compile_inline('@<m>{X = \\{ {x_1\\},{x_2\\}, \\cdots ,{x_n\\} \\\\\\}}')
236
- ## expected text: $X = \{ {x_1},{x_2}, \cdots ,{x_n} \}$
237
- assert_equal ' $X = \\{ {x_1},{x_2}, \\cdots ,{x_n} \\}$ ', actual
238
- end
239
-
240
- def test_inline_tt
241
- actual = compile_inline('test @<tt>{inline test} test2')
242
- assert_equal 'test \\reviewtt{inline test} test2', actual
243
- end
244
-
245
- def test_inline_tt_endash
246
- actual = compile_inline('test @<tt>{in-line --test ---foo ----bar -----buz} --test2')
247
- assert_equal 'test \\reviewtt{in{-}line {-}{-}test {-}{-}{-}foo {-}{-}{-}{-}bar {-}{-}{-}{-}{-}buz} {-}{-}test2', actual
248
- end
249
-
250
- def test_inline_tti
251
- actual = compile_inline('test @<tti>{inline test} test2')
252
- assert_equal 'test \\reviewtti{inline test} test2', actual
253
- end
254
-
255
- def test_inline_ttb
256
- actual = compile_inline('test @<ttb>{inline test} test2')
257
- assert_equal 'test \\reviewttb{inline test} test2', actual
258
- end
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
-
274
- def test_inline_hd_chap
275
- def @chapter.headline_index
276
- item = Book::Index::Item.new('chap1|test', [1, 1], 'te_st')
277
- idx = Book::HeadlineIndex.new(self)
278
- idx.add_item(item)
279
- idx
280
- end
281
-
282
- @config['secnolevel'] = 3
283
- actual = compile_inline('test @<hd>{chap1|test} test2')
284
- assert_equal 'test \reviewsecref{「1.1.1 te\\textunderscore{}st」}{sec:1-1-1} test2', actual
285
-
286
- @config['chapterlink'] = nil
287
- actual = compile_inline('test @<hd>{chap1|test} test2')
288
- assert_equal 'test 「1.1.1 te\\textunderscore{}st」 test2', actual
289
- end
290
-
291
- def test_inline_sec
292
- def @chapter.headline_index
293
- item = Book::Index::Item.new('chap1|test', [1, 1], 'te_st<>')
294
- idx = Book::HeadlineIndex.new(self)
295
- idx.add_item(item)
296
- idx
297
- end
298
-
299
- @config['secnolevel'] = 3
300
- actual = compile_inline('test @<secref>{test}')
301
- assert_equal 'test \reviewsecref{「1.1.1 te\textunderscore{}st\textless{}\textgreater{}」}{sec:1-1-1}', actual
302
- actual = compile_inline('test @<sectitle>{test}')
303
- assert_equal 'test \reviewsecref{te\textunderscore{}st\textless{}\textgreater{}}{sec:1-1-1}', actual
304
- actual = compile_inline('test @<sec>{test}')
305
- assert_equal 'test \reviewsecref{1.1.1}{sec:1-1-1}', actual
306
-
307
- @config['secnolevel'] = 2
308
- actual = compile_inline('test @<secref>{test}')
309
- assert_equal 'test \reviewsecref{「te\textunderscore{}st\textless{}\textgreater{}」}{sec:1-1-1}', actual
310
- actual = compile_inline('test @<sectitle>{test}')
311
- assert_equal 'test \reviewsecref{te\textunderscore{}st\textless{}\textgreater{}}{sec:1-1-1}', actual
312
- assert_raises(ReVIEW::ApplicationError) { compile_block('test @<sec>{test}') }
313
- assert_match(/the target headline doesn't have a number/, @log_io.string)
314
-
315
- @config['chapterlink'] = nil
316
- @config['secnolevel'] = 3
317
- actual = compile_inline('test @<secref>{test}')
318
- assert_equal 'test 「1.1.1 te\textunderscore{}st\textless{}\textgreater{}」', actual
319
- actual = compile_inline('test @<sectitle>{test}')
320
- assert_equal 'test te\textunderscore{}st\textless{}\textgreater{}', actual
321
- actual = compile_inline('test @<sec>{test}')
322
- assert_equal 'test 1.1.1', actual
323
- end
324
-
325
- def test_inline_pageref
326
- actual = compile_inline('test p.@<pageref>{p1}')
327
- assert_equal 'test p.\pageref{p1}', actual
328
- end
329
-
330
- def test_inline_ruby_comma
331
- actual = compile_inline('@<ruby>{foo\\, bar\\, buz,フー・バー・バズ}')
332
- assert_equal '\\ruby{foo, bar, buz}{フー・バー・バズ}', actual
333
- end
334
-
335
- def test_inline_uchar
336
- actual = compile_inline('test @<uchar>{2460} test2')
337
- assert_equal 'test ① test2', actual
338
- end
339
-
340
- def test_inline_balloon
341
- actual = compile_inline('test @<balloon>{①}')
342
- assert_equal 'test \\reviewballoon{①}', actual
343
- end
344
-
345
- def test_inline_idx
346
- actual = compile_inline('@<idx>{__TEST%$}, @<hidx>{__TEST%$}')
347
- assert_equal '\\textunderscore{}\\textunderscore{}TEST\\%\\textdollar{}\\index{__TEST%$@\\textunderscore{}\\textunderscore{}TEST\\%\\textdollar{}}, \\index{__TEST%$@\\textunderscore{}\\textunderscore{}TEST\\%\\textdollar{}}', actual
348
- end
349
-
350
- def test_inline_idx_yomi
351
- require 'nkf'
352
- begin
353
- require 'MeCab'
354
- rescue LoadError
355
- $stderr.puts 'skip test_inline_idx_yomi (cannot find MeCab)'
356
- return true
357
- end
358
- tmpdir = Dir.mktmpdir
359
- File.write(File.join(tmpdir, 'sample.dic'), "強運\tはーどらっく\nmain(ブロック)\tmain{|}\n")
360
- @book.config['pdfmaker']['makeindex'] = true
361
- @book.config['pdfmaker']['makeindex_dic'] = "#{tmpdir}/sample.dic"
362
- @builder.setup_index
363
- actual = compile_inline('@<hidx>{漢字}@<hidx>{強運}@<hidx>{項目@1<<>>項目@2}')
364
- assert_equal %Q(\\index{かんじ@漢字}\\index{はーどらっく@強運}\\index{こうもく"@1@項目"@1!こうもく"@2@項目"@2}), actual
365
- actual = compile_inline('@<hidx>{main(ブロック)}@<hidx>{あいうえお{\}}')
366
- FileUtils.remove_entry_secure(tmpdir)
367
- assert_equal %Q(\\index{main{|}@main(ブロック)}\\index{あいうえお{}@あいうえお\\reviewleftcurlybrace{}\\reviewrightcurlybrace{}}), actual
368
- end
369
-
370
- def test_inline_idx_escape
371
- # as is
372
- %w[a あ ' ( ) = ` + ; * : , . ? /].each do |c|
373
- actual = @builder.index(c)
374
- assert_equal %Q(\\index{#{c}}), actual
375
- end
376
- actual = @builder.index('[')
377
- assert_equal %Q(\\index{[}), actual
378
- actual = @builder.index(']')
379
- assert_equal %Q(\\index{]}), actual
380
-
381
- # escape display string by "
382
- %w[! " @].each do |c|
383
- actual = @builder.index(c)
384
- assert_equal %Q(\\index{"#{c}@"#{c}}), actual
385
- end
386
-
387
- # escape display string by \
388
- %w[# % &].each do |c|
389
- actual = @builder.index(c)
390
- assert_equal %Q(\\index{#{c}@\\#{c}}), actual
391
- end
392
-
393
- # escape display string by macro
394
- actual = @builder.index('$')
395
- assert_equal %Q(\\index{$@\\textdollar{}}), actual
396
- actual = @builder.index('-')
397
- assert_equal %Q(\\index{-@{-}}), actual
398
- actual = @builder.index('~')
399
- assert_equal %Q(\\index{~@\\textasciitilde{}}), actual
400
- actual = @builder.index('^')
401
- assert_equal %Q(\\index{^@\\textasciicircum{}}), actual
402
- actual = @builder.index('\\')
403
- assert_equal %Q(\\index{\\@\\reviewbackslash{}}), actual
404
- actual = @builder.index('<')
405
- assert_equal %Q(\\index{<@\\textless{}}), actual
406
- actual = @builder.index('>')
407
- assert_equal %Q(\\index{>@\\textgreater{}}), actual
408
- actual = @builder.index('_')
409
- assert_equal %Q(\\index{_@\\textunderscore{}}), actual
410
-
411
- # escape both sort key and display string
412
- actual = @builder.index('{')
413
- assert_equal %Q(\\index{{@\\reviewleftcurlybrace{}}), actual
414
- actual = @builder.index('|')
415
- assert_equal %Q(\\index{|@\\textbar{}}), actual
416
- actual = @builder.index('}')
417
- assert_equal %Q(\\index{}@\\reviewrightcurlybrace{}}), actual
418
- end
419
-
420
- def test_jis_x_0201_kana
421
- # uplatex can handle half-width kana natively
422
- actual = compile_inline('foo・カンジ、テスト')
423
- assert_equal 'foo・カンジ、テスト', actual
424
- # assert_equal %Q(foo\\aj半角{・}\\aj半角{カ}\\aj半角{ン}\\aj半角{シ}\\aj半角{゛}\\aj半角{、}テスト), actual
425
- end
426
-
427
- def test_dlist
428
- actual = compile_block(" : foo\n foo.\n bar.\n")
429
- expected = <<-EOS
430
-
431
- \\begin{description}
432
- \\item[foo] \\mbox{} \\\\
433
- foo.
434
- bar.
435
- \\end{description}
436
- EOS
437
- assert_equal expected, actual
438
-
439
- @book.config['join_lines_by_lang'] = true
440
- actual = compile_block(" : foo\n foo.\n bar.\n")
441
- expected = <<-EOS
442
-
443
- \\begin{description}
444
- \\item[foo] \\mbox{} \\\\
445
- foo. bar.
446
- \\end{description}
447
- EOS
448
- assert_equal expected, actual
449
- end
450
-
451
- def test_dlist_with_bracket
452
- actual = compile_block(" : foo[bar]\n foo.\n bar.\n")
453
- expected = <<-EOS
454
-
455
- \\begin{description}
456
- \\item[foo\\lbrack{}bar\\rbrack{}] \\mbox{} \\\\
457
- foo.
458
- bar.
459
- \\end{description}
460
- EOS
461
- assert_equal expected, actual
462
-
463
- @book.config['join_lines_by_lang'] = true
464
- actual = compile_block(" : foo[bar]\n foo.\n bar.\n")
465
- expected = <<-EOS
466
-
467
- \\begin{description}
468
- \\item[foo\\lbrack{}bar\\rbrack{}] \\mbox{} \\\\
469
- foo. bar.
470
- \\end{description}
471
- EOS
472
- assert_equal expected, actual
473
- end
474
-
475
- def test_dlist_beforeulol
476
- actual = compile_block(" : foo\n foo.\n\npara\n\n : foo\n foo.\n\n 1. bar\n\n : foo\n foo.\n\n * bar\n")
477
- expected = <<-EOS
478
-
479
- \\begin{description}
480
- \\item[foo] \\mbox{} \\\\
481
- foo.
482
- \\end{description}
483
-
484
- para
485
-
486
- \\begin{description}
487
- \\item[foo] \\mbox{} \\\\
488
- foo.
489
- \\end{description}
490
-
491
- \\begin{enumerate}
492
- \\item bar
493
- \\end{enumerate}
494
-
495
- \\begin{description}
496
- \\item[foo] \\mbox{} \\\\
497
- foo.
498
- \\end{description}
499
-
500
- \\begin{itemize}
501
- \\item bar
502
- \\end{itemize}
503
- EOS
504
- assert_equal expected, actual
505
- end
506
-
507
- def test_dt_inline
508
- actual = compile_block("//footnote[bar][bar]\n\n : foo@<fn>{bar}[]<>&@<m>$\\alpha[]$\n")
509
-
510
- expected = <<-EOS
511
-
512
- \\begin{description}
513
- \\item[foo\\protect\\footnotemark{}\\lbrack{}\\rbrack{}\\textless{}\\textgreater{}\\&$\\alpha\\lbrack{}\\rbrack{}$] \\mbox{} \\\\
514
-
515
- \\end{description}
516
- EOS
517
- assert_equal expected, actual
518
- end
519
-
520
- def test_cmd
521
- actual = compile_block("//cmd{\nfoo\nbar\n\nbuz\n//}\n")
522
- expected = <<-EOS
523
-
524
- \\begin{reviewlistblock}
525
- \\begin{reviewcmd}
526
- foo
527
- bar
528
-
529
- buz
530
- \\end{reviewcmd}
531
- \\end{reviewlistblock}
532
- EOS
533
- assert_equal expected, actual
534
- end
535
-
536
- def test_cmd_caption
537
- actual = compile_block("//cmd[cap1]{\nfoo\nbar\n\nbuz\n//}\n")
538
- expected = <<-EOS
539
-
540
- \\begin{reviewlistblock}
541
- \\reviewcmdcaption{cap1}
542
- \\begin{reviewcmd}
543
- foo
544
- bar
545
-
546
- buz
547
- \\end{reviewcmd}
548
- \\end{reviewlistblock}
549
- EOS
550
- assert_equal expected, actual
551
-
552
- @config['caption_position']['list'] = 'bottom'
553
- actual = compile_block("//cmd[cap1]{\nfoo\nbar\n\nbuz\n//}\n")
554
- expected = <<-EOS
555
-
556
- \\begin{reviewlistblock}
557
- \\begin{reviewcmd}
558
- foo
559
- bar
560
-
561
- buz
562
- \\end{reviewcmd}
563
- \\reviewcmdcaption{cap1}
564
- \\end{reviewlistblock}
565
- EOS
566
- assert_equal expected, actual
567
- end
568
-
569
- def test_cmd_lst
570
- @book.config['highlight'] = {}
571
- @book.config['highlight']['latex'] = 'listings'
572
- actual = compile_block("//cmd{\nfoo\nbar\n\nbuz\n//}\n")
573
- expected = <<-EOS
574
- \\begin{reviewcmdlst}[language={}]
575
- foo
576
- bar
577
-
578
- buz
579
- \\end{reviewcmdlst}
580
- EOS
581
- assert_equal expected, actual
582
- end
583
-
584
- def test_emlist
585
- actual = compile_block("//emlist{\nfoo\nbar\n\nbuz\n//}\n")
586
- expected = <<-EOS
587
-
588
- \\begin{reviewlistblock}
589
- \\begin{reviewemlist}
590
- foo
591
- bar
592
-
593
- buz
594
- \\end{reviewemlist}
595
- \\end{reviewlistblock}
596
- EOS
597
- assert_equal expected, actual
598
- end
599
-
600
- def test_emlist_lst
601
- @book.config['highlight'] = {}
602
- @book.config['highlight']['latex'] = 'listings'
603
- actual = compile_block("//emlist[][sql]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n")
604
- expected = <<-EOS
605
-
606
- \\begin{reviewemlistlst}[language={sql}]
607
- SELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'
608
- \\end{reviewemlistlst}
609
- EOS
610
- assert_equal expected, actual
611
- end
612
-
613
- def test_emlist_lst_without_lang
614
- @book.config['highlight'] = {}
615
- @book.config['highlight']['latex'] = 'listings'
616
- @book.config['highlight']['lang'] = 'sql'
617
- actual = compile_block("//emlist[]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n")
618
- expected = <<-EOS
619
-
620
- \\begin{reviewemlistlst}[language={sql}]
621
- SELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'
622
- \\end{reviewemlistlst}
623
- EOS
624
- assert_equal expected, actual
625
- end
626
-
627
- def test_emlist_caption
628
- actual = compile_block("//emlist[cap1]{\nfoo\nbar\n\nbuz\n//}\n")
629
- expected = <<-EOS
630
-
631
- \\begin{reviewlistblock}
632
- \\reviewemlistcaption{cap1}
633
- \\begin{reviewemlist}
634
- foo
635
- bar
636
-
637
- buz
638
- \\end{reviewemlist}
639
- \\end{reviewlistblock}
640
- EOS
641
- assert_equal expected, actual
642
-
643
- @config['caption_position']['list'] = 'bottom'
644
- actual = compile_block("//emlist[cap1]{\nfoo\nbar\n\nbuz\n//}\n")
645
- expected = <<-EOS
646
-
647
- \\begin{reviewlistblock}
648
- \\begin{reviewemlist}
649
- foo
650
- bar
651
-
652
- buz
653
- \\end{reviewemlist}
654
- \\reviewemlistcaption{cap1}
655
- \\end{reviewlistblock}
656
- EOS
657
- assert_equal expected, actual
658
- end
659
-
660
- def test_emlist_empty_caption
661
- actual = compile_block("//emlist[]{\nfoo\nbar\n\nbuz\n//}\n")
662
- expected = <<-EOS
663
-
664
- \\begin{reviewlistblock}
665
- \\begin{reviewemlist}
666
- foo
667
- bar
668
-
669
- buz
670
- \\end{reviewemlist}
671
- \\end{reviewlistblock}
672
- EOS
673
- assert_equal expected, actual
674
- end
675
-
676
- def test_emlist_with_tab
677
- actual = compile_block("//emlist{\n\tfoo\n\t\tbar\n\n\tbuz\n//}\n")
678
- expected = <<-EOS
679
-
680
- \\begin{reviewlistblock}
681
- \\begin{reviewemlist}
682
- foo
683
- bar
684
-
685
- buz
686
- \\end{reviewemlist}
687
- \\end{reviewlistblock}
688
- EOS
689
- assert_equal expected, actual
690
- end
691
-
692
- def test_emlist_with_tab4
693
- @config['tabwidth'] = 4
694
- actual = compile_block("//emlist{\n\tfoo\n\t\tbar\n\n\tbuz\n//}\n")
695
- expected = <<-EOS
696
-
697
- \\begin{reviewlistblock}
698
- \\begin{reviewemlist}
699
- foo
700
- bar
701
-
702
- buz
703
- \\end{reviewemlist}
704
- \\end{reviewlistblock}
705
- EOS
706
- assert_equal expected, actual
707
- end
708
-
709
- def test_emlistnum_caption
710
- actual = compile_block("//emlistnum[cap1]{\nfoo\nbar\n\nbuz\n//}\n")
711
- expected = <<-EOS
712
-
713
- \\begin{reviewlistblock}
714
- \\reviewemlistcaption{cap1}
715
- \\begin{reviewemlist}
716
- 1: foo
717
- 2: bar
718
- 3:
719
- 4: buz
720
- \\end{reviewemlist}
721
- \\end{reviewlistblock}
722
- EOS
723
- assert_equal expected, actual
724
-
725
- @config['caption_position']['list'] = 'bottom'
726
- actual = compile_block("//emlistnum[cap1]{\nfoo\nbar\n\nbuz\n//}\n")
727
- expected = <<-EOS
728
-
729
- \\begin{reviewlistblock}
730
- \\begin{reviewemlist}
731
- 1: foo
732
- 2: bar
733
- 3:
734
- 4: buz
735
- \\end{reviewemlist}
736
- \\reviewemlistcaption{cap1}
737
- \\end{reviewlistblock}
738
- EOS
739
- assert_equal expected, actual
740
- end
741
-
742
- def test_list
743
- actual = compile_block("//list[id1][cap1]{\nfoo\nbar\n\nbuz\n//}\n")
744
- expected = <<-EOS
745
- \\begin{reviewlistblock}
746
- \\reviewlistcaption{リスト1.1: cap1}
747
- \\begin{reviewlist}
748
- foo
749
- bar
750
-
751
- buz
752
- \\end{reviewlist}
753
- \\end{reviewlistblock}
754
- EOS
755
- assert_equal expected, actual
756
-
757
- @config['caption_position']['list'] = 'bottom'
758
- actual = compile_block("//list[id1][cap1]{\nfoo\nbar\n\nbuz\n//}\n")
759
- expected = <<-EOS
760
- \\begin{reviewlistblock}
761
- \\begin{reviewlist}
762
- foo
763
- bar
764
-
765
- buz
766
- \\end{reviewlist}
767
- \\reviewlistcaption{リスト1.1: cap1}
768
- \\end{reviewlistblock}
769
- EOS
770
- assert_equal expected, actual
771
- end
772
-
773
- def test_list_lst
774
- @book.config['highlight'] = {}
775
- @book.config['highlight']['latex'] = 'listings'
776
- actual = compile_block("//list[id1][cap1][sql]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n")
777
- expected = <<-EOS
778
- \\begin{reviewlistlst}[caption={cap1},language={sql}]
779
- SELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'
780
- \\end{reviewlistlst}
781
- EOS
782
- assert_equal expected, actual
783
-
784
- @config['caption_position']['list'] = 'bottom'
785
- # XXX: caption_position won't work with highlight
786
- actual = compile_block("//list[id1][cap1][sql]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n")
787
- expected = <<-EOS
788
- \\begin{reviewlistlst}[caption={cap1},language={sql}]
789
- SELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'
790
- \\end{reviewlistlst}
791
- EOS
792
- assert_equal expected, actual
793
- end
794
-
795
- def test_list_lst_with_lang
796
- @book.config['highlight'] = {}
797
- @book.config['highlight']['latex'] = 'listings'
798
- @book.config['highlight']['lang'] = 'sql'
799
- actual = compile_block("//list[id1][cap1]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n")
800
- expected = <<-EOS
801
- \\begin{reviewlistlst}[caption={cap1},language={sql}]
802
- SELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'
803
- \\end{reviewlistlst}
804
- EOS
805
- assert_equal expected, actual
806
- end
807
-
808
- def test_listnum
809
- actual = compile_block("//listnum[test1][ruby]{\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n//}\n")
810
- expected = <<-EOS
811
- \\begin{reviewlistblock}
812
- \\reviewlistcaption{リスト1.1: ruby}
813
- \\begin{reviewlist}
814
- 1: class Foo
815
- 2: def foo
816
- 3: bar
817
- 4:
818
- 5: buz
819
- 6: end
820
- 7: end
821
- \\end{reviewlist}
822
- \\end{reviewlistblock}
823
- EOS
824
- assert_equal expected, actual
825
-
826
- @config['caption_position']['list'] = 'bottom'
827
- actual = compile_block("//listnum[test1][ruby]{\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n//}\n")
828
- expected = <<-EOS
829
- \\begin{reviewlistblock}
830
- \\begin{reviewlist}
831
- 1: class Foo
832
- 2: def foo
833
- 3: bar
834
- 4:
835
- 5: buz
836
- 6: end
837
- 7: end
838
- \\end{reviewlist}
839
- \\reviewlistcaption{リスト1.1: ruby}
840
- \\end{reviewlistblock}
841
- EOS
842
- assert_equal expected, actual
843
- end
844
-
845
- def test_listnum_linenum
846
- actual = compile_block("//firstlinenum[100]\n//listnum[test1][ruby]{\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n//}\n")
847
- expected = <<-EOS
848
- \\begin{reviewlistblock}
849
- \\reviewlistcaption{リスト1.1: ruby}
850
- \\begin{reviewlist}
851
- 100: class Foo
852
- 101: def foo
853
- 102: bar
854
- 103:
855
- 104: buz
856
- 105: end
857
- 106: end
858
- \\end{reviewlist}
859
- \\end{reviewlistblock}
860
- EOS
861
- assert_equal expected, actual
862
- end
863
-
864
- def test_listnum_lst
865
- @book.config['highlight'] = {}
866
- @book.config['highlight']['latex'] = 'listings'
867
- actual = compile_block("//listnum[test1][ruby]{\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n//}\n")
868
- expected = <<-EOS
869
- \\begin{reviewlistnumlst}[caption={ruby},language={}]
870
- class Foo
871
- def foo
872
- bar
873
-
874
- buz
875
- end
876
- end
877
- \\end{reviewlistnumlst}
878
- EOS
879
- assert_equal expected, actual
880
-
881
- @config['caption_position']['list'] = 'bottom'
882
- # XXX: caption_position won't work with highlight
883
- actual = compile_block("//listnum[test1][ruby]{\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n//}\n")
884
- expected = <<-EOS
885
- \\begin{reviewlistnumlst}[caption={ruby},language={}]
886
- class Foo
887
- def foo
888
- bar
889
-
890
- buz
891
- end
892
- end
893
- \\end{reviewlistnumlst}
894
- EOS
895
- assert_equal expected, actual
896
- end
897
-
898
- def test_listnum_lst_linenum
899
- @book.config['highlight'] = {}
900
- @book.config['highlight']['latex'] = 'listings'
901
- actual = compile_block("//firstlinenum[100]\n//listnum[test1][ruby]{\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n//}\n")
902
- expected = <<-EOS
903
- \\begin{reviewlistnumlst}[caption={ruby},language={},firstnumber=100]
904
- class Foo
905
- def foo
906
- bar
907
-
908
- buz
909
- end
910
- end
911
- \\end{reviewlistnumlst}
912
- EOS
913
- assert_equal expected, actual
914
- end
915
-
916
- def test_source
917
- actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n")
918
- expected = <<-EOS
919
- \\begin{reviewlistblock}
920
- \\reviewsourcecaption{foo/bar/test.rb}
921
- \\begin{reviewsource}
922
- foo
923
- bar
924
-
925
- buz
926
- \\end{reviewsource}
927
- \\end{reviewlistblock}
928
- EOS
929
- assert_equal expected, actual
930
-
931
- @config['caption_position']['list'] = 'bottom'
932
- actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n")
933
- expected = <<-EOS
934
- \\begin{reviewlistblock}
935
- \\begin{reviewsource}
936
- foo
937
- bar
938
-
939
- buz
940
- \\end{reviewsource}
941
- \\reviewsourcecaption{foo/bar/test.rb}
942
- \\end{reviewlistblock}
943
- EOS
944
- assert_equal expected, actual
945
- end
946
-
947
- def test_source_empty_caption
948
- actual = compile_block("//source[]{\nfoo\nbar\n\nbuz\n//}\n")
949
- expected = <<-EOS
950
- \\begin{reviewlistblock}
951
- \\begin{reviewsource}
952
- foo
953
- bar
954
-
955
- buz
956
- \\end{reviewsource}
957
- \\end{reviewlistblock}
958
- EOS
959
- assert_equal expected, actual
960
- end
961
-
962
- def test_source_lst
963
- @book.config['highlight'] = {}
964
- @book.config['highlight']['latex'] = 'listings'
965
- actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n")
966
- expected = <<-EOS
967
- \\begin{reviewsourcelst}[title={foo/bar/test.rb},language={}]
968
- foo
969
- bar
970
-
971
- buz
972
- \\end{reviewsourcelst}
973
- EOS
974
- assert_equal expected, actual
975
-
976
- @config['caption_position']['list'] = 'bottom'
977
- # XXX: caption_position won't work with highlight
978
- actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n")
979
- expected = <<-EOS
980
- \\begin{reviewsourcelst}[title={foo/bar/test.rb},language={}]
981
- foo
982
- bar
983
-
984
- buz
985
- \\end{reviewsourcelst}
986
- EOS
987
- assert_equal expected, actual
988
- end
989
-
990
- def test_quote
991
- actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n")
992
- expected = <<-EOS
993
-
994
- \\begin{quote}
995
- foobar
996
-
997
- buz
998
- \\end{quote}
999
- EOS
1000
- assert_equal expected, actual
1001
-
1002
- @book.config['join_lines_by_lang'] = true
1003
- actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n")
1004
- expected = <<-EOS
1005
-
1006
- \\begin{quote}
1007
- foo bar
1008
-
1009
- buz
1010
- \\end{quote}
1011
- EOS
1012
- assert_equal expected, actual
1013
- end
1014
-
1015
- def test_memo
1016
- actual = compile_block("//memo[this is @<b>{test}<&>_]{\ntest1\n\ntest@<i>{2}\n//}\n")
1017
- expected = <<-EOS
1018
- \\begin{reviewmemo}[this is \\reviewbold{test}\\textless{}\\&\\textgreater{}\\textunderscore{}]
1019
-
1020
- test1
1021
-
1022
- test\\reviewit{2}
1023
-
1024
- \\end{reviewmemo}
1025
- EOS
1026
- assert_equal expected, actual
1027
- end
1028
-
1029
- def test_flushright
1030
- actual = compile_block("//flushright{\nfoo\nbar\n\nbuz\n//}\n")
1031
- expected = <<-EOS
1032
-
1033
- \\begin{flushright}
1034
- foobar
1035
-
1036
- buz
1037
- \\end{flushright}
1038
- EOS
1039
- assert_equal expected, actual
1040
-
1041
- @book.config['join_lines_by_lang'] = true
1042
- actual = compile_block("//flushright{\nfoo\nbar\n\nbuz\n//}\n")
1043
- expected = <<-EOS
1044
-
1045
- \\begin{flushright}
1046
- foo bar
1047
-
1048
- buz
1049
- \\end{flushright}
1050
- EOS
1051
- assert_equal expected, actual
1052
- end
1053
-
1054
- def test_centering
1055
- actual = compile_block("//centering{\nfoo\nbar\n\nbuz\n//}\n")
1056
- expected = <<-EOS
1057
-
1058
- \\begin{center}
1059
- foobar
1060
-
1061
- buz
1062
- \\end{center}
1063
- EOS
1064
- assert_equal expected, actual
1065
-
1066
- @book.config['join_lines_by_lang'] = true
1067
- actual = compile_block("//centering{\nfoo\nbar\n\nbuz\n//}\n")
1068
- expected = <<-EOS
1069
-
1070
- \\begin{center}
1071
- foo bar
1072
-
1073
- buz
1074
- \\end{center}
1075
- EOS
1076
- assert_equal expected, actual
1077
- end
1078
-
1079
- def test_blankline
1080
- actual = compile_block("//blankline\nfoo\n")
1081
- expected = <<-EOS
1082
- \\vspace*{\\baselineskip}
1083
-
1084
- foo
1085
- EOS
1086
- assert_equal expected, actual
1087
- end
1088
-
1089
- def test_noindent
1090
- actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n")
1091
- expected = <<-EOS
1092
- \\noindent
1093
- foo
1094
- bar
1095
-
1096
- foo2
1097
- bar2
1098
- EOS
1099
- assert_equal expected, actual
1100
-
1101
- @book.config['join_lines_by_lang'] = true
1102
- actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n")
1103
- expected = <<-EOS
1104
- \\noindent
1105
- foo bar
1106
-
1107
- foo2 bar2
1108
- EOS
1109
- assert_equal expected, actual
1110
- end
1111
-
1112
- def test_image
1113
- def @chapter.image(_id)
1114
- item = Book::Index::Item.new('sampleimg', 1)
1115
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
1116
- item
1117
- end
1118
-
1119
- actual = compile_block("//image[sampleimg][sample photo]{\n//}\n")
1120
- expected = <<-EOS
1121
- \\begin{reviewimage}%%sampleimg
1122
- \\reviewincludegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}
1123
- \\reviewimagecaption{sample photo}
1124
- \\label{image:chap1:sampleimg}
1125
- \\end{reviewimage}
1126
- EOS
1127
- assert_equal expected, actual
1128
-
1129
- @book.config['pdfmaker']['use_original_image_size'] = true
1130
- actual = compile_block("//image[sampleimg][sample photo]{\n//}\n")
1131
- expected = <<-EOS
1132
- \\begin{reviewimage}%%sampleimg
1133
- \\reviewincludegraphics[ ]{./images/chap1-sampleimg.png}
1134
- \\reviewimagecaption{sample photo}
1135
- \\label{image:chap1:sampleimg}
1136
- \\end{reviewimage}
1137
- EOS
1138
- assert_equal expected, actual
1139
-
1140
- actual = compile_block("//image[sampleimg][sample photo][]{\n//}\n")
1141
- assert_equal expected, actual
1142
-
1143
- @book.config['pdfmaker']['use_original_image_size'] = nil
1144
- @config['caption_position']['image'] = 'top'
1145
- actual = compile_block("//image[sampleimg][sample photo]{\n//}\n")
1146
- expected = <<-EOS
1147
- \\begin{reviewimage}%%sampleimg
1148
- \\reviewimagecaption{sample photo}
1149
- \\label{image:chap1:sampleimg}
1150
- \\reviewincludegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}
1151
- \\end{reviewimage}
1152
- EOS
1153
- assert_equal expected, actual
1154
-
1155
- actual = compile_block("//image[sampleimg][]{\n//}\n")
1156
- expected = <<-EOS
1157
- \\begin{reviewimage}%%sampleimg
1158
- \\reviewimagecaption{}
1159
- \\label{image:chap1:sampleimg}
1160
- \\reviewincludegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}
1161
- \\end{reviewimage}
1162
- EOS
1163
- assert_equal expected, actual
1164
-
1165
- actual = compile_block("//image[sampleimg][][]{\n//}\n")
1166
- assert_equal expected, actual
1167
- end
1168
-
1169
- def test_image_with_metric
1170
- def @chapter.image(_id)
1171
- item = Book::Index::Item.new('sampleimg', 1)
1172
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
1173
- item
1174
- end
1175
-
1176
- actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n")
1177
- expected = <<-EOS
1178
- \\begin{reviewimage}%%sampleimg
1179
- \\reviewincludegraphics[scale=1.2]{./images/chap1-sampleimg.png}
1180
- \\reviewimagecaption{sample photo}
1181
- \\label{image:chap1:sampleimg}
1182
- \\end{reviewimage}
1183
- EOS
1184
- assert_equal expected, actual
1185
-
1186
- @book.config['pdfmaker']['use_original_image_size'] = true
1187
- actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n")
1188
- assert_equal expected, actual
1189
- end
1190
-
1191
- def test_image_with_metric_width
1192
- def @chapter.image(_id)
1193
- item = Book::Index::Item.new('sampleimg', 1)
1194
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
1195
- item
1196
- end
1197
-
1198
- @config['pdfmaker']['image_scale2width'] = true
1199
- actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n")
1200
- expected = <<-EOS
1201
- \\begin{reviewimage}%%sampleimg
1202
- \\reviewincludegraphics[width=1.2\\maxwidth]{./images/chap1-sampleimg.png}
1203
- \\reviewimagecaption{sample photo}
1204
- \\label{image:chap1:sampleimg}
1205
- \\end{reviewimage}
1206
- EOS
1207
- assert_equal expected, actual
1208
-
1209
- @book.config['pdfmaker']['use_original_image_size'] = true
1210
- actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n")
1211
- assert_equal expected, actual
1212
- end
1213
-
1214
- def test_image_with_metric2
1215
- def @chapter.image(_id)
1216
- item = Book::Index::Item.new('sampleimg', 1)
1217
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
1218
- item
1219
- end
1220
-
1221
- actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n")
1222
- expected = <<-EOS
1223
- \\begin{reviewimage}%%sampleimg
1224
- \\reviewincludegraphics[scale=1.2,ignore=params]{./images/chap1-sampleimg.png}
1225
- \\reviewimagecaption{sample photo}
1226
- \\label{image:chap1:sampleimg}
1227
- \\end{reviewimage}
1228
- EOS
1229
- assert_equal expected, actual
1230
-
1231
- @book.config['pdfmaker']['use_original_image_size'] = true
1232
- actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n")
1233
- assert_equal expected, actual
1234
- end
1235
-
1236
- def test_image_with_metric2_width
1237
- def @chapter.image(_id)
1238
- item = Book::Index::Item.new('sampleimg', 1)
1239
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
1240
- item
1241
- end
1242
-
1243
- @config['pdfmaker']['image_scale2width'] = true
1244
- actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n")
1245
- expected = <<-EOS
1246
- \\begin{reviewimage}%%sampleimg
1247
- \\reviewincludegraphics[width=1.2\\maxwidth,ignore=params]{./images/chap1-sampleimg.png}
1248
- \\reviewimagecaption{sample photo}
1249
- \\label{image:chap1:sampleimg}
1250
- \\end{reviewimage}
1251
- EOS
1252
- assert_equal expected, actual
1253
-
1254
- @book.config['pdfmaker']['use_original_image_size'] = true
1255
- actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n")
1256
- assert_equal expected, actual
1257
- end
1258
-
1259
- def test_indepimage
1260
- def @chapter.image(_id)
1261
- item = Book::Index::Item.new('sampleimg', 1)
1262
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
1263
- item
1264
- end
1265
-
1266
- actual = compile_block("//indepimage[sampleimg][sample photo]\n")
1267
- expected = <<-EOS
1268
- \\begin{reviewimage}%%sampleimg
1269
- \\reviewincludegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}
1270
- \\reviewindepimagecaption{図: sample photo}
1271
- \\end{reviewimage}
1272
- EOS
1273
- assert_equal expected, actual
1274
-
1275
- @book.config['pdfmaker']['use_original_image_size'] = true
1276
- actual = compile_block("//indepimage[sampleimg][sample photo]\n")
1277
- expected = <<-EOS
1278
- \\begin{reviewimage}%%sampleimg
1279
- \\reviewincludegraphics[ ]{./images/chap1-sampleimg.png}
1280
- \\reviewindepimagecaption{図: sample photo}
1281
- \\end{reviewimage}
1282
- EOS
1283
- assert_equal expected, actual
1284
-
1285
- actual = compile_block("//indepimage[sampleimg][sample photo][]\n")
1286
- assert_equal expected, actual
1287
-
1288
- @book.config['pdfmaker']['use_original_image_size'] = nil
1289
- @config['caption_position']['image'] = 'top'
1290
- actual = compile_block("//indepimage[sampleimg][sample photo]\n")
1291
- expected = <<-EOS
1292
- \\begin{reviewimage}%%sampleimg
1293
- \\reviewindepimagecaption{図: sample photo}
1294
- \\reviewincludegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}
1295
- \\end{reviewimage}
1296
- EOS
1297
- assert_equal expected, actual
1298
- end
1299
-
1300
- def test_indepimage_without_caption
1301
- def @chapter.image(_id)
1302
- item = Book::Index::Item.new('sampleimg', 1)
1303
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
1304
- item
1305
- end
1306
-
1307
- # FIXME: indepimage's caption should not be with a counter.
1308
- actual = compile_block("//indepimage[sampleimg]\n")
1309
- expected = <<-EOS
1310
- \\begin{reviewimage}%%sampleimg
1311
- \\reviewincludegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}
1312
- \\end{reviewimage}
1313
- EOS
1314
- assert_equal expected, actual
1315
-
1316
- actual = compile_block("//indepimage[sampleimg][]\n")
1317
- assert_equal expected, actual
1318
-
1319
- actual = compile_block("//indepimage[sampleimg][][]\n")
1320
- assert_equal expected, actual
1321
- end
1322
-
1323
- def test_indepimage_with_metric
1324
- def @chapter.image(_id)
1325
- item = Book::Index::Item.new('sampleimg', 1)
1326
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
1327
- item
1328
- end
1329
-
1330
- actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n")
1331
- expected = <<-EOS
1332
- \\begin{reviewimage}%%sampleimg
1333
- \\reviewincludegraphics[scale=1.2]{./images/chap1-sampleimg.png}
1334
- \\reviewindepimagecaption{図: sample photo}
1335
- \\end{reviewimage}
1336
- EOS
1337
- assert_equal expected, actual
1338
-
1339
- @book.config['pdfmaker']['use_original_image_size'] = true
1340
- actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n")
1341
- assert_equal expected, actual
1342
- end
1343
-
1344
- def test_indepimage_with_metric_width
1345
- def @chapter.image(_id)
1346
- item = Book::Index::Item.new('sampleimg', 1)
1347
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
1348
- item
1349
- end
1350
-
1351
- @config['pdfmaker']['image_scale2width'] = true
1352
- actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n")
1353
- expected = <<-EOS
1354
- \\begin{reviewimage}%%sampleimg
1355
- \\reviewincludegraphics[width=1.2\\maxwidth]{./images/chap1-sampleimg.png}
1356
- \\reviewindepimagecaption{図: sample photo}
1357
- \\end{reviewimage}
1358
- EOS
1359
- assert_equal expected, actual
1360
-
1361
- @book.config['pdfmaker']['use_original_image_size'] = true
1362
- actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n")
1363
- assert_equal expected, actual
1364
- end
1365
-
1366
- def test_indepimage_with_metric2
1367
- def @chapter.image(_id)
1368
- item = Book::Index::Item.new('sampleimg', 1)
1369
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
1370
- item
1371
- end
1372
-
1373
- actual = compile_block(%Q(//indepimage[sampleimg][sample photo][scale=1.2, html::class="sample",latex::ignore=params]\n))
1374
- expected = <<-EOS
1375
- \\begin{reviewimage}%%sampleimg
1376
- \\reviewincludegraphics[scale=1.2,ignore=params]{./images/chap1-sampleimg.png}
1377
- \\reviewindepimagecaption{図: sample photo}
1378
- \\end{reviewimage}
1379
- EOS
1380
- assert_equal expected, actual
1381
-
1382
- @book.config['pdfmaker']['use_original_image_size'] = true
1383
- actual = compile_block(%Q(//indepimage[sampleimg][sample photo][scale=1.2, html::class="sample",latex::ignore=params]\n))
1384
- assert_equal expected, actual
1385
- end
1386
-
1387
- def test_indepimage_without_caption_but_with_metric
1388
- def @chapter.image(_id)
1389
- item = Book::Index::Item.new('sampleimg', 1)
1390
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
1391
- item
1392
- end
1393
-
1394
- # FIXME: indepimage's caption should not be with a counter.
1395
- actual = compile_block("//indepimage[sampleimg][][scale=1.2]\n")
1396
- expected = <<-EOS
1397
- \\begin{reviewimage}%%sampleimg
1398
- \\reviewincludegraphics[scale=1.2]{./images/chap1-sampleimg.png}
1399
- \\end{reviewimage}
1400
- EOS
1401
- assert_equal expected, actual
1402
-
1403
- @book.config['pdfmaker']['use_original_image_size'] = true
1404
- actual = compile_block("//indepimage[sampleimg][][scale=1.2]\n")
1405
- assert_equal expected, actual
1406
- end
1407
-
1408
- def test_indepimage_nofile
1409
- def @chapter.image(_id)
1410
- item = Book::Index::Item.new('sample_img_nofile_', 1)
1411
- item.instance_eval do
1412
- def path
1413
- nil
1414
- end
1415
- end
1416
- item
1417
- end
1418
-
1419
- io = StringIO.new
1420
- @builder.instance_eval { @logger = ReVIEW::Logger.new(io) }
1421
-
1422
- actual = compile_block("//indepimage[sample_img_nofile_][sample photo]\n")
1423
- expected = <<-EOS
1424
- \\begin{reviewdummyimage}
1425
- {-}{-}[[path = sample\\reviewbackslash{}textunderscore\\{\\}img\\reviewbackslash{}textunderscore\\{\\}nofile\\reviewbackslash{}textunderscore\\{\\} (not exist)]]{-}{-}
1426
- \\reviewindepimagecaption{図: sample photo}
1427
- \\end{reviewdummyimage}
1428
- EOS
1429
- assert_equal expected, actual
1430
- assert_match(/WARN --: :1: image not bound: sample_img_nofile_/, io.string)
1431
- end
1432
-
1433
- def test_table
1434
- actual = compile_block("//table{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
1435
- expected = <<-EOS
1436
- \\begin{reviewtable}{|l|l|}
1437
- \\hline
1438
- \\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline
1439
- ccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline
1440
- \\end{reviewtable}
1441
- EOS
1442
- assert_equal expected, actual
1443
-
1444
- actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
1445
- expected = <<-EOS
1446
- \\begin{table}%%foo
1447
- \\reviewtablecaption{FOO}
1448
- \\label{table:chap1:foo}
1449
- \\begin{reviewtable}{|l|l|}
1450
- \\hline
1451
- \\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline
1452
- ccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline
1453
- \\end{reviewtable}
1454
- \\end{table}
1455
- EOS
1456
- assert_equal expected, actual
1457
-
1458
- actual = compile_block("//table[foo][]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
1459
- expected = <<-EOS
1460
- \\begin{reviewtable}{|l|l|}
1461
- \\hline
1462
- \\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline
1463
- ccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline
1464
- \\end{reviewtable}
1465
- EOS
1466
- assert_equal expected, actual
1467
-
1468
- @config['caption_position']['table'] = 'bottom'
1469
- actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
1470
- expected = <<-EOS
1471
- \\begin{table}%%foo
1472
- \\begin{reviewtable}{|l|l|}
1473
- \\hline
1474
- \\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline
1475
- ccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline
1476
- \\end{reviewtable}
1477
- \\reviewtablecaption{FOO}
1478
- \\label{table:chap1:foo}
1479
- \\end{table}
1480
- EOS
1481
- assert_equal expected, actual
1482
- end
1483
-
1484
- def test_empty_table
1485
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n//}\n") }
1486
- assert_equal 'no rows in the table', e.message
1487
-
1488
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n------------\n//}\n") }
1489
- assert_equal 'no rows in the table', e.message
1490
- end
1491
-
1492
- def test_customize_cellwidth
1493
- actual = compile_block("//tsize[2,3,5]\n//table{\nA\tB\tC\n//}\n")
1494
- expected = <<-EOS
1495
- \\begin{reviewtable}{|p{2mm}|p{3mm}|p{5mm}|}
1496
- \\hline
1497
- \\reviewth{A} & B & C \\\\ \\hline
1498
- \\end{reviewtable}
1499
- EOS
1500
- assert_equal expected, actual
1501
-
1502
- actual = compile_block("//tsize[|latex,html|2,3,5]\n//table{\nA\tB\tC\n//}\n")
1503
- expected = <<-EOS
1504
- \\begin{reviewtable}{|p{2mm}|p{3mm}|p{5mm}|}
1505
- \\hline
1506
- \\reviewth{A} & B & C \\\\ \\hline
1507
- \\end{reviewtable}
1508
- EOS
1509
- assert_equal expected, actual
1510
-
1511
- actual = compile_block("//tsize[|html|2,3,5]\n//table{\nA\tB\tC\n//}\n")
1512
- expected = <<-EOS
1513
- \\begin{reviewtable}{|l|l|l|}
1514
- \\hline
1515
- \\reviewth{A} & B & C \\\\ \\hline
1516
- \\end{reviewtable}
1517
- EOS
1518
- assert_equal expected, actual
1519
-
1520
- actual = compile_block("//tsize[|latex|2,3,5]\n//table{\nA\tB\tC\n//}\n")
1521
- expected = <<-EOS
1522
- \\begin{reviewtable}{|p{2mm}|p{3mm}|p{5mm}|}
1523
- \\hline
1524
- \\reviewth{A} & B & C \\\\ \\hline
1525
- \\end{reviewtable}
1526
- EOS
1527
- assert_equal expected, actual
1528
-
1529
- actual = compile_block("//tsize[|latex||p{5mm}|cr|]\n//table{\nA\tB\tC\n//}\n")
1530
- expected = <<-EOS
1531
- \\begin{reviewtable}{|p{5mm}|cr|}
1532
- \\hline
1533
- \\reviewth{A} & B & C \\\\ \\hline
1534
- \\end{reviewtable}
1535
- EOS
1536
- assert_equal expected, actual
1537
- end
1538
-
1539
- def test_separate_tsize
1540
- actual = @builder.separate_tsize('|l|c|r|p{1cm}lp{1.5cm}|p{5mm}').join(',')
1541
- assert_equal 'l,c,r,p{1cm},l,p{1.5cm},p{5mm}', actual
1542
-
1543
- actual = @builder.separate_tsize('|lcr').join(',')
1544
- assert_equal 'l,c,r', actual
1545
-
1546
- actual = @builder.separate_tsize('{p}p{').join(',')
1547
- assert_equal '{p},p{', actual
1548
- end
1549
-
1550
- def test_break_tablecell
1551
- actual = compile_block("//tsize[|latex||p{10mm}|cp{10mm}|]\n//table{\nA@<br>{}A\tB@<br>{}B\tC@<br>{}C\n//}\n")
1552
- expected = <<-EOS
1553
- \\begin{reviewtable}{|p{10mm}|cp{10mm}|}
1554
- \\hline
1555
- \\reviewth{A\\newline{}A} & \\shortstack[l]{B\\\\
1556
- B} & C\\newline{}C \\\\ \\hline
1557
- \\end{reviewtable}
1558
- EOS
1559
- assert_equal expected, actual
1560
-
1561
- actual = compile_block("//tsize[|latex||p{10mm}|cp{10mm}|]\n//table{\n1@<br>{}1\t2@<br>{}2\t3\n------------\nA@<br>{}A\tB@<br>{}B\tC@<br>{}C\n//}\n")
1562
- expected = <<-EOS
1563
- \\begin{reviewtable}{|p{10mm}|cp{10mm}|}
1564
- \\hline
1565
- \\reviewth{1\\newline{}1} & \\reviewth{\\shortstack[l]{2\\\\
1566
- 2}} & \\reviewth{3} \\\\ \\hline
1567
- A\\newline{}A & \\shortstack[l]{B\\\\
1568
- B} & C\\newline{}C \\\\ \\hline
1569
- \\end{reviewtable}
1570
- EOS
1571
- assert_equal expected, actual
1572
- end
1573
-
1574
- def test_emtable
1575
- actual = compile_block("//emtable[foo]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n//emtable{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
1576
- expected = <<-EOS
1577
- \\begin{table}%%
1578
- \\reviewtablecaption*{foo}
1579
- \\begin{reviewtable}{|l|l|}
1580
- \\hline
1581
- \\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline
1582
- ccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline
1583
- \\end{reviewtable}
1584
- \\end{table}
1585
-
1586
- \\begin{reviewtable}{|l|l|}
1587
- \\hline
1588
- \\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline
1589
- ccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline
1590
- \\end{reviewtable}
1591
- EOS
1592
- assert_equal expected, actual
1593
-
1594
- @config['caption_position']['table'] = 'bottom'
1595
- actual = compile_block("//emtable[foo]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n//emtable{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
1596
- expected = <<-EOS
1597
- \\begin{table}%%
1598
- \\begin{reviewtable}{|l|l|}
1599
- \\hline
1600
- \\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline
1601
- ccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline
1602
- \\end{reviewtable}
1603
- \\reviewtablecaption*{foo}
1604
- \\end{table}
1605
-
1606
- \\begin{reviewtable}{|l|l|}
1607
- \\hline
1608
- \\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline
1609
- ccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline
1610
- \\end{reviewtable}
1611
- EOS
1612
- assert_equal expected, actual
1613
- end
1614
-
1615
- def test_imgtable
1616
- def @chapter.image(_id)
1617
- item = Book::Index::Item.new('sampleimg', 1, 'sample img')
1618
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
1619
- item
1620
- end
1621
-
1622
- actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n")
1623
-
1624
- expected = <<-EOS
1625
- \\begin{table}[h]%%sampleimg
1626
- \\reviewimgtablecaption{test for imgtable}
1627
- \\label{table:chap1:sampleimg}
1628
- \\begin{reviewimage}%%sampleimg
1629
- \\reviewincludegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}
1630
- \\end{reviewimage}
1631
- \\end{table}
1632
- EOS
1633
- assert_equal expected, actual
1634
-
1635
- actual = compile_block("//imgtable[sampleimg][]{\n//}\n")
1636
- expected = <<-EOS
1637
- \\label{table:chap1:sampleimg}
1638
- \\begin{reviewimage}%%sampleimg
1639
- \\reviewincludegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}
1640
- \\end{reviewimage}
1641
- EOS
1642
- assert_equal expected, actual
1643
-
1644
- actual = compile_block("//imgtable[sampleimg][][]{\n//}\n")
1645
- assert_equal expected, actual
1646
-
1647
- @book.config['pdfmaker']['use_original_image_size'] = true
1648
- actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n")
1649
-
1650
- expected = <<-EOS
1651
- \\begin{table}[h]%%sampleimg
1652
- \\reviewimgtablecaption{test for imgtable}
1653
- \\label{table:chap1:sampleimg}
1654
- \\begin{reviewimage}%%sampleimg
1655
- \\reviewincludegraphics[ ]{./images/chap1-sampleimg.png}
1656
- \\end{reviewimage}
1657
- \\end{table}
1658
- EOS
1659
- assert_equal expected, actual
1660
-
1661
- actual = compile_block("//imgtable[sampleimg][test for imgtable][]{\n//}\n")
1662
- assert_equal expected, actual
1663
-
1664
- @book.config['pdfmaker']['use_original_image_size'] = nil
1665
- @config['caption_position']['table'] = 'bottom'
1666
- actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n")
1667
-
1668
- expected = <<-EOS
1669
- \\begin{table}[h]%%sampleimg
1670
- \\label{table:chap1:sampleimg}
1671
- \\begin{reviewimage}%%sampleimg
1672
- \\reviewincludegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}
1673
- \\end{reviewimage}
1674
- \\reviewimgtablecaption{test for imgtable}
1675
- \\end{table}
1676
- EOS
1677
- assert_equal expected, actual
1678
- end
1679
-
1680
- def test_imgtable_with_metrics
1681
- def @chapter.image(_id)
1682
- item = Book::Index::Item.new('sampleimg', 1, 'sample img')
1683
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
1684
- item
1685
- end
1686
-
1687
- actual = compile_block("//imgtable[sampleimg][test for imgtable][scale=1.2]{\n//}\n")
1688
- expected = <<-EOS
1689
- \\begin{table}[h]%%sampleimg
1690
- \\reviewimgtablecaption{test for imgtable}
1691
- \\label{table:chap1:sampleimg}
1692
- \\begin{reviewimage}%%sampleimg
1693
- \\reviewincludegraphics[scale=1.2]{./images/chap1-sampleimg.png}
1694
- \\end{reviewimage}
1695
- \\end{table}
1696
- EOS
1697
- assert_equal expected, actual
1698
-
1699
- @book.config['pdfmaker']['use_original_image_size'] = true
1700
- actual = compile_block("//imgtable[sampleimg][test for imgtable][scale=1.2]{\n//}\n")
1701
- assert_equal expected, actual
1702
- end
1703
-
1704
- def test_table_row_separator
1705
- src = "//table{\n1\t2\t\t3 4| 5\n------------\na b\tc d |e\n//}\n"
1706
- expected = <<-EOS
1707
- \\begin{reviewtable}{|l|l|l|}
1708
- \\hline
1709
- \\reviewth{1} & \\reviewth{2} & \\reviewth{3 4\\textbar{} 5} \\\\ \\hline
1710
- a b & c d \\textbar{}e & \\\\ \\hline
1711
- \\end{reviewtable}
1712
- EOS
1713
- actual = compile_block(src)
1714
- assert_equal expected, actual
1715
-
1716
- @config['table_row_separator'] = 'singletab'
1717
- actual = compile_block(src)
1718
- expected = <<-EOS
1719
- \\begin{reviewtable}{|l|l|l|l|}
1720
- \\hline
1721
- \\reviewth{1} & \\reviewth{2} & \\reviewth{} & \\reviewth{3 4\\textbar{} 5} \\\\ \\hline
1722
- a b & c d \\textbar{}e & & \\\\ \\hline
1723
- \\end{reviewtable}
1724
- EOS
1725
- assert_equal expected, actual
1726
-
1727
- @config['table_row_separator'] = 'spaces'
1728
- actual = compile_block(src)
1729
- expected = <<-EOS
1730
- \\begin{reviewtable}{|l|l|l|l|l|}
1731
- \\hline
1732
- \\reviewth{1} & \\reviewth{2} & \\reviewth{3} & \\reviewth{4\\textbar{}} & \\reviewth{5} \\\\ \\hline
1733
- a & b & c & d & \\textbar{}e \\\\ \\hline
1734
- \\end{reviewtable}
1735
- EOS
1736
- assert_equal expected, actual
1737
-
1738
- @config['table_row_separator'] = 'verticalbar'
1739
- actual = compile_block(src)
1740
- expected = <<-EOS
1741
- \\begin{reviewtable}{|l|l|}
1742
- \\hline
1743
- \\reviewth{1 2 3 4} & \\reviewth{5} \\\\ \\hline
1744
- a b c d & e \\\\ \\hline
1745
- \\end{reviewtable}
1746
- EOS
1747
- assert_equal expected, actual
1748
- end
1749
-
1750
- def test_bib
1751
- def @chapter.bibpaper(_id)
1752
- Book::Index::Item.new('samplebib', 1, 'sample bib')
1753
- end
1754
-
1755
- assert_equal '\\reviewbibref{[1]}{bib:samplebib}', compile_inline('@<bib>{samplebib}')
1756
- end
1757
-
1758
- def test_bibpaper
1759
- def @chapter.bibpaper(_id)
1760
- Book::Index::Item.new('samplebib', 1, 'sample bib')
1761
- end
1762
-
1763
- actual = compile_block("//bibpaper[samplebib][sample bib @<b>{bold}]{\na\nb\n//}\n")
1764
- expected = <<-EOS
1765
- [1] sample bib \\reviewbold{bold}
1766
- \\label{bib:samplebib}
1767
-
1768
- ab
1769
-
1770
- EOS
1771
- assert_equal expected, actual
1772
-
1773
- @book.config['join_lines_by_lang'] = true
1774
- actual = compile_block("//bibpaper[samplebib][sample bib @<b>{bold}]{\na\nb\n//}\n")
1775
- expected = <<-EOS
1776
- [1] sample bib \\reviewbold{bold}
1777
- \\label{bib:samplebib}
1778
-
1779
- a b
1780
-
1781
- EOS
1782
- assert_equal expected, actual
1783
- end
1784
-
1785
- def test_bibpaper_without_body
1786
- def @chapter.bibpaper(_id)
1787
- Book::Index::Item.new('samplebib', 1, 'sample bib')
1788
- end
1789
-
1790
- actual = compile_block("//bibpaper[samplebib][sample bib]\n")
1791
- expected = <<-EOS
1792
- [1] sample bib
1793
- \\label{bib:samplebib}
1794
-
1795
- EOS
1796
- assert_equal expected, actual
1797
- end
1798
-
1799
- def column_helper(review)
1800
- compile_block(review)
1801
- end
1802
-
1803
- def test_column_1
1804
- review = <<-EOS
1805
- ===[column] prev column
1806
-
1807
- inside prev column
1808
-
1809
- ===[column] test
1810
-
1811
- inside column
1812
-
1813
- ===[/column]
1814
- EOS
1815
- expected = <<-EOS
1816
-
1817
- \\begin{reviewcolumn}[prev column\\hypertarget{column:chap1:1}{}]
1818
- \\addcontentsline{toc}{subsection}{prev column}
1819
-
1820
- inside prev column
1821
-
1822
- \\end{reviewcolumn}
1823
-
1824
- \\begin{reviewcolumn}[test\\hypertarget{column:chap1:2}{}]
1825
- \\addcontentsline{toc}{subsection}{test}
1826
-
1827
- inside column
1828
-
1829
- \\end{reviewcolumn}
1830
- EOS
1831
- @config['toclevel'] = 3
1832
- assert_equal expected, column_helper(review)
1833
- end
1834
-
1835
- def test_column_2
1836
- review = <<-EOS
1837
- ===[column] test
1838
-
1839
- inside column
1840
-
1841
- === next level
1842
- EOS
1843
- expected = <<-EOS
1844
-
1845
- \\begin{reviewcolumn}[test\\hypertarget{column:chap1:1}{}]
1846
-
1847
- inside column
1848
-
1849
- \\end{reviewcolumn}
1850
-
1851
- \\subsection*{next level}
1852
- \\label{sec:1-0-1}
1853
- EOS
1854
-
1855
- @config['toclevel'] = 1
1856
- assert_equal expected, column_helper(review)
1857
- end
1858
-
1859
- def test_column_3
1860
- review = <<-EOS
1861
- ===[column] test
1862
-
1863
- inside column
1864
-
1865
- ===[/column_dummy]
1866
- EOS
1867
- assert_raise(ReVIEW::ApplicationError) do
1868
- column_helper(review)
1869
- end
1870
- end
1871
-
1872
- def test_ul
1873
- src = <<-EOS
1874
- * AAA
1875
- * BBB
1876
- EOS
1877
- expected = <<-EOS
1878
-
1879
- \\begin{itemize}
1880
- \\item AAA
1881
- \\item BBB
1882
- \\end{itemize}
1883
- EOS
1884
- actual = compile_block(src)
1885
- assert_equal expected, actual
1886
- end
1887
-
1888
- def test_ul_with_bracket
1889
- src = <<-EOS
1890
- * AAA
1891
- * []BBB
1892
- EOS
1893
- expected = <<-EOS
1894
-
1895
- \\begin{itemize}
1896
- \\item AAA
1897
- \\item \\lbrack{}]BBB
1898
- \\end{itemize}
1899
- EOS
1900
- actual = compile_block(src)
1901
- assert_equal expected, actual
1902
- end
1903
-
1904
- def test_cont
1905
- src = <<-EOS
1906
- * AAA
1907
- -AA
1908
- * BBB
1909
- -BB
1910
- EOS
1911
- expected = <<-EOS
1912
-
1913
- \\begin{itemize}
1914
- \\item AAA
1915
- {-}AA
1916
- \\item BBB
1917
- {-}BB
1918
- \\end{itemize}
1919
- EOS
1920
- actual = compile_block(src)
1921
- assert_equal expected, actual
1922
-
1923
- @book.config['join_lines_by_lang'] = true
1924
- expected = <<-EOS
1925
-
1926
- \\begin{itemize}
1927
- \\item AAA {-}AA
1928
- \\item BBB {-}BB
1929
- \\end{itemize}
1930
- EOS
1931
- actual = compile_block(src)
1932
- assert_equal expected, actual
1933
- end
1934
-
1935
- def test_cont_with_br
1936
- src = <<-EOS
1937
- * AAA@<br>{}
1938
- -AA
1939
- * BBB@<br>{}1@<br>{}
1940
- -BB
1941
- EOS
1942
- expected = <<-EOS
1943
-
1944
- \\begin{itemize}
1945
- \\item AAA\\\\
1946
- {-}AA
1947
- \\item BBB\\\\
1948
- 1\\\\
1949
- {-}BB
1950
- \\end{itemize}
1951
- EOS
1952
- actual = compile_block(src)
1953
- assert_equal expected, actual
1954
-
1955
- @book.config['join_lines_by_lang'] = true
1956
- expected = <<-EOS
1957
-
1958
- \\begin{itemize}
1959
- \\item AAA\\\\
1960
- {-}AA
1961
- \\item BBB\\\\
1962
- 1\\\\
1963
- {-}BB
1964
- \\end{itemize}
1965
- EOS
1966
- actual = compile_block(src)
1967
- assert_equal expected, actual
1968
- end
1969
-
1970
- def test_ul_nest1
1971
- src = <<-EOS
1972
- * AAA
1973
- ** AA
1974
- EOS
1975
-
1976
- expected = <<-EOS
1977
-
1978
- \\begin{itemize}
1979
- \\item AAA
1980
-
1981
- \\begin{itemize}
1982
- \\item AA
1983
- \\end{itemize}
1984
-
1985
- \\end{itemize}
1986
- EOS
1987
- actual = compile_block(src)
1988
- assert_equal expected, actual
1989
- end
1990
-
1991
- def test_ul_nest3
1992
- src = <<-EOS
1993
- * AAA
1994
- ** AA
1995
- * BBB
1996
- ** BB
1997
- EOS
1998
-
1999
- expected = <<-EOS
2000
-
2001
- \\begin{itemize}
2002
- \\item AAA
2003
-
2004
- \\begin{itemize}
2005
- \\item AA
2006
- \\end{itemize}
2007
-
2008
- \\item BBB
2009
-
2010
- \\begin{itemize}
2011
- \\item BB
2012
- \\end{itemize}
2013
-
2014
- \\end{itemize}
2015
- EOS
2016
- actual = compile_block(src)
2017
- assert_equal expected, actual
2018
- end
2019
-
2020
- def test_ol
2021
- src = <<-EOS
2022
- 3. AAA
2023
- 3. BBB
2024
- EOS
2025
-
2026
- expected = <<-EOS
2027
-
2028
- \\begin{enumerate}
2029
- \\item AAA
2030
- \\item BBB
2031
- \\end{enumerate}
2032
- EOS
2033
- actual = compile_block(src)
2034
- assert_equal expected, actual
2035
- end
2036
-
2037
- def test_ol_with_bracket
2038
- src = <<-EOS
2039
- 1. AAA
2040
- 2. []BBB
2041
- EOS
2042
- expected = <<-EOS
2043
-
2044
- \\begin{enumerate}
2045
- \\item AAA
2046
- \\item \\lbrack{}]BBB
2047
- \\end{enumerate}
2048
- EOS
2049
- actual = compile_block(src)
2050
- assert_equal expected, actual
2051
- end
2052
-
2053
- def test_major_blocks
2054
- actual = compile_block("//note{\nA\n\nB\n//}\n//note[caption]{\nA\n//}")
2055
- expected = <<-EOS
2056
- \\begin{reviewnote}
2057
-
2058
- A
2059
-
2060
- B
2061
-
2062
- \\end{reviewnote}
2063
- \\begin{reviewnote}[caption]
2064
-
2065
- A
2066
-
2067
- \\end{reviewnote}
2068
- EOS
2069
- assert_equal expected, actual
2070
-
2071
- actual = compile_block("//memo{\nA\n\nB\n//}\n//memo[caption]{\nA\n//}")
2072
- expected = <<-EOS
2073
- \\begin{reviewmemo}
2074
-
2075
- A
2076
-
2077
- B
2078
-
2079
- \\end{reviewmemo}
2080
- \\begin{reviewmemo}[caption]
2081
-
2082
- A
2083
-
2084
- \\end{reviewmemo}
2085
- EOS
2086
- assert_equal expected, actual
2087
-
2088
- actual = compile_block("//info{\nA\n\nB\n//}\n//info[caption]{\nA\n//}")
2089
- expected = <<-EOS
2090
- \\begin{reviewinfo}
2091
-
2092
- A
2093
-
2094
- B
2095
-
2096
- \\end{reviewinfo}
2097
- \\begin{reviewinfo}[caption]
2098
-
2099
- A
2100
-
2101
- \\end{reviewinfo}
2102
- EOS
2103
- assert_equal expected, actual
2104
-
2105
- actual = compile_block("//important{\nA\n\nB\n//}\n//important[caption]{\nA\n//}")
2106
- expected = <<-EOS
2107
- \\begin{reviewimportant}
2108
-
2109
- A
2110
-
2111
- B
2112
-
2113
- \\end{reviewimportant}
2114
- \\begin{reviewimportant}[caption]
2115
-
2116
- A
2117
-
2118
- \\end{reviewimportant}
2119
- EOS
2120
- assert_equal expected, actual
2121
-
2122
- actual = compile_block("//caution{\nA\n\nB\n//}\n//caution[caption]{\nA\n//}")
2123
- expected = <<-EOS
2124
- \\begin{reviewcaution}
2125
-
2126
- A
2127
-
2128
- B
2129
-
2130
- \\end{reviewcaution}
2131
- \\begin{reviewcaution}[caption]
2132
-
2133
- A
2134
-
2135
- \\end{reviewcaution}
2136
- EOS
2137
- assert_equal expected, actual
2138
-
2139
- actual = compile_block("//notice{\nA\n\nB\n//}\n//notice[caption]{\nA\n//}")
2140
- expected = <<-EOS
2141
- \\begin{reviewnotice}
2142
-
2143
- A
2144
-
2145
- B
2146
-
2147
- \\end{reviewnotice}
2148
- \\begin{reviewnotice}[caption]
2149
-
2150
- A
2151
-
2152
- \\end{reviewnotice}
2153
- EOS
2154
- assert_equal expected, actual
2155
-
2156
- actual = compile_block("//warning{\nA\n\nB\n//}\n//warning[caption]{\nA\n//}")
2157
- expected = <<-EOS
2158
- \\begin{reviewwarning}
2159
-
2160
- A
2161
-
2162
- B
2163
-
2164
- \\end{reviewwarning}
2165
- \\begin{reviewwarning}[caption]
2166
-
2167
- A
2168
-
2169
- \\end{reviewwarning}
2170
- EOS
2171
- assert_equal expected, actual
2172
-
2173
- actual = compile_block("//tip{\nA\n\nB\n//}\n//tip[caption]{\nA\n//}")
2174
- expected = <<-EOS
2175
- \\begin{reviewtip}
2176
-
2177
- A
2178
-
2179
- B
2180
-
2181
- \\end{reviewtip}
2182
- \\begin{reviewtip}[caption]
2183
-
2184
- A
2185
-
2186
- \\end{reviewtip}
2187
- EOS
2188
- assert_equal expected, actual
2189
- end
2190
-
2191
- def test_minicolumn_blocks
2192
- %w[note memo tip info warning important caution notice].each do |type|
2193
- src = <<-EOS
2194
- //#{type}[#{type}1]{
2195
-
2196
- //}
2197
-
2198
- //#{type}[#{type}2]{
2199
- //}
2200
- EOS
2201
-
2202
- expected = <<-EOS
2203
- \\begin{review#{type}}[#{type}1]
2204
- \\end{review#{type}}
2205
- \\begin{review#{type}}[#{type}2]
2206
- \\end{review#{type}}
2207
- EOS
2208
- assert_equal expected, compile_block(src)
2209
-
2210
- src = <<-EOS
2211
- //#{type}[#{type}2]{
2212
-
2213
- //}
2214
-
2215
- //#{type}[#{type}3]{
2216
-
2217
- //}
2218
-
2219
- //#{type}[#{type}4]{
2220
-
2221
- //}
2222
-
2223
- //#{type}[#{type}5]{
2224
-
2225
- //}
2226
-
2227
- //#{type}[#{type}6]{
2228
-
2229
- //}
2230
- EOS
2231
-
2232
- expected = <<-EOS
2233
- \\begin{review#{type}}[#{type}2]
2234
- \\end{review#{type}}
2235
- \\begin{review#{type}}[#{type}3]
2236
- \\end{review#{type}}
2237
- \\begin{review#{type}}[#{type}4]
2238
- \\end{review#{type}}
2239
- \\begin{review#{type}}[#{type}5]
2240
- \\end{review#{type}}
2241
- \\begin{review#{type}}[#{type}6]
2242
- \\end{review#{type}}
2243
- EOS
2244
- assert_equal expected, compile_block(src)
2245
-
2246
- src = <<-EOS
2247
- //#{type}{
2248
-
2249
- * A
2250
-
2251
- 1. B
2252
-
2253
- //}
2254
-
2255
- //#{type}[OMITEND1]{
2256
-
2257
- //emlist{
2258
- LIST
2259
- //}
2260
-
2261
- //}
2262
- //#{type}[OMITEND2]{
2263
- //}
2264
- EOS
2265
-
2266
- expected = <<-EOS
2267
- \\begin{review#{type}}
2268
-
2269
- \\begin{itemize}
2270
- \\item A
2271
- \\end{itemize}
2272
-
2273
- \\begin{enumerate}
2274
- \\item B
2275
- \\end{enumerate}
2276
-
2277
- \\end{review#{type}}
2278
- \\begin{review#{type}}[OMITEND1]
2279
-
2280
- \\begin{reviewlistblock}
2281
- \\begin{reviewemlist}
2282
- LIST
2283
- \\end{reviewemlist}
2284
- \\end{reviewlistblock}
2285
-
2286
- \\end{review#{type}}
2287
- \\begin{review#{type}}[OMITEND2]
2288
- \\end{review#{type}}
2289
- EOS
2290
- assert_equal expected, compile_block(src)
2291
- end
2292
- end
2293
-
2294
- def test_minicolumn_blocks_nest_error1
2295
- %w[note memo tip info warning important caution notice].each do |type|
2296
- @builder.doc_status.clear
2297
- src = <<-EOS
2298
- //#{type}{
2299
-
2300
- //#{type}{
2301
- //}
2302
-
2303
- //}
2304
- EOS
2305
- assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2306
- assert_match(/minicolumn cannot be nested:/, @log_io.string)
2307
- end
2308
- end
2309
-
2310
- def test_minicolumn_blocks_nest_error2
2311
- %w[note memo tip info warning important caution notice].each do |type|
2312
- @builder.doc_status.clear
2313
- src = <<-EOS
2314
- //#{type}{
2315
-
2316
- //#{type}{
2317
-
2318
- //}
2319
-
2320
- //}
2321
- EOS
2322
- assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2323
- assert_match(/minicolumn cannot be nested:/, @log_io.string)
2324
- end
2325
- end
2326
-
2327
- def test_minicolumn_blocks_nest_error3
2328
- %w[memo tip info warning important caution notice].each do |type|
2329
- @builder.doc_status.clear
2330
- src = <<-EOS
2331
- //#{type}{
2332
-
2333
- //note{
2334
- //}
2335
-
2336
- //}
2337
- EOS
2338
- assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2339
- assert_match(/minicolumn cannot be nested:/, @log_io.string)
2340
- end
2341
- end
2342
-
2343
- def test_inline_raw0
2344
- assert_equal 'normal', compile_inline('@<raw>{normal}')
2345
- end
2346
-
2347
- def test_inline_raw1
2348
- assert_equal 'body', compile_inline('@<raw>{|latex|body}')
2349
- end
2350
-
2351
- def test_inline_raw2
2352
- assert_equal 'body', compile_inline('@<raw>{|html, latex|body}')
2353
- end
2354
-
2355
- def test_inline_raw3
2356
- assert_equal '', compile_inline('@<raw>{|idgxml, html|body}')
2357
- end
2358
-
2359
- def test_inline_raw4
2360
- assert_equal '|latex body', compile_inline('@<raw>{|latex body}')
2361
- end
2362
-
2363
- def test_inline_raw5
2364
- assert_equal "nor\nmal", compile_inline('@<raw>{|latex|nor\\nmal}')
2365
- end
2366
-
2367
- def test_inline_endash
2368
- actual = compile_inline('- -- --- ----')
2369
- assert_equal '{-} {-}{-} {-}{-}{-} {-}{-}{-}{-}', actual
2370
- end
2371
-
2372
- def test_inline_imgref
2373
- def @chapter.image(_id)
2374
- item = Book::Index::Item.new('sampleimg', 1, 'sample photo')
2375
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
2376
- item
2377
- end
2378
-
2379
- actual = compile_block("@<imgref>{sampleimg}\n")
2380
- expected = "\n\\reviewimageref{1.1}{image:chap1:sampleimg}「sample photo」\n"
2381
- assert_equal expected, actual
2382
- end
2383
-
2384
- def test_inline_imgref2
2385
- def @chapter.image(_id)
2386
- item = Book::Index::Item.new('sampleimg', 1)
2387
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
2388
- item
2389
- end
2390
-
2391
- actual = compile_block("@<imgref>{sampleimg}\n")
2392
- expected = "\n\\reviewimageref{1.1}{image:chap1:sampleimg}\n"
2393
- assert_equal expected, actual
2394
- end
2395
-
2396
- def test_block_raw0
2397
- actual = compile_block(%Q(//raw[<>!"\\n& ]\n))
2398
- expected = %Q(<>!"\n& )
2399
- assert_equal expected, actual
2400
- end
2401
-
2402
- def test_block_raw1
2403
- actual = compile_block(%Q(//raw[|latex|<>!"\\n& ]\n))
2404
- expected = %Q(<>!"\n& )
2405
- assert_equal expected, actual
2406
- end
2407
-
2408
- def test_block_raw2
2409
- actual = compile_block(%Q(//raw[|html, latex|<>!"\\n& ]\n))
2410
- expected = %Q(<>!"\n& )
2411
- assert_equal expected, actual
2412
- end
2413
-
2414
- def test_block_raw3
2415
- actual = compile_block(%Q(//raw[|html, idgxml|<>!"\\n& ]\n))
2416
- expected = ''
2417
- assert_equal expected, actual
2418
- end
2419
-
2420
- def test_block_raw4
2421
- actual = compile_block(%Q(//raw[|latex <>!"\\n& ]\n))
2422
- expected = %Q(|latex <>!"\n& )
2423
- assert_equal expected, actual
2424
- end
2425
-
2426
- def test_comment
2427
- actual = compile_block('//comment[コメント]')
2428
- assert_equal '', actual
2429
- end
2430
-
2431
- def test_comment_for_draft
2432
- @config['draft'] = true
2433
- actual = compile_block('//comment[コメント<]')
2434
- assert_equal %Q(\\pdfcomment{コメント\\textless{}}\n), actual
2435
- actual = compile_block("//comment{\nA<>\nB&\n//}")
2436
- assert_equal %Q(\\pdfcomment{A\\textless{}\\textgreater{}\\par B\\&}\n), actual
2437
- end
2438
-
2439
- def test_inline_comment
2440
- actual = compile_inline('test @<comment>{コメント} test2')
2441
- assert_equal 'test test2', actual
2442
- end
2443
-
2444
- def test_inline_comment_for_draft
2445
- @config['draft'] = true
2446
- actual = compile_inline('test @<comment>{コメント} test2')
2447
- assert_equal 'test \\pdfcomment{コメント} test2', actual
2448
- end
2449
-
2450
- def test_inline_fence
2451
- actual = compile_inline('test @<code>|@<code>{$サンプル$}|')
2452
- assert_equal 'test \\reviewcode{@\\textless{}code\\textgreater{}\\{\\textdollar{}サンプル\\textdollar{}\\}}', actual
2453
- actual2 = compile_inline('test @<code>|@<code>{$サンプル$}|, @<m>$\begin{array}{ll}a & b\\\alpha & @\\\end{array}$')
2454
- assert_equal 'test \\reviewcode{@\\textless{}code\\textgreater{}\\{\\textdollar{}サンプル\\textdollar{}\\}}, $\begin{array}{ll}a & b\\\alpha & @\\\end{array}$', actual2
2455
- end
2456
-
2457
- def test_inline_w
2458
- Dir.mktmpdir do |dir|
2459
- File.write(File.join(dir, 'words.csv'), <<EOB
2460
- "F","foo"
2461
- "B","bar""\\<>_@<b>{BAZ}"
2462
- EOB
2463
- )
2464
- @book.config['words_file'] = File.join(dir, 'words.csv')
2465
-
2466
- io = StringIO.new
2467
- @builder.instance_eval { @logger = ReVIEW::Logger.new(io) }
2468
- actual = compile_block('@<w>{F} @<w>{B} @<wb>{B} @<w>{N}')
2469
- expected = <<-EOS
2470
-
2471
- foo bar"\\reviewbackslash{}\\textless{}\\textgreater{}\\textunderscore{}@\\textless{}b\\textgreater{}\\{BAZ\\} \\reviewbold{bar"\\reviewbackslash{}\\textless{}\\textgreater{}\\textunderscore{}@\\textless{}b\\textgreater{}\\{BAZ\\}} [missing word: N]
2472
- EOS
2473
- assert_equal expected, actual
2474
- assert_match(/WARN --: :1: word not bound: N/, io.string)
2475
- end
2476
- end
2477
-
2478
- def test_inline_unknown
2479
- assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
2480
- assert_match(/unknown image: n/, @log_io.string)
2481
-
2482
- @log_io.string = ''
2483
- assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
2484
- assert_match(/unknown footnote: n/, @log_io.string)
2485
-
2486
- @log_io.string = ''
2487
- assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
2488
- assert_match(/unknown headline: n/, @log_io.string)
2489
- %w[list table column].each do |name|
2490
- @log_io.string = ''
2491
- assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
2492
- assert_match(/unknown #{name}: n/, @log_io.string)
2493
- end
2494
- %w[chap chapref title].each do |name|
2495
- @log_io.string = ''
2496
- assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
2497
- assert_match(/key not found: "n"/, @log_io.string)
2498
- end
2499
- end
2500
-
2501
- def test_appendix_list
2502
- @chapter.instance_eval do
2503
- def on_appendix?
2504
- true
2505
- end
2506
- end
2507
- src = <<-EOS
2508
- @<list>{foo}
2509
- //list[foo][FOO]{
2510
- //}
2511
- EOS
2512
- expected = <<-EOS
2513
-
2514
- \\reviewlistref{A.1}
2515
-
2516
- \\begin{reviewlistblock}
2517
- \\reviewlistcaption{リストA.1: FOO}
2518
- \\begin{reviewlist}
2519
- \\end{reviewlist}
2520
- \\end{reviewlistblock}
2521
- EOS
2522
- actual = compile_block(src)
2523
- assert_equal expected, actual
2524
- end
2525
-
2526
- def test_appendix_table
2527
- @chapter.instance_eval do
2528
- def on_appendix?
2529
- true
2530
- end
2531
- end
2532
- src = <<-EOS
2533
- @<table>{foo}
2534
- //table[foo][FOO]{
2535
- A B
2536
- //}
2537
- EOS
2538
- expected = <<-EOS
2539
-
2540
- \\reviewtableref{A.1}{table:chap1:foo}
2541
-
2542
- \\begin{table}%%foo
2543
- \\reviewtablecaption{FOO}
2544
- \\label{table:chap1:foo}
2545
- \\begin{reviewtable}{|l|l|}
2546
- \\hline
2547
- \\reviewth{A} & B \\\\ \\hline
2548
- \\end{reviewtable}
2549
- \\end{table}
2550
- EOS
2551
- actual = compile_block(src)
2552
- assert_equal expected, actual
2553
- end
2554
-
2555
- def test_appendix_image
2556
- @chapter.instance_eval do
2557
- def on_appendix?
2558
- true
2559
- end
2560
- end
2561
-
2562
- def @chapter.image(_id)
2563
- item = Book::Index::Item.new('sampleimg', 1)
2564
- item.instance_eval { @path = './images/chap1-sampleimg.png' }
2565
- item
2566
- end
2567
-
2568
- src = <<-EOS
2569
- @<img>{sampleimg}
2570
- //image[sampleimg][FOO]{
2571
- //}
2572
- EOS
2573
- expected = <<-EOS
2574
-
2575
- \\reviewimageref{A.1}{image:chap1:sampleimg}
2576
-
2577
- \\begin{reviewimage}%%sampleimg
2578
- \\reviewincludegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}
2579
- \\reviewimagecaption{FOO}
2580
- \\label{image:chap1:sampleimg}
2581
- \\end{reviewimage}
2582
- EOS
2583
- actual = compile_block(src)
2584
- assert_equal expected, actual
2585
- end
2586
-
2587
- def test_texequation
2588
- src = <<-EOS
2589
- //texequation{
2590
- e=mc^2
2591
- //}
2592
- EOS
2593
- expected = <<-EOS
2594
-
2595
- \\begin{equation*}
2596
- e=mc^2
2597
- \\end{equation*}
2598
- EOS
2599
- actual = compile_block(src)
2600
- assert_equal expected, actual
2601
- end
2602
-
2603
- def test_texequation_with_caption
2604
- src = <<-EOS
2605
- @<eq>{emc2}
2606
-
2607
- //texequation[emc2][The Equivalence of Mass @<i>{and} Energy]{
2608
- e=mc^2
2609
- //}
2610
- EOS
2611
- expected = <<-EOS
2612
-
2613
- \\reviewequationref{1.1}
2614
-
2615
- \\begin{reviewequationblock}
2616
- \\reviewequationcaption{式1.1: The Equivalence of Mass \\reviewit{and} Energy}
2617
- \\begin{equation*}
2618
- e=mc^2
2619
- \\end{equation*}
2620
- \\end{reviewequationblock}
2621
- EOS
2622
- actual = compile_block(src)
2623
- assert_equal expected, actual
2624
-
2625
- @config['caption_position']['equation'] = 'bottom'
2626
- expected = <<-EOS
2627
-
2628
- \\reviewequationref{1.1}
2629
-
2630
- \\begin{reviewequationblock}
2631
- \\begin{equation*}
2632
- e=mc^2
2633
- \\end{equation*}
2634
- \\reviewequationcaption{式1.1: The Equivalence of Mass \\reviewit{and} Energy}
2635
- \\end{reviewequationblock}
2636
- EOS
2637
- actual = compile_block(src)
2638
- assert_equal expected, actual
2639
- end
2640
-
2641
- def test_nest_error_close1
2642
- src = <<-EOS
2643
- //beginchild
2644
- EOS
2645
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2646
- assert_equal ":1: //beginchild is shown, but previous element isn't ul, ol, or dl", e.message
2647
- end
2648
-
2649
- def test_nest_error_close2
2650
- src = <<-EOS
2651
- * foo
2652
-
2653
- //beginchild
2654
-
2655
- 1. foo
2656
-
2657
- //beginchild
2658
-
2659
- : foo
2660
-
2661
- //beginchild
2662
- EOS
2663
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2664
- assert_equal ':12: //beginchild of dl,ol,ul misses //endchild', e.message
2665
- end
2666
-
2667
- def test_nest_error_close3
2668
- src = <<-EOS
2669
- * foo
2670
-
2671
- //beginchild
2672
-
2673
- 1. foo
2674
-
2675
- //beginchild
2676
-
2677
- : foo
2678
-
2679
- //beginchild
2680
-
2681
- //endchild
2682
- EOS
2683
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2684
- assert_equal ':14: //beginchild of ol,ul misses //endchild', e.message
2685
- end
2686
-
2687
- def test_nest_ul
2688
- src = <<-EOS
2689
- * UL1
2690
-
2691
- //beginchild
2692
-
2693
- 1. UL1-OL1
2694
- 2. UL1-OL2
2695
-
2696
- * UL1-UL1
2697
- * UL1-UL2
2698
-
2699
- : UL1-DL1
2700
- UL1-DD1
2701
- : UL1-DL2
2702
- UL1-DD2
2703
-
2704
- //endchild
2705
-
2706
- * UL2
2707
-
2708
- //beginchild
2709
-
2710
- UL2-PARA
2711
-
2712
- //endchild
2713
- EOS
2714
-
2715
- expected = <<-EOS
2716
-
2717
- \\begin{itemize}
2718
- \\item UL1
2719
-
2720
-
2721
- \\begin{enumerate}
2722
- \\item UL1{-}OL1
2723
- \\item UL1{-}OL2
2724
- \\end{enumerate}
2725
-
2726
- \\begin{itemize}
2727
- \\item UL1{-}UL1
2728
- \\item UL1{-}UL2
2729
- \\end{itemize}
2730
-
2731
- \\begin{description}
2732
- \\item[UL1{-}DL1] \\mbox{} \\\\
2733
- UL1{-}DD1
2734
- \\item[UL1{-}DL2] \\mbox{} \\\\
2735
- UL1{-}DD2
2736
- \\end{description}
2737
-
2738
-
2739
- \\item UL2
2740
-
2741
-
2742
- UL2{-}PARA
2743
-
2744
- \\end{itemize}
2745
- EOS
2746
-
2747
- actual = compile_block(src)
2748
- assert_equal expected, actual
2749
- end
2750
-
2751
- def test_nest_ol
2752
- src = <<-EOS
2753
- 1. OL1
2754
-
2755
- //beginchild
2756
-
2757
- 1. OL1-OL1
2758
- 2. OL1-OL2
2759
-
2760
- * OL1-UL1
2761
- * OL1-UL2
2762
-
2763
- : OL1-DL1
2764
- OL1-DD1
2765
- : OL1-DL2
2766
- OL1-DD2
2767
-
2768
- //endchild
2769
-
2770
- 2. OL2
2771
-
2772
- //beginchild
2773
-
2774
- OL2-PARA
2775
-
2776
- //endchild
2777
- EOS
2778
-
2779
- expected = <<-EOS
2780
-
2781
- \\begin{enumerate}
2782
- \\item OL1
2783
-
2784
-
2785
- \\begin{enumerate}
2786
- \\item OL1{-}OL1
2787
- \\item OL1{-}OL2
2788
- \\end{enumerate}
2789
-
2790
- \\begin{itemize}
2791
- \\item OL1{-}UL1
2792
- \\item OL1{-}UL2
2793
- \\end{itemize}
2794
-
2795
- \\begin{description}
2796
- \\item[OL1{-}DL1] \\mbox{} \\\\
2797
- OL1{-}DD1
2798
- \\item[OL1{-}DL2] \\mbox{} \\\\
2799
- OL1{-}DD2
2800
- \\end{description}
2801
-
2802
-
2803
- \\item OL2
2804
-
2805
-
2806
- OL2{-}PARA
2807
-
2808
- \\end{enumerate}
2809
- EOS
2810
-
2811
- actual = compile_block(src)
2812
- assert_equal expected, actual
2813
- end
2814
-
2815
- def test_nest_dl
2816
- src = <<-EOS
2817
- : DL1
2818
-
2819
- //beginchild
2820
-
2821
- 1. DL1-OL1
2822
- 2. DL1-OL2
2823
-
2824
- * DL1-UL1
2825
- * DL1-UL2
2826
-
2827
- : DL1-DL1
2828
- DL1-DD1
2829
- : DL1-DL2
2830
- DL1-DD2
2831
-
2832
- //endchild
2833
-
2834
- : DL2
2835
- DD2
2836
-
2837
- //beginchild
2838
-
2839
- * DD2-UL1
2840
- * DD2-UL2
2841
-
2842
- DD2-PARA
2843
-
2844
- //endchild
2845
- EOS
2846
-
2847
- expected = <<-EOS
2848
-
2849
- \\begin{description}
2850
- \\item[DL1] \\mbox{} \\\\
2851
-
2852
-
2853
-
2854
- \\begin{enumerate}
2855
- \\item DL1{-}OL1
2856
- \\item DL1{-}OL2
2857
- \\end{enumerate}
2858
-
2859
- \\begin{itemize}
2860
- \\item DL1{-}UL1
2861
- \\item DL1{-}UL2
2862
- \\end{itemize}
2863
-
2864
- \\begin{description}
2865
- \\item[DL1{-}DL1] \\mbox{} \\\\
2866
- DL1{-}DD1
2867
- \\item[DL1{-}DL2] \\mbox{} \\\\
2868
- DL1{-}DD2
2869
- \\end{description}
2870
-
2871
-
2872
- \\item[DL2] \\mbox{} \\\\
2873
- DD2
2874
-
2875
-
2876
- \\begin{itemize}
2877
- \\item DD2{-}UL1
2878
- \\item DD2{-}UL2
2879
- \\end{itemize}
2880
-
2881
- DD2{-}PARA
2882
-
2883
- \\end{description}
2884
- EOS
2885
-
2886
- actual = compile_block(src)
2887
- assert_equal expected, actual
2888
- end
2889
-
2890
- def test_nest_multi
2891
- src = <<-EOS
2892
- 1. OL1
2893
-
2894
- //beginchild
2895
-
2896
- 1. OL1-OL1
2897
-
2898
- //beginchild
2899
-
2900
- * OL1-OL1-UL1
2901
-
2902
- OL1-OL1-PARA
2903
-
2904
- //endchild
2905
-
2906
- 2. OL1-OL2
2907
-
2908
- * OL1-UL1
2909
-
2910
- //beginchild
2911
-
2912
- : OL1-UL1-DL1
2913
- OL1-UL1-DD1
2914
-
2915
- OL1-UL1-PARA
2916
-
2917
- //endchild
2918
-
2919
- * OL1-UL2
2920
-
2921
- //endchild
2922
- EOS
2923
- expected = <<-EOS
2924
-
2925
- \\begin{enumerate}
2926
- \\item OL1
2927
-
2928
-
2929
- \\begin{enumerate}
2930
- \\item OL1{-}OL1
2931
-
2932
-
2933
- \\begin{itemize}
2934
- \\item OL1{-}OL1{-}UL1
2935
- \\end{itemize}
2936
-
2937
- OL1{-}OL1{-}PARA
2938
-
2939
-
2940
- \\item OL1{-}OL2
2941
- \\end{enumerate}
2942
-
2943
- \\begin{itemize}
2944
- \\item OL1{-}UL1
2945
-
2946
-
2947
- \\begin{description}
2948
- \\item[OL1{-}UL1{-}DL1] \\mbox{} \\\\
2949
- OL1{-}UL1{-}DD1
2950
- \\end{description}
2951
-
2952
- OL1{-}UL1{-}PARA
2953
-
2954
-
2955
- \\item OL1{-}UL2
2956
- \\end{itemize}
2957
-
2958
- \\end{enumerate}
2959
- EOS
2960
-
2961
- actual = compile_block(src)
2962
- assert_equal expected, actual
2963
- end
2964
- end