review 5.1.1 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby-tex.yml +5 -1
  3. data/.github/workflows/ruby-win.yml +5 -1
  4. data/.github/workflows/ruby.yml +5 -1
  5. data/.rubocop.yml +6 -2
  6. data/NEWS.ja.md +48 -0
  7. data/NEWS.md +48 -1
  8. data/bin/review-compile +8 -15
  9. data/bin/review-preproc +28 -34
  10. data/doc/config.yml.sample +2 -0
  11. data/doc/writing_vertical.ja.md +6 -0
  12. data/lib/review/builder.rb +34 -40
  13. data/lib/review/compiler.rb +59 -43
  14. data/lib/review/epubmaker.rb +24 -38
  15. data/lib/review/epubmaker/producer.rb +3 -4
  16. data/lib/review/exception.rb +7 -0
  17. data/lib/review/htmlbuilder.rb +51 -20
  18. data/lib/review/idgxmlbuilder.rb +19 -18
  19. data/lib/review/idgxmlmaker.rb +12 -13
  20. data/lib/review/img_math.rb +11 -18
  21. data/lib/review/index_builder.rb +6 -15
  22. data/lib/review/latexbuilder.rb +38 -43
  23. data/lib/review/loggable.rb +27 -0
  24. data/lib/review/logger.rb +48 -0
  25. data/lib/review/makerhelper.rb +5 -1
  26. data/lib/review/markdownbuilder.rb +5 -4
  27. data/lib/review/pdfmaker.rb +23 -21
  28. data/lib/review/plaintextbuilder.rb +8 -8
  29. data/lib/review/preprocessor.rb +94 -296
  30. data/lib/review/preprocessor/directive.rb +35 -0
  31. data/lib/review/preprocessor/line.rb +34 -0
  32. data/lib/review/preprocessor/repository.rb +177 -0
  33. data/lib/review/rstbuilder.rb +1 -1
  34. data/lib/review/template.rb +5 -1
  35. data/lib/review/textmaker.rb +12 -13
  36. data/lib/review/tocprinter.rb +1 -1
  37. data/lib/review/topbuilder.rb +7 -7
  38. data/lib/review/version.rb +1 -1
  39. data/lib/review/webmaker.rb +13 -14
  40. data/review.gemspec +1 -1
  41. data/samples/sample-book/src/lib/tasks/review.rake +3 -1
  42. data/samples/sample-book/src/lib/tasks/z01_copy_sty.rake +2 -1
  43. data/samples/syntax-book/lib/tasks/z01_copy_sty.rake +2 -1
  44. data/templates/latex/review-jlreq/review-base.sty +3 -5
  45. data/templates/latex/review-jlreq/review-jlreq.cls +4 -3
  46. data/templates/latex/review-jsbook/review-base.sty +3 -3
  47. data/templates/latex/review-jsbook/review-jsbook.cls +1 -1
  48. data/test/test_builder.rb +8 -8
  49. data/test/test_epubmaker.rb +13 -8
  50. data/test/test_epubmaker_cmd.rb +13 -2
  51. data/test/test_htmlbuilder.rb +68 -26
  52. data/test/test_idgxmlbuilder.rb +31 -23
  53. data/test/test_latexbuilder.rb +30 -22
  54. data/test/test_latexbuilder_v2.rb +18 -10
  55. data/test/test_plaintextbuilder.rb +30 -22
  56. data/test/test_preprocessor.rb +188 -1
  57. data/test/test_topbuilder.rb +26 -18
  58. metadata +12 -8
@@ -14,6 +14,8 @@ class IDGXMLBuidlerTest < Test::Unit::TestCase
14
14
  @config['tableopt'] = '10'
15
15
  @book = Book::Base.new
16
16
  @book.config = @config
17
+ @log_io = StringIO.new
18
+ ReVIEW.logger = ReVIEW::Logger.new(@log_io)
17
19
  @compiler = ReVIEW::Compiler.new(@builder)
18
20
  @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
19
21
  location = Location.new(nil, nil)
@@ -169,10 +171,10 @@ EOS
169
171
 
170
172
  def test_empty_table
171
173
  e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n//}\n") }
172
- assert_equal ':2: error: no rows in the table', e.message
174
+ assert_equal 'no rows in the table', e.message
173
175
 
174
176
  e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n------------\n//}\n") }
175
- assert_equal ':3: error: no rows in the table', e.message
177
+ assert_equal 'no rows in the table', e.message
176
178
  end
177
179
 
178
180
  def test_emtable
@@ -436,8 +438,8 @@ EOS
436
438
 
437
439
  //}
438
440
  EOS
439
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
440
- assert_match(/minicolumn cannot be nested:/, e.message)
441
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
442
+ assert_match(/minicolumn cannot be nested:/, @log_io.string)
441
443
  end
442
444
  end
443
445
 
@@ -453,8 +455,8 @@ EOS
453
455
 
454
456
  //}
455
457
  EOS
456
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
457
- assert_match(/minicolumn cannot be nested:/, e.message)
458
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
459
+ assert_match(/minicolumn cannot be nested:/, @log_io.string)
458
460
  end
459
461
  end
460
462
 
@@ -469,8 +471,8 @@ EOS
469
471
 
470
472
  //}
471
473
  EOS
472
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
473
- assert_match(/minicolumn cannot be nested:/, e.message)
474
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
475
+ assert_match(/minicolumn cannot be nested:/, @log_io.string)
474
476
  end
475
477
  end
476
478
 
@@ -1095,8 +1097,8 @@ EOS
1095
1097
  * AA
1096
1098
  EOS
1097
1099
 
1098
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
1099
- assert_equal ':1: error: too many *.', e.message
1100
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
1101
+ assert_match(/too many \*\./, @log_io.string)
1100
1102
  end
1101
1103
 
1102
1104
  def test_ul_nest4
@@ -1131,19 +1133,25 @@ EOS
1131
1133
  end
1132
1134
 
1133
1135
  def test_inline_unknown
1134
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
1135
- assert_equal ':1: error: unknown image: n', e.message
1136
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
1137
- assert_equal ':1: error: unknown footnote: n', e.message
1138
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
1139
- assert_equal ':1: error: unknown headline: n', e.message
1136
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
1137
+ assert_match(/unknown image: n/, @log_io.string)
1138
+
1139
+ @log_io.string = ''
1140
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
1141
+ assert_match(/unknown footnote: n/, @log_io.string)
1142
+
1143
+ @log_io.string = ''
1144
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
1145
+ assert_match(/unknown headline: n/, @log_io.string)
1140
1146
  %w[list table column].each do |name|
1141
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1142
- assert_equal ":1: error: unknown #{name}: n", e.message
1147
+ @log_io.string = ''
1148
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1149
+ assert_match(/unknown #{name}: n/, @log_io.string)
1143
1150
  end
1144
1151
  %w[chap chapref title].each do |name|
1145
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1146
- assert_equal ':1: error: key not found: "n"', e.message
1152
+ @log_io.string = ''
1153
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1154
+ assert_match(/key not found: "n"/, @log_io.string)
1147
1155
  end
1148
1156
  end
1149
1157
 
@@ -1283,7 +1291,7 @@ EOS
1283
1291
  //beginchild
1284
1292
  EOS
1285
1293
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
1286
- assert_equal ":1: error: //beginchild is shown, but previous element isn't ul, ol, or dl", e.message
1294
+ assert_equal "//beginchild is shown, but previous element isn't ul, ol, or dl", e.message
1287
1295
  end
1288
1296
 
1289
1297
  def test_nest_error_close2
@@ -1301,7 +1309,7 @@ EOS
1301
1309
  //beginchild
1302
1310
  EOS
1303
1311
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
1304
- assert_equal ':12: error: //beginchild of dl,ol,ul misses //endchild', e.message
1312
+ assert_equal '//beginchild of dl,ol,ul misses //endchild', e.message
1305
1313
  end
1306
1314
 
1307
1315
  def test_nest_error_close3
@@ -1321,7 +1329,7 @@ EOS
1321
1329
  //endchild
1322
1330
  EOS
1323
1331
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
1324
- assert_equal ':14: error: //beginchild of ol,ul misses //endchild', e.message
1332
+ assert_equal '//beginchild of ol,ul misses //endchild', e.message
1325
1333
  end
1326
1334
 
1327
1335
  def test_nest_ul
@@ -20,6 +20,8 @@ class LATEXBuidlerTest < Test::Unit::TestCase
20
20
  @config['pdfmaker']['image_scale2width'] = nil
21
21
  @book = Book::Base.new
22
22
  @book.config = @config
23
+ @log_io = StringIO.new
24
+ ReVIEW.logger = ReVIEW::Logger.new(@log_io)
23
25
  @compiler = ReVIEW::Compiler.new(@builder)
24
26
  @chapter = Book::Chapter.new(@book, 1, 'chap1', nil, StringIO.new)
25
27
  location = Location.new(nil, nil)
@@ -1372,7 +1374,7 @@ EOS
1372
1374
  actual = compile_block("//indepimage[sample_img_nofile_][sample photo]\n")
1373
1375
  expected = <<-EOS
1374
1376
  \\begin{reviewdummyimage}
1375
- --[[path = sample\\textunderscore{}img\\textunderscore{}nofile\\textunderscore{} (not exist)]]--
1377
+ {-}{-}[[path = sample\\reviewbackslash{}textunderscore\\{\\}img\\reviewbackslash{}textunderscore\\{\\}nofile\\reviewbackslash{}textunderscore\\{\\} (not exist)]]{-}{-}
1376
1378
  \\reviewindepimagecaption{図: sample photo}
1377
1379
  \\end{reviewdummyimage}
1378
1380
  EOS
@@ -1433,10 +1435,10 @@ EOS
1433
1435
 
1434
1436
  def test_empty_table
1435
1437
  e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n//}\n") }
1436
- assert_equal ':2: error: no rows in the table', e.message
1438
+ assert_equal 'no rows in the table', e.message
1437
1439
 
1438
1440
  e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n------------\n//}\n") }
1439
- assert_equal ':3: error: no rows in the table', e.message
1441
+ assert_equal 'no rows in the table', e.message
1440
1442
  end
1441
1443
 
1442
1444
  def test_customize_cellwidth
@@ -2252,8 +2254,8 @@ EOS
2252
2254
 
2253
2255
  //}
2254
2256
  EOS
2255
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2256
- assert_match(/minicolumn cannot be nested:/, e.message)
2257
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2258
+ assert_match(/minicolumn cannot be nested:/, @log_io.string)
2257
2259
  end
2258
2260
  end
2259
2261
 
@@ -2269,8 +2271,8 @@ EOS
2269
2271
 
2270
2272
  //}
2271
2273
  EOS
2272
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2273
- assert_match(/minicolumn cannot be nested:/, e.message)
2274
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2275
+ assert_match(/minicolumn cannot be nested:/, @log_io.string)
2274
2276
  end
2275
2277
  end
2276
2278
 
@@ -2285,8 +2287,8 @@ EOS
2285
2287
 
2286
2288
  //}
2287
2289
  EOS
2288
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2289
- assert_match(/minicolumn cannot be nested:/, e.message)
2290
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2291
+ assert_match(/minicolumn cannot be nested:/, @log_io.string)
2290
2292
  end
2291
2293
  end
2292
2294
 
@@ -2427,19 +2429,25 @@ EOS
2427
2429
  end
2428
2430
 
2429
2431
  def test_inline_unknown
2430
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
2431
- assert_equal ':1: error: unknown image: n', e.message
2432
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
2433
- assert_equal ':1: error: unknown footnote: n', e.message
2434
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
2435
- assert_equal ':1: error: unknown headline: n', e.message
2432
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
2433
+ assert_match(/unknown image: n/, @log_io.string)
2434
+
2435
+ @log_io.string = ''
2436
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
2437
+ assert_match(/unknown footnote: n/, @log_io.string)
2438
+
2439
+ @log_io.string = ''
2440
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
2441
+ assert_match(/unknown headline: n/, @log_io.string)
2436
2442
  %w[list table column].each do |name|
2437
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
2438
- assert_equal ":1: error: unknown #{name}: n", e.message
2443
+ @log_io.string = ''
2444
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
2445
+ assert_match(/unknown #{name}: n/, @log_io.string)
2439
2446
  end
2440
2447
  %w[chap chapref title].each do |name|
2441
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
2442
- assert_equal ':1: error: key not found: "n"', e.message
2448
+ @log_io.string = ''
2449
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
2450
+ assert_match(/key not found: "n"/, @log_io.string)
2443
2451
  end
2444
2452
  end
2445
2453
 
@@ -2588,7 +2596,7 @@ EOS
2588
2596
  //beginchild
2589
2597
  EOS
2590
2598
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2591
- assert_equal ":1: error: //beginchild is shown, but previous element isn't ul, ol, or dl", e.message
2599
+ assert_equal "//beginchild is shown, but previous element isn't ul, ol, or dl", e.message
2592
2600
  end
2593
2601
 
2594
2602
  def test_nest_error_close2
@@ -2606,7 +2614,7 @@ EOS
2606
2614
  //beginchild
2607
2615
  EOS
2608
2616
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2609
- assert_equal ':12: error: //beginchild of dl,ol,ul misses //endchild', e.message
2617
+ assert_equal '//beginchild of dl,ol,ul misses //endchild', e.message
2610
2618
  end
2611
2619
 
2612
2620
  def test_nest_error_close3
@@ -2626,7 +2634,7 @@ EOS
2626
2634
  //endchild
2627
2635
  EOS
2628
2636
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
2629
- assert_equal ':14: error: //beginchild of ol,ul misses //endchild', e.message
2637
+ assert_equal '//beginchild of ol,ul misses //endchild', e.message
2630
2638
  end
2631
2639
 
2632
2640
  def test_nest_ul
@@ -20,6 +20,8 @@ class LATEXBuidlerV2Test < Test::Unit::TestCase
20
20
  @config['pdfmaker']['image_scale2width'] = nil
21
21
  @book = Book::Base.new
22
22
  @book.config = @config
23
+ @log_io = StringIO.new
24
+ ReVIEW.logger = ReVIEW::Logger.new(@log_io)
23
25
  @compiler = ReVIEW::Compiler.new(@builder)
24
26
  @chapter = Book::Chapter.new(@book, 1, 'chap1', nil, StringIO.new)
25
27
  location = Location.new(nil, nil)
@@ -1544,19 +1546,25 @@ EOS
1544
1546
  end
1545
1547
 
1546
1548
  def test_inline_unknown
1547
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
1548
- assert_equal ':1: error: unknown image: n', e.message
1549
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
1550
- assert_equal ':1: error: unknown footnote: n', e.message
1551
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
1552
- assert_equal ':1: error: unknown headline: n', e.message
1549
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
1550
+ assert_match(/unknown image: n/, @log_io.string)
1551
+
1552
+ @log_io.string = ''
1553
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
1554
+ assert_match(/unknown footnote: n/, @log_io.string)
1555
+
1556
+ @log_io.string = ''
1557
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
1558
+ assert_match(/unknown headline: n/, @log_io.string)
1553
1559
  %w[list table column].each do |name|
1554
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1555
- assert_equal ":1: error: unknown #{name}: n", e.message
1560
+ @log_io.string = ''
1561
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1562
+ assert_match(/unknown #{name}: n/, @log_io.string)
1556
1563
  end
1557
1564
  %w[chap chapref title].each do |name|
1558
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1559
- assert_equal ':1: error: key not found: "n"', e.message
1565
+ @log_io.string = ''
1566
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
1567
+ assert_match(/key not found: "n"/, @log_io.string)
1560
1568
  end
1561
1569
  end
1562
1570
 
@@ -14,6 +14,8 @@ class PLAINTEXTBuidlerTest < Test::Unit::TestCase
14
14
  @config['language'] = 'ja'
15
15
  @book = Book::Base.new
16
16
  @book.config = @config
17
+ @log_io = StringIO.new
18
+ ReVIEW.logger = ReVIEW::Logger.new(@log_io)
17
19
  @compiler = ReVIEW::Compiler.new(@builder)
18
20
  @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
19
21
  location = Location.new(nil, nil)
@@ -469,10 +471,10 @@ EOS
469
471
 
470
472
  def test_empty_table
471
473
  e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n//}\n") }
472
- assert_equal ':2: error: no rows in the table', e.message
474
+ assert_equal 'no rows in the table', e.message
473
475
 
474
476
  e = assert_raises(ReVIEW::ApplicationError) { compile_block("//table{\n------------\n//}\n") }
475
- assert_equal ':3: error: no rows in the table', e.message
477
+ assert_equal 'no rows in the table', e.message
476
478
  end
477
479
 
478
480
  def test_inline_table
@@ -691,8 +693,8 @@ EOS
691
693
 
692
694
  //}
693
695
  EOS
694
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
695
- assert_match(/minicolumn cannot be nested:/, e.message)
696
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
697
+ assert_match(/minicolumn cannot be nested:/, @log_io.string)
696
698
  end
697
699
  end
698
700
 
@@ -708,8 +710,8 @@ EOS
708
710
 
709
711
  //}
710
712
  EOS
711
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
712
- assert_match(/minicolumn cannot be nested:/, e.message)
713
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
714
+ assert_match(/minicolumn cannot be nested:/, @log_io.string)
713
715
  end
714
716
  end
715
717
 
@@ -724,8 +726,8 @@ EOS
724
726
 
725
727
  //}
726
728
  EOS
727
- e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
728
- assert_match(/minicolumn cannot be nested:/, e.message)
729
+ assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
730
+ assert_match(/minicolumn cannot be nested:/, @log_io.string)
729
731
  end
730
732
  end
731
733
 
@@ -761,19 +763,25 @@ EOS
761
763
  end
762
764
 
763
765
  def test_inline_unknown
764
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
765
- assert_equal ':1: error: unknown image: n', e.message
766
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
767
- assert_equal ':1: error: unknown footnote: n', e.message
768
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
769
- assert_equal ':1: error: unknown headline: n', e.message
766
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<img>{n}\n") }
767
+ assert_match(/unknown image: n/, @log_io.string)
768
+
769
+ @log_io.string = ''
770
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<fn>{n}\n") }
771
+ assert_match(/unknown footnote: n/, @log_io.string)
772
+
773
+ @log_io.string = ''
774
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<hd>{n}\n") }
775
+ assert_match(/unknown headline: n/, @log_io.string)
770
776
  %w[list table column].each do |name|
771
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
772
- assert_equal ":1: error: unknown #{name}: n", e.message
777
+ @log_io.string = ''
778
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
779
+ assert_match(/unknown #{name}: n/, @log_io.string)
773
780
  end
774
781
  %w[chap chapref title].each do |name|
775
- e = assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
776
- assert_equal ':1: error: key not found: "n"', e.message
782
+ @log_io.string = ''
783
+ assert_raises(ReVIEW::ApplicationError) { compile_block("@<#{name}>{n}\n") }
784
+ assert_match(/key not found: "n"/, @log_io.string)
777
785
  end
778
786
  end
779
787
 
@@ -891,7 +899,7 @@ EOS
891
899
  //endchild
892
900
  EOS
893
901
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
894
- assert_equal ":1: error: //endchild is shown, but any opened //beginchild doesn't exist", e.message
902
+ assert_equal "//endchild is shown, but any opened //beginchild doesn't exist", e.message
895
903
  end
896
904
 
897
905
  def test_nest_error_close1
@@ -899,7 +907,7 @@ EOS
899
907
  //beginchild
900
908
  EOS
901
909
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
902
- assert_equal ":1: error: //beginchild is shown, but previous element isn't ul, ol, or dl", e.message
910
+ assert_equal "//beginchild is shown, but previous element isn't ul, ol, or dl", e.message
903
911
  end
904
912
 
905
913
  def test_nest_error_close2
@@ -917,7 +925,7 @@ EOS
917
925
  //beginchild
918
926
  EOS
919
927
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
920
- assert_equal ':12: error: //beginchild of dl,ol,ul misses //endchild', e.message
928
+ assert_equal '//beginchild of dl,ol,ul misses //endchild', e.message
921
929
  end
922
930
 
923
931
  def test_nest_error_close3
@@ -937,7 +945,7 @@ EOS
937
945
  //endchild
938
946
  EOS
939
947
  e = assert_raises(ReVIEW::ApplicationError) { compile_block(src) }
940
- assert_equal ':14: error: //beginchild of ol,ul misses //endchild', e.message
948
+ assert_equal '//beginchild of ol,ul misses //endchild', e.message
941
949
  end
942
950
 
943
951
  def test_nest_ul
@@ -1,9 +1,196 @@
1
1
  require 'test_helper'
2
2
  require 'review/preprocessor'
3
3
  require 'stringio'
4
+ require 'book_test_helper'
4
5
 
5
6
  class PreprocessorTest < Test::Unit::TestCase
6
7
  include ReVIEW
8
+ include BookTestHelper
7
9
 
8
- ## TODO: add tests
10
+ def test_mapfile
11
+ preproc = ReVIEW::Preprocessor.new({})
12
+
13
+ ch01_re = <<-'REFILE'
14
+ = test1
15
+
16
+ //list[hello.rb.1][hello.re]{
17
+ #@mapfile(hello.rb)
18
+ #@end
19
+ //}
20
+ REFILE
21
+
22
+ hello_rb = <<-'RBFILE'
23
+ #!/usr/bin/env ruby
24
+
25
+ class Hello
26
+ def hello(name)
27
+ print "hello, #{name}!\n"
28
+ end
29
+ end
30
+
31
+ if __FILE__ == $0
32
+ Hello.new.hello("world")
33
+ end
34
+ RBFILE
35
+
36
+ expected = <<-'EXPECTED'
37
+ = test1
38
+
39
+ //list[hello.rb.1][hello.re]{
40
+ #@mapfile(hello.rb)
41
+ #!/usr/bin/env ruby
42
+
43
+ class Hello
44
+ def hello(name)
45
+ print "hello, #{name}!\n"
46
+ end
47
+ end
48
+
49
+ if __FILE__ == $0
50
+ Hello.new.hello("world")
51
+ end
52
+ #@end
53
+ //}
54
+ EXPECTED
55
+ converted = mktmpbookdir('catalog.yml' => "CHAPS:\n - ch01.re\n",
56
+ 'ch01.re' => ch01_re,
57
+ 'hello.rb' => hello_rb) do |_dir, _book, _files|
58
+ preproc.process('ch01.re')
59
+ end
60
+ assert_equal expected, converted
61
+ end
62
+
63
+ def test_mapfile_tabwidth_is_4
64
+ param = { 'tabwidth' => 4 }
65
+ preproc = ReVIEW::Preprocessor.new(param)
66
+
67
+ ch01 = <<-'REFILE'
68
+ //emlist[test1][inc.txt]{
69
+ #@mapfile(inc.txt)
70
+ #@end
71
+ //}
72
+ REFILE
73
+
74
+ inc_txt = <<-'INC_TXT'
75
+ test.
76
+ test2.
77
+
78
+ test3.
79
+
80
+ test4.
81
+
82
+ test5.
83
+ INC_TXT
84
+
85
+ expected = <<-'EXPECTED'
86
+ //emlist[test1][inc.txt]{
87
+ #@mapfile(inc.txt)
88
+ test.
89
+ test2.
90
+
91
+ test3.
92
+
93
+ test4.
94
+
95
+ test5.
96
+ #@end
97
+ //}
98
+ EXPECTED
99
+ converted = nil
100
+ mktmpbookdir('catalog.yml' => "CHAPS:\n - ch01.re\n",
101
+ 'inc.txt' => inc_txt,
102
+ 'ch01.re' => ch01) do |_dir, _book, _files|
103
+ converted = preproc.process('ch01.re')
104
+ end
105
+ assert_equal expected, converted
106
+ end
107
+
108
+ def test_maprange
109
+ preproc = ReVIEW::Preprocessor.new({})
110
+
111
+ ch01_re = <<-'REFILE'
112
+ //list[range.rb][range.rb(抜粋)]{
113
+ #@maprange(range.rb,sample)
114
+ #@end
115
+ //}
116
+ REFILE
117
+
118
+ range_rb = <<-'RBFILE'
119
+ #!/usr/bin/env ruby
120
+
121
+ class Hello
122
+ #@range_begin(sample)
123
+ def hello(name)
124
+ print "hello, #{name}!\n"
125
+ end
126
+ #@range_end(sample)
127
+ end
128
+
129
+ if __FILE__ == $0
130
+ Hello.new.hello("world")
131
+ end
132
+ RBFILE
133
+
134
+ expected = <<-'EXPECTED'
135
+ //list[range.rb][range.rb(抜粋)]{
136
+ #@maprange(range.rb,sample)
137
+ def hello(name)
138
+ print "hello, #{name}!\n"
139
+ end
140
+ #@end
141
+ //}
142
+ EXPECTED
143
+ converted = mktmpbookdir('catalog.yml' => "CHAPS:\n - ch01.re\n",
144
+ 'ch01.re' => ch01_re,
145
+ 'range.rb' => range_rb) do |_dir, _book, _files|
146
+ preproc.process('ch01.re')
147
+ end
148
+ assert_equal expected, converted
149
+ end
150
+
151
+ def test_at_at_maprange
152
+ preproc = ReVIEW::Preprocessor.new({})
153
+
154
+ ch01_re = <<-'REFILE'
155
+ //list[range.c][range.c(抜粋)]{
156
+ #@maprange(range.c,sample)
157
+ #@end
158
+ //}
159
+ REFILE
160
+
161
+ range_c = <<-'CFILE'
162
+ #include <stdio.h>
163
+
164
+ /* #@@range_begin(sample) */
165
+ void
166
+ put_hello(char *name)
167
+ {
168
+ printf("hello, %s!\n", name);
169
+ }
170
+ /* #@@range_end(sample) */
171
+
172
+ int main()
173
+ {
174
+ put_hello("world");
175
+ }
176
+ CFILE
177
+
178
+ expected = <<-'EXPECTED'
179
+ //list[range.c][range.c(抜粋)]{
180
+ #@maprange(range.c,sample)
181
+ void
182
+ put_hello(char *name)
183
+ {
184
+ printf("hello, %s!\n", name);
185
+ }
186
+ #@end
187
+ //}
188
+ EXPECTED
189
+ converted = mktmpbookdir('catalog.yml' => "CHAPS:\n - ch01.re\n",
190
+ 'ch01.re' => ch01_re,
191
+ 'range.c' => range_c) do |_dir, _book, _files|
192
+ preproc.process('ch01.re')
193
+ end
194
+ assert_equal expected, converted
195
+ end
9
196
  end