review 2.5.0 → 3.0.0.preview1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +28 -10
- data/.travis.yml +11 -2
- data/NEWS.ja.md +89 -17
- data/NEWS.md +92 -0
- data/README.md +1 -1
- data/Rakefile +0 -13
- data/bin/review-catalog-converter +83 -37
- data/bin/review-check +17 -5
- data/bin/review-compile +1 -1
- data/bin/review-index +6 -0
- data/bin/review-init +3 -155
- data/bin/review-preproc +0 -5
- data/bin/review-validate +21 -7
- data/bin/review-vol +13 -5
- data/doc/config.yml.sample +12 -7
- data/doc/config.yml.sample-simple +1 -1
- data/doc/format.ja.md +39 -3
- data/doc/format.md +39 -3
- data/doc/format_idg.ja.md +0 -4
- data/doc/pdfmaker.ja.md +1 -1
- data/doc/pdfmaker.md +1 -1
- data/doc/sample.css +7 -0
- data/lib/epubmaker/content.rb +31 -12
- data/lib/epubmaker/epubcommon.rb +10 -3
- data/lib/epubmaker/epubv2.rb +11 -3
- data/lib/epubmaker/epubv3.rb +11 -3
- data/lib/epubmaker/producer.rb +55 -20
- data/lib/review/book/base.rb +63 -48
- data/lib/review/book/chapter.rb +19 -7
- data/lib/review/book/compilable.rb +5 -20
- data/lib/review/book/image_finder.rb +10 -3
- data/lib/review/book/index.rb +30 -9
- data/lib/review/book/part.rb +9 -6
- data/lib/review/book.rb +0 -14
- data/lib/review/builder.rb +110 -18
- data/lib/review/catalog.rb +24 -4
- data/lib/review/compiler.rb +3 -1
- data/lib/review/configure.rb +43 -9
- data/lib/review/epubmaker/reviewheaderlistener.rb +57 -0
- data/lib/review/epubmaker.rb +129 -85
- data/lib/review/htmlbuilder.rb +76 -58
- data/lib/review/htmlutils.rb +20 -13
- data/lib/review/i18n.rb +6 -2
- data/lib/review/idgxmlbuilder.rb +52 -41
- data/lib/review/init.rb +194 -0
- data/lib/review/latexbuilder.rb +118 -34
- data/lib/review/latexutils.rb +5 -5
- data/lib/review/logger.rb +2 -1
- data/lib/review/makerhelper.rb +1 -1
- data/lib/review/markdownbuilder.rb +66 -6
- data/lib/review/md2inaobuilder.rb +2 -2
- data/lib/review/pdfmaker.rb +74 -22
- data/lib/review/plaintextbuilder.rb +8 -4
- data/lib/review/preprocessor.rb +14 -17
- data/lib/review/sec_counter.rb +8 -2
- data/lib/review/textmaker.rb +2 -2
- data/lib/review/textutils.rb +9 -2
- data/lib/review/tocparser.rb +7 -4
- data/lib/review/tocprinter.rb +3 -1
- data/lib/review/version.rb +1 -1
- data/lib/review/webmaker.rb +19 -7
- data/lib/review/webtocprinter.rb +8 -4
- data/review.gemspec +4 -3
- data/templates/latex/config.erb +84 -0
- data/templates/latex/layout.tex.erb +76 -361
- data/templates/latex/review-jlreq/README.md +22 -0
- data/templates/latex/review-jlreq/review-base.sty +178 -0
- data/templates/latex/review-jlreq/review-custom.sty +1 -0
- data/templates/latex/review-jlreq/review-jlreq.cls +141 -0
- data/templates/latex/review-jlreq/review-style.sty +149 -0
- data/templates/latex/review-jlreq/reviewmacro.sty +8 -0
- data/templates/latex/review-jsbook/jumoline.sty +310 -0
- data/templates/latex/review-jsbook/plistings.sty +326 -0
- data/templates/latex/review-jsbook/review-base.sty +405 -0
- data/templates/latex/review-jsbook/review-custom.sty +1 -0
- data/templates/latex/review-jsbook/review-style.sty +38 -0
- data/templates/latex/review-jsbook/reviewmacro.sty +8 -0
- data/templates/latex-compat2/layout.tex.erb +387 -0
- data/test/assets/test_template.tex +105 -235
- data/test/assets/test_template_backmatter.tex +133 -14
- data/test/book_test_helper.rb +1 -1
- data/test/run_test.rb +2 -0
- data/test/sample-book/src/Rakefile +11 -6
- data/test/sample-book/src/config.yml +2 -2
- data/test/sample-book/src/sty/reviewmacro.sty +1 -39
- data/test/sample-book/src/style.css +6 -0
- data/test/syntax-book/config.yml +1 -1
- data/test/test_book.rb +13 -16
- data/test/test_book_chapter.rb +4 -10
- data/test/test_book_part.rb +4 -3
- data/test/test_catalog.rb +15 -4
- data/test/test_helper.rb +2 -2
- data/test/test_htmlbuilder.rb +78 -10
- data/test/test_htmlutils.rb +12 -5
- data/test/test_idgxmlbuilder.rb +1 -1
- data/test/test_latexbuilder.rb +94 -49
- data/test/test_latexbuilder_v2.rb +1077 -0
- data/test/test_logger.rb +20 -0
- data/test/test_markdownbuilder.rb +10 -0
- data/test/test_pdfmaker.rb +6 -7
- data/test/test_plaintextbuilder.rb +1 -1
- data/test/test_review_ext.rb +0 -1
- data/test/test_rstbuilder.rb +1 -1
- data/test/test_topbuilder.rb +19 -7
- data/test/test_webtocprinter.rb +14 -14
- data/{test/sample-book/src/vendor → vendor}/jumoline/README +0 -0
- data/{test/sample-book/src/vendor → vendor}/jumoline/jumoline.dtx +0 -0
- data/{test/sample-book/src/vendor → vendor}/jumoline/jumoline.ins +0 -0
- data/{test/sample-book/src/vendor → vendor}/jumoline/lppl.txt +0 -0
- data/vendor/plistings/.gitignore +9 -0
- data/vendor/plistings/LICENSE +21 -0
- data/vendor/plistings/README.md +18 -0
- data/vendor/plistings/plistings.sty +326 -0
- data/vendor/plistings/test1.tex +174 -0
- data/vendor/plistings/test2.tex +54 -0
- metadata +48 -19
- data/lib/review/unfold.rb +0 -129
- data/test/CHAPS +0 -2
- data/test/bib.re +0 -13
- data/test/test.re +0 -43
@@ -0,0 +1,1077 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'review/compiler'
|
3
|
+
require 'review/book'
|
4
|
+
require 'review/latexbuilder'
|
5
|
+
require 'review/i18n'
|
6
|
+
|
7
|
+
class LATEXBuidlerV2Test < 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
|
+
'image_scale2width' => false,
|
18
|
+
'texcommand' => 'uplatex',
|
19
|
+
'review_version' => '2.0'
|
20
|
+
)
|
21
|
+
@book = Book::Base.new
|
22
|
+
@book.config = @config
|
23
|
+
@compiler = ReVIEW::Compiler.new(@builder)
|
24
|
+
@chapter = Book::Chapter.new(@book, 1, 'chap1', nil, StringIO.new)
|
25
|
+
location = Location.new(nil, nil)
|
26
|
+
@builder.bind(@compiler, @chapter, location)
|
27
|
+
I18n.setup('ja')
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_headline_level1
|
31
|
+
actual = compile_block("={test} this is test.\n")
|
32
|
+
assert_equal %Q(\\chapter{this is test.}\n\\label{chap:chap1}\n), actual
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_headline_level1_without_secno
|
36
|
+
@config['secnolevel'] = 0
|
37
|
+
actual = compile_block("={test} this is test.\n")
|
38
|
+
assert_equal %Q(\\chapter*{this is test.}\n\\addcontentsline{toc}{chapter}{this is test.}\n\\label{chap:chap1}\n), actual
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_headline_level1_with_inlinetag
|
42
|
+
actual = compile_block(%Q(={test} this @<b>{is} test.<&"_>\n))
|
43
|
+
assert_equal %Q(\\chapter{this \\textbf{is} test.\\textless{}\\&"\\textunderscore{}\\textgreater{}}\n\\label{chap:chap1}\n), actual
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_headline_level2
|
47
|
+
actual = compile_block("=={test} this is test.\n")
|
48
|
+
assert_equal %Q(\\section{this is test.}\n\\label{sec:1-1}\n\\label{test}\n), actual
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_headline_level3
|
52
|
+
actual = compile_block("==={test} this is test.\n")
|
53
|
+
assert_equal %Q(\\subsection*{this is test.}\n\\label{sec:1-0-1}\n\\label{test}\n), actual
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_headline_level3_with_secno
|
57
|
+
@config['secnolevel'] = 3
|
58
|
+
actual = compile_block("==={test} this is test.\n")
|
59
|
+
assert_equal %Q(\\subsection{this is test.}\n\\label{sec:1-0-1}\n\\label{test}\n), actual
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_label
|
63
|
+
actual = compile_block("//label[label_test]\n")
|
64
|
+
assert_equal %Q(\\label{label_test}\n), actual
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_href
|
68
|
+
actual = compile_inline('@<href>{http://github.com,GitHub}')
|
69
|
+
assert_equal '\\href{http://github.com}{GitHub}', actual
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_inline_href
|
73
|
+
actual = compile_inline('@<href>{http://github.com,Git\\,Hub}')
|
74
|
+
assert_equal '\\href{http://github.com}{Git,Hub}', actual
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_href_without_label
|
78
|
+
actual = compile_inline('@<href>{http://github.com}')
|
79
|
+
assert_equal '\\url{http://github.com}', actual
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_href_with_underscore
|
83
|
+
actual = compile_inline('@<href>{http://example.com/aaa/bbb, AAA_BBB}')
|
84
|
+
assert_equal '\\href{http://example.com/aaa/bbb}{AAA\\textunderscore{}BBB}', actual
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_href_mailto
|
88
|
+
actual = compile_inline('@<href>{mailto:takahashim@example.com, takahashim@example.com}')
|
89
|
+
assert_equal '\\href{mailto:takahashim@example.com}{takahashim@example.com}', actual
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_inline_br
|
93
|
+
actual = compile_inline('@<br>{}')
|
94
|
+
assert_equal %Q(\\\\\n), actual
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_inline_br_with_other_strings
|
98
|
+
actual = compile_inline('abc@<br>{}def')
|
99
|
+
assert_equal %Q(abc\\\\\ndef), actual
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_inline_i
|
103
|
+
actual = compile_inline('abc@<i>{def}ghi')
|
104
|
+
assert_equal 'abc\\textit{def}ghi', actual
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_inline_i_and_escape
|
108
|
+
actual = compile_inline('test @<i>{inline<&;\\ test} test2')
|
109
|
+
assert_equal 'test \\textit{inline\\textless{}\\&;\\reviewbackslash{} test} test2', actual
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_inline_dtp
|
113
|
+
actual = compile_inline('abc@<dtp>{def}ghi')
|
114
|
+
assert_equal 'abcghi', actual
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_inline_code
|
118
|
+
actual = compile_inline('abc@<code>{def}ghi')
|
119
|
+
assert_equal 'abc\\texttt{def}ghi', actual
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_inline_raw
|
123
|
+
actual = compile_inline('@<raw>{@<tt>{inline!$%\\}}')
|
124
|
+
assert_equal '@<tt>{inline!$%}', actual
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_inline_sup
|
128
|
+
actual = compile_inline('abc@<sup>{def}')
|
129
|
+
assert_equal 'abc\\textsuperscript{def}', actual
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_inline_sub
|
133
|
+
actual = compile_inline('abc@<sub>{def}')
|
134
|
+
assert_equal 'abc\\textsubscript{def}', actual
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_inline_b
|
138
|
+
actual = compile_inline('abc@<b>{def}')
|
139
|
+
assert_equal 'abc\\textbf{def}', actual
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_inline_b_and_escape
|
143
|
+
actual = compile_inline('test @<b>{inline<&;\\ test} test2')
|
144
|
+
assert_equal 'test \\textbf{inline\\textless{}\\&;\\reviewbackslash{} test} test2', actual
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_inline_em
|
148
|
+
actual = compile_inline('abc@<em>{def}')
|
149
|
+
assert_equal 'abc\\reviewem{def}', actual
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_inline_strong
|
153
|
+
actual = compile_inline('abc@<strong>{def}')
|
154
|
+
assert_equal 'abc\\reviewstrong{def}', actual
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_inline_u
|
158
|
+
actual = compile_inline('abc@<u>{def}ghi')
|
159
|
+
assert_equal 'abc\\reviewunderline{def}ghi', actual
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_inline_m
|
163
|
+
actual = compile_inline('abc@<m>{\\alpha^n = \\inf < 2}ghi')
|
164
|
+
assert_equal 'abc $\\alpha^n = \\inf < 2$ ghi', actual
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_inline_m2
|
168
|
+
## target text: @<m>{X = \{ {x_1\},{x_2\}, \cdots ,{x_n\} \\\}}
|
169
|
+
actual = compile_inline('@<m>{X = \\{ {x_1\\},{x_2\\}, \\cdots ,{x_n\\} \\\\\\}}')
|
170
|
+
## expected text: $X = \{ {x_1},{x_2}, \cdots ,{x_n} \}$
|
171
|
+
assert_equal ' $X = \\{ {x_1},{x_2}, \\cdots ,{x_n} \\}$ ', actual
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_inline_tt
|
175
|
+
actual = compile_inline('test @<tt>{inline test} test2')
|
176
|
+
assert_equal 'test \\texttt{inline test} test2', actual
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_inline_tt_endash
|
180
|
+
actual = compile_inline('test @<tt>{in-line --test ---foo ----bar -----buz} --test2')
|
181
|
+
assert_equal 'test \\texttt{in{-}line {-}{-}test {-}{-}{-}foo {-}{-}{-}{-}bar {-}{-}{-}{-}{-}buz} {-}{-}test2', actual
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_inline_tti
|
185
|
+
actual = compile_inline('test @<tti>{inline test} test2')
|
186
|
+
assert_equal 'test \\texttt{\\textit{inline test}} test2', actual
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_inline_ttb
|
190
|
+
actual = compile_inline('test @<ttb>{inline test} test2')
|
191
|
+
assert_equal 'test \\texttt{\\textbf{inline test}} test2', actual
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_inline_hd_chap
|
195
|
+
def @chapter.headline_index
|
196
|
+
items = [Book::HeadlineIndex::Item.new('chap1|test', [1, 1], 'te_st')]
|
197
|
+
Book::HeadlineIndex.new(items, self)
|
198
|
+
end
|
199
|
+
|
200
|
+
@config['secnolevel'] = 3
|
201
|
+
actual = compile_inline('test @<hd>{chap1|test} test2')
|
202
|
+
assert_equal 'test 「1.1.1 te\\textunderscore{}st」 test2', actual
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_inline_pageref
|
206
|
+
actual = compile_inline('test p.@<pageref>{p1}')
|
207
|
+
assert_equal 'test p.\pageref{p1}', actual
|
208
|
+
end
|
209
|
+
|
210
|
+
def test_inline_ruby_comma
|
211
|
+
actual = compile_inline('@<ruby>{foo\\, bar\\, buz,フー・バー・バズ}')
|
212
|
+
assert_equal '\\ruby{foo, bar, buz}{フー・バー・バズ}', actual
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_inline_uchar
|
216
|
+
actual = compile_inline('test @<uchar>{2460} test2')
|
217
|
+
assert_equal 'test ① test2', actual
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_inline_idx
|
221
|
+
actual = compile_inline('@<idx>{__TEST%$}, @<hidx>{__TEST%$}')
|
222
|
+
assert_equal '\\textunderscore{}\\textunderscore{}TEST\\%\\textdollar{}\\index{__TEST%$@\\textunderscore{}\\textunderscore{}TEST\\%\\textdollar{}}, \\index{__TEST%$@\\textunderscore{}\\textunderscore{}TEST\\%\\textdollar{}}', actual
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_inline_idx_yomi
|
226
|
+
begin
|
227
|
+
require 'MeCab'
|
228
|
+
require 'nkf'
|
229
|
+
rescue LoadError
|
230
|
+
$stderr.puts 'skip test_inline_idx_yomi (cannot find MeCab)'
|
231
|
+
return true
|
232
|
+
end
|
233
|
+
tmpdir = Dir.mktmpdir
|
234
|
+
File.write("#{tmpdir}/sample.dic", "強運\tはーどらっく\n")
|
235
|
+
@book.config['pdfmaker']['makeindex'] = true
|
236
|
+
@book.config['pdfmaker']['makeindex_dic'] = "#{tmpdir}/sample.dic"
|
237
|
+
@builder.setup_index
|
238
|
+
actual = compile_inline('@<hidx>{漢字}@<hidx>{強運}@<hidx>{項目@1<<>>項目@2}')
|
239
|
+
FileUtils.remove_entry_secure(tmpdir)
|
240
|
+
assert_equal %Q(\\index{かんじ@漢字}\\index{はーどらっく@強運}\\index{こうもく"@1@項目"@1!こうもく"@2@項目"@2}), actual
|
241
|
+
end
|
242
|
+
|
243
|
+
def test_jis_x_0201_kana
|
244
|
+
# uplatex can handle half-width kana natively
|
245
|
+
actual = compile_inline('foo・カンジ、テスト')
|
246
|
+
assert_equal 'foo・カンジ、テスト', actual
|
247
|
+
# assert_equal %Q(foo\\aj半角{・}\\aj半角{カ}\\aj半角{ン}\\aj半角{シ}\\aj半角{゛}\\aj半角{、}テスト), actual
|
248
|
+
end
|
249
|
+
|
250
|
+
def test_dlist
|
251
|
+
actual = compile_block(": foo\n foo.\n bar.\n")
|
252
|
+
assert_equal %Q(\n\\begin{description}\n\\item[foo] \\mbox{} \\\\\nfoo.bar.\n\\end{description}\n), actual
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_dlist_with_bracket
|
256
|
+
actual = compile_block(": foo[bar]\n foo.\n bar.\n")
|
257
|
+
assert_equal %Q(\n\\begin{description}\n\\item[foo\\lbrack{}bar\\rbrack{}] \\mbox{} \\\\\nfoo.bar.\n\\end{description}\n), actual
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_dlist_beforeulol
|
261
|
+
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")
|
262
|
+
assert_equal %Q(\n\\begin{description}\n\\item[foo] \\mbox{} \\\\\nfoo.\n\\end{description}\n\npara\n\n\\begin{description}\n\\item[foo] \\mbox{} \\\\\nfoo.\n\\end{description}\n\n\\begin{enumerate}\n\\item bar\n\\end{enumerate}\n\n\\begin{description}\n\\item[foo] \\mbox{} \\\\\nfoo.\n\\end{description}\n\n\\begin{itemize}\n\\item bar\n\\end{itemize}\n), actual
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_cmd
|
266
|
+
actual = compile_block("//cmd{\nfoo\nbar\n\nbuz\n//}\n")
|
267
|
+
assert_equal %Q(\n\\begin{reviewcmd}\nfoo\nbar\n\nbuz\n\\end{reviewcmd}\n), actual
|
268
|
+
end
|
269
|
+
|
270
|
+
def test_cmd_caption
|
271
|
+
actual = compile_block("//cmd[cap1]{\nfoo\nbar\n\nbuz\n//}\n")
|
272
|
+
assert_equal %Q(\n\\reviewcmdcaption{cap1}\n\\begin{reviewcmd}\nfoo\nbar\n\nbuz\n\\end{reviewcmd}\n), actual
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_cmd_lst
|
276
|
+
@book.config['highlight'] = {}
|
277
|
+
@book.config['highlight']['latex'] = 'listings'
|
278
|
+
actual = compile_block("//cmd{\nfoo\nbar\n\nbuz\n//}\n")
|
279
|
+
assert_equal %Q(\\vspace{-1.5em}\\begin{reviewcmdlst}[title={\\relax},language={}]\nfoo\nbar\n\nbuz\n\\end{reviewcmdlst}\n), actual
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_emlist
|
283
|
+
actual = compile_block("//emlist{\nfoo\nbar\n\nbuz\n//}\n")
|
284
|
+
assert_equal %Q(\n\\begin{reviewemlist}\nfoo\nbar\n\nbuz\n\\end{reviewemlist}\n), actual
|
285
|
+
end
|
286
|
+
|
287
|
+
def test_emlist_lst
|
288
|
+
@book.config['highlight'] = {}
|
289
|
+
@book.config['highlight']['latex'] = 'listings'
|
290
|
+
actual = compile_block("//emlist[][sql]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n")
|
291
|
+
assert_equal %Q(\n\\vspace{-1.5em}\\begin{reviewemlistlst}[title={\\relax},language={sql}]\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n\\end{reviewemlistlst}\n), actual
|
292
|
+
end
|
293
|
+
|
294
|
+
def test_emlist_lst_without_lang
|
295
|
+
@book.config['highlight'] = {}
|
296
|
+
@book.config['highlight']['latex'] = 'listings'
|
297
|
+
@book.config['highlight']['lang'] = 'sql'
|
298
|
+
actual = compile_block("//emlist[]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n")
|
299
|
+
assert_equal %Q(\n\\vspace{-1.5em}\\begin{reviewemlistlst}[title={\\relax},language={sql}]\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n\\end{reviewemlistlst}\n), actual
|
300
|
+
end
|
301
|
+
|
302
|
+
def test_emlist_caption
|
303
|
+
actual = compile_block("//emlist[cap1]{\nfoo\nbar\n\nbuz\n//}\n")
|
304
|
+
assert_equal %Q(\n\\reviewemlistcaption{cap1}\n\\begin{reviewemlist}\nfoo\nbar\n\nbuz\n\\end{reviewemlist}\n), actual
|
305
|
+
end
|
306
|
+
|
307
|
+
def test_emlist_empty_caption
|
308
|
+
actual = compile_block("//emlist[]{\nfoo\nbar\n\nbuz\n//}\n")
|
309
|
+
assert_equal %Q(\n\\begin{reviewemlist}\nfoo\nbar\n\nbuz\n\\end{reviewemlist}\n), actual
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_emlist_with_tab
|
313
|
+
actual = compile_block("//emlist{\n\tfoo\n\t\tbar\n\n\tbuz\n//}\n")
|
314
|
+
assert_equal %Q(\n\\begin{reviewemlist}\n foo\n bar\n\n buz\n\\end{reviewemlist}\n), actual
|
315
|
+
end
|
316
|
+
|
317
|
+
def test_emlist_with_tab4
|
318
|
+
@config['tabwidth'] = 4
|
319
|
+
actual = compile_block("//emlist{\n\tfoo\n\t\tbar\n\n\tbuz\n//}\n")
|
320
|
+
assert_equal %Q(\n\\begin{reviewemlist}\n foo\n bar\n\n buz\n\\end{reviewemlist}\n), actual
|
321
|
+
end
|
322
|
+
|
323
|
+
def test_emlistnum_caption
|
324
|
+
actual = compile_block("//emlistnum[cap1]{\nfoo\nbar\n\nbuz\n//}\n")
|
325
|
+
assert_equal %Q(\n\\reviewemlistcaption{cap1}\n\\begin{reviewemlist}\n 1: foo\n 2: bar\n 3: \n 4: buz\n\\end{reviewemlist}\n), actual
|
326
|
+
end
|
327
|
+
|
328
|
+
def test_list
|
329
|
+
actual = compile_block("//list[id1][cap1]{\nfoo\nbar\n\nbuz\n//}\n")
|
330
|
+
assert_equal %Q(\\reviewlistcaption{リスト1.1: cap1}\n\\begin{reviewlist}\nfoo\nbar\n\nbuz\n\\end{reviewlist}\n), actual
|
331
|
+
end
|
332
|
+
|
333
|
+
def test_list_lst
|
334
|
+
@book.config['highlight'] = {}
|
335
|
+
@book.config['highlight']['latex'] = 'listings'
|
336
|
+
actual = compile_block("//list[id1][cap1][sql]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n")
|
337
|
+
assert_equal %Q(\\begin{reviewlistlst}[caption={cap1},language={sql}]\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n\\end{reviewlistlst}\n), actual
|
338
|
+
end
|
339
|
+
|
340
|
+
def test_list_lst_with_lang
|
341
|
+
@book.config['highlight'] = {}
|
342
|
+
@book.config['highlight']['latex'] = 'listings'
|
343
|
+
@book.config['highlight']['lang'] = 'sql'
|
344
|
+
actual = compile_block("//list[id1][cap1]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n")
|
345
|
+
assert_equal %Q(\\begin{reviewlistlst}[caption={cap1},language={sql}]\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n\\end{reviewlistlst}\n), actual
|
346
|
+
end
|
347
|
+
|
348
|
+
def test_listnum
|
349
|
+
actual = compile_block("//listnum[test1][ruby]{\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n//}\n")
|
350
|
+
assert_equal %Q(\\reviewlistcaption{リスト1.1: ruby}\n\\begin{reviewlist}\n 1: class Foo\n 2: def foo\n 3: bar\n 4: \n 5: buz\n 6: end\n 7: end\n\\end{reviewlist}\n), actual
|
351
|
+
end
|
352
|
+
|
353
|
+
def test_listnum_linenum
|
354
|
+
actual = compile_block("//firstlinenum[100]\n//listnum[test1][ruby]{\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n//}\n")
|
355
|
+
assert_equal %Q(\\reviewlistcaption{リスト1.1: ruby}\n\\begin{reviewlist}\n100: class Foo\n101: def foo\n102: bar\n103: \n104: buz\n105: end\n106: end\n\\end{reviewlist}\n), actual
|
356
|
+
end
|
357
|
+
|
358
|
+
def test_listnum_lst
|
359
|
+
@book.config['highlight'] = {}
|
360
|
+
@book.config['highlight']['latex'] = 'listings'
|
361
|
+
actual = compile_block("//listnum[test1][ruby]{\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n//}\n")
|
362
|
+
assert_equal %Q(\\begin{reviewlistnumlst}[caption={ruby},language={}]\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n\\end{reviewlistnumlst}\n), actual
|
363
|
+
end
|
364
|
+
|
365
|
+
def test_listnum_lst_linenum
|
366
|
+
@book.config['highlight'] = {}
|
367
|
+
@book.config['highlight']['latex'] = 'listings'
|
368
|
+
actual = compile_block("//firstlinenum[100]\n//listnum[test1][ruby]{\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n//}\n")
|
369
|
+
assert_equal %Q(\\begin{reviewlistnumlst}[caption={ruby},language={},firstnumber=100]\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n\\end{reviewlistnumlst}\n), actual
|
370
|
+
end
|
371
|
+
|
372
|
+
def test_source
|
373
|
+
actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n")
|
374
|
+
assert_equal %Q(\\reviewsourcecaption{foo/bar/test.rb}\n\\begin{reviewsource}\nfoo\nbar\n\nbuz\n\\end{reviewsource}\n), actual
|
375
|
+
end
|
376
|
+
|
377
|
+
def test_source_empty_caption
|
378
|
+
actual = compile_block("//source[]{\nfoo\nbar\n\nbuz\n//}\n")
|
379
|
+
assert_equal %Q(\\begin{reviewsource}\nfoo\nbar\n\nbuz\n\\end{reviewsource}\n), actual
|
380
|
+
end
|
381
|
+
|
382
|
+
def test_source_lst
|
383
|
+
@book.config['highlight'] = {}
|
384
|
+
@book.config['highlight']['latex'] = 'listings'
|
385
|
+
actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n")
|
386
|
+
assert_equal %Q(\\begin{reviewsourcelst}[title={foo/bar/test.rb},language={}]\nfoo\nbar\n\nbuz\n\\end{reviewsourcelst}\n), actual
|
387
|
+
end
|
388
|
+
|
389
|
+
def test_quote
|
390
|
+
actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n")
|
391
|
+
assert_equal %Q(\n\\begin{quote}\nfoobar\n\nbuz\n\\end{quote}\n), actual
|
392
|
+
end
|
393
|
+
|
394
|
+
def test_memo
|
395
|
+
actual = compile_block("//memo[this is @<b>{test}<&>_]{\ntest1\n\ntest@<i>{2}\n//}\n")
|
396
|
+
assert_equal %Q(\\begin{reviewminicolumn}\n\\reviewminicolumntitle{this is \\textbf{test}\\textless{}\\&\\textgreater{}\\textunderscore{}}\ntest1\n\ntest\\textit{2}\n\\end{reviewminicolumn}\n), actual
|
397
|
+
end
|
398
|
+
|
399
|
+
def test_flushright
|
400
|
+
actual = compile_block("//flushright{\nfoo\nbar\n\nbuz\n//}\n")
|
401
|
+
assert_equal %Q(\n\\begin{flushright}\nfoobar\n\nbuz\n\\end{flushright}\n), actual
|
402
|
+
end
|
403
|
+
|
404
|
+
def test_centering
|
405
|
+
actual = compile_block("//centering{\nfoo\nbar\n\nbuz\n//}\n")
|
406
|
+
assert_equal %Q(\n\\begin{center}\nfoobar\n\nbuz\n\\end{center}\n), actual
|
407
|
+
end
|
408
|
+
|
409
|
+
def test_blankline
|
410
|
+
actual = compile_block("//blankline\nfoo\n")
|
411
|
+
assert_equal %Q(\\vspace*{\\baselineskip}\n\nfoo\n), actual
|
412
|
+
end
|
413
|
+
|
414
|
+
def test_noindent
|
415
|
+
actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n")
|
416
|
+
assert_equal %Q(\\noindent\nfoo\nbar\n\nfoo2\nbar2\n), actual
|
417
|
+
end
|
418
|
+
|
419
|
+
def test_image
|
420
|
+
def @chapter.image(_id)
|
421
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1)
|
422
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
423
|
+
item
|
424
|
+
end
|
425
|
+
|
426
|
+
actual = compile_block("//image[sampleimg][sample photo]{\n//}\n")
|
427
|
+
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual
|
428
|
+
end
|
429
|
+
|
430
|
+
def test_image_with_metric
|
431
|
+
def @chapter.image(_id)
|
432
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1)
|
433
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
434
|
+
item
|
435
|
+
end
|
436
|
+
|
437
|
+
actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n")
|
438
|
+
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual
|
439
|
+
end
|
440
|
+
|
441
|
+
def test_image_with_metric_width
|
442
|
+
def @chapter.image(_id)
|
443
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1)
|
444
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
445
|
+
item
|
446
|
+
end
|
447
|
+
|
448
|
+
@config['image_scale2width'] = true
|
449
|
+
actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n")
|
450
|
+
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[width=1.2\\maxwidth]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual
|
451
|
+
end
|
452
|
+
|
453
|
+
def test_image_with_metric2
|
454
|
+
def @chapter.image(_id)
|
455
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1)
|
456
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
457
|
+
item
|
458
|
+
end
|
459
|
+
|
460
|
+
actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n")
|
461
|
+
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[scale=1.2,ignore=params]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual
|
462
|
+
end
|
463
|
+
|
464
|
+
def test_image_with_metric2_width
|
465
|
+
def @chapter.image(_id)
|
466
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1)
|
467
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
468
|
+
item
|
469
|
+
end
|
470
|
+
|
471
|
+
@config['image_scale2width'] = true
|
472
|
+
actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n")
|
473
|
+
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[width=1.2\\maxwidth,ignore=params]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual
|
474
|
+
end
|
475
|
+
|
476
|
+
def test_indepimage
|
477
|
+
def @chapter.image(_id)
|
478
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1)
|
479
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
480
|
+
item
|
481
|
+
end
|
482
|
+
|
483
|
+
actual = compile_block("//indepimage[sampleimg][sample photo]\n")
|
484
|
+
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual
|
485
|
+
end
|
486
|
+
|
487
|
+
def test_indepimage_without_caption
|
488
|
+
def @chapter.image(_id)
|
489
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1)
|
490
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
491
|
+
item
|
492
|
+
end
|
493
|
+
|
494
|
+
# FIXME: indepimage's caption should not be with a counter.
|
495
|
+
actual = compile_block("//indepimage[sampleimg]\n")
|
496
|
+
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\end{reviewimage}\n), actual
|
497
|
+
end
|
498
|
+
|
499
|
+
def test_indepimage_with_metric
|
500
|
+
def @chapter.image(_id)
|
501
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1)
|
502
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
503
|
+
item
|
504
|
+
end
|
505
|
+
|
506
|
+
actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n")
|
507
|
+
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual
|
508
|
+
end
|
509
|
+
|
510
|
+
def test_indepimage_with_metric_width
|
511
|
+
def @chapter.image(_id)
|
512
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1)
|
513
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
514
|
+
item
|
515
|
+
end
|
516
|
+
|
517
|
+
@config['image_scale2width'] = true
|
518
|
+
actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n")
|
519
|
+
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[width=1.2\\maxwidth]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual
|
520
|
+
end
|
521
|
+
|
522
|
+
def test_indepimage_with_metric2
|
523
|
+
def @chapter.image(_id)
|
524
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1)
|
525
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
526
|
+
item
|
527
|
+
end
|
528
|
+
|
529
|
+
actual = compile_block(%Q(//indepimage[sampleimg][sample photo][scale=1.2, html::class="sample",latex::ignore=params]\n))
|
530
|
+
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[scale=1.2,ignore=params]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual
|
531
|
+
end
|
532
|
+
|
533
|
+
def test_indepimage_without_caption_but_with_metric
|
534
|
+
def @chapter.image(_id)
|
535
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1)
|
536
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
537
|
+
item
|
538
|
+
end
|
539
|
+
|
540
|
+
# FIXME: indepimage's caption should not be with a counter.
|
541
|
+
actual = compile_block("//indepimage[sampleimg][][scale=1.2]\n")
|
542
|
+
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\end{reviewimage}\n), actual
|
543
|
+
end
|
544
|
+
|
545
|
+
def test_table
|
546
|
+
actual = compile_block("//table{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
|
547
|
+
assert_equal "\\begin{reviewtable}{|l|l|}\n\\hline\n\\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline\nccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline\n\\end{reviewtable}\n",
|
548
|
+
actual
|
549
|
+
end
|
550
|
+
|
551
|
+
def test_customize_cellwidth
|
552
|
+
actual = compile_block("//tsize[2,3,5]\n//table{\nA\tB\tC\n//}\n")
|
553
|
+
assert_equal %Q(\\begin{reviewtable}{|p{2mm}|p{3mm}|p{5mm}|}\n\\hline\n\\reviewth{A} & B & C \\\\ \\hline\n\\end{reviewtable}\n), actual
|
554
|
+
|
555
|
+
actual = compile_block("//tsize[|latex,html|2,3,5]\n//table{\nA\tB\tC\n//}\n")
|
556
|
+
assert_equal %Q(\\begin{reviewtable}{|p{2mm}|p{3mm}|p{5mm}|}\n\\hline\n\\reviewth{A} & B & C \\\\ \\hline\n\\end{reviewtable}\n), actual
|
557
|
+
|
558
|
+
actual = compile_block("//tsize[|html|2,3,5]\n//table{\nA\tB\tC\n//}\n")
|
559
|
+
assert_equal %Q(\\begin{reviewtable}{|l|l|l|}\n\\hline\n\\reviewth{A} & B & C \\\\ \\hline\n\\end{reviewtable}\n), actual
|
560
|
+
|
561
|
+
actual = compile_block("//tsize[|latex|2,3,5]\n//table{\nA\tB\tC\n//}\n")
|
562
|
+
assert_equal %Q(\\begin{reviewtable}{|p{2mm}|p{3mm}|p{5mm}|}\n\\hline\n\\reviewth{A} & B & C \\\\ \\hline\n\\end{reviewtable}\n), actual
|
563
|
+
|
564
|
+
actual = compile_block("//tsize[|latex||p{5mm}|cr|]\n//table{\nA\tB\tC\n//}\n")
|
565
|
+
assert_equal %Q(\\begin{reviewtable}{|p{5mm}|cr|}\n\\hline\n\\reviewth{A} & B & C \\\\ \\hline\n\\end{reviewtable}\n), actual
|
566
|
+
end
|
567
|
+
|
568
|
+
def test_emtable
|
569
|
+
actual = compile_block("//emtable[foo]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n//emtable{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
|
570
|
+
assert_equal "\\begin{table}[h]%%\n\\reviewtablecaption*{foo}\n\\begin{reviewtable}{|l|l|}\n\\hline\n\\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline\nccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline\n\\end{reviewtable}\n\\end{table}\n\n\\begin{reviewtable}{|l|l|}\n\\hline\n\\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline\nccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline\n\\end{reviewtable}\n",
|
571
|
+
actual
|
572
|
+
end
|
573
|
+
|
574
|
+
def test_imgtable
|
575
|
+
def @chapter.image(_id)
|
576
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1, 'sample img')
|
577
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
578
|
+
item
|
579
|
+
end
|
580
|
+
|
581
|
+
actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n")
|
582
|
+
|
583
|
+
expected = <<-EOS
|
584
|
+
\\begin{table}[h]%%sampleimg
|
585
|
+
\\reviewimgtablecaption{test for imgtable}
|
586
|
+
\\label{table:chap1:sampleimg}
|
587
|
+
\\begin{reviewimage}%%sampleimg
|
588
|
+
\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}
|
589
|
+
\\end{reviewimage}
|
590
|
+
\\end{table}
|
591
|
+
EOS
|
592
|
+
assert_equal expected, actual
|
593
|
+
end
|
594
|
+
|
595
|
+
def test_bib
|
596
|
+
def @chapter.bibpaper(_id)
|
597
|
+
Book::BibpaperIndex::Item.new('samplebib', 1, 'sample bib')
|
598
|
+
end
|
599
|
+
|
600
|
+
assert_equal '\\reviewbibref{[1]}{bib:samplebib}', compile_inline('@<bib>{samplebib}')
|
601
|
+
end
|
602
|
+
|
603
|
+
def test_bibpaper
|
604
|
+
def @chapter.bibpaper(_id)
|
605
|
+
Book::BibpaperIndex::Item.new('samplebib', 1, 'sample bib')
|
606
|
+
end
|
607
|
+
|
608
|
+
actual = compile_block("//bibpaper[samplebib][sample bib @<b>{bold}]{\na\nb\n//}\n")
|
609
|
+
assert_equal %Q([1] sample bib \\textbf{bold}\n\\label{bib:samplebib}\n\nab\n\n), actual
|
610
|
+
end
|
611
|
+
|
612
|
+
def test_bibpaper_without_body
|
613
|
+
def @chapter.bibpaper(_id)
|
614
|
+
Book::BibpaperIndex::Item.new('samplebib', 1, 'sample bib')
|
615
|
+
end
|
616
|
+
|
617
|
+
actual = compile_block("//bibpaper[samplebib][sample bib]\n")
|
618
|
+
assert_equal %Q([1] sample bib\n\\label{bib:samplebib}\n\n), actual
|
619
|
+
end
|
620
|
+
|
621
|
+
def column_helper(review)
|
622
|
+
compile_block(review)
|
623
|
+
end
|
624
|
+
|
625
|
+
def test_column_1
|
626
|
+
review = <<-EOS
|
627
|
+
===[column] prev column
|
628
|
+
|
629
|
+
inside prev column
|
630
|
+
|
631
|
+
===[column] test
|
632
|
+
|
633
|
+
inside column
|
634
|
+
|
635
|
+
===[/column]
|
636
|
+
EOS
|
637
|
+
expected = <<-EOS
|
638
|
+
|
639
|
+
\\begin{reviewcolumn}
|
640
|
+
\\hypertarget{column:chap1:1}{}
|
641
|
+
\\reviewcolumnhead{}{prev column}
|
642
|
+
\\addcontentsline{toc}{subsection}{prev column}
|
643
|
+
|
644
|
+
inside prev column
|
645
|
+
|
646
|
+
\\end{reviewcolumn}
|
647
|
+
|
648
|
+
\\begin{reviewcolumn}
|
649
|
+
\\hypertarget{column:chap1:2}{}
|
650
|
+
\\reviewcolumnhead{}{test}
|
651
|
+
\\addcontentsline{toc}{subsection}{test}
|
652
|
+
|
653
|
+
inside column
|
654
|
+
|
655
|
+
\\end{reviewcolumn}
|
656
|
+
EOS
|
657
|
+
@config['toclevel'] = 3
|
658
|
+
assert_equal expected, column_helper(review)
|
659
|
+
end
|
660
|
+
|
661
|
+
def test_column_2
|
662
|
+
review = <<-EOS
|
663
|
+
===[column] test
|
664
|
+
|
665
|
+
inside column
|
666
|
+
|
667
|
+
=== next level
|
668
|
+
EOS
|
669
|
+
expected = <<-EOS
|
670
|
+
|
671
|
+
\\begin{reviewcolumn}
|
672
|
+
\\hypertarget{column:chap1:1}{}
|
673
|
+
\\reviewcolumnhead{}{test}
|
674
|
+
|
675
|
+
inside column
|
676
|
+
|
677
|
+
\\end{reviewcolumn}
|
678
|
+
|
679
|
+
\\subsection*{next level}
|
680
|
+
\\label{sec:1-0-1}
|
681
|
+
EOS
|
682
|
+
|
683
|
+
@config['toclevel'] = 1
|
684
|
+
assert_equal expected, column_helper(review)
|
685
|
+
end
|
686
|
+
|
687
|
+
def test_column_3
|
688
|
+
review = <<-EOS
|
689
|
+
===[column] test
|
690
|
+
|
691
|
+
inside column
|
692
|
+
|
693
|
+
===[/column_dummy]
|
694
|
+
EOS
|
695
|
+
assert_raise(ReVIEW::ApplicationError) do
|
696
|
+
column_helper(review)
|
697
|
+
end
|
698
|
+
end
|
699
|
+
|
700
|
+
def test_ul
|
701
|
+
src = <<-EOS
|
702
|
+
* AAA
|
703
|
+
* BBB
|
704
|
+
EOS
|
705
|
+
expected = <<-EOS
|
706
|
+
|
707
|
+
\\begin{itemize}
|
708
|
+
\\item AAA
|
709
|
+
\\item BBB
|
710
|
+
\\end{itemize}
|
711
|
+
EOS
|
712
|
+
actual = compile_block(src)
|
713
|
+
assert_equal expected, actual
|
714
|
+
end
|
715
|
+
|
716
|
+
def test_ul_with_bracket
|
717
|
+
src = <<-EOS
|
718
|
+
* AAA
|
719
|
+
* []BBB
|
720
|
+
EOS
|
721
|
+
expected = <<-EOS
|
722
|
+
|
723
|
+
\\begin{itemize}
|
724
|
+
\\item AAA
|
725
|
+
\\item \\lbrack{}]BBB
|
726
|
+
\\end{itemize}
|
727
|
+
EOS
|
728
|
+
actual = compile_block(src)
|
729
|
+
assert_equal expected, actual
|
730
|
+
end
|
731
|
+
|
732
|
+
def test_cont
|
733
|
+
src = <<-EOS
|
734
|
+
* AAA
|
735
|
+
-AA
|
736
|
+
* BBB
|
737
|
+
-BB
|
738
|
+
EOS
|
739
|
+
expected = <<-EOS
|
740
|
+
|
741
|
+
\\begin{itemize}
|
742
|
+
\\item AAA{-}AA
|
743
|
+
\\item BBB{-}BB
|
744
|
+
\\end{itemize}
|
745
|
+
EOS
|
746
|
+
actual = compile_block(src)
|
747
|
+
assert_equal expected, actual
|
748
|
+
end
|
749
|
+
|
750
|
+
def test_ul_nest1
|
751
|
+
src = <<-EOS
|
752
|
+
* AAA
|
753
|
+
** AA
|
754
|
+
EOS
|
755
|
+
|
756
|
+
expected = <<-EOS
|
757
|
+
|
758
|
+
\\begin{itemize}
|
759
|
+
\\item AAA
|
760
|
+
|
761
|
+
\\begin{itemize}
|
762
|
+
\\item AA
|
763
|
+
\\end{itemize}
|
764
|
+
|
765
|
+
\\end{itemize}
|
766
|
+
EOS
|
767
|
+
actual = compile_block(src)
|
768
|
+
assert_equal expected, actual
|
769
|
+
end
|
770
|
+
|
771
|
+
def test_ul_nest3
|
772
|
+
src = <<-EOS
|
773
|
+
* AAA
|
774
|
+
** AA
|
775
|
+
* BBB
|
776
|
+
** BB
|
777
|
+
EOS
|
778
|
+
|
779
|
+
expected = <<-EOS
|
780
|
+
|
781
|
+
\\begin{itemize}
|
782
|
+
\\item AAA
|
783
|
+
|
784
|
+
\\begin{itemize}
|
785
|
+
\\item AA
|
786
|
+
\\end{itemize}
|
787
|
+
|
788
|
+
\\item BBB
|
789
|
+
|
790
|
+
\\begin{itemize}
|
791
|
+
\\item BB
|
792
|
+
\\end{itemize}
|
793
|
+
|
794
|
+
\\end{itemize}
|
795
|
+
EOS
|
796
|
+
actual = compile_block(src)
|
797
|
+
assert_equal expected, actual
|
798
|
+
end
|
799
|
+
|
800
|
+
def test_ol
|
801
|
+
src = <<-EOS
|
802
|
+
3. AAA
|
803
|
+
3. BBB
|
804
|
+
EOS
|
805
|
+
|
806
|
+
expected = <<-EOS
|
807
|
+
|
808
|
+
\\begin{enumerate}
|
809
|
+
\\item AAA
|
810
|
+
\\item BBB
|
811
|
+
\\end{enumerate}
|
812
|
+
EOS
|
813
|
+
actual = compile_block(src)
|
814
|
+
assert_equal expected, actual
|
815
|
+
end
|
816
|
+
|
817
|
+
def test_ol_with_bracket
|
818
|
+
src = <<-EOS
|
819
|
+
1. AAA
|
820
|
+
2. []BBB
|
821
|
+
EOS
|
822
|
+
expected = <<-EOS
|
823
|
+
|
824
|
+
\\begin{enumerate}
|
825
|
+
\\item AAA
|
826
|
+
\\item \\lbrack{}]BBB
|
827
|
+
\\end{enumerate}
|
828
|
+
EOS
|
829
|
+
actual = compile_block(src)
|
830
|
+
assert_equal expected, actual
|
831
|
+
end
|
832
|
+
|
833
|
+
def test_major_blocks
|
834
|
+
actual = compile_block("//note{\nA\n\nB\n//}\n//note[caption]{\nA\n//}")
|
835
|
+
expected = %Q(\\begin{reviewminicolumn}\nA\n\nB\n\\end{reviewminicolumn}\n\\begin{reviewminicolumn}\n\\reviewminicolumntitle{caption}\nA\n\\end{reviewminicolumn}\n)
|
836
|
+
assert_equal expected, actual
|
837
|
+
|
838
|
+
actual = compile_block("//memo{\nA\n\nB\n//}\n//memo[caption]{\nA\n//}")
|
839
|
+
expected = %Q(\\begin{reviewminicolumn}\nA\n\nB\n\\end{reviewminicolumn}\n\\begin{reviewminicolumn}\n\\reviewminicolumntitle{caption}\nA\n\\end{reviewminicolumn}\n)
|
840
|
+
assert_equal expected, actual
|
841
|
+
|
842
|
+
actual = compile_block("//info{\nA\n\nB\n//}\n//info[caption]{\nA\n//}")
|
843
|
+
expected = %Q(\\begin{reviewminicolumn}\nA\n\nB\n\\end{reviewminicolumn}\n\\begin{reviewminicolumn}\n\\reviewminicolumntitle{caption}\nA\n\\end{reviewminicolumn}\n)
|
844
|
+
assert_equal expected, actual
|
845
|
+
|
846
|
+
actual = compile_block("//important{\nA\n\nB\n//}\n//important[caption]{\nA\n//}")
|
847
|
+
expected = %Q(\\begin{reviewminicolumn}\nA\n\nB\n\\end{reviewminicolumn}\n\\begin{reviewminicolumn}\n\\reviewminicolumntitle{caption}\nA\n\\end{reviewminicolumn}\n)
|
848
|
+
assert_equal expected, actual
|
849
|
+
|
850
|
+
actual = compile_block("//caution{\nA\n\nB\n//}\n//caution[caption]{\nA\n//}")
|
851
|
+
expected = %Q(\\begin{reviewminicolumn}\nA\n\nB\n\\end{reviewminicolumn}\n\\begin{reviewminicolumn}\n\\reviewminicolumntitle{caption}\nA\n\\end{reviewminicolumn}\n)
|
852
|
+
assert_equal expected, actual
|
853
|
+
|
854
|
+
actual = compile_block("//notice{\nA\n\nB\n//}\n//notice[caption]{\nA\n//}")
|
855
|
+
expected = %Q(\\begin{reviewminicolumn}\nA\n\nB\n\\end{reviewminicolumn}\n\\begin{reviewminicolumn}\n\\reviewminicolumntitle{caption}\nA\n\\end{reviewminicolumn}\n)
|
856
|
+
assert_equal expected, actual
|
857
|
+
|
858
|
+
actual = compile_block("//warning{\nA\n\nB\n//}\n//warning[caption]{\nA\n//}")
|
859
|
+
expected = %Q(\\begin{reviewminicolumn}\nA\n\nB\n\\end{reviewminicolumn}\n\\begin{reviewminicolumn}\n\\reviewminicolumntitle{caption}\nA\n\\end{reviewminicolumn}\n)
|
860
|
+
assert_equal expected, actual
|
861
|
+
|
862
|
+
actual = compile_block("//tip{\nA\n\nB\n//}\n//tip[caption]{\nA\n//}")
|
863
|
+
expected = %Q(\\begin{reviewminicolumn}\nA\n\nB\n\\end{reviewminicolumn}\n\\begin{reviewminicolumn}\n\\reviewminicolumntitle{caption}\nA\n\\end{reviewminicolumn}\n)
|
864
|
+
assert_equal expected, actual
|
865
|
+
end
|
866
|
+
|
867
|
+
def test_inline_raw0
|
868
|
+
assert_equal 'normal', compile_inline('@<raw>{normal}')
|
869
|
+
end
|
870
|
+
|
871
|
+
def test_inline_raw1
|
872
|
+
assert_equal 'body', compile_inline('@<raw>{|latex|body}')
|
873
|
+
end
|
874
|
+
|
875
|
+
def test_inline_raw2
|
876
|
+
assert_equal 'body', compile_inline('@<raw>{|html, latex|body}')
|
877
|
+
end
|
878
|
+
|
879
|
+
def test_inline_raw3
|
880
|
+
assert_equal '', compile_inline('@<raw>{|idgxml, html|body}')
|
881
|
+
end
|
882
|
+
|
883
|
+
def test_inline_raw4
|
884
|
+
assert_equal '|latex body', compile_inline('@<raw>{|latex body}')
|
885
|
+
end
|
886
|
+
|
887
|
+
def test_inline_raw5
|
888
|
+
assert_equal "nor\nmal", compile_inline('@<raw>{|latex|nor\\nmal}')
|
889
|
+
end
|
890
|
+
|
891
|
+
def test_inline_endash
|
892
|
+
actual = compile_inline('- -- --- ----')
|
893
|
+
assert_equal '{-} {-}{-} {-}{-}{-} {-}{-}{-}{-}', actual
|
894
|
+
end
|
895
|
+
|
896
|
+
def test_inline_imgref
|
897
|
+
def @chapter.image(_id)
|
898
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1, 'sample photo')
|
899
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
900
|
+
item
|
901
|
+
end
|
902
|
+
|
903
|
+
actual = compile_block "@<imgref>{sampleimg}\n"
|
904
|
+
expected = "\n\\reviewimageref{1.1}{image:chap1:sampleimg}「sample photo」\n"
|
905
|
+
assert_equal expected, actual
|
906
|
+
end
|
907
|
+
|
908
|
+
def test_inline_imgref2
|
909
|
+
def @chapter.image(_id)
|
910
|
+
item = Book::NumberlessImageIndex::Item.new('sampleimg', 1)
|
911
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
912
|
+
item
|
913
|
+
end
|
914
|
+
|
915
|
+
actual = compile_block "@<imgref>{sampleimg}\n"
|
916
|
+
expected = "\n\\reviewimageref{1.1}{image:chap1:sampleimg}\n"
|
917
|
+
assert_equal expected, actual
|
918
|
+
end
|
919
|
+
|
920
|
+
def test_block_raw0
|
921
|
+
actual = compile_block(%Q(//raw[<>!"\\n& ]\n))
|
922
|
+
expected = %Q(<>!"\n& )
|
923
|
+
assert_equal expected, actual
|
924
|
+
end
|
925
|
+
|
926
|
+
def test_block_raw1
|
927
|
+
actual = compile_block(%Q(//raw[|latex|<>!"\\n& ]\n))
|
928
|
+
expected = %Q(<>!"\n& )
|
929
|
+
assert_equal expected, actual
|
930
|
+
end
|
931
|
+
|
932
|
+
def test_block_raw2
|
933
|
+
actual = compile_block(%Q(//raw[|html, latex|<>!"\\n& ]\n))
|
934
|
+
expected = %Q(<>!"\n& )
|
935
|
+
assert_equal expected, actual
|
936
|
+
end
|
937
|
+
|
938
|
+
def test_block_raw3
|
939
|
+
actual = compile_block(%Q(//raw[|html, idgxml|<>!"\\n& ]\n))
|
940
|
+
expected = ''
|
941
|
+
assert_equal expected, actual
|
942
|
+
end
|
943
|
+
|
944
|
+
def test_block_raw4
|
945
|
+
actual = compile_block(%Q(//raw[|latex <>!"\\n& ]\n))
|
946
|
+
expected = %Q(|latex <>!"\n& )
|
947
|
+
assert_equal expected, actual
|
948
|
+
end
|
949
|
+
|
950
|
+
def test_comment
|
951
|
+
actual = compile_block('//comment[コメント]')
|
952
|
+
assert_equal '', actual
|
953
|
+
end
|
954
|
+
|
955
|
+
def test_comment_for_draft
|
956
|
+
@config['draft'] = true
|
957
|
+
actual = compile_block('//comment[コメント]')
|
958
|
+
assert_equal %Q(\\pdfcomment{コメント}\n), actual
|
959
|
+
end
|
960
|
+
|
961
|
+
def test_inline_comment
|
962
|
+
actual = compile_inline('test @<comment>{コメント} test2')
|
963
|
+
assert_equal 'test test2', actual
|
964
|
+
end
|
965
|
+
|
966
|
+
def test_inline_comment_for_draft
|
967
|
+
@config['draft'] = true
|
968
|
+
actual = compile_inline('test @<comment>{コメント} test2')
|
969
|
+
assert_equal 'test \\pdfcomment{コメント} test2', actual
|
970
|
+
end
|
971
|
+
|
972
|
+
def test_inline_fence
|
973
|
+
actual = compile_inline('test @<code>|@<code>{$サンプル$}|')
|
974
|
+
assert_equal 'test \\texttt{@\\textless{}code\\textgreater{}\\{\\textdollar{}サンプル\\textdollar{}\\}}', actual
|
975
|
+
end
|
976
|
+
|
977
|
+
def test_inline_unknown
|
978
|
+
e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<img>{n}\n" }
|
979
|
+
assert_equal ':1: error: unknown image: n', e.message
|
980
|
+
e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<fn>{n}\n" }
|
981
|
+
assert_equal ':1: error: unknown footnote: n', e.message
|
982
|
+
e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<hd>{n}\n" }
|
983
|
+
assert_equal ':1: error: unknown headline: n', e.message
|
984
|
+
%w[list table column].each do |name|
|
985
|
+
e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<#{name}>{n}\n" }
|
986
|
+
assert_equal ":1: error: unknown #{name}: n", e.message
|
987
|
+
end
|
988
|
+
%w[chap chapref title].each do |name|
|
989
|
+
e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<#{name}>{n}\n" }
|
990
|
+
assert_equal ':1: error: key not found: "n"', e.message
|
991
|
+
end
|
992
|
+
end
|
993
|
+
|
994
|
+
def test_appendix_list
|
995
|
+
@chapter.instance_eval do
|
996
|
+
def on_appendix?
|
997
|
+
true
|
998
|
+
end
|
999
|
+
end
|
1000
|
+
src = <<-EOS
|
1001
|
+
@<list>{foo}
|
1002
|
+
//list[foo][FOO]{
|
1003
|
+
//}
|
1004
|
+
EOS
|
1005
|
+
expected = <<-EOS
|
1006
|
+
|
1007
|
+
\\reviewlistref{A.1}
|
1008
|
+
|
1009
|
+
\\reviewlistcaption{リストA.1: FOO}
|
1010
|
+
\\begin{reviewlist}
|
1011
|
+
\\end{reviewlist}
|
1012
|
+
EOS
|
1013
|
+
actual = compile_block(src)
|
1014
|
+
assert_equal expected, actual
|
1015
|
+
end
|
1016
|
+
|
1017
|
+
def test_appendix_table
|
1018
|
+
@chapter.instance_eval do
|
1019
|
+
def on_appendix?
|
1020
|
+
true
|
1021
|
+
end
|
1022
|
+
end
|
1023
|
+
src = <<-EOS
|
1024
|
+
@<table>{foo}
|
1025
|
+
//table[foo][FOO]{
|
1026
|
+
A B
|
1027
|
+
//}
|
1028
|
+
EOS
|
1029
|
+
expected = <<-EOS
|
1030
|
+
|
1031
|
+
\\reviewtableref{A.1}{table:chap1:foo}
|
1032
|
+
|
1033
|
+
\\begin{table}[h]%%foo
|
1034
|
+
\\reviewtablecaption{FOO}
|
1035
|
+
\\label{table:chap1:foo}
|
1036
|
+
\\begin{reviewtable}{|l|l|}
|
1037
|
+
\\hline
|
1038
|
+
\\reviewth{A} & B \\\\ \\hline
|
1039
|
+
\\end{reviewtable}
|
1040
|
+
\\end{table}
|
1041
|
+
EOS
|
1042
|
+
actual = compile_block(src)
|
1043
|
+
assert_equal expected, actual
|
1044
|
+
end
|
1045
|
+
|
1046
|
+
def test_appendix_image
|
1047
|
+
@chapter.instance_eval do
|
1048
|
+
def on_appendix?
|
1049
|
+
true
|
1050
|
+
end
|
1051
|
+
end
|
1052
|
+
|
1053
|
+
def @chapter.image(_id)
|
1054
|
+
item = Book::NumberlessImageIndex::Item.new('sampleimg', 1)
|
1055
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
1056
|
+
item
|
1057
|
+
end
|
1058
|
+
|
1059
|
+
src = <<-EOS
|
1060
|
+
@<img>{sampleimg}
|
1061
|
+
//image[sampleimg][FOO]{
|
1062
|
+
//}
|
1063
|
+
EOS
|
1064
|
+
expected = <<-EOS
|
1065
|
+
|
1066
|
+
\\reviewimageref{A.1}{image:chap1:sampleimg}
|
1067
|
+
|
1068
|
+
\\begin{reviewimage}%%sampleimg
|
1069
|
+
\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}
|
1070
|
+
\\caption{FOO}
|
1071
|
+
\\label{image:chap1:sampleimg}
|
1072
|
+
\\end{reviewimage}
|
1073
|
+
EOS
|
1074
|
+
actual = compile_block(src)
|
1075
|
+
assert_equal expected, actual
|
1076
|
+
end
|
1077
|
+
end
|