review 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +20 -5
  3. data/.travis.yml +2 -1
  4. data/NEWS.ja.md +93 -0
  5. data/NEWS.md +77 -0
  6. data/README.md +1 -1
  7. data/bin/review +38 -12
  8. data/bin/review-compile +106 -88
  9. data/bin/review-epubmaker +6 -1
  10. data/bin/review-init +21 -1
  11. data/bin/review-textmaker +16 -0
  12. data/doc/config.yml.sample +6 -1
  13. data/doc/format.ja.md +23 -0
  14. data/doc/format.md +20 -2
  15. data/doc/quickstart.ja.md +8 -4
  16. data/doc/quickstart.md +11 -8
  17. data/lib/review/book/base.rb +29 -18
  18. data/lib/review/book/index.rb +10 -5
  19. data/lib/review/builder.rb +58 -33
  20. data/lib/review/catalog.rb +30 -0
  21. data/lib/review/compiler.rb +53 -19
  22. data/lib/review/configure.rb +15 -14
  23. data/lib/review/epubmaker.rb +15 -4
  24. data/lib/review/htmlbuilder.rb +56 -24
  25. data/lib/review/idgxmlbuilder.rb +17 -7
  26. data/lib/review/latexbuilder.rb +113 -38
  27. data/lib/review/markdownbuilder.rb +12 -5
  28. data/lib/review/md2inaobuilder.rb +3 -1
  29. data/lib/review/pdfmaker.rb +23 -9
  30. data/lib/review/plaintextbuilder.rb +683 -0
  31. data/lib/review/rstbuilder.rb +30 -10
  32. data/lib/review/textmaker.rb +158 -0
  33. data/lib/review/textutils.rb +10 -1
  34. data/lib/review/topbuilder.rb +32 -417
  35. data/lib/review/version.rb +1 -1
  36. data/lib/review/webmaker.rb +29 -8
  37. data/review.gemspec +3 -4
  38. data/templates/html/layout-xhtml1.html.erb +0 -2
  39. data/templates/latex/layout.tex.erb +6 -4
  40. data/templates/web/html/layout-xhtml1.html.erb +0 -2
  41. data/test/book_test_helper.rb +1 -0
  42. data/test/run_test.rb +1 -1
  43. data/test/sample-book/src/Rakefile +19 -3
  44. data/test/syntax-book/Rakefile +19 -3
  45. data/test/test_catalog.rb +45 -0
  46. data/test/test_compiler.rb +8 -2
  47. data/test/test_htmlbuilder.rb +22 -0
  48. data/test/test_idgxmlbuilder.rb +22 -0
  49. data/test/test_index.rb +31 -0
  50. data/test/test_latexbuilder.rb +48 -16
  51. data/test/test_plaintextbuilder.rb +390 -0
  52. data/test/test_textutils.rb +2 -0
  53. data/test/test_topbuilder.rb +23 -1
  54. metadata +13 -7
@@ -303,6 +303,11 @@ class LATEXBuidlerTest < Test::Unit::TestCase
303
303
  assert_equal %Q(\n\\reviewemlistcaption{cap1}\n\\begin{reviewemlist}\nfoo\nbar\n\nbuz\n\\end{reviewemlist}\n), actual
304
304
  end
305
305
 
306
+ def test_emlist_empty_caption
307
+ actual = compile_block("//emlist[]{\nfoo\nbar\n\nbuz\n//}\n")
308
+ assert_equal %Q(\n\\begin{reviewemlist}\nfoo\nbar\n\nbuz\n\\end{reviewemlist}\n), actual
309
+ end
310
+
306
311
  def test_emlist_with_tab
307
312
  actual = compile_block("//emlist{\n\tfoo\n\t\tbar\n\n\tbuz\n//}\n")
308
313
  assert_equal %Q(\n\\begin{reviewemlist}\n foo\n bar\n\n buz\n\\end{reviewemlist}\n), actual
@@ -368,6 +373,11 @@ class LATEXBuidlerTest < Test::Unit::TestCase
368
373
  assert_equal %Q(\\reviewsourcecaption{foo/bar/test.rb}\n\\begin{reviewsource}\nfoo\nbar\n\nbuz\n\\end{reviewsource}\n), actual
369
374
  end
370
375
 
376
+ def test_source_empty_caption
377
+ actual = compile_block("//source[]{\nfoo\nbar\n\nbuz\n//}\n")
378
+ assert_equal %Q(\\begin{reviewsource}\nfoo\nbar\n\nbuz\n\\end{reviewsource}\n), actual
379
+ end
380
+
371
381
  def test_source_lst
372
382
  @book.config['highlight'] = {}
373
383
  @book.config['highlight']['latex'] = 'listings'
@@ -395,6 +405,11 @@ class LATEXBuidlerTest < Test::Unit::TestCase
395
405
  assert_equal %Q(\n\\begin{center}\nfoobar\n\nbuz\n\\end{center}\n), actual
396
406
  end
397
407
 
408
+ def test_blankline
409
+ actual = compile_block("//blankline\nfoo\n")
410
+ assert_equal %Q(\\vspace*{\\baselineskip}\n\nfoo\n), actual
411
+ end
412
+
398
413
  def test_noindent
399
414
  actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n")
400
415
  assert_equal %Q(\\noindent\nfoo\nbar\n\nfoo2\nbar2\n), actual
@@ -408,7 +423,7 @@ class LATEXBuidlerTest < Test::Unit::TestCase
408
423
  end
409
424
 
410
425
  actual = compile_block("//image[sampleimg][sample photo]{\n//}\n")
411
- 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
426
+ 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
412
427
  end
413
428
 
414
429
  def test_image_with_metric
@@ -419,7 +434,7 @@ class LATEXBuidlerTest < Test::Unit::TestCase
419
434
  end
420
435
 
421
436
  actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n")
422
- 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
437
+ 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
423
438
  end
424
439
 
425
440
  def test_image_with_metric_width
@@ -431,7 +446,7 @@ class LATEXBuidlerTest < Test::Unit::TestCase
431
446
 
432
447
  @config['image_scale2width'] = true
433
448
  actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n")
434
- assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[width=1.2\\maxwidth]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual
449
+ 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
435
450
  end
436
451
 
437
452
  def test_image_with_metric2
@@ -442,7 +457,7 @@ class LATEXBuidlerTest < Test::Unit::TestCase
442
457
  end
443
458
 
444
459
  actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n")
445
- 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
460
+ 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
446
461
  end
447
462
 
448
463
  def test_image_with_metric2_width
@@ -454,7 +469,7 @@ class LATEXBuidlerTest < Test::Unit::TestCase
454
469
 
455
470
  @config['image_scale2width'] = true
456
471
  actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n")
457
- assert_equal %Q(\\begin{reviewimage}\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
472
+ 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
458
473
  end
459
474
 
460
475
  def test_indepimage
@@ -465,7 +480,7 @@ class LATEXBuidlerTest < Test::Unit::TestCase
465
480
  end
466
481
 
467
482
  actual = compile_block("//indepimage[sampleimg][sample photo]\n")
468
- assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual
483
+ assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual
469
484
  end
470
485
 
471
486
  def test_indepimage_without_caption
@@ -477,7 +492,7 @@ class LATEXBuidlerTest < Test::Unit::TestCase
477
492
 
478
493
  # FIXME: indepimage's caption should not be with a counter.
479
494
  actual = compile_block("//indepimage[sampleimg]\n")
480
- assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\end{reviewimage}\n), actual
495
+ assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\end{reviewimage}\n), actual
481
496
  end
482
497
 
483
498
  def test_indepimage_with_metric
@@ -488,7 +503,7 @@ class LATEXBuidlerTest < Test::Unit::TestCase
488
503
  end
489
504
 
490
505
  actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n")
491
- assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual
506
+ assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual
492
507
  end
493
508
 
494
509
  def test_indepimage_with_metric_width
@@ -500,7 +515,7 @@ class LATEXBuidlerTest < Test::Unit::TestCase
500
515
 
501
516
  @config['image_scale2width'] = true
502
517
  actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n")
503
- assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[width=1.2\\maxwidth]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual
518
+ 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
504
519
  end
505
520
 
506
521
  def test_indepimage_with_metric2
@@ -511,7 +526,7 @@ class LATEXBuidlerTest < Test::Unit::TestCase
511
526
  end
512
527
 
513
528
  actual = compile_block(%Q(//indepimage[sampleimg][sample photo][scale=1.2, html::class="sample",latex::ignore=params]\n))
514
- 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
529
+ 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
515
530
  end
516
531
 
517
532
  def test_indepimage_without_caption_but_with_metric
@@ -523,7 +538,7 @@ class LATEXBuidlerTest < Test::Unit::TestCase
523
538
 
524
539
  # FIXME: indepimage's caption should not be with a counter.
525
540
  actual = compile_block("//indepimage[sampleimg][][scale=1.2]\n")
526
- assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\end{reviewimage}\n), actual
541
+ assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\end{reviewimage}\n), actual
527
542
  end
528
543
 
529
544
  def test_table
@@ -551,7 +566,7 @@ class LATEXBuidlerTest < Test::Unit::TestCase
551
566
 
552
567
  def test_emtable
553
568
  actual = compile_block("//emtable[foo]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n//emtable{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
554
- 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",
569
+ 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",
555
570
  actual
556
571
  end
557
572
 
@@ -565,10 +580,10 @@ class LATEXBuidlerTest < Test::Unit::TestCase
565
580
  actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n")
566
581
 
567
582
  expected = <<-EOS
568
- \\begin{table}[h]
583
+ \\begin{table}[h]%%sampleimg
569
584
  \\reviewimgtablecaption{test for imgtable}
570
585
  \\label{table:chap1:sampleimg}
571
- \\begin{reviewimage}
586
+ \\begin{reviewimage}%%sampleimg
572
587
  \\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}
573
588
  \\end{reviewimage}
574
589
  \\end{table}
@@ -958,6 +973,23 @@ EOS
958
973
  assert_equal 'test \\texttt{@\\textless{}code\\textgreater{}\\{\\textdollar{}サンプル\\textdollar{}\\}}', actual
959
974
  end
960
975
 
976
+ def test_inline_unknown
977
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<img>{n}\n" }
978
+ assert_equal ':1: error: unknown image: n', e.message
979
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<fn>{n}\n" }
980
+ assert_equal ':1: error: unknown footnote: n', e.message
981
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<hd>{n}\n" }
982
+ assert_equal ':1: error: unknown headline: n', e.message
983
+ %w[list table column].each do |name|
984
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<#{name}>{n}\n" }
985
+ assert_equal ":1: error: unknown #{name}: n", e.message
986
+ end
987
+ %w[chap chapref title].each do |name|
988
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<#{name}>{n}\n" }
989
+ assert_equal ':1: error: key not found: "n"', e.message
990
+ end
991
+ end
992
+
961
993
  def test_appendix_list
962
994
  @chapter.instance_eval do
963
995
  def on_appendix?
@@ -997,7 +1029,7 @@ EOS
997
1029
 
998
1030
  \\reviewtableref{A.1}{table:chap1:foo}
999
1031
 
1000
- \\begin{table}[h]
1032
+ \\begin{table}[h]%%foo
1001
1033
  \\reviewtablecaption{FOO}
1002
1034
  \\label{table:chap1:foo}
1003
1035
  \\begin{reviewtable}{|l|l|}
@@ -1032,7 +1064,7 @@ EOS
1032
1064
 
1033
1065
  \\reviewimageref{A.1}{image:chap1:sampleimg}
1034
1066
 
1035
- \\begin{reviewimage}
1067
+ \\begin{reviewimage}%%sampleimg
1036
1068
  \\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}
1037
1069
  \\caption{FOO}
1038
1070
  \\label{image:chap1:sampleimg}
@@ -0,0 +1,390 @@
1
+ require 'test_helper'
2
+ require 'review/compiler'
3
+ require 'review/book'
4
+ require 'review/plaintextbuilder'
5
+ require 'review/i18n'
6
+
7
+ class PLAINTEXTBuidlerTest < Test::Unit::TestCase
8
+ include ReVIEW
9
+
10
+ def setup
11
+ @builder = PLAINTEXTBuilder.new
12
+ @config = ReVIEW::Configure.values
13
+ @config['secnolevel'] = 2
14
+ @config['language'] = 'ja'
15
+ @book = Book::Base.new(nil)
16
+ @book.config = @config
17
+ @compiler = ReVIEW::Compiler.new(@builder)
18
+ @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
19
+ location = Location.new(nil, nil)
20
+ @builder.bind(@compiler, @chapter, location)
21
+
22
+ @builder.instance_eval do
23
+ # to ignore lineno in original method
24
+ def warn(msg)
25
+ puts msg
26
+ end
27
+ end
28
+ I18n.setup(@config['language'])
29
+ end
30
+
31
+ def test_headline_level1
32
+ actual = compile_block("={test} this is test.\n")
33
+ assert_equal %Q(第1章 this is test.\n), actual
34
+ end
35
+
36
+ def test_headline_level1_without_secno
37
+ @config['secnolevel'] = 0
38
+ actual = compile_block("={test} this is test.\n")
39
+ assert_equal %Q(this is test.\n), actual
40
+ end
41
+
42
+ def test_headline_level2
43
+ actual = compile_block("=={test} this is test.\n")
44
+ assert_equal %Q(1.1 this is test.\n), actual
45
+ end
46
+
47
+ def test_headline_level3
48
+ actual = compile_block("==={test} this is test.\n")
49
+ assert_equal %Q(this is test.\n), actual
50
+ end
51
+
52
+ def test_headline_level3_with_secno
53
+ @config['secnolevel'] = 3
54
+ actual = compile_block("==={test} this is test.\n")
55
+ assert_equal %Q(1.0.1 this is test.\n), actual
56
+ end
57
+
58
+ def test_href
59
+ actual = compile_inline('@<href>{http://github.com, GitHub}')
60
+ assert_equal 'GitHub(http://github.com)', actual
61
+ end
62
+
63
+ def test_href_without_label
64
+ actual = compile_inline('@<href>{http://github.com}')
65
+ assert_equal 'http://github.com', actual
66
+ end
67
+
68
+ def test_inline_raw
69
+ actual = compile_inline('@<raw>{@<tt>{inline\}}')
70
+ assert_equal '@<tt>{inline}', actual
71
+ end
72
+
73
+ def test_inline_ruby
74
+ actual = compile_inline('@<ruby>{coffin,bed}')
75
+ assert_equal 'coffin', actual
76
+ end
77
+
78
+ def test_inline_kw
79
+ actual = compile_inline('@<kw>{ISO, International Organization for Standardization } @<kw>{Ruby<>}')
80
+ assert_equal 'ISO(International Organization for Standardization) Ruby<>', actual
81
+ end
82
+
83
+ def test_inline_maru
84
+ actual = compile_inline('@<maru>{1}@<maru>{20}@<maru>{A}@<maru>{z}')
85
+ assert_equal '120Az', actual
86
+ end
87
+
88
+ def test_inline_br
89
+ actual = compile_inline('@<br>{}')
90
+ assert_equal "\n", actual
91
+ end
92
+
93
+ def test_inline_i
94
+ actual = compile_inline('test @<i>{inline test} test2')
95
+ assert_equal 'test inline test test2', actual
96
+ end
97
+
98
+ def test_inline_i_and_escape
99
+ actual = compile_inline('test @<i>{inline<&;\\ test} test2')
100
+ assert_equal 'test inline<&;\\ test test2', actual
101
+ end
102
+
103
+ def test_inline_b
104
+ actual = compile_inline('test @<b>{inline test} test2')
105
+ assert_equal 'test inline test test2', actual
106
+ end
107
+
108
+ def test_inline_b_and_escape
109
+ actual = compile_inline('test @<b>{inline<&;\\ test} test2')
110
+ assert_equal 'test inline<&;\\ test test2', actual
111
+ end
112
+
113
+ def test_inline_tt
114
+ actual = compile_inline('test @<tt>{inline test} test2@<tt>{\\}}')
115
+ assert_equal 'test inline test test2}', actual
116
+ end
117
+
118
+ def test_inline_tti
119
+ actual = compile_inline('test @<tti>{inline test} test2')
120
+ assert_equal 'test inline test test2', actual
121
+ end
122
+
123
+ def test_inline_ttb
124
+ actual = compile_inline('test @<ttb>{inline test} test2')
125
+ assert_equal 'test inline test test2', actual
126
+ end
127
+
128
+ def test_inline_uchar
129
+ actual = compile_inline('test @<uchar>{2460} test2')
130
+ assert_equal 'test ① test2', actual
131
+ end
132
+
133
+ def test_inline_comment
134
+ actual = compile_inline('test @<comment>{コメント} test2')
135
+ assert_equal 'test test2', actual
136
+ end
137
+
138
+ def test_inline_comment_for_draft
139
+ @config['draft'] = true
140
+ actual = compile_inline('test @<comment>{コメント} test2')
141
+ assert_equal 'test test2', actual
142
+ end
143
+
144
+ def test_inline_in_table
145
+ actual = compile_block("//table{\n★1☆\t▲2☆\n------------\n★3☆\t▲4☆<>&\n//}\n")
146
+ assert_equal %Q(★1☆\t▲2☆\n★3☆\t▲4☆<>&\n\n), actual
147
+ end
148
+
149
+ def test_dlist_beforeulol
150
+ 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")
151
+ assert_equal %Q(foo\nfoo.\n\npara\n\nfoo\nfoo.\n\n1 bar\n\nfoo\nfoo.\n\nbar\n\n), actual
152
+ end
153
+
154
+ def test_paragraph
155
+ actual = compile_block("foo\nbar\n")
156
+ assert_equal %Q(foobar\n), actual
157
+ end
158
+
159
+ def test_tabbed_paragraph
160
+ actual = compile_block("\tfoo\nbar\n")
161
+ assert_equal %Q(\tfoobar\n), actual
162
+ end
163
+
164
+ def test_flushright
165
+ actual = compile_block("//flushright{\nfoo\nbar\n\nbuz\n//}\n")
166
+ assert_equal %Q(foobar\nbuz\n\n), actual
167
+ end
168
+
169
+ def test_noindent
170
+ actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n")
171
+ assert_equal %Q(foobar\nfoo2bar2\n), actual
172
+ end
173
+
174
+ def test_comment
175
+ actual = compile_block('//comment[コメント]')
176
+ assert_equal '', actual
177
+ end
178
+
179
+ def test_comment_for_draft
180
+ @config['draft'] = true
181
+ actual = compile_block('//comment[コメント]')
182
+ assert_equal '', actual
183
+ end
184
+
185
+ def test_list
186
+ def @chapter.list(_id)
187
+ Book::ListIndex::Item.new('test', 1)
188
+ end
189
+ actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\nfoo\nbar\n//}\n")
190
+ assert_equal %Q(リスト1.1 this is test<&>_\n\nfoo\nbar\n\n), actual
191
+ end
192
+
193
+ def test_listnum
194
+ def @chapter.list(_id)
195
+ Book::ListIndex::Item.new('test', 1)
196
+ end
197
+ actual = compile_block("//listnum[test][this is @<b>{test}<&>_]{\nfoo\nbar\n//}\n")
198
+ assert_equal %Q(リスト1.1 this is test<&>_\n\n 1: foo\n 2: bar\n\n), actual
199
+ end
200
+
201
+ def test_emlistnum
202
+ actual = compile_block("//emlistnum[this is @<b>{test}<&>_]{\nfoo\nbar\n//}\n")
203
+ assert_equal %Q(this is test<&>_\n 1: foo\n 2: bar\n\n), actual
204
+ end
205
+
206
+ def test_bib
207
+ def @chapter.bibpaper(_id)
208
+ Book::BibpaperIndex::Item.new('samplebib', 1, 'sample bib')
209
+ end
210
+
211
+ assert_equal '1 ', compile_inline('@<bib>{samplebib}')
212
+ end
213
+
214
+ def test_table
215
+ actual = compile_block("//table{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
216
+ assert_equal %Q(aaa\tbbb\nccc\tddd<>&\n\n),
217
+ actual
218
+ end
219
+
220
+ def test_inline_table
221
+ def @chapter.table(_id)
222
+ Book::TableIndex::Item.new('sampletable', 1)
223
+ end
224
+ actual = compile_block("@<table>{sampletest}\n")
225
+ assert_equal "表1.1\n", actual
226
+ end
227
+
228
+ def test_emtable
229
+ actual = compile_block("//emtable[foo]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n//emtable{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
230
+ assert_equal %Q(foo\n\naaa\tbbb\nccc\tddd<>&\n\naaa\tbbb\nccc\tddd<>&\n\n),
231
+ actual
232
+ end
233
+
234
+ def test_major_blocks
235
+ actual = compile_block("//note{\nA\n\nB\n//}\n//note[caption]{\nA\n//}")
236
+ expected = %Q(A\nB\n\ncaption\nA\n\n)
237
+ assert_equal expected, actual
238
+
239
+ actual = compile_block("//memo{\nA\n\nB\n//}\n//memo[caption]{\nA\n//}")
240
+ expected = %Q(A\nB\n\ncaption\nA\n\n)
241
+ assert_equal expected, actual
242
+
243
+ actual = compile_block("//info{\nA\n\nB\n//}\n//info[caption]{\nA\n//}")
244
+ expected = %Q(A\nB\n\ncaption\nA\n\n)
245
+ assert_equal expected, actual
246
+
247
+ actual = compile_block("//important{\nA\n\nB\n//}\n//important[caption]{\nA\n//}")
248
+ expected = %Q(A\nB\n\ncaption\nA\n\n)
249
+ assert_equal expected, actual
250
+
251
+ actual = compile_block("//caution{\nA\n\nB\n//}\n//caution[caption]{\nA\n//}")
252
+ expected = %Q(A\nB\n\ncaption\nA\n\n)
253
+ assert_equal expected, actual
254
+
255
+ actual = compile_block("//notice{\nA\n\nB\n//}\n//notice[caption]{\nA\n//}")
256
+ expected = %Q(A\nB\n\ncaption\nA\n\n)
257
+ assert_equal expected, actual
258
+
259
+ actual = compile_block("//warning{\nA\n\nB\n//}\n//warning[caption]{\nA\n//}")
260
+ expected = %Q(A\nB\n\ncaption\nA\n\n)
261
+ assert_equal expected, actual
262
+
263
+ actual = compile_block("//tip{\nA\n\nB\n//}\n//tip[caption]{\nA\n//}")
264
+ expected = %Q(A\nB\n\ncaption\nA\n\n)
265
+ assert_equal expected, actual
266
+ end
267
+
268
+ def test_image
269
+ def @chapter.image(_id)
270
+ item = Book::ImageIndex::Item.new('sampleimg', 1)
271
+ item.instance_eval { @path = './images/chap1-sampleimg.png' }
272
+ item
273
+ end
274
+
275
+ actual = compile_block("//image[sampleimg][sample photo]{\nfoo\n//}\n")
276
+ assert_equal %Q(図1.1 sample photo\n\n), actual
277
+ end
278
+
279
+ def test_image_with_metric
280
+ def @chapter.image(_id)
281
+ item = Book::ImageIndex::Item.new('sampleimg', 1)
282
+ item.instance_eval { @path = './images/chap1-sampleimg.png' }
283
+ item
284
+ end
285
+
286
+ actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\nfoo\n//}\n")
287
+ assert_equal %Q(図1.1 sample photo\n\n), actual
288
+ end
289
+
290
+ def test_texequation
291
+ actual = compile_block("//texequation{\n\\sin\n1^{2}\n//}\n")
292
+ assert_equal %Q(\\sin\n1^{2}\n\n), actual
293
+ end
294
+
295
+ def test_inline_unknown
296
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<img>{n}\n" }
297
+ assert_equal ':1: error: unknown image: n', e.message
298
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<fn>{n}\n" }
299
+ assert_equal ':1: error: unknown footnote: n', e.message
300
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<hd>{n}\n" }
301
+ assert_equal ':1: error: unknown headline: n', e.message
302
+ %w[list table column].each do |name|
303
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<#{name}>{n}\n" }
304
+ assert_equal ":1: error: unknown #{name}: n", e.message
305
+ end
306
+ %w[chap chapref title].each do |name|
307
+ e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<#{name}>{n}\n" }
308
+ assert_equal ':1: error: key not found: "n"', e.message
309
+ end
310
+ end
311
+
312
+ def test_inline_raw0
313
+ assert_equal 'normal', compile_inline('@<raw>{normal}')
314
+ end
315
+
316
+ def test_inline_raw1
317
+ assert_equal 'body', compile_inline('@<raw>{|plaintext|body}')
318
+ end
319
+
320
+ def test_inline_raw2
321
+ assert_equal 'body', compile_inline('@<raw>{|plaintext, latex|body}')
322
+ end
323
+
324
+ def test_inline_raw3
325
+ assert_equal '', compile_inline('@<raw>{|idgxml, html|body}')
326
+ end
327
+
328
+ def test_inline_raw4
329
+ assert_equal '|plaintext body', compile_inline('@<raw>{|plaintext body}')
330
+ end
331
+
332
+ def test_inline_raw5
333
+ assert_equal "nor\nmal", compile_inline('@<raw>{|plaintext|nor\\nmal}')
334
+ end
335
+
336
+ def test_block_raw0
337
+ actual = compile_block(%Q(//raw[<>!"\\n& ]\n))
338
+ expected = %Q(<>!"\n& )
339
+ assert_equal expected.chomp, actual
340
+ end
341
+
342
+ def test_block_raw1
343
+ actual = compile_block(%Q(//raw[|plaintext|<>!"\\n& ]\n))
344
+ expected = %Q(<>!"\n& )
345
+ assert_equal expected.chomp, actual
346
+ end
347
+
348
+ def test_block_raw2
349
+ actual = compile_block(%Q(//raw[|plaintext, latex|<>!"\\n& ]\n))
350
+ expected = %Q(<>!"\n& )
351
+ assert_equal expected.chomp, actual
352
+ end
353
+
354
+ def test_block_raw3
355
+ actual = compile_block(%Q(//raw[|latex, idgxml|<>!"\\n& ]\n))
356
+ expected = ''
357
+ assert_equal expected.chomp, actual
358
+ end
359
+
360
+ def test_block_raw4
361
+ actual = compile_block(%Q(//raw[|plaintext <>!"\\n& ]\n))
362
+ expected = %Q(|plaintext <>!"\n& )
363
+ assert_equal expected.chomp, actual
364
+ end
365
+
366
+ def column_helper(review)
367
+ compile_block(review)
368
+ end
369
+
370
+ def test_column_ref
371
+ review = <<-EOS
372
+ ===[column]{foo} test
373
+
374
+ inside column
375
+
376
+ === next level
377
+
378
+ this is @<column>{foo}.
379
+ EOS
380
+ expected = <<-EOS
381
+ test
382
+ inside column
383
+
384
+ next level
385
+ this is test.
386
+ EOS
387
+
388
+ assert_equal expected, column_helper(review)
389
+ end
390
+ end