review 1.0.0 → 1.1.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 (100) hide show
  1. data/.travis.yml +1 -2
  2. data/ChangeLog +65 -0
  3. data/Gemfile +5 -0
  4. data/README.rdoc +6 -1
  5. data/Rakefile +14 -28
  6. data/bin/review-check +9 -21
  7. data/bin/review-compile +45 -12
  8. data/bin/review-epubmaker +477 -220
  9. data/bin/review-epubmaker-ng +5 -14
  10. data/bin/review-index +4 -2
  11. data/bin/review-init +94 -0
  12. data/bin/review-pdfmaker +70 -287
  13. data/bin/review-preproc +5 -2
  14. data/bin/review-vol +4 -11
  15. data/debian/changelog +3 -3
  16. data/debian/copyright +5 -3
  17. data/debian/docs +1 -0
  18. data/doc/format.rdoc +57 -11
  19. data/doc/quickstart.rdoc +4 -4
  20. data/doc/sample.yaml +11 -7
  21. data/lib/epubmaker.rb +1 -1
  22. data/lib/epubmaker/epubv2.rb +26 -27
  23. data/lib/epubmaker/epubv3.rb +13 -13
  24. data/lib/epubmaker/producer.rb +1 -1
  25. data/lib/review.rb +3 -4
  26. data/lib/review/book.rb +17 -581
  27. data/lib/review/book/base.rb +247 -0
  28. data/lib/review/book/chapter.rb +81 -0
  29. data/lib/review/book/compilable.rb +163 -0
  30. data/lib/review/book/index.rb +339 -0
  31. data/lib/review/book/page_metric.rb +38 -0
  32. data/lib/review/book/parameters.rb +97 -0
  33. data/lib/review/book/part.rb +44 -0
  34. data/lib/review/book/volume.rb +65 -0
  35. data/lib/review/builder.rb +34 -40
  36. data/lib/review/compiler.rb +32 -13
  37. data/lib/review/configure.rb +38 -0
  38. data/lib/review/ewbbuilder.rb +23 -21
  39. data/lib/review/extentions.rb +3 -0
  40. data/lib/review/extentions/object.rb +9 -0
  41. data/lib/review/{compat.rb → extentions/string.rb} +11 -0
  42. data/lib/review/htmlbuilder.rb +162 -74
  43. data/lib/review/htmlutils.rb +28 -1
  44. data/lib/review/i18n.yaml +11 -0
  45. data/lib/review/idgxmlbuilder.rb +119 -35
  46. data/lib/review/inaobuilder.rb +355 -0
  47. data/lib/review/latexbuilder.rb +133 -59
  48. data/lib/review/latexutils.rb +15 -6
  49. data/lib/review/makerhelper.rb +59 -0
  50. data/lib/review/markdownbuilder.rb +129 -0
  51. data/lib/review/preprocessor.rb +20 -7
  52. data/lib/review/review.tex.erb +250 -0
  53. data/lib/review/textutils.rb +28 -3
  54. data/lib/review/tocparser.rb +20 -12
  55. data/lib/review/tocprinter.rb +7 -3
  56. data/lib/review/topbuilder.rb +44 -27
  57. data/lib/review/version.rb +3 -0
  58. data/review.gemspec +20 -117
  59. data/test/book_test_helper.rb +35 -0
  60. data/test/sample-book/README.md +5 -0
  61. data/test/sample-book/src/CHAPS +2 -0
  62. data/test/sample-book/src/PREDEF +1 -0
  63. data/test/sample-book/src/Rakefile +26 -0
  64. data/test/sample-book/src/_cover.html +3 -0
  65. data/test/sample-book/src/ch01.re +71 -0
  66. data/test/sample-book/src/ch02.re +3 -0
  67. data/test/sample-book/src/config.yml +55 -0
  68. data/test/sample-book/src/images/ch01-imgsample.jpg +0 -0
  69. data/test/sample-book/src/images/cover.jpg +0 -0
  70. data/test/sample-book/src/main.css +251 -0
  71. data/test/sample-book/src/preface.re +15 -0
  72. data/test/sample-book/src/sty/jumoline.sty +310 -0
  73. data/test/sample-book/src/sty/samplemacro.sty +21 -0
  74. data/test/sample-book/src/vendor/jumoline/README +29 -0
  75. data/test/sample-book/src/vendor/jumoline/jumoline.dtx +2988 -0
  76. data/test/sample-book/src/vendor/jumoline/jumoline.ins +6 -0
  77. data/test/test_book.rb +26 -646
  78. data/test/test_book_chapter.rb +418 -0
  79. data/test/test_book_parameter.rb +42 -0
  80. data/test/test_book_part.rb +53 -0
  81. data/test/test_builder.rb +17 -10
  82. data/test/test_compiler.rb +46 -0
  83. data/test/test_epubmaker.rb +1 -1
  84. data/test/test_epubmaker_cmd.rb +36 -0
  85. data/test/test_helper.rb +17 -0
  86. data/test/test_htmlbuilder.rb +156 -24
  87. data/test/test_htmlutils.rb +4 -0
  88. data/test/test_i18n.rb +6 -2
  89. data/test/test_idgxmlbuilder.rb +33 -11
  90. data/test/test_inaobuilder.rb +247 -0
  91. data/test/test_index.rb +31 -0
  92. data/test/test_latexbuilder.rb +115 -35
  93. data/test/test_makerhelper.rb +50 -0
  94. data/test/test_pdfmaker_cmd.rb +36 -0
  95. data/test/test_preprocessor.rb +7 -7
  96. data/test/test_topbuilder.rb +6 -7
  97. data/test/test_uuid.rb +1 -0
  98. metadata +117 -12
  99. data/lib/review/index.rb +0 -323
  100. data/lib/review/volume.rb +0 -66
@@ -0,0 +1,6 @@
1
+ \input docstrip.tex
2
+ \keepsilent
3
+ \askonceonly
4
+ \generate{\file{jumoline.sty}{\from{jumoline.dtx}{package}}
5
+ \file{jumoline-man.tex}{\from{jumoline.dtx}{driver}}}
6
+ \endbatchfile
@@ -1,40 +1,5 @@
1
1
  # encoding: utf-8
2
-
3
- require 'test_helper'
4
- require 'review/book'
5
-
6
- require 'stringio'
7
- require 'tempfile'
8
- require 'tmpdir'
9
-
10
- include ReVIEW
11
-
12
- module BookTestHelper
13
- def mktmpbookdir(files = {})
14
- created_files = {}
15
- Dir.mktmpdir do |dir|
16
- files.each_pair do |basename, content|
17
- path = File.join(dir, basename)
18
- File.open(path, 'w') {|o| o.print content }
19
- created_files[basename] = path
20
- end
21
- book = Book.new(dir)
22
- yield(dir, book, created_files)
23
- end
24
- end
25
-
26
- def get_instance_variables(obj)
27
- obj.instance_variables.inject({}) do |memo, name|
28
- value = obj.instance_variable_get(name)
29
- if value.instance_variables.empty?
30
- memo[name] = value
31
- else
32
- memo[name] = get_instance_variables(value)
33
- end
34
- memo
35
- end
36
- end
37
- end
2
+ require 'book_test_helper'
38
3
 
39
4
  class BookTest < Test::Unit::TestCase
40
5
  include BookTestHelper
@@ -90,7 +55,7 @@ class BookTest < Test::Unit::TestCase
90
55
  def test_s_load
91
56
  Dir.mktmpdir do |dir|
92
57
  book = Book.load(dir)
93
- defs = get_instance_variables(Parameters.default)
58
+ defs = get_instance_variables(Book::Parameters.default)
94
59
  pars = get_instance_variables(book.instance_eval { @parameters })
95
60
  assert_equal defs, pars
96
61
  end
@@ -140,13 +105,13 @@ class BookTest < Test::Unit::TestCase
140
105
  end
141
106
 
142
107
  def test_ext
143
- book = Book.new(File.dirname(__FILE__))
108
+ book = Book::Base.new(File.dirname(__FILE__))
144
109
  assert_equal '.re', book.ext
145
110
  end
146
111
 
147
112
  def test_read_CHAPS
148
113
  Dir.mktmpdir do |dir|
149
- book = Book.new(dir)
114
+ book = Book::Base.new(dir)
150
115
  assert_equal "", book.read_CHAPS
151
116
 
152
117
  chaps_path = File.join(dir, 'CHAPS')
@@ -172,13 +137,13 @@ class BookTest < Test::Unit::TestCase
172
137
 
173
138
  def test_read_PART
174
139
  Dir.mktmpdir do |dir|
175
- book = Book.new(dir)
140
+ book = Book::Base.new(dir)
176
141
  assert !book.part_exist?
177
142
  assert_raises Errno::ENOENT do # XXX: OK?
178
143
  book.read_PART
179
144
  end
180
145
 
181
- chaps_path = File.join(dir, 'CHAPS')
146
+ chaps_path = File.join(dir, 'PART')
182
147
  chaps_content = "abc\n"
183
148
  File.open(chaps_path, 'w') {|o| o.print chaps_content }
184
149
 
@@ -192,7 +157,7 @@ class BookTest < Test::Unit::TestCase
192
157
 
193
158
  def test_read_bib
194
159
  Dir.mktmpdir do |dir|
195
- book = Book.new(dir)
160
+ book = Book::Base.new(dir)
196
161
  assert !book.bib_exist?
197
162
  assert_raises Errno::ENOENT do # XXX: OK?
198
163
  book.read_bib
@@ -207,7 +172,7 @@ class BookTest < Test::Unit::TestCase
207
172
  end
208
173
 
209
174
  def test_setParameter
210
- book = Book.new(File.dirname(__FILE__))
175
+ book = Book::Base.new(File.dirname(__FILE__))
211
176
  book.param = :test
212
177
  assert_equal :test, book.instance_eval {@param}
213
178
  end
@@ -223,7 +188,6 @@ class BookTest < Test::Unit::TestCase
223
188
  assert_equal 1, parts.size
224
189
 
225
190
  assert_equal 1, parts[0].number
226
- assert_equal 'chapter1.re', parts[0].name # XXX: OK?
227
191
  assert_equal 2, parts[0].chapters.size
228
192
  chaps = parts[0].chapters.map {|ch| [ch.number, ch.name, ch.path] }
229
193
  expect = [
@@ -248,7 +212,6 @@ EOC
248
212
  assert_equal 3, parts.size
249
213
 
250
214
  assert_equal 1, parts[0].number
251
- assert_equal 'part1_chapter1.re', parts[0].name
252
215
  assert_equal 2, parts[0].chapters.size
253
216
  chaps = parts[0].chapters.map {|ch| [ch.number, ch.name, ch.path] }
254
217
  expect = [
@@ -258,7 +221,6 @@ EOC
258
221
  assert_equal expect, chaps
259
222
 
260
223
  assert_equal 2, parts[1].number
261
- assert_equal 'part1_chapter2.re', parts[1].name # XXX: OK?
262
224
  assert_equal 3, parts[1].chapters.size
263
225
  chaps = parts[1].chapters.map {|ch| [ch.number, ch.name, ch.path] }
264
226
  expect = [
@@ -269,7 +231,6 @@ EOC
269
231
  assert_equal expect, chaps
270
232
 
271
233
  assert_equal 3, parts[2].number
272
- assert_equal '', parts[2].name # XXX: OK?
273
234
  assert_equal 1, parts[2].chapters.size
274
235
  chaps = parts[2].chapters.map {|ch| [ch.number, ch.name, ch.path] }
275
236
  expect = [
@@ -318,8 +279,8 @@ EOC
318
279
  ].each do |n_parts, chaps_text, parts_text, part_names|
319
280
  n_test += 1
320
281
  Dir.mktmpdir do |dir|
321
- params = Parameters.new(:part_file => 'PARTS')
322
- book = Book.new(dir, params)
282
+ params = Book::Parameters.new(:part_file => 'PARTS')
283
+ book = Book::Base.new(dir, params)
323
284
  chaps_path = File.join(dir, 'CHAPS')
324
285
  File.open(chaps_path, 'w') {|o| o.print chaps_text }
325
286
  unless parts_text.nil?
@@ -340,7 +301,7 @@ EOC
340
301
  end
341
302
 
342
303
  mktmpbookdir 'preface.re' => '' do |dir, book, files|
343
- assert_kind_of Part, book.prefaces
304
+ assert_kind_of Book::Part, book.prefaces
344
305
  assert_equal '', book.prefaces.name
345
306
  assert_equal 1, book.prefaces.chapters.size
346
307
  assert_equal "preface", book.prefaces.chapters.first.name
@@ -359,7 +320,7 @@ EOC
359
320
 
360
321
  mktmpbookdir 'PREDEF' => 'chapter1',
361
322
  'chapter1.re' => '' do |dir, book, files|
362
- assert_kind_of Part, book.prefaces
323
+ assert_kind_of Book::Part, book.prefaces
363
324
  assert_equal '', book.prefaces.name
364
325
  assert_equal 1, book.prefaces.chapters.size
365
326
  assert_equal "chapter1", book.prefaces.chapters.first.name
@@ -368,7 +329,7 @@ EOC
368
329
 
369
330
  mktmpbookdir 'PREDEF' => "chapter1\n\nchapter2",
370
331
  'chapter1.re' => '', 'chapter2.re' => '' do |dir, book, files|
371
- assert_kind_of Part, book.prefaces
332
+ assert_kind_of Book::Part, book.prefaces
372
333
  assert_equal '', book.prefaces.name
373
334
  assert_equal 2, book.prefaces.chapters.size
374
335
  assert_equal "chapter1", book.prefaces.chapters.first.name
@@ -379,7 +340,7 @@ EOC
379
340
 
380
341
  mktmpbookdir 'PREDEF' => "chapter1 chapter2",
381
342
  'chapter1.re' => '', 'chapter2.re' => '' do |dir, book, files|
382
- assert_kind_of Part, book.prefaces
343
+ assert_kind_of Book::Part, book.prefaces
383
344
  assert_equal '', book.prefaces.name
384
345
  assert_equal 2, book.prefaces.chapters.size # XXX: OK?
385
346
  end
@@ -392,14 +353,14 @@ EOC
392
353
 
393
354
  mktmpbookdir 'PREDEF' => 'chapter1.re',
394
355
  'chapter1.re' => '' do |dir, book, files|
395
- assert_kind_of Part, book.prefaces
356
+ assert_kind_of Book::Part, book.prefaces
396
357
  assert_equal '', book.prefaces.name
397
358
  assert_equal 1, book.prefaces.chapters.size
398
359
  end
399
360
 
400
361
  mktmpbookdir 'PREDEF' => 'chapter1.txt',
401
362
  'chapter1.txt' => '' do |dir, book, files|
402
- assert_kind_of Part, book.prefaces
363
+ assert_kind_of Book::Part, book.prefaces
403
364
  assert_equal '', book.prefaces.name
404
365
  assert_equal 1, book.prefaces.chapters.size
405
366
  end
@@ -411,7 +372,7 @@ EOC
411
372
  end
412
373
 
413
374
  mktmpbookdir 'appendix.re' => '' do |dir, book, files|
414
- assert_kind_of Part, book.postscripts
375
+ assert_kind_of Book::Part, book.postscripts
415
376
  assert_equal '', book.postscripts.name
416
377
  assert_equal 1, book.postscripts.chapters.size
417
378
  assert_equal "appendix", book.postscripts.chapters.first.name
@@ -420,7 +381,7 @@ EOC
420
381
  end
421
382
 
422
383
  mktmpbookdir 'postscript.re' => '' do |dir, book, files|
423
- assert_kind_of Part, book.postscripts
384
+ assert_kind_of Book::Part, book.postscripts
424
385
  assert_equal '', book.postscripts.name
425
386
  assert_equal 1, book.postscripts.chapters.size
426
387
  assert_equal "postscript", book.postscripts.chapters.first.name
@@ -430,7 +391,7 @@ EOC
430
391
 
431
392
  mktmpbookdir 'appendix.re' => '',
432
393
  'postscript.re' => '' do |dir, book, files|
433
- assert_kind_of Part, book.postscripts
394
+ assert_kind_of Book::Part, book.postscripts
434
395
  assert_equal '', book.postscripts.name
435
396
  assert_equal 2, book.postscripts.chapters.size
436
397
  assert_equal "appendix", book.postscripts.chapters.first.name
@@ -452,7 +413,7 @@ EOC
452
413
 
453
414
  mktmpbookdir 'POSTDEF' => 'chapter1',
454
415
  'chapter1.re' => '' do |dir, book, files|
455
- assert_kind_of Part, book.postscripts
416
+ assert_kind_of Book::Part, book.postscripts
456
417
  assert_equal '', book.postscripts.name
457
418
  assert_equal 1, book.postscripts.chapters.size
458
419
  assert_equal "chapter1", book.postscripts.chapters.first.name
@@ -461,7 +422,7 @@ EOC
461
422
 
462
423
  mktmpbookdir 'POSTDEF' => "chapter1\n\nchapter2",
463
424
  'chapter1.re' => '', 'chapter2.re' => '' do |dir, book, files|
464
- assert_kind_of Part, book.postscripts
425
+ assert_kind_of Book::Part, book.postscripts
465
426
  assert_equal '', book.postscripts.name
466
427
  assert_equal 2, book.postscripts.chapters.size
467
428
  assert_equal "chapter1", book.postscripts.chapters.first.name
@@ -472,7 +433,7 @@ EOC
472
433
 
473
434
  mktmpbookdir 'POSTDEF' => "chapter1 chapter2",
474
435
  'chapter1.re' => '', 'chapter2.re' => '' do |dir, book, files|
475
- assert_kind_of Part, book.postscripts
436
+ assert_kind_of Book::Part, book.postscripts
476
437
  assert_equal '', book.postscripts.name
477
438
  assert_equal 2, book.postscripts.chapters.size # XXX: OK?
478
439
  end
@@ -489,7 +450,6 @@ EOC
489
450
  assert book.parts.empty?
490
451
  assert !book.part(0)
491
452
  assert !book.part(1)
492
- assert !book.no_part?
493
453
 
494
454
  tmp = []
495
455
  book.each_part { tmp << true }
@@ -503,7 +463,6 @@ EOC
503
463
  assert book.part(1)
504
464
  assert book.part(2)
505
465
  assert !book.part(3)
506
- assert !book.no_part? # XXX: OK?
507
466
 
508
467
  tmp = []
509
468
  book.each_part {|p| tmp << p.number }
@@ -574,7 +533,7 @@ EOC
574
533
  assert_equal name, book.chapter(name).name
575
534
  end
576
535
 
577
- assert_raises IndexError,KeyError do
536
+ assert_raises ReVIEW::KeyError do
578
537
  book.chapter('not exist')
579
538
  end
580
539
  end
@@ -594,7 +553,7 @@ EOC
594
553
  assert_equal name, book.chapter(name).name
595
554
  end
596
555
 
597
- assert_raises IndexError,KeyError do
556
+ assert_raises ReVIEW::KeyError do
598
557
  book.chapter('not exist')
599
558
  end
600
559
  end
@@ -621,7 +580,7 @@ EOC
621
580
  end
622
581
 
623
582
  Dir.chdir(dir) do
624
- book2 = Book.new('.')
583
+ book2 = Book::Base.new('.')
625
584
  assert book2.volume
626
585
  assert book2.volume.bytes > 0
627
586
  assert book2.volume.chars > 0
@@ -632,587 +591,8 @@ EOC
632
591
 
633
592
  def test_basedir
634
593
  Dir.mktmpdir do |dir|
635
- book = Book.new(dir)
594
+ book = Book::Base.new(dir)
636
595
  assert_equal dir, book.basedir
637
596
  end
638
597
  end
639
598
  end
640
-
641
- class ParametersTest < Test::Unit::TestCase
642
- def test_s_default
643
- assert Parameters.default
644
- end
645
-
646
- def test_s_load
647
- Tempfile.open('parameters_test') do |io|
648
- io.puts 'CHAPS_FILE = "x_CHAPS"'
649
- io.puts 'PAPER = "B5"' # XXX: avoid erros of the last line of Parameters.get_page_metric
650
- io.close
651
-
652
- params = Parameters.load(io.path)
653
- assert_equal '/x_CHAPS', params.chapter_file # XXX: OK? (leading / and uninitialized @basedir)
654
- assert_equal '/CHAPS', params.part_file
655
- end
656
- end
657
-
658
- def test_s_get_page_metric
659
- mod = Module.new
660
- assert_raises ArgumentError do # XXX: OK?
661
- params = Parameters.get_page_metric(mod)
662
- assert params
663
- end
664
-
665
- mod = Module.new
666
- mod.module_eval { const_set(:PAPER, 'A5') }
667
- assert_nothing_raised do
668
- params = Parameters.get_page_metric(mod)
669
- assert params
670
- end
671
-
672
- mod = Module.new
673
- mod.module_eval { const_set(:PAPER, 'X5') }
674
- assert_raises ConfigError do
675
- Parameters.get_page_metric(mod)
676
- end
677
- end
678
- end
679
-
680
- class PartTest < Test::Unit::TestCase
681
- def test_initialize
682
- part = Part.new(nil, nil)
683
- assert_equal nil, part.number
684
- assert_equal nil, part.chapters
685
- assert_equal '', part.name
686
-
687
- part = Part.new(123, [], 'name')
688
- assert_equal 123, part.number
689
- assert_equal [], part.chapters
690
- assert_equal 'name', part.name
691
- end
692
-
693
- def test_each_chapter
694
- part = Part.new(nil, [1, 2, 3])
695
-
696
- tmp = []
697
- part.each_chapter do |ch|
698
- tmp << ch
699
- end
700
- assert_equal [1, 2, 3], tmp
701
- end
702
-
703
- def test_volume
704
- part = Part.new(nil, [])
705
- assert part.volume
706
- assert_equal 0, part.volume.bytes
707
- assert_equal 0, part.volume.chars
708
- assert_equal 0, part.volume.lines
709
-
710
- chs = []
711
- Tempfile.open('part_test') do |o|
712
- o.print "12345"
713
- chs << Chapter.new(nil, nil, nil, o.path)
714
- end
715
- Tempfile.open('part_test') do |o|
716
- o.print "67890"
717
- chs << Chapter.new(nil, nil, nil, o.path)
718
- end
719
-
720
- part = Part.new(nil, chs)
721
- assert part.volume
722
- assert part.volume.bytes > 0
723
- assert part.volume.chars > 0
724
- assert part.volume.lines > 0
725
- end
726
- end
727
-
728
- class ChapterTest < Test::Unit::TestCase
729
- include BookTestHelper
730
-
731
- def setup
732
-
733
- if "".respond_to?(:encode)
734
- @utf8_str = "あいうえお"
735
- @eucjp_str = "あいうえお".encode("EUC-JP")
736
- @sjis_str = "あいうえお".encode("Shift_JIS")
737
- @jis_str = "あいうえお".encode("ISO-2022-JP")
738
- else
739
- @utf8_str = "\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\xe3\x81\x8a" # "あいうえお"
740
- @eucjp_str = "\xa4\xa2\xa4\xa4\xa4\xa6\xa4\xa8\xa4\xaa"
741
- @sjis_str = "\x82\xa0\x82\xa2\x82\xa4\x82\xa6\x82\xa8"
742
- @jis_str = "\x1b\x24\x42\x24\x22\x24\x24\x24\x26\x24\x28\x24\x2a\x1b\x28\x42"
743
- end
744
- =begin
745
- @utf8_str = "\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\xe3\x81\x8a" # "あいうえお"
746
- @eucjp_str = "\xa4\xa2\xa4\xa4\xa4\xa6\xa4\xa8\xa4\xaa"
747
- @sjis_str = "\x82\xa0\x82\xa2\x82\xa4\x82\xa6\x82\xa8"
748
- @jis_str = "\x1b\x24\x42\x24\x22\x24\x24\x24\x26\x24\x28\x24\x2a\x1b\x28\x42"
749
- =end
750
- end
751
-
752
- def test_s_intern_pathes
753
- dir1_files = {
754
- 'CHAPS' => "ch1.re\nch2.re\n",
755
- 'ch1.re' => 'ch1',
756
- 'ch2.re' => 'ch2',
757
- }
758
- dir2_files = {
759
- 'CHAPS' => "ch1.re\n",
760
- 'ch1.re' => 'ch1',
761
- }
762
- mktmpbookdir dir1_files do |dir1, book1, files1|
763
- mktmpbookdir dir2_files do |dir2, book2, files2|
764
- paths = (files1.values + files2.values).flatten.grep(/\.re\z/)
765
- chs = Chapter.intern_pathes(paths)
766
-
767
- assert_equal 3, chs.size
768
- assert chs[0].book == chs[1].book
769
- assert chs[0].book != chs[2].book
770
- assert dir1, chs[0].book.basedir
771
- assert dir2, chs[2].book.basedir
772
- end
773
- end
774
-
775
- dir_files = {
776
- 'CHAPS' => "ch1.re\n",
777
- 'ch1.re' => 'ch1',
778
- }
779
- mktmpbookdir dir_files do |dir, book, files|
780
- paths = files.values.grep(/\.re\z/)
781
- paths << __FILE__ + ' not exist file.re'
782
- assert_raises IndexError,KeyError do # XXX: OK? (KeyError?)
783
- Chapter.intern_pathes(paths)
784
- end
785
- end
786
-
787
- dir_files = {
788
- 'ch1.re' => 'ch1 not in CHAPS',
789
- 'ch2.re' => 'ch2 not in CHAPS',
790
- }
791
- mktmpbookdir dir_files do |dir, book, files|
792
- paths = files.values.grep(/\.re\z/)
793
- assert_nothing_raised do
794
- Chapter.intern_pathes(paths)
795
- end
796
- end
797
-
798
- dir_files = {
799
- 'CHAPS' => "ch1.re\n",
800
- 'ch1.re' => 'ch1',
801
- 'ch2.re' => 'ch2 not in CHAPS',
802
- }
803
- mktmpbookdir dir_files do |dir, book, files|
804
- paths = files.values.grep(/\.re\z/)
805
- assert_raises IndexError,KeyError do # XXX: OK? (should not be raised?)
806
- Chapter.intern_pathes(paths)
807
- end
808
- end
809
-
810
- dir_files = {
811
- 'CHAPS' => "ch1.re\n",
812
- 'ch1.re' => 'ch1',
813
- 'preface.re' => 'preface',
814
- }
815
- mktmpbookdir dir_files do |dir, book, files|
816
- paths = files.values.grep(/\.re\z/)
817
- assert_nothing_raised do
818
- Chapter.intern_pathes(paths)
819
- end
820
- end
821
- end
822
-
823
- def test_s_for_stdin
824
- assert Chapter.for_stdin
825
- end
826
-
827
- def test_s_for_path
828
- assert Chapter.for_path(1, __FILE__)
829
- end
830
-
831
- def test_initialize
832
- ch = Chapter.new(:book, :number, :name, '/foo/bar', :io)
833
- assert_equal :book, ch.env
834
- assert_equal :book, ch.book
835
- assert_equal :number, ch.number
836
- assert_equal '/foo/bar', ch.path
837
- assert_equal "#<ReVIEW::Chapter number /foo/bar>", ch.inspect
838
- end
839
-
840
- def test_dirname_and_basename
841
- ch = Chapter.new(nil, nil, nil, nil, nil)
842
- assert_equal nil, ch.dirname
843
- assert_equal nil, ch.basename
844
-
845
- ch = Chapter.new(nil, nil, nil, '/foo/bar', nil)
846
- assert_equal '/foo', ch.dirname
847
- assert_equal 'bar', ch.basename
848
-
849
- ch = Chapter.new(nil, nil, nil, 'bar', nil)
850
- assert_equal '.', ch.dirname
851
- assert_equal 'bar', ch.basename
852
- end
853
-
854
- def test_name
855
- ch = Chapter.new(nil, nil, 'foo', nil)
856
- assert_equal 'foo', ch.name
857
-
858
- ch = Chapter.new(nil, nil, 'foo.bar', nil)
859
- assert_equal 'foo', ch.name
860
-
861
- ch = Chapter.new(nil, nil, nil, nil)
862
- assert_raises(TypeError) { ch.name } # XXX: OK?
863
- end
864
-
865
- def test_open
866
- ch = Chapter.new(nil, nil, nil, __FILE__, :io)
867
- assert_equal :io, ch.open
868
- assert_equal [:io], ch.open {|io| [io] }
869
-
870
- ch = Chapter.new(nil, nil, nil, __FILE__)
871
- assert_equal __FILE__, ch.open.path
872
- assert_equal [__FILE__], ch.open {|io| [io.path] }
873
- end
874
-
875
- def test_size
876
- ch = Chapter.new(nil, nil, nil, __FILE__, :io)
877
- assert_equal File.size(__FILE__), ch.size
878
-
879
- File.open(__FILE__, 'r') do |i|
880
- ch = Chapter.new(nil, nil, nil, nil, i)
881
- assert_raises(TypeError) do # XXX: OK?
882
- ch.size
883
- end
884
- end
885
- end
886
-
887
- def test_title
888
- io = StringIO.new
889
- ch = Chapter.new(nil, nil, nil, nil, io)
890
- assert_equal '', ch.title
891
-
892
- io = StringIO.new("=1\n=2\n")
893
- ch = Chapter.new(nil, nil, nil, nil, io)
894
- assert_equal '1', ch.title
895
-
896
-
897
- [
898
- ['EUC', @eucjp_str],
899
- ['SJIS', @sjis_str],
900
- # ['JIS', @jis_str],
901
- ['XYZ', @eucjp_str],
902
- ].each do |enc, instr|
903
- io = StringIO.new("= #{instr}\n")
904
- ch = Chapter.new(nil, nil, nil, nil, io)
905
- ReVIEW.book.param = {'inencoding' => enc}
906
- assert_equal @utf8_str, ch.title
907
- assert_equal @utf8_str, ch.instance_eval { @title }
908
- end
909
- end
910
-
911
- def test_content
912
- [
913
- ['EUC', @eucjp_str],
914
- ['SJIS', @sjis_str],
915
- ['JIS', @jis_str],
916
- ['XYZ', @eucjp_str],
917
- ].each do |enc, instr|
918
- tf = Tempfile.new('chapter_test')
919
- begin
920
- tf.print instr
921
- tf.close
922
-
923
- ch = Chapter.new(nil, nil, nil, tf.path)
924
- ReVIEW.book.param = {'inencoding' => enc}
925
- assert_equal @utf8_str, ch.content
926
- assert_equal @utf8_str, ch.instance_eval { @content }
927
- ensure
928
- tf.close(true)
929
- end
930
-
931
- tf1 = Tempfile.new('chapter_test1')
932
- tf2 = Tempfile.new('chapter_test2')
933
- begin
934
- tf1.puts instr
935
- tf1.puts instr
936
- tf1.close
937
- tf2.puts instr
938
- tf1.close
939
-
940
- ch = Chapter.new(nil, nil, nil, tf1.path, tf2)
941
- ReVIEW.book.param = {'inencoding' => enc}
942
- assert_equal "#{@utf8_str}\n#{@utf8_str}\n", ch.content # XXX: OK?
943
- ensure
944
- tf1.close(true)
945
- tf2.close(true)
946
- end
947
- end
948
- end
949
-
950
- def test_lines
951
- lines = ["1\n", "2\n", "3"]
952
- tf = Tempfile.new('chapter_test')
953
- tf.print lines.join('')
954
- tf.close
955
-
956
- ch = Chapter.new(nil, nil, nil, tf.path)
957
- assert_equal lines, ch.lines
958
-
959
- lines = ["1\n", "2\n", "3"]
960
- tf1 = Tempfile.new('chapter_test1')
961
- tf1.print lines.join('')
962
- tf1.close
963
- tf2 = Tempfile.new('chapter_test2')
964
- tf2.puts lines.join('')
965
- tf2.puts lines.join('')
966
- tf2.close
967
-
968
- ch = Chapter.new(nil, nil, nil, tf1.path, tf2.path)
969
- assert_equal lines, ch.lines # XXX: OK?
970
- end
971
-
972
- def test_volume
973
- content = "abc\ndef"
974
- tf1 = Tempfile.new('chapter_test1')
975
- tf1.print content
976
- tf1.close
977
- tf2 = Tempfile.new('chapter_test2')
978
- tf2.print content
979
- tf2.print content
980
- tf2.close
981
-
982
- ch = Chapter.new(nil, nil, nil, tf1.path)
983
- assert ch.volume
984
- assert_equal content.gsub(/\s/, '').size, ch.volume.bytes
985
-
986
- ch = Chapter.new(nil, nil, nil, tf1.path, tf2)
987
- assert ch.volume
988
- assert_equal content.gsub(/\s/, '').size, ch.volume.bytes # XXX: OK?
989
- end
990
-
991
- def test_on_CHAPS?
992
- mktmpbookdir 'CHAPS' => "chapter1.re\nchapter2.re",
993
- 'chapter1.re' => '12345', 'preface.re' => 'abcde' do |dir, book, files|
994
- ch1 = Chapter.new(book, 1, 'chapter1', files['chapter1.re'])
995
- pre = Chapter.new(book, nil, 'preface', files['preface.re'])
996
-
997
- assert ch1.on_CHAPS?
998
- assert !pre.on_CHAPS?
999
-
1000
- ch2_path = File.join(dir, 'chapter2.er')
1001
- File.open(ch2_path, 'w') {}
1002
- ch2 = Chapter.new(book, 2, 'chapter2', ch2_path)
1003
-
1004
- ch3_path = File.join(dir, 'chapter3.er')
1005
- File.open(ch3_path, 'w') {}
1006
- ch3 = Chapter.new(book, 3, 'chapter3', ch3_path)
1007
-
1008
- assert ch2.on_CHAPS?
1009
- assert !ch3.on_CHAPS?
1010
- end
1011
- end
1012
-
1013
- def test_list_index
1014
- do_test_index(<<E, ListIndex, :list_index, :list)
1015
- //list
1016
- //listnum [abc]
1017
- //list [def]
1018
- //table [def]
1019
- //table [others]
1020
- E
1021
- end
1022
-
1023
- def test_table_index
1024
- do_test_index(<<E, TableIndex, :table_index, :table)
1025
- //table
1026
- //table [abc]
1027
- //table [def]
1028
- //list [def]
1029
- //list [others]
1030
- E
1031
- end
1032
-
1033
- def test_footnote_index
1034
- content = <<E
1035
- //footnote
1036
- //footnote [abc][text...]
1037
- //footnote [def][text...]
1038
- //footnote [xyz]
1039
- //list [def]
1040
- //list [others]
1041
- E
1042
- do_test_index(content, FootnoteIndex, :footnote_index, :footnote) do |ch|
1043
- assert_raises IndexError,KeyError do
1044
- ch.footnote('xyz')
1045
- end
1046
- end
1047
- end
1048
-
1049
- def test_bibpaper
1050
- do_test_index(<<E, BibpaperIndex, :bibpaper_index, :bibpaper, :filename => 'bib.re')
1051
- //bibpaper
1052
- //bibpaper [abc][text...]
1053
- //bibpaper [def][text...]
1054
- //bibpaper [xyz]
1055
- //list [def]
1056
- //list [others]
1057
- E
1058
- assert_raises FileNotFound do
1059
- do_test_index('', BibpaperIndex, :bibpaper_index, :bibpaper, :filename => 'bib')
1060
- end
1061
- end
1062
-
1063
- def test_headline_index
1064
- do_test_index(<<E, HeadlineIndex, :headline_index, :headline, :propagate => false)
1065
- ==
1066
- == abc
1067
- == def
1068
- === def
1069
- //table others
1070
- E
1071
- end
1072
-
1073
- def test_image
1074
- do_test_index(<<E, ImageIndex, :image_index, :image)
1075
- //image
1076
- //image [abc]
1077
- //image [def]
1078
- //list [def]
1079
- //list [others]
1080
- E
1081
-
1082
- do_test_index(<<E, NumberlessImageIndex, :numberless_image_index, :image, :propagate => false)
1083
- //numberlessimage
1084
- //numberlessimage [abc]
1085
- //numberlessimage [def]
1086
- //list [def]
1087
- //list [others]
1088
- E
1089
-
1090
- do_test_index(<<E, ImageIndex, :image_index, :image)
1091
- //image
1092
- //numberlessimage [abc]
1093
- //image [def]
1094
- //list [def]
1095
- //list [others]
1096
- E
1097
-
1098
- do_test_index(<<E, NumberlessImageIndex, :numberless_image_index, :image, :propagate => false)
1099
- //image
1100
- //numberlessimage [abc]
1101
- //image [def]
1102
- //list [def]
1103
- //list [others]
1104
- E
1105
- end
1106
-
1107
- def do_test_index(content, klass, list_method, ref_method, opts = {})
1108
- Dir.mktmpdir do |dir|
1109
- path = File.join(dir, opts[:filename] || 'chapter.re')
1110
-
1111
- book = Book.new(dir)
1112
-
1113
- ch = nil
1114
- File.open(path, 'w') do |o|
1115
- o.print content
1116
- ch = Chapter.new(book, 1, 'chapter', o.path)
1117
- end
1118
-
1119
- assert ch.__send__(ref_method, 'abc')
1120
- assert ch.__send__(ref_method, 'def')
1121
- assert_raises IndexError,KeyError do
1122
- ch.__send__(ref_method, nil)
1123
- end
1124
- assert_raises IndexError,KeyError do
1125
- ch.__send__(ref_method, 'others')
1126
- end
1127
- assert_raises IndexError,KeyError do
1128
- ch.__send__(ref_method, 'not exist id')
1129
- end
1130
-
1131
- yield(ch) if block_given?
1132
- end
1133
- end
1134
- end
1135
-
1136
- class ChapterSetTest < Test::Unit::TestCase
1137
- include BookTestHelper
1138
-
1139
- def test_s_for_pathes
1140
- dir_files = {
1141
- 'ch1.re' => 'ch1',
1142
- 'ch2.re' => 'ch2',
1143
- }
1144
- mktmpbookdir dir_files do |dir, book, files|
1145
- paths = files.values.grep(/\.re\z/)
1146
- cs = nil
1147
- assert_nothing_raised do
1148
- cs = ChapterSet.for_pathes(paths)
1149
- end
1150
- assert_equal 2, cs.chapters.size
1151
- end
1152
- end
1153
-
1154
- def test_s_for_argv
1155
- begin
1156
- paths = []
1157
- ChapterSet.class_eval { const_set(:ARGV, paths) }
1158
-
1159
- dir_files = {
1160
- 'ch1.re' => 'ch1',
1161
- 'ch2.re' => 'ch2',
1162
- }
1163
- mktmpbookdir dir_files do |dir, book, files|
1164
- paths.concat files.values.grep(/\.re\z/)
1165
- cs = nil
1166
- assert_nothing_raised do
1167
- cs = ChapterSet.for_argv
1168
- end
1169
- assert_equal 2, cs.chapters.size
1170
- assert_equal ['ch1', 'ch2'], cs.chapters.map(&:name).sort
1171
- end
1172
-
1173
- ensure
1174
- ChapterSet.class_eval { remove_const(:ARGV) }
1175
- ChapterSet.class_eval { const_set(:ARGV, []) }
1176
- end
1177
-
1178
- begin
1179
- $stdin = StringIO.new('abc')
1180
- cs = nil
1181
- assert_nothing_raised do
1182
- cs = ChapterSet.for_argv
1183
- end
1184
- assert_equal 1, cs.chapters.size
1185
- assert_equal '-', cs.chapters.first.name
1186
-
1187
- ensure
1188
- $stdin = STDIN
1189
- end
1190
- end
1191
-
1192
- def test_no_part?
1193
- cs = ChapterSet.new([])
1194
- assert cs.no_part?
1195
-
1196
- ch = Chapter.new(nil, nil, nil, nil, StringIO.new)
1197
- cs = ChapterSet.new([ch])
1198
- assert cs.no_part?
1199
- end
1200
-
1201
- def test_chapters
1202
- ch1 = Chapter.new(nil, 123, nil, nil, StringIO.new)
1203
- ch2 = Chapter.new(nil, 456, nil, nil, StringIO.new)
1204
- cs = ChapterSet.new([ch1, ch2])
1205
- assert_equal [123, 456], cs.chapters.map(&:number)
1206
-
1207
- tmp = [ch1, ch2]
1208
- cs.each_chapter do |ch|
1209
- assert tmp.delete(ch)
1210
- end
1211
- assert tmp.empty?
1212
- end
1213
-
1214
- def test_ext
1215
- cs = ChapterSet.new([])
1216
- assert_equal '.re', cs.ext
1217
- end
1218
- end