review 5.6.0 → 5.7.0

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