review 0.9.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +9 -0
- data/ChangeLog +326 -0
- data/Rakefile +3 -5
- data/VERSION +1 -1
- data/bin/review-compile +50 -50
- data/bin/review-epubmaker +62 -75
- data/bin/review-epubmaker-ng +185 -0
- data/bin/review-index +2 -1
- data/bin/review-pdfmaker +158 -101
- data/bin/review-vol +6 -2
- data/doc/format.rdoc +111 -46
- data/doc/libepubmaker/sample.yaml +90 -0
- data/doc/quickstart.rdoc +188 -0
- data/doc/sample.yaml +8 -0
- data/lib/epubmaker.rb +28 -0
- data/lib/epubmaker/content.rb +82 -0
- data/lib/epubmaker/epubv2.rb +419 -0
- data/lib/epubmaker/epubv3.rb +249 -0
- data/lib/epubmaker/producer.rb +204 -0
- data/lib/epubmaker/resource.rb +66 -0
- data/lib/review.rb +1 -1
- data/lib/review/book.rb +27 -4
- data/lib/review/builder.rb +153 -20
- data/lib/review/compiler.rb +61 -10
- data/lib/review/ewbbuilder.rb +3 -2
- data/lib/review/htmlbuilder.rb +174 -67
- data/lib/review/i18n.rb +30 -0
- data/lib/review/i18n.yaml +23 -0
- data/lib/review/idgxmlbuilder.rb +110 -63
- data/lib/review/index.rb +34 -12
- data/lib/review/latexbuilder.rb +128 -33
- data/lib/review/latexutils.rb +18 -1
- data/lib/review/textbuilder.rb +17 -0
- data/lib/review/tocparser.rb +3 -1
- data/lib/review/tocprinter.rb +1 -0
- data/lib/review/topbuilder.rb +397 -198
- data/review.gemspec +101 -100
- data/test/test_book.rb +27 -0
- data/test/test_epubmaker.rb +507 -0
- data/test/test_helper.rb +8 -0
- data/test/test_htmlbuilder.rb +295 -10
- data/test/test_i18n.rb +64 -0
- data/test/test_idgxmlbuilder.rb +268 -10
- data/test/test_latexbuilder.rb +316 -20
- data/test/test_preprocessor.rb +23 -0
- data/test/test_topbuilder.rb +246 -0
- metadata +46 -53
- data/doc/format.re +0 -505
- data/test/test_index.rb +0 -15
data/test/test_latexbuilder.rb
CHANGED
@@ -24,18 +24,18 @@ class LATEXBuidlerTest < Test::Unit::TestCase
|
|
24
24
|
|
25
25
|
def test_headline_level1
|
26
26
|
@builder.headline(1,"test","this is test.")
|
27
|
-
assert_equal %Q|\\chapter{this is test.}\n|, @builder.result
|
27
|
+
assert_equal %Q|\\chapter{this is test.}\n\\label{chap:chap1}\n|, @builder.result
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_headline_level1_without_secno
|
31
31
|
@param["secnolevel"] = 0
|
32
32
|
@builder.headline(1,"test","this is test.")
|
33
|
-
assert_equal %Q|\\chapter*{this is test.}\n|, @builder.result
|
33
|
+
assert_equal %Q|\\chapter*{this is test.}\n\\label{chap:chap1}\n|, @builder.result
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_headline_level1_with_inlinetag
|
37
37
|
@builder.headline(1,"test","this @<b>{is} test.<&\"_>")
|
38
|
-
assert_equal %Q|\\chapter{this \\textbf{is} test.\\textless{}\\&"\\textunderscore{}\\textgreater{}}\n|, @builder.result
|
38
|
+
assert_equal %Q|\\chapter{this \\textbf{is} test.\\textless{}\\&"\\textunderscore{}\\textgreater{}}\n\\label{chap:chap1}\n|, @builder.result
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_headline_level2
|
@@ -61,17 +61,22 @@ class LATEXBuidlerTest < Test::Unit::TestCase
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def test_href
|
64
|
-
ret = @builder.
|
64
|
+
ret = @builder.compile_inline('@<href>{http://github.com,GitHub}')
|
65
65
|
assert_equal %Q|\\href{http://github.com}{GitHub}|, ret
|
66
66
|
end
|
67
67
|
|
68
|
+
def test_inline_href
|
69
|
+
ret = @builder.compile_inline('@<href>{http://github.com,Git\\,Hub}')
|
70
|
+
assert_equal %Q|\\href{http://github.com}{Git,Hub}|, ret
|
71
|
+
end
|
72
|
+
|
68
73
|
def test_href_without_label
|
69
|
-
ret = @builder.
|
70
|
-
assert_equal %Q|\\
|
74
|
+
ret = @builder.compile_inline('@<href>{http://github.com}')
|
75
|
+
assert_equal %Q|\\url{http://github.com}|, ret
|
71
76
|
end
|
72
77
|
|
73
78
|
def test_href_with_underscore
|
74
|
-
ret = @builder.
|
79
|
+
ret = @builder.compile_inline('@<href>{http://example.com/aaa/bbb, AAA_BBB}')
|
75
80
|
assert_equal %Q|\\href{http://example.com/aaa/bbb}{AAA\\textunderscore{}BBB}|, ret
|
76
81
|
end
|
77
82
|
|
@@ -112,7 +117,7 @@ class LATEXBuidlerTest < Test::Unit::TestCase
|
|
112
117
|
|
113
118
|
def test_inline_raw
|
114
119
|
ret = @builder.compile_inline("@<raw>{@<tt>{inline!$%\\}}")
|
115
|
-
assert_equal
|
120
|
+
assert_equal "@<tt>{inline!$%}", ret
|
116
121
|
end
|
117
122
|
|
118
123
|
def test_inline_sup
|
@@ -179,9 +184,36 @@ class LATEXBuidlerTest < Test::Unit::TestCase
|
|
179
184
|
assert_equal %Q|test \\UTF{2460} test2|, ret
|
180
185
|
end
|
181
186
|
|
182
|
-
def
|
183
|
-
@builder.
|
184
|
-
|
187
|
+
def test_dlist
|
188
|
+
@builder.dl_begin
|
189
|
+
@builder.dt "foo"
|
190
|
+
@builder.dd ["foo.\n", "bar.\n"]
|
191
|
+
@builder.dl_end
|
192
|
+
assert_equal %Q|\n\\begin{description}\n\\item[foo] \\mbox{} \\\\\nfoo.\nbar.\n\\end{description}\n|, @builder.result
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_cmd
|
196
|
+
lines = ["foo", "bar", "","buz"]
|
197
|
+
@builder.cmd(lines)
|
198
|
+
assert_equal %Q|\n\\begin{reviewcmd}\n\\begin{alltt}\nfoo\nbar\n\nbuz\n\\end{alltt}\n\\end{reviewcmd}\n|, @builder.result
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_cmd_caption
|
202
|
+
lines = ["foo", "bar", "","buz"]
|
203
|
+
@builder.cmd(lines, "cap1")
|
204
|
+
assert_equal %Q|\n\\reviewcmdcaption{cap1}\n\\begin{reviewcmd}\n\\begin{alltt}\nfoo\nbar\n\nbuz\n\\end{alltt}\n\\end{reviewcmd}\n|, @builder.result
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_emlist
|
208
|
+
lines = ["foo", "bar", "","buz"]
|
209
|
+
@builder.emlist(lines)
|
210
|
+
assert_equal %Q|\n\\begin{reviewemlist}\n\\begin{alltt}\nfoo\nbar\n\nbuz\n\\end{alltt}\n\\end{reviewemlist}\n|, @builder.result
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_emlist_caption
|
214
|
+
lines = ["foo", "bar", "","buz"]
|
215
|
+
@builder.emlist(lines, "cap1")
|
216
|
+
assert_equal %Q|\n\\reviewemlistcaption{cap1}\n\\begin{reviewemlist}\n\\begin{alltt}\nfoo\nbar\n\nbuz\n\\end{alltt}\n\\end{reviewemlist}\n|, @builder.result
|
185
217
|
end
|
186
218
|
|
187
219
|
def test_quote
|
@@ -204,12 +236,7 @@ class LATEXBuidlerTest < Test::Unit::TestCase
|
|
204
236
|
@builder.noindent
|
205
237
|
@builder.paragraph(["foo", "bar"])
|
206
238
|
@builder.paragraph(["foo2", "bar2"])
|
207
|
-
assert_equal %Q|\\noindent\
|
208
|
-
end
|
209
|
-
|
210
|
-
def test_raw
|
211
|
-
@builder.raw("<&>\\n")
|
212
|
-
assert_equal %Q|<&>\n|, @builder.result
|
239
|
+
assert_equal %Q|\\noindent\nfoo\nbar\n\nfoo2\nbar2\n|, @builder.raw_result
|
213
240
|
end
|
214
241
|
|
215
242
|
def test_image
|
@@ -220,7 +247,7 @@ class LATEXBuidlerTest < Test::Unit::TestCase
|
|
220
247
|
end
|
221
248
|
|
222
249
|
@builder.image_image("sampleimg","sample photo",nil)
|
223
|
-
assert_equal %Q|\\begin{reviewimage}\n\\includegraphics{./images/chap1-sampleimg.png}\n\\label{image:chap1:sampleimg}\n\\caption{sample photo}\n\\end{reviewimage}\n|, @builder.raw_result
|
250
|
+
assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\label{image:chap1:sampleimg}\n\\caption{sample photo}\n\\end{reviewimage}\n|, @builder.raw_result
|
224
251
|
end
|
225
252
|
|
226
253
|
def test_image_with_metric
|
@@ -234,6 +261,17 @@ class LATEXBuidlerTest < Test::Unit::TestCase
|
|
234
261
|
assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\label{image:chap1:sampleimg}\n\\caption{sample photo}\n\\end{reviewimage}\n|, @builder.raw_result
|
235
262
|
end
|
236
263
|
|
264
|
+
def test_image_with_metric2
|
265
|
+
def @chapter.image(id)
|
266
|
+
item = ImageIndex::Item.new("sampleimg",1)
|
267
|
+
item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]}
|
268
|
+
item
|
269
|
+
end
|
270
|
+
|
271
|
+
@builder.image_image("sampleimg","sample photo","scale=1.2, html::class=\"sample\", latex::height=3cm")
|
272
|
+
assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[scale=1.2,height=3cm]{./images/chap1-sampleimg.png}\n\\label{image:chap1:sampleimg}\n\\caption{sample photo}\n\\end{reviewimage}\n|, @builder.raw_result
|
273
|
+
end
|
274
|
+
|
237
275
|
def test_indepimage
|
238
276
|
def @chapter.image(id)
|
239
277
|
item = ImageIndex::Item.new("sampleimg",1)
|
@@ -243,7 +281,7 @@ class LATEXBuidlerTest < Test::Unit::TestCase
|
|
243
281
|
|
244
282
|
# FIXME: indepimage's caption should not be with a counter.
|
245
283
|
@builder.indepimage("sampleimg","sample photo",nil)
|
246
|
-
assert_equal %Q|\\begin{reviewimage}\n\\includegraphics{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\end{reviewimage}\n|, @builder.raw_result
|
284
|
+
assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\end{reviewimage}\n|, @builder.raw_result
|
247
285
|
end
|
248
286
|
|
249
287
|
def test_indepimage_without_caption
|
@@ -255,7 +293,7 @@ class LATEXBuidlerTest < Test::Unit::TestCase
|
|
255
293
|
|
256
294
|
# FIXME: indepimage's caption should not be with a counter.
|
257
295
|
@builder.indepimage("sampleimg",nil,nil)
|
258
|
-
assert_equal %Q|\\begin{reviewimage}\n\\includegraphics{./images/chap1-sampleimg.png}\n\\end{reviewimage}\n|, @builder.raw_result
|
296
|
+
assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\end{reviewimage}\n|, @builder.raw_result
|
259
297
|
end
|
260
298
|
|
261
299
|
def test_indepimage_with_metric
|
@@ -270,6 +308,18 @@ class LATEXBuidlerTest < Test::Unit::TestCase
|
|
270
308
|
assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\end{reviewimage}\n|, @builder.raw_result
|
271
309
|
end
|
272
310
|
|
311
|
+
def test_indepimage_with_metric2
|
312
|
+
def @chapter.image(id)
|
313
|
+
item = ImageIndex::Item.new("sampleimg",1)
|
314
|
+
item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]}
|
315
|
+
item
|
316
|
+
end
|
317
|
+
|
318
|
+
# FIXME: indepimage's caption should not be with a counter.
|
319
|
+
@builder.indepimage("sampleimg","sample photo","scale=1.2, latex::height=3cm, html::class=\"sample\"")
|
320
|
+
assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[scale=1.2,height=3cm]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\end{reviewimage}\n|, @builder.raw_result
|
321
|
+
end
|
322
|
+
|
273
323
|
def test_indepimage_without_caption_but_with_metric
|
274
324
|
def @chapter.image(id)
|
275
325
|
item = ImageIndex::Item.new("sampleimg",1)
|
@@ -282,4 +332,250 @@ class LATEXBuidlerTest < Test::Unit::TestCase
|
|
282
332
|
assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\end{reviewimage}\n|, @builder.raw_result
|
283
333
|
end
|
284
334
|
|
335
|
+
def test_bib
|
336
|
+
def @chapter.bibpaper(id)
|
337
|
+
BibpaperIndex::Item.new("samplebib",1,"sample bib")
|
338
|
+
end
|
339
|
+
|
340
|
+
assert_equal "[1]", @builder.inline_bib("samplebib")
|
341
|
+
end
|
342
|
+
|
343
|
+
def test_bibpaper
|
344
|
+
def @chapter.bibpaper(id)
|
345
|
+
BibpaperIndex::Item.new("samplebib",1,"sample bib")
|
346
|
+
end
|
347
|
+
|
348
|
+
@builder.bibpaper(["a", "b"], "samplebib", "sample bib @<b>{bold}")
|
349
|
+
assert_equal %Q|[1] sample bib \\textbf{bold}\n\na\nb\n\n|, @builder.raw_result
|
350
|
+
end
|
351
|
+
|
352
|
+
def test_bibpaper_without_body
|
353
|
+
def @chapter.bibpaper(id)
|
354
|
+
BibpaperIndex::Item.new("samplebib",1,"sample bib")
|
355
|
+
end
|
356
|
+
|
357
|
+
@builder.bibpaper([], "samplebib", "sample bib")
|
358
|
+
assert_equal %Q|[1] sample bib\n\n|, @builder.raw_result
|
359
|
+
end
|
360
|
+
|
361
|
+
def column_helper(review)
|
362
|
+
chap_singleton = class << @chapter; self; end
|
363
|
+
chap_singleton.send(:define_method, :content) { review }
|
364
|
+
@compiler.compile(@chapter)
|
365
|
+
end
|
366
|
+
|
367
|
+
def test_column_1
|
368
|
+
review =<<-EOS
|
369
|
+
===[column] prev column
|
370
|
+
|
371
|
+
inside prev column
|
372
|
+
|
373
|
+
===[column] test
|
374
|
+
|
375
|
+
inside column
|
376
|
+
|
377
|
+
===[/column]
|
378
|
+
EOS
|
379
|
+
expect =<<-EOS
|
380
|
+
|
381
|
+
\\begin{reviewcolumn}
|
382
|
+
\\reviewcolumnhead{}{prev column}
|
383
|
+
|
384
|
+
inside prev column
|
385
|
+
|
386
|
+
\\end{reviewcolumn}
|
387
|
+
|
388
|
+
\\begin{reviewcolumn}
|
389
|
+
\\reviewcolumnhead{}{test}
|
390
|
+
|
391
|
+
inside column
|
392
|
+
|
393
|
+
\\end{reviewcolumn}
|
394
|
+
EOS
|
395
|
+
assert_equal expect, column_helper(review)
|
396
|
+
end
|
397
|
+
|
398
|
+
def test_column_2
|
399
|
+
review =<<-EOS
|
400
|
+
===[column] test
|
401
|
+
|
402
|
+
inside column
|
403
|
+
|
404
|
+
=== next level
|
405
|
+
EOS
|
406
|
+
expect =<<-EOS
|
407
|
+
|
408
|
+
\\begin{reviewcolumn}
|
409
|
+
\\reviewcolumnhead{}{test}
|
410
|
+
|
411
|
+
inside column
|
412
|
+
|
413
|
+
\\end{reviewcolumn}
|
414
|
+
|
415
|
+
\\subsection*{next level}
|
416
|
+
EOS
|
417
|
+
|
418
|
+
assert_equal expect, column_helper(review)
|
419
|
+
end
|
420
|
+
|
421
|
+
def test_column_3
|
422
|
+
review =<<-EOS
|
423
|
+
===[column] test
|
424
|
+
|
425
|
+
inside column
|
426
|
+
|
427
|
+
===[/column_dummy]
|
428
|
+
EOS
|
429
|
+
assert_raise(ReVIEW::CompileError) do
|
430
|
+
column_helper(review)
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
def test_ul
|
435
|
+
src =<<-EOS
|
436
|
+
* AAA
|
437
|
+
* BBB
|
438
|
+
EOS
|
439
|
+
expect =<<-EOS
|
440
|
+
|
441
|
+
\\begin{itemize}
|
442
|
+
\\item AAA
|
443
|
+
\\item BBB
|
444
|
+
\\end{itemize}
|
445
|
+
EOS
|
446
|
+
ul_helper(src, expect)
|
447
|
+
end
|
448
|
+
|
449
|
+
def test_cont
|
450
|
+
src =<<-EOS
|
451
|
+
* AAA
|
452
|
+
-AA
|
453
|
+
* BBB
|
454
|
+
-BB
|
455
|
+
EOS
|
456
|
+
expect =<<-EOS
|
457
|
+
|
458
|
+
\\begin{itemize}
|
459
|
+
\\item AAA-AA
|
460
|
+
\\item BBB-BB
|
461
|
+
\\end{itemize}
|
462
|
+
EOS
|
463
|
+
ul_helper(src, expect)
|
464
|
+
end
|
465
|
+
|
466
|
+
def test_ul_nest1
|
467
|
+
src =<<-EOS
|
468
|
+
* AAA
|
469
|
+
** AA
|
470
|
+
EOS
|
471
|
+
|
472
|
+
expect =<<-EOS
|
473
|
+
|
474
|
+
\\begin{itemize}
|
475
|
+
\\item AAA
|
476
|
+
|
477
|
+
\\begin{itemize}
|
478
|
+
\\item AA
|
479
|
+
\\end{itemize}
|
480
|
+
|
481
|
+
\\end{itemize}
|
482
|
+
EOS
|
483
|
+
ul_helper(src, expect)
|
484
|
+
end
|
485
|
+
|
486
|
+
def test_ul_nest3
|
487
|
+
src =<<-EOS
|
488
|
+
* AAA
|
489
|
+
** AA
|
490
|
+
* BBB
|
491
|
+
** BB
|
492
|
+
EOS
|
493
|
+
|
494
|
+
expect =<<-EOS
|
495
|
+
|
496
|
+
\\begin{itemize}
|
497
|
+
\\item AAA
|
498
|
+
|
499
|
+
\\begin{itemize}
|
500
|
+
\\item AA
|
501
|
+
\\end{itemize}
|
502
|
+
|
503
|
+
\\item BBB
|
504
|
+
|
505
|
+
\\begin{itemize}
|
506
|
+
\\item BB
|
507
|
+
\\end{itemize}
|
508
|
+
|
509
|
+
\\end{itemize}
|
510
|
+
EOS
|
511
|
+
ul_helper(src, expect)
|
512
|
+
end
|
513
|
+
|
514
|
+
def test_inline_raw0
|
515
|
+
assert_equal "normal", @builder.inline_raw("normal")
|
516
|
+
end
|
517
|
+
|
518
|
+
def test_inline_raw1
|
519
|
+
assert_equal "body", @builder.inline_raw("|latex|body")
|
520
|
+
end
|
521
|
+
|
522
|
+
def test_inline_raw2
|
523
|
+
assert_equal "body", @builder.inline_raw("|html, latex|body")
|
524
|
+
end
|
525
|
+
|
526
|
+
def test_inline_raw3
|
527
|
+
assert_equal "", @builder.inline_raw("|idgxml, html|body")
|
528
|
+
end
|
529
|
+
|
530
|
+
def test_inline_raw4
|
531
|
+
assert_equal "|latex body", @builder.inline_raw("|latex body")
|
532
|
+
end
|
533
|
+
|
534
|
+
def test_inline_raw5
|
535
|
+
assert_equal "nor\nmal", @builder.inline_raw("|latex|nor\\nmal")
|
536
|
+
end
|
537
|
+
|
538
|
+
def test_block_raw0
|
539
|
+
@builder.raw("<>!\"\\n& ")
|
540
|
+
expect =<<-EOS
|
541
|
+
<>!"
|
542
|
+
&
|
543
|
+
EOS
|
544
|
+
assert_equal expect.chomp, @builder.raw_result
|
545
|
+
end
|
546
|
+
|
547
|
+
def test_block_raw1
|
548
|
+
@builder.raw("|latex|<>!\"\\n& ")
|
549
|
+
expect =<<-EOS
|
550
|
+
<>!"
|
551
|
+
&
|
552
|
+
EOS
|
553
|
+
assert_equal expect.chomp, @builder.raw_result
|
554
|
+
end
|
555
|
+
|
556
|
+
def test_block_raw2
|
557
|
+
@builder.raw("|html, latex|<>!\"\\n& ")
|
558
|
+
expect =<<-EOS
|
559
|
+
<>!\"
|
560
|
+
&
|
561
|
+
EOS
|
562
|
+
assert_equal expect.chomp, @builder.raw_result
|
563
|
+
end
|
564
|
+
|
565
|
+
def test_block_raw3
|
566
|
+
@builder.raw("|html, idgxml|<>!\"\\n& ")
|
567
|
+
expect =<<-EOS
|
568
|
+
EOS
|
569
|
+
assert_equal expect.chomp, @builder.raw_result
|
570
|
+
end
|
571
|
+
|
572
|
+
def test_block_raw4
|
573
|
+
@builder.raw("|latex <>!\"\\n& ")
|
574
|
+
expect =<<-EOS
|
575
|
+
|latex <>!\"
|
576
|
+
&
|
577
|
+
EOS
|
578
|
+
assert_equal expect.chomp, @builder.raw_result
|
579
|
+
end
|
580
|
+
|
285
581
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'review/preprocessor'
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
class PreprocessorStripTest < Test::Unit::TestCase
|
6
|
+
include ReVIEW
|
7
|
+
|
8
|
+
def test_gets
|
9
|
+
f = StringIO.new '= Header'
|
10
|
+
s = Preprocessor::Strip.new(f)
|
11
|
+
expect = '= Header'
|
12
|
+
actual = s.gets
|
13
|
+
assert_equal expect, actual
|
14
|
+
end
|
15
|
+
|
16
|
+
# def test_gets_with_comment
|
17
|
+
# f = StringIO.new '#@warn(write it later)'
|
18
|
+
# s = Preprocessor::Strip.new(f)
|
19
|
+
# expect = '#@#' + "\n"
|
20
|
+
# actual = s.gets
|
21
|
+
# assert_equal expect, actual
|
22
|
+
# end
|
23
|
+
end
|
@@ -0,0 +1,246 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'review/compiler'
|
5
|
+
require 'review/book'
|
6
|
+
require 'review/topbuilder'
|
7
|
+
|
8
|
+
class TOPBuidlerTest < Test::Unit::TestCase
|
9
|
+
include ReVIEW
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@builder = TOPBuilder.new()
|
13
|
+
@param = {
|
14
|
+
"secnolevel" => 2,
|
15
|
+
"inencoding" => "UTF-8",
|
16
|
+
"outencoding" => "UTF-8",
|
17
|
+
"subdirmode" => nil,
|
18
|
+
}
|
19
|
+
ReVIEW.book.param = @param
|
20
|
+
@compiler = ReVIEW::Compiler.new(@builder)
|
21
|
+
@chapter = Chapter.new(nil, 1, '-', nil, StringIO.new)
|
22
|
+
location = Location.new(nil, nil)
|
23
|
+
@builder.bind(@compiler, @chapter, location)
|
24
|
+
|
25
|
+
@builder.instance_eval do
|
26
|
+
# to ignore lineno in original method
|
27
|
+
def warn(msg)
|
28
|
+
puts msg
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_headline_level1
|
34
|
+
@builder.headline(1,"test","this is test.")
|
35
|
+
assert_equal %Q|■H1■第1章 this is test.\n|, @builder.raw_result
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_headline_level1_without_secno
|
39
|
+
@param["secnolevel"] = 0
|
40
|
+
@builder.headline(1,"test","this is test.")
|
41
|
+
assert_equal %Q|■H1■this is test.\n|, @builder.raw_result
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_headline_level2
|
45
|
+
@builder.headline(2,"test","this is test.")
|
46
|
+
assert_equal %Q|■H2■1.1 this is test.\n|, @builder.raw_result
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_headline_level3
|
50
|
+
@builder.headline(3,"test","this is test.")
|
51
|
+
assert_equal %Q|■H3■this is test.\n|, @builder.raw_result
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_headline_level3_with_secno
|
55
|
+
@param["secnolevel"] = 3
|
56
|
+
@builder.headline(3,"test","this is test.")
|
57
|
+
assert_equal %Q|■H3■1.0.1 this is test.\n|, @builder.raw_result
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_href
|
61
|
+
ret = @builder.compile_href("http://github.com", "GitHub")
|
62
|
+
assert_equal %Q|GitHub(△http://github.com☆)|, ret
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_href_without_label
|
66
|
+
ret = @builder.compile_href("http://github.com",nil)
|
67
|
+
assert_equal %Q|△http://github.com☆|, ret
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_inline_raw
|
71
|
+
ret = @builder.inline_raw("@<tt>{inline}")
|
72
|
+
assert_equal %Q|@<tt>{inline}|, ret
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_inline_ruby
|
76
|
+
ret = @builder.compile_ruby("coffin", "bed")
|
77
|
+
assert_equal %Q|coffin◆→DTP連絡:「coffin」に「bed」とルビ←◆|, ret
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_inline_kw
|
81
|
+
ret = @builder.compile_inline("@<kw>{ISO, International Organization for Standardization } @<kw>{Ruby<>}")
|
82
|
+
assert_equal %Q|★ISO☆(International Organization for Standardization) ★Ruby<>☆|, ret
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_inline_maru
|
86
|
+
ret = @builder.compile_inline("@<maru>{1}@<maru>{20}@<maru>{A}@<maru>{z}")
|
87
|
+
assert_equal %Q|1◆→丸数字1←◆20◆→丸数字20←◆A◆→丸数字A←◆z◆→丸数字z←◆|, ret
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_inline_br
|
91
|
+
ret = @builder.inline_br("")
|
92
|
+
assert_equal %Q|\n|, ret
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_inline_uchar
|
96
|
+
ret = @builder.compile_inline("test @<uchar>{2460} test2")
|
97
|
+
assert_equal %Q|test ① test2|, ret
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_inline_in_table
|
101
|
+
@builder.table(["★1☆\t▲2☆", "------------", "★3☆\t▲4☆<>&"])
|
102
|
+
assert_equal %Q|★★1☆☆\t★▲2☆☆\n★3☆\t▲4☆<>&\n◆→終了:表←◆\n\n|, @builder.raw_result
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_paragraph
|
106
|
+
lines = ["foo","bar"]
|
107
|
+
@builder.paragraph(lines)
|
108
|
+
assert_equal %Q|foobar\n|, @builder.raw_result
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_tabbed_paragraph
|
112
|
+
lines = ["\tfoo","bar"]
|
113
|
+
@builder.paragraph(lines)
|
114
|
+
assert_equal %Q|\tfoobar\n|, @builder.raw_result
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_flushright
|
118
|
+
@builder.flushright(["foo", "bar", "","buz"])
|
119
|
+
assert_equal %Q|◆→開始:右寄せ←◆\nfoobar\nbuz\n◆→終了:右寄せ←◆\n\n|, @builder.raw_result
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_noindent
|
123
|
+
@builder.noindent
|
124
|
+
@builder.paragraph(["foo", "bar"])
|
125
|
+
@builder.paragraph(["foo2", "bar2"])
|
126
|
+
assert_equal %Q|◆→DTP連絡:次の1行インデントなし←◆\nfoobar\nfoo2bar2\n|, @builder.raw_result
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_list
|
130
|
+
def @chapter.list(id)
|
131
|
+
ListIndex::Item.new("test",1)
|
132
|
+
end
|
133
|
+
@builder.list(["foo", "bar"], "test", "this is @<b>{test}<&>_")
|
134
|
+
assert_equal %Q|◆→開始:リスト←◆\nリスト1.1 this is ★test☆<&>_\n\nfoo\nbar\n◆→終了:リスト←◆\n\n|, @builder.raw_result
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_listnum
|
138
|
+
def @chapter.list(id)
|
139
|
+
ListIndex::Item.new("test",1)
|
140
|
+
end
|
141
|
+
@builder.listnum(["foo", "bar"], "test", "this is @<b>{test}<&>_")
|
142
|
+
assert_equal %Q|◆→開始:リスト←◆\nリスト1.1 this is ★test☆<&>_\n\n 1: foo\n 2: bar\n◆→終了:リスト←◆\n\n|, @builder.raw_result
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_emlistnum
|
146
|
+
@builder.emlistnum(["foo", "bar"], "this is @<b>{test}<&>_")
|
147
|
+
assert_equal %Q|◆→開始:インラインリスト←◆\n■this is ★test☆<&>_\n 1: foo\n 2: bar\n◆→終了:インラインリスト←◆\n\n|, @builder.raw_result
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_image
|
151
|
+
def @chapter.image(id)
|
152
|
+
item = ImageIndex::Item.new("sampleimg",1)
|
153
|
+
item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]}
|
154
|
+
item
|
155
|
+
end
|
156
|
+
|
157
|
+
@builder.image(["foo"], "sampleimg","sample photo",nil)
|
158
|
+
assert_equal %Q|◆→開始:図←◆\n図1.1 sample photo\n\n◆→./images/chap1-sampleimg.png←◆\n◆→終了:図←◆\n\n|, @builder.raw_result
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_image_with_metric
|
162
|
+
def @chapter.image(id)
|
163
|
+
item = ImageIndex::Item.new("sampleimg",1)
|
164
|
+
item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]}
|
165
|
+
item
|
166
|
+
end
|
167
|
+
|
168
|
+
@builder.image(["foo"], "sampleimg","sample photo","scale=1.2")
|
169
|
+
assert_equal %Q|◆→開始:図←◆\n図1.1 sample photo\n\n◆→./images/chap1-sampleimg.png←◆\n◆→終了:図←◆\n\n|, @builder.raw_result
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_texequation
|
173
|
+
@builder.texequation(["\\sin", "1^{2}"])
|
174
|
+
assert_equal %Q|◆→開始:TeX式←◆\n\\sin\n1^{2}\n◆→終了:TeX式←◆\n\n|, @builder.raw_result
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_inline_raw0
|
178
|
+
assert_equal "normal", @builder.inline_raw("normal")
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_inline_raw1
|
182
|
+
assert_equal "body", @builder.inline_raw("|top|body")
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_inline_raw2
|
186
|
+
assert_equal "body", @builder.inline_raw("|top, latex|body")
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_inline_raw3
|
190
|
+
assert_equal "", @builder.inline_raw("|idgxml, html|body")
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_inline_raw4
|
194
|
+
assert_equal "|top body", @builder.inline_raw("|top body")
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_inline_raw5
|
198
|
+
assert_equal "nor\nmal", @builder.inline_raw("|top|nor\\nmal")
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_block_raw0
|
202
|
+
@builder.raw("<>!\"\\n& ")
|
203
|
+
expect =<<-EOS
|
204
|
+
It is recommended to set builder(s).
|
205
|
+
<>!"
|
206
|
+
&
|
207
|
+
EOS
|
208
|
+
assert_equal expect.chomp, @builder.raw_result
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_block_raw1
|
212
|
+
@builder.raw("|top|<>!\"\\n& ")
|
213
|
+
expect =<<-EOS
|
214
|
+
<>!"
|
215
|
+
&
|
216
|
+
EOS
|
217
|
+
assert_equal expect.chomp, @builder.raw_result
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_block_raw2
|
221
|
+
@builder.raw("|top, latex|<>!\"\\n& ")
|
222
|
+
expect =<<-EOS
|
223
|
+
<>!\"
|
224
|
+
&
|
225
|
+
EOS
|
226
|
+
assert_equal expect.chomp, @builder.raw_result
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_block_raw3
|
230
|
+
@builder.raw("|latex, idgxml|<>!\"\\n& ")
|
231
|
+
expect =<<-EOS
|
232
|
+
EOS
|
233
|
+
assert_equal expect.chomp, @builder.raw_result
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_block_raw4
|
237
|
+
@builder.raw("|top <>!\"\\n& ")
|
238
|
+
expect =<<-EOS
|
239
|
+
It is recommended to set builder(s).
|
240
|
+
|top <>!\"
|
241
|
+
&
|
242
|
+
EOS
|
243
|
+
assert_equal expect.chomp, @builder.raw_result
|
244
|
+
end
|
245
|
+
|
246
|
+
end
|