review-peg 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +36 -0
  3. data/.rubocop.yml +47 -0
  4. data/.rubocop_todo.yml +605 -0
  5. data/.travis.yml +18 -0
  6. data/COPYING +515 -0
  7. data/ChangeLog +2449 -0
  8. data/Dockerfile +22 -0
  9. data/Gemfile +6 -0
  10. data/README.rdoc +81 -0
  11. data/Rakefile +51 -0
  12. data/bin/review-catalog-converter-peg +129 -0
  13. data/bin/review-check-peg +169 -0
  14. data/bin/review-checkdep-peg +63 -0
  15. data/bin/review-compile-peg +202 -0
  16. data/bin/review-epubmaker-legacy-peg +1024 -0
  17. data/bin/review-epubmaker-peg +44 -0
  18. data/bin/review-index-peg +110 -0
  19. data/bin/review-init-peg +151 -0
  20. data/bin/review-pdfmaker-peg +18 -0
  21. data/bin/review-preproc-peg +131 -0
  22. data/bin/review-validate-peg +51 -0
  23. data/bin/review-vol-peg +100 -0
  24. data/debian/README.Debian +12 -0
  25. data/debian/README.source +5 -0
  26. data/debian/changelog +5 -0
  27. data/debian/compat +1 -0
  28. data/debian/control +22 -0
  29. data/debian/copyright +62 -0
  30. data/debian/docs +6 -0
  31. data/debian/manpage.1.ex +59 -0
  32. data/debian/patches/path.diff +91 -0
  33. data/debian/patches/series +1 -0
  34. data/debian/review.install +13 -0
  35. data/debian/review.links +4 -0
  36. data/debian/rules +13 -0
  37. data/debian/source/format +1 -0
  38. data/doc/NEWS.ja.md +350 -0
  39. data/doc/NEWS.md +354 -0
  40. data/doc/catalog.ja.md +53 -0
  41. data/doc/catalog.md +52 -0
  42. data/doc/format.ja.md +734 -0
  43. data/doc/format.md +746 -0
  44. data/doc/format_idg.ja.md +203 -0
  45. data/doc/quickstart.ja.md +222 -0
  46. data/doc/quickstart.md +252 -0
  47. data/doc/ruby-uuid/README +11 -0
  48. data/doc/ruby-uuid/README.ja +34 -0
  49. data/doc/sample.css +108 -0
  50. data/doc/sample.yml +238 -0
  51. data/lib/epubmaker.rb +24 -0
  52. data/lib/epubmaker/content.rb +93 -0
  53. data/lib/epubmaker/epubcommon.rb +424 -0
  54. data/lib/epubmaker/epubv2.rb +139 -0
  55. data/lib/epubmaker/epubv3.rb +222 -0
  56. data/lib/epubmaker/producer.rb +330 -0
  57. data/lib/lineinput.rb +107 -0
  58. data/lib/review.rb +3 -0
  59. data/lib/review/book.rb +43 -0
  60. data/lib/review/book/base.rb +401 -0
  61. data/lib/review/book/chapter.rb +100 -0
  62. data/lib/review/book/compilable.rb +184 -0
  63. data/lib/review/book/image_finder.rb +71 -0
  64. data/lib/review/book/index.rb +413 -0
  65. data/lib/review/book/page_metric.rb +47 -0
  66. data/lib/review/book/part.rb +54 -0
  67. data/lib/review/book/volume.rb +67 -0
  68. data/lib/review/builder.rb +452 -0
  69. data/lib/review/catalog.rb +52 -0
  70. data/lib/review/compiler.rb +5183 -0
  71. data/lib/review/compiler/literals_1_9.kpeg +22 -0
  72. data/lib/review/compiler/literals_1_9.rb +435 -0
  73. data/lib/review/configure.rb +64 -0
  74. data/lib/review/epubbuilder.rb +18 -0
  75. data/lib/review/epubmaker.rb +480 -0
  76. data/lib/review/ewbbuilder.rb +381 -0
  77. data/lib/review/exception.rb +21 -0
  78. data/lib/review/extentions.rb +4 -0
  79. data/lib/review/extentions/array.rb +25 -0
  80. data/lib/review/extentions/object.rb +9 -0
  81. data/lib/review/extentions/string.rb +33 -0
  82. data/lib/review/htmlbuilder.rb +1166 -0
  83. data/lib/review/htmllayout.rb +41 -0
  84. data/lib/review/htmltoc.rb +45 -0
  85. data/lib/review/htmlutils.rb +90 -0
  86. data/lib/review/i18n.rb +96 -0
  87. data/lib/review/i18n.yml +169 -0
  88. data/lib/review/idgxmlbuilder.rb +1233 -0
  89. data/lib/review/inaobuilder.rb +357 -0
  90. data/lib/review/latexbuilder.rb +941 -0
  91. data/lib/review/latexindex.rb +35 -0
  92. data/lib/review/latexutils.rb +95 -0
  93. data/lib/review/layout.tex.erb +340 -0
  94. data/lib/review/lineinput.rb +17 -0
  95. data/lib/review/location.rb +24 -0
  96. data/lib/review/makerhelper.rb +67 -0
  97. data/lib/review/markdownbuilder.rb +339 -0
  98. data/lib/review/node.rb +288 -0
  99. data/lib/review/pdfmaker.rb +332 -0
  100. data/lib/review/preprocessor.rb +530 -0
  101. data/lib/review/review.kpeg +745 -0
  102. data/lib/review/sec_counter.rb +69 -0
  103. data/lib/review/template.rb +21 -0
  104. data/lib/review/textbuilder.rb +17 -0
  105. data/lib/review/textutils.rb +16 -0
  106. data/lib/review/tocparser.rb +348 -0
  107. data/lib/review/tocprinter.rb +205 -0
  108. data/lib/review/topbuilder.rb +796 -0
  109. data/lib/review/unfold.rb +138 -0
  110. data/lib/review/version.rb +3 -0
  111. data/lib/uuid.rb +312 -0
  112. data/review.gemspec +32 -0
  113. data/templates/html/layout-html5.html.erb +17 -0
  114. data/templates/html/layout-xhtml1.html.erb +20 -0
  115. data/templates/ncx/epubv2.ncx.erb +11 -0
  116. data/templates/opf/epubv2.opf.erb +21 -0
  117. data/templates/opf/epubv3.opf.erb +18 -0
  118. data/templates/xml/container.xml.erb +6 -0
  119. data/test/CHAPS +2 -0
  120. data/test/assets/test.xml.erb +3 -0
  121. data/test/assets/test_template.tex +255 -0
  122. data/test/assets/test_template_backmatter.tex +32 -0
  123. data/test/bib.re +13 -0
  124. data/test/book_test_helper.rb +35 -0
  125. data/test/sample-book/README.md +7 -0
  126. data/test/sample-book/src/Rakefile +58 -0
  127. data/test/sample-book/src/_cover.html +3 -0
  128. data/test/sample-book/src/catalog.yml +10 -0
  129. data/test/sample-book/src/ch01.re +71 -0
  130. data/test/sample-book/src/ch02.re +3 -0
  131. data/test/sample-book/src/config.yml +186 -0
  132. data/test/sample-book/src/images/ch01-imgsample.jpg +0 -0
  133. data/test/sample-book/src/images/cover.jpg +0 -0
  134. data/test/sample-book/src/preface.re +15 -0
  135. data/test/sample-book/src/sty/jumoline.sty +310 -0
  136. data/test/sample-book/src/sty/reviewmacro.sty +39 -0
  137. data/test/sample-book/src/style.css +251 -0
  138. data/test/sample-book/src/vendor/jumoline/README +29 -0
  139. data/test/sample-book/src/vendor/jumoline/jumoline.dtx +2988 -0
  140. data/test/sample-book/src/vendor/jumoline/jumoline.ins +6 -0
  141. data/test/test.re +43 -0
  142. data/test/test_book.rb +556 -0
  143. data/test/test_book_chapter.rb +280 -0
  144. data/test/test_book_part.rb +54 -0
  145. data/test/test_builder.rb +80 -0
  146. data/test/test_catalog.rb +119 -0
  147. data/test/test_catalog_converter_cmd.rb +73 -0
  148. data/test/test_compiler.rb +92 -0
  149. data/test/test_configure.rb +50 -0
  150. data/test/test_epub3maker.rb +529 -0
  151. data/test/test_epubmaker.rb +569 -0
  152. data/test/test_epubmaker_cmd.rb +40 -0
  153. data/test/test_helper.rb +92 -0
  154. data/test/test_htmlbuilder.rb +1114 -0
  155. data/test/test_htmltoc.rb +32 -0
  156. data/test/test_htmlutils.rb +50 -0
  157. data/test/test_i18n.rb +180 -0
  158. data/test/test_idgxmlbuilder.rb +608 -0
  159. data/test/test_image_finder.rb +82 -0
  160. data/test/test_inaobuilder.rb +245 -0
  161. data/test/test_index.rb +174 -0
  162. data/test/test_latexbuilder.rb +732 -0
  163. data/test/test_lineinput.rb +182 -0
  164. data/test/test_makerhelper.rb +66 -0
  165. data/test/test_markdownbuilder.rb +125 -0
  166. data/test/test_pdfmaker.rb +171 -0
  167. data/test/test_pdfmaker_cmd.rb +40 -0
  168. data/test/test_preprocessor.rb +23 -0
  169. data/test/test_review_ext.rb +31 -0
  170. data/test/test_template.rb +26 -0
  171. data/test/test_textutils.rb +32 -0
  172. data/test/test_topbuilder.rb +291 -0
  173. data/test/test_uuid.rb +157 -0
  174. metadata +357 -0
@@ -0,0 +1,732 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test_helper'
3
+ require 'review/book'
4
+ require 'review/compiler'
5
+ require 'review/latexbuilder'
6
+ require 'review/i18n'
7
+
8
+ class LATEXBuidlerTest < Test::Unit::TestCase
9
+ include ReVIEW
10
+
11
+ def setup
12
+ @builder = LATEXBuilder.new()
13
+ @config = ReVIEW::Configure.values
14
+ @config.merge!( {
15
+ "secnolevel" => 2, # for IDGXMLBuilder, EPUBBuilder
16
+ "toclevel" => 2,
17
+ "stylesheet" => nil, # for EPUBBuilder
18
+ })
19
+ @book = Book::Base.new(nil)
20
+ @book.config = @config
21
+ @compiler = ReVIEW::Compiler.new(@builder)
22
+ @chapter = Book::Chapter.new(@book, 1, 'chap1', nil, StringIO.new)
23
+ location = Location.new(nil, nil)
24
+ @builder.bind(@compiler, @chapter, location)
25
+ I18n.setup("ja")
26
+ end
27
+
28
+ def test_headline_level1
29
+ actual = compile_block("={test} this is test.\n")
30
+ assert_equal %Q|\\chapter{this is test.}\n\\label{chap:chap1}\n|, actual
31
+ end
32
+
33
+ def test_headline_level1_without_secno
34
+ @config["secnolevel"] = 0
35
+ actual = compile_block("={test} this is test.\n")
36
+ assert_equal %Q|\\chapter*{this is test.}\n\\addcontentsline{toc}{chapter}{this is test.}\n\\label{chap:chap1}\n|, actual
37
+ end
38
+
39
+ def test_headline_level1_with_inlinetag
40
+ actual = compile_block("={test} this @<b>{is} test.<&\"_>\n")
41
+ assert_equal %Q|\\chapter{this \\textbf{is} test.\\textless{}\\&\"\\textunderscore{}\\textgreater{}}\n\\label{chap:chap1}\n|, actual
42
+ end
43
+
44
+ def test_headline_level2
45
+ actual = compile_block("=={test} this is test.\n")
46
+ assert_equal %Q|\\section{this is test.}\n\\label{sec:1-1}\n|, actual
47
+ end
48
+
49
+ def test_headline_level3
50
+ actual = compile_block("==={test} this is test.\n")
51
+ assert_equal %Q|\\subsection*{this is test.}\n\\label{sec:1-0-1}\n|, actual
52
+ end
53
+
54
+
55
+ def test_headline_level3_with_secno
56
+ @config["secnolevel"] = 3
57
+ actual = compile_block("==={test} this is test.\n")
58
+ assert_equal %Q|\\subsection{this is test.}\n\\label{sec:1-0-1}\n|, actual
59
+ end
60
+
61
+ def test_label
62
+ actual = compile_block("//label[label_test]\n")
63
+ assert_equal %Q|\\label{label_test}\n|, actual
64
+ end
65
+
66
+ def test_href
67
+ actual = compile_inline("@<href>{http://github.com,GitHub}")
68
+ assert_equal %Q|\\href{http://github.com}{GitHub}|, actual
69
+ end
70
+
71
+ def test_inline_href
72
+ actual = compile_inline('@<href>{http://github.com,Git\\,Hub}')
73
+ assert_equal %Q|\\href{http://github.com}{Git,Hub}|, actual
74
+ end
75
+
76
+ def test_href_without_label
77
+ actual = compile_inline('@<href>{http://github.com}')
78
+ assert_equal %Q|\\url{http://github.com}|, actual
79
+ end
80
+
81
+ def test_href_with_underscore
82
+ actual = compile_inline('@<href>{http://example.com/aaa/bbb, AAA_BBB}')
83
+ assert_equal %Q|\\href{http://example.com/aaa/bbb}{AAA\\textunderscore{}BBB}|, actual
84
+ end
85
+
86
+ def test_href_mailto
87
+ actual = compile_inline('@<href>{mailto:takahashim@example.com, takahashim@example.com}')
88
+ assert_equal %Q|\\href{mailto:takahashim@example.com}{takahashim@example.com}|, actual
89
+ end
90
+
91
+ def test_inline_br
92
+ actual = compile_inline("@<br>{}")
93
+ assert_equal %Q|\\\\\n|, actual
94
+ end
95
+
96
+ def test_inline_br_with_other_strings
97
+ actual = compile_inline("abc@<br>{}def")
98
+ assert_equal %Q|abc\\\\\ndef|, actual
99
+ end
100
+
101
+ def test_inline_i
102
+ actual = compile_inline("abc@<i>{def}ghi")
103
+ assert_equal %Q|abc\\textit{def}ghi|, actual
104
+ end
105
+
106
+ def test_inline_i_and_escape
107
+ actual = compile_inline("test @<i>{inline<&;\\ test} test2")
108
+ assert_equal %Q|test \\textit{inline\\textless{}\\&;\\reviewbackslash{} test} test2|, actual
109
+ end
110
+
111
+ def test_inline_dtp
112
+ actual = compile_inline("abc@<dtp>{def}ghi")
113
+ assert_equal %Q|abcghi|, actual
114
+ end
115
+
116
+ def test_inline_code
117
+ actual = compile_inline("abc@<code>{def}ghi")
118
+ assert_equal %Q|abc\\texttt{def}ghi|, actual
119
+ end
120
+
121
+ def test_inline_raw
122
+ actual = compile_inline("@<raw>{@<tt>{inline!$%\\}}")
123
+ assert_equal "@<tt>{inline!$%}", actual
124
+ end
125
+
126
+ def test_inline_sup
127
+ actual = compile_inline("abc@<sup>{def}")
128
+ assert_equal %Q|abc\\textsuperscript{def}|, actual
129
+ end
130
+
131
+ def test_inline_sub
132
+ actual = compile_inline("abc@<sub>{def}")
133
+ assert_equal %Q|abc\\textsubscript{def}|, actual
134
+ end
135
+
136
+ def test_inline_b
137
+ actual = compile_inline("abc@<b>{def}")
138
+ assert_equal %Q|abc\\textbf{def}|, actual
139
+ end
140
+
141
+ def test_inline_b_and_escape
142
+ actual = compile_inline("test @<b>{inline<&;\\ test} test2")
143
+ assert_equal %Q|test \\textbf{inline\\textless{}\\&;\\reviewbackslash{} test} test2|, actual
144
+ end
145
+ def test_inline_em
146
+ actual = compile_inline("abc@<em>{def}")
147
+ assert_equal %Q|abc\\reviewem{def}|, actual
148
+ end
149
+
150
+ def test_inline_strong
151
+ actual = compile_inline("abc@<strong>{def}")
152
+ assert_equal %Q|abc\\reviewstrong{def}|, actual
153
+ end
154
+
155
+ def test_inline_u
156
+ actual = compile_inline("abc@<u>{def}ghi")
157
+ assert_equal %Q|abc\\Underline{def}ghi|, actual
158
+ end
159
+
160
+ def test_inline_m
161
+ actual = compile_inline("abc@<m>{\\alpha^n = \inf < 2}ghi")
162
+ assert_equal "abc $\\alpha^n = inf < 2$ ghi", actual
163
+ end
164
+
165
+ def test_inline_tt
166
+ actual = compile_inline("test @<tt>{inline test} test2")
167
+ assert_equal %Q|test \\texttt{inline test} test2|, actual
168
+ end
169
+
170
+ def test_inline_tt_endash
171
+ actual = compile_inline("test @<tt>{in-line --test ---foo ----bar -----buz} --test2")
172
+ assert_equal %Q|test \\texttt{in{-}line {-}{-}test {-}{-}{-}foo {-}{-}{-}{-}bar {-}{-}{-}{-}{-}buz} {-}{-}test2|, actual
173
+ end
174
+
175
+ def test_inline_tti
176
+ actual = compile_inline("test @<tti>{inline test} test2")
177
+ assert_equal %Q|test \\texttt{\\textit{inline test}} test2|, actual
178
+ end
179
+
180
+ def test_inline_ttb
181
+ actual = compile_inline("test @<ttb>{inline test} test2")
182
+ assert_equal %Q|test \\texttt{\\textbf{inline test}} test2|, actual
183
+ end
184
+
185
+ def test_inline_hd_chap
186
+ def @chapter.headline_index
187
+ items = [Book::HeadlineIndex::Item.new("chap1|test", [1, 1], "te_st")]
188
+ Book::HeadlineIndex.new(items, self)
189
+ end
190
+
191
+ @config["secnolevel"] = 3
192
+ actual = compile_inline("test @<hd>{chap1|test} test2")
193
+ assert_equal %Q|test 「1.1.1 te\\textunderscore{}st」 test2|, actual
194
+ end
195
+
196
+ def test_inline_ruby_comma
197
+ actual = compile_inline("@<ruby>{foo\\, bar\\, buz,フー・バー・バズ}")
198
+ assert_equal "\\ruby{foo, bar, buz}{フー・バー・バズ}", actual
199
+ end
200
+
201
+ def test_inline_uchar
202
+ actual = compile_inline("test @<uchar>{2460} test2")
203
+ assert_equal %Q|test \\UTF{2460} test2|, actual
204
+ end
205
+
206
+ def test_inline_idx
207
+ actual = compile_inline("@<idx>{__TEST%$}, @<hidx>{__TEST%$}")
208
+ assert_equal %Q|\\textunderscore{}\\textunderscore{}TEST\\%\\textdollar{}\\index{__TEST%$}, \\index{__TEST%$}|, actual
209
+ end
210
+
211
+ def test_jis_x_0201_kana
212
+ actual = compile_inline("foo・カンジ、テスト")
213
+ assert_equal %Q|foo\\aj半角{・}\\aj半角{カ}\\aj半角{ン}\\aj半角{シ}\\aj半角{゛}\\aj半角{、}テスト|, actual
214
+ end
215
+
216
+ def test_dlist
217
+ actual = compile_block(": foo\n foo.\n bar.\n")
218
+ assert_equal %Q|\n\\begin{description}\n\\item[foo] \\mbox{} \\\\\nfoo.bar.\n\\end{description}\n|, actual
219
+ end
220
+
221
+ def test_dlist_with_bracket
222
+ actual = compile_block(": foo[bar]\n foo.\n bar.\n")
223
+ assert_equal %Q|\n\\begin{description}\n\\item[foo\\lbrack{}bar\\rbrack{}] \\mbox{} \\\\\nfoo.bar.\n\\end{description}\n|, actual
224
+ end
225
+
226
+ def test_cmd
227
+ actual = compile_block("//cmd{\nfoo\nbar\n\nbuz\n//}\n")
228
+ assert_equal %Q|\n\\begin{reviewcmd}\nfoo\nbar\n\nbuz\n\\end{reviewcmd}\n|, actual
229
+ end
230
+
231
+ def test_cmd_caption
232
+ actual = compile_block("//cmd[cap1]{\nfoo\nbar\n\nbuz\n//}\n")
233
+ assert_equal %Q|\n\\reviewcmdcaption{cap1}\n\\begin{reviewcmd}\nfoo\nbar\n\nbuz\n\\end{reviewcmd}\n|, actual
234
+ end
235
+
236
+ def test_cmd_lst
237
+ @book.config["highlight"] = {}
238
+ @book.config["highlight"]["latex"] = "listings"
239
+ actual = compile_block("//cmd{\nfoo\nbar\n\nbuz\n//}\n")
240
+ assert_equal %Q|\\vspace{-1.5em}\\begin{reviewcmdlst}[title={\\relax},language={}]\nfoo\nbar\n\nbuz\n\\end{reviewcmdlst}\n|, actual
241
+ end
242
+
243
+ def test_emlist
244
+ actual = compile_block("//emlist{\nfoo\nbar\n\nbuz\n//}\n")
245
+ assert_equal %Q|\n\\begin{reviewemlist}\nfoo\nbar\n\nbuz\n\\end{reviewemlist}\n|, actual
246
+ end
247
+
248
+ def test_emlist_lst
249
+ @book.config["highlight"] = {}
250
+ @book.config["highlight"]["latex"] = "listings"
251
+ actual = compile_block("//emlist[][sql]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n")
252
+ 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
253
+ end
254
+
255
+ def test_emlist_lst_without_lang
256
+ @book.config["highlight"] = {}
257
+ @book.config["highlight"]["latex"] = "listings"
258
+ @book.config["highlight"]["lang"] = "sql"
259
+ actual = compile_block("//emlist[]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n")
260
+ 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
261
+ end
262
+
263
+
264
+ def test_emlist_caption
265
+ actual = compile_block("//emlist[cap1]{\nfoo\nbar\n\nbuz\n//}\n")
266
+ assert_equal %Q|\n\\reviewemlistcaption{cap1}\n\\begin{reviewemlist}\nfoo\nbar\n\nbuz\n\\end{reviewemlist}\n|, actual
267
+ end
268
+
269
+ def test_emlist_with_tab
270
+ actual = compile_block("//emlist{\n\tfoo\n\t\tbar\n\n\tbuz\n//}\n")
271
+ assert_equal %Q|\n\\begin{reviewemlist}\n foo\n bar\n\n buz\n\\end{reviewemlist}\n|, actual
272
+ end
273
+
274
+ def test_emlist_with_tab4
275
+ @config["tabwidth"] = 4
276
+ actual = compile_block("//emlist{\n\tfoo\n\t\tbar\n\n\tbuz\n//}\n")
277
+ assert_equal %Q|\n\\begin{reviewemlist}\n foo\n bar\n\n buz\n\\end{reviewemlist}\n|, actual
278
+ end
279
+
280
+ def test_listnum
281
+ actual = compile_block("//listnum[test1][ruby]{\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n//}\n")
282
+ assert_equal %Q|\\reviewlistcaption{リスト1.1: ruby}\n\\reviewlistcaption{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
283
+ end
284
+
285
+ def test_listnum_lst
286
+ @book.config["highlight"] = {}
287
+ @book.config["highlight"]["latex"] = "listings"
288
+ actual = compile_block("//listnum[test1][ruby]{\nclass Foo\n def foo\n bar\n\n buz\n end\nend\n//}\n")
289
+ 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
290
+ end
291
+
292
+ def test_quote
293
+ actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n")
294
+ assert_equal %Q|\n\\begin{quote}\nfoobar\n\nbuz\n\\end{quote}\n|, actual
295
+ end
296
+
297
+ def test_memo
298
+ actual = compile_block("//memo[this is @<b>{test}<&>_]{\ntest1\n\ntest@<i>{2}\n//}\n")
299
+ assert_equal %Q|\\begin{reviewminicolumn}\n\\reviewminicolumntitle{this is \\textbf{test}\\textless{}\\&\\textgreater{}\\textunderscore{}}\ntest1\n\ntest\\textit{2}\n\\end{reviewminicolumn}\n|, actual
300
+ end
301
+
302
+ def test_flushright
303
+ actual = compile_block("//flushright{\nfoo\nbar\n\nbuz\n//}\n")
304
+ assert_equal %Q|\n\\begin{flushright}\nfoobar\n\nbuz\n\\end{flushright}\n|, actual
305
+ end
306
+
307
+ def test_centering
308
+ actual = compile_block("//centering{\nfoo\nbar\n\nbuz\n//}\n")
309
+ assert_equal %Q|\n\\begin{center}\nfoobar\n\nbuz\n\\end{center}\n|, actual
310
+ end
311
+
312
+ def test_noindent
313
+ actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n")
314
+ assert_equal %Q|\\noindent\nfoobar\n\nfoo2bar2\n|, actual
315
+ end
316
+
317
+ def test_image
318
+ def @chapter.image(id)
319
+ item = Book::ImageIndex::Item.new("sampleimg",1)
320
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
321
+ item
322
+ end
323
+
324
+ actual = compile_block("//image[sampleimg][sample photo]{\n//}\n")
325
+ assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n|, actual
326
+ end
327
+
328
+ def test_image_with_metric
329
+ def @chapter.image(id)
330
+ item = Book::ImageIndex::Item.new("sampleimg",1)
331
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
332
+ item
333
+ end
334
+
335
+ actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n")
336
+ assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n|, actual
337
+ end
338
+
339
+ def test_image_with_metric2
340
+ def @chapter.image(id)
341
+ item = Book::ImageIndex::Item.new("sampleimg",1)
342
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
343
+ item
344
+ end
345
+
346
+ actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n")
347
+ assert_equal %Q|\\begin{reviewimage}\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
348
+ end
349
+
350
+ def test_indepimage
351
+ def @chapter.image(id)
352
+ item = Book::ImageIndex::Item.new("sampleimg",1)
353
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
354
+ item
355
+ end
356
+
357
+ actual = compile_block("//indepimage[sampleimg][sample photo]\n")
358
+ assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n|, actual
359
+ end
360
+
361
+ def test_indepimage_esc
362
+ def @chapter.image(id)
363
+ item = Book::ImageIndex::Item.new("sampleimg",1)
364
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
365
+ item
366
+ end
367
+
368
+ actual = compile_block("//indepimage[sean_2_10][sample photo][]\n")
369
+ assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n|, actual
370
+ end
371
+
372
+ def test_indepimage_without_caption
373
+ def @chapter.image(id)
374
+ item = Book::ImageIndex::Item.new("sampleimg",1)
375
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
376
+ item
377
+ end
378
+
379
+ # FIXME: indepimage's caption should not be with a counter.
380
+ actual = compile_block("//indepimage[sampleimg]\n")
381
+ assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\end{reviewimage}\n|, actual
382
+ end
383
+
384
+ def test_indepimage_with_metric
385
+ def @chapter.image(id)
386
+ item = Book::ImageIndex::Item.new("sampleimg",1)
387
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
388
+ item
389
+ end
390
+
391
+ actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n")
392
+ assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n|, actual
393
+ end
394
+
395
+ def test_indepimage_with_metric2
396
+ def @chapter.image(id)
397
+ item = Book::ImageIndex::Item.new("sampleimg",1)
398
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
399
+ item
400
+ end
401
+
402
+ actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2, html::class=\"sample\",latex::ignore=params]\n")
403
+ assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[scale=1.2,ignore=params]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n|, actual
404
+ end
405
+
406
+ def test_indepimage_without_caption_but_with_metric
407
+ def @chapter.image(id)
408
+ item = Book::ImageIndex::Item.new("sampleimg",1)
409
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
410
+ item
411
+ end
412
+
413
+ # FIXME: indepimage's caption should not be with a counter.
414
+ actual = compile_block("//indepimage[sampleimg][][scale=1.2]\n")
415
+ assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\end{reviewimage}\n|, actual
416
+ end
417
+
418
+ def test_bib
419
+ def @chapter.bibpaper(id)
420
+ Book::BibpaperIndex::Item.new("samplebib",1,"sample bib")
421
+ end
422
+
423
+ assert_equal "\\reviewbibref{[1]}{bib:samplebib}", compile_inline("@<bib>{samplebib}")
424
+ end
425
+
426
+ def test_bibpaper
427
+ def @chapter.bibpaper(id)
428
+ Book::BibpaperIndex::Item.new("samplebib",1,"sample bib")
429
+ end
430
+
431
+ actual = compile_block("//bibpaper[samplebib][sample bib @<b>{bold}]{\na\nb\n//}\n")
432
+ assert_equal %Q|[1] sample bib \\textbf{bold}\n\\label{bib:samplebib}\n\nab\n\n|, actual
433
+ end
434
+
435
+ def test_bibpaper_without_body
436
+ def @chapter.bibpaper(id)
437
+ Book::BibpaperIndex::Item.new("samplebib",1,"sample bib")
438
+ end
439
+
440
+ actual = compile_block("//bibpaper[samplebib][sample bib]\n")
441
+ assert_equal %Q|[1] sample bib\n\\label{bib:samplebib}\n\n|, actual
442
+ end
443
+
444
+ def column_helper(review)
445
+ compile_block(review)
446
+ end
447
+
448
+ def test_column_1
449
+ review =<<-EOS
450
+ ===[column] prev column
451
+
452
+ inside prev column
453
+
454
+ ===[column] test
455
+
456
+ inside column
457
+
458
+ ===[/column]
459
+ EOS
460
+ expected =<<-EOS
461
+
462
+ \\begin{reviewcolumn}
463
+ \\hypertarget{column:chap1:1}{}
464
+ \\reviewcolumnhead{}{prev column}
465
+ \\addcontentsline{toc}{subsection}{prev column}
466
+
467
+ inside prev column
468
+ \\end{reviewcolumn}
469
+
470
+ \\begin{reviewcolumn}
471
+ \\hypertarget{column:chap1:2}{}
472
+ \\reviewcolumnhead{}{test}
473
+ \\addcontentsline{toc}{subsection}{test}
474
+
475
+ inside column
476
+ \\end{reviewcolumn}
477
+ EOS
478
+ @config["toclevel"] = 3
479
+ assert_equal expected, column_helper(review)
480
+ end
481
+
482
+ def test_column_2
483
+ review =<<-EOS
484
+ ===[column] test
485
+
486
+ inside column
487
+
488
+ === next level
489
+ EOS
490
+ expected =<<-EOS
491
+
492
+ \\begin{reviewcolumn}
493
+ \\hypertarget{column:chap1:1}{}
494
+ \\reviewcolumnhead{}{test}
495
+
496
+ inside column
497
+ \\end{reviewcolumn}
498
+ \\subsection*{next level}
499
+ \\label{sec:1-0-1}
500
+ EOS
501
+
502
+ @config["toclevel"] = 1
503
+ assert_equal expected, column_helper(review)
504
+ end
505
+
506
+ def test_column_3
507
+ review =<<-EOS
508
+ ===[column] test
509
+
510
+ inside column
511
+
512
+ ===[/column_dummy]
513
+ EOS
514
+ assert_raise(ReVIEW::CompileError) do
515
+ column_helper(review)
516
+ end
517
+ end
518
+
519
+ def test_ul
520
+ src =<<-EOS
521
+ * AAA
522
+ * BBB
523
+ EOS
524
+ expected =<<-EOS
525
+
526
+ \\begin{itemize}
527
+ \\item AAA
528
+ \\item BBB
529
+ \\end{itemize}
530
+ EOS
531
+ actual = compile_block(src)
532
+ assert_equal expected, actual
533
+ end
534
+
535
+ def test_ul_with_bracket
536
+ src =<<-EOS
537
+ * AAA
538
+ * []BBB
539
+ EOS
540
+ expected =<<-EOS
541
+
542
+ \\begin{itemize}
543
+ \\item AAA
544
+ \\item \\lbrack{}]BBB
545
+ \\end{itemize}
546
+ EOS
547
+ actual = compile_block(src)
548
+ assert_equal expected, actual
549
+ end
550
+
551
+ def test_cont
552
+ src =<<-EOS
553
+ * AAA
554
+ -AA
555
+ * BBB
556
+ -BB
557
+ EOS
558
+ expected =<<-EOS
559
+
560
+ \\begin{itemize}
561
+ \\item AAA{-}AA
562
+ \\item BBB{-}BB
563
+ \\end{itemize}
564
+ EOS
565
+ actual = compile_block(src)
566
+ assert_equal expected, actual
567
+ end
568
+
569
+ def test_ul_nest1
570
+ src =<<-EOS
571
+ * AAA
572
+ ** AA
573
+ EOS
574
+
575
+ expected =<<-EOS
576
+
577
+ \\begin{itemize}
578
+ \\item AAA
579
+
580
+ \\begin{itemize}
581
+ \\item AA
582
+ \\end{itemize}
583
+ \\end{itemize}
584
+ EOS
585
+ actual = compile_block(src)
586
+ assert_equal expected, actual
587
+ end
588
+
589
+ def test_ul_nest3
590
+ src =<<-EOS
591
+ * AAA
592
+ ** AA
593
+ * BBB
594
+ ** BB
595
+ EOS
596
+
597
+ expected =<<-EOS
598
+
599
+ \\begin{itemize}
600
+ \\item AAA
601
+
602
+ \\begin{itemize}
603
+ \\item AA
604
+ \\end{itemize}
605
+ \\item BBB
606
+
607
+ \\begin{itemize}
608
+ \\item BB
609
+ \\end{itemize}
610
+ \\end{itemize}
611
+ EOS
612
+ actual = compile_block(src)
613
+ assert_equal expected, actual
614
+ end
615
+
616
+ def test_ol
617
+ src =<<-EOS
618
+ 3. AAA
619
+ 3. BBB
620
+ EOS
621
+
622
+ expected =<<-EOS
623
+
624
+ \\begin{enumerate}
625
+ \\item AAA
626
+ \\item BBB
627
+ \\end{enumerate}
628
+ EOS
629
+ actual = compile_block(src)
630
+ assert_equal expected, actual
631
+ end
632
+
633
+ def test_ol_with_bracket
634
+ src =<<-EOS
635
+ 1. AAA
636
+ 2. []BBB
637
+ EOS
638
+ expected =<<-EOS
639
+
640
+ \\begin{enumerate}
641
+ \\item AAA
642
+ \\item \\lbrack{}]BBB
643
+ \\end{enumerate}
644
+ EOS
645
+ actual = compile_block(src)
646
+ assert_equal expected, actual
647
+ end
648
+
649
+ def test_inline_raw0
650
+ assert_equal "normal", compile_inline("@<raw>{normal}")
651
+ end
652
+
653
+ def test_inline_raw1
654
+ assert_equal "body", compile_inline("@<raw>{|latex|body}")
655
+ end
656
+
657
+ def test_inline_raw2
658
+ assert_equal "body", compile_inline("@<raw>{|html, latex|body}")
659
+ end
660
+
661
+ def test_inline_raw3
662
+ assert_equal "", compile_inline("@<raw>{|idgxml, html|body}")
663
+ end
664
+
665
+ def test_inline_raw4
666
+ assert_equal "|latex body", compile_inline("@<raw>{|latex body}")
667
+ end
668
+
669
+ def test_inline_raw5
670
+ assert_equal "nor\nmal", compile_inline("@<raw>{|latex|nor\\nmal}")
671
+ end
672
+
673
+ def test_inline_endash
674
+ actual = compile_inline("- -- --- ----")
675
+ assert_equal "{-} {-}{-} {-}{-}{-} {-}{-}{-}{-}", actual
676
+ end
677
+
678
+ def test_inline_imgref
679
+ def @chapter.image(id)
680
+ item = Book::ImageIndex::Item.new("sampleimg", 1, 'sample photo')
681
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
682
+ item
683
+ end
684
+
685
+ actual = compile_block "@<imgref>{sampleimg}\n"
686
+ expected = "\n\\reviewimageref{1.1}{image:chap1:sampleimg}「sample photo」\n"
687
+ assert_equal expected, actual
688
+ end
689
+
690
+ def test_inline_imgref2
691
+ def @chapter.image(id)
692
+ item = Book::NumberlessImageIndex::Item.new("sampleimg", 1)
693
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
694
+ item
695
+ end
696
+
697
+ actual = compile_block "@<imgref>{sampleimg}\n"
698
+ expected = "\n\\reviewimageref{1.1}{image:chap1:sampleimg}\n"
699
+ assert_equal expected, actual
700
+ end
701
+
702
+ def test_block_raw0
703
+ actual = compile_block("//raw[<>!\"\\n& ]\n")
704
+ expected = %Q(<>!\"\n& )
705
+ assert_equal expected, actual
706
+ end
707
+
708
+ def test_block_raw1
709
+ actual = compile_block("//raw[|latex|<>!\"\\n& ]\n")
710
+ expected = %Q(<>!\"\n& )
711
+ assert_equal expected, actual
712
+ end
713
+
714
+ def test_block_raw2
715
+ actual = compile_block("//raw[|html, latex|<>!\"\\n& ]\n")
716
+ expected = %Q(<>!\"\n& )
717
+ assert_equal expected, actual
718
+ end
719
+
720
+ def test_block_raw3
721
+ actual = compile_block("//raw[|html, idgxml|<>!\"\\n& ]\n")
722
+ expected = ''
723
+ assert_equal expected, actual
724
+ end
725
+
726
+ def test_block_raw4
727
+ actual = compile_block("//raw[|latex <>!\"\\n& ]\n")
728
+ expected = %Q(|latex <>!\"\n& )
729
+ assert_equal expected, actual
730
+ end
731
+
732
+ end