review 5.0.0 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby-tex.yml +31 -0
  3. data/.github/workflows/ruby-win.yml +3 -3
  4. data/.github/workflows/ruby.yml +1 -1
  5. data/.rubocop.yml +15 -7
  6. data/NEWS.ja.md +108 -0
  7. data/NEWS.md +108 -0
  8. data/README.md +7 -6
  9. data/Rakefile +7 -2
  10. data/bin/review +2 -4
  11. data/bin/review-catalog-converter +3 -3
  12. data/bin/review-check +6 -8
  13. data/bin/review-checkdep +1 -4
  14. data/bin/review-compile +2 -5
  15. data/bin/review-epub2html +1 -4
  16. data/bin/review-epubmaker +3 -4
  17. data/bin/review-idgxmlmaker +1 -3
  18. data/bin/review-index +11 -5
  19. data/bin/review-init +1 -4
  20. data/bin/review-pdfmaker +1 -3
  21. data/bin/review-preproc +2 -4
  22. data/bin/review-textmaker +1 -3
  23. data/bin/review-update +1 -4
  24. data/bin/review-validate +3 -3
  25. data/bin/review-vol +1 -4
  26. data/bin/review-webmaker +1 -3
  27. data/doc/config.yml.sample +21 -5
  28. data/doc/config.yml.sample-simple +1 -1
  29. data/doc/format.ja.md +21 -10
  30. data/doc/format.md +21 -10
  31. data/doc/quickstart.ja.md +11 -1
  32. data/doc/quickstart.md +11 -2
  33. data/lib/review.rb +1 -1
  34. data/lib/review/book/base.rb +4 -0
  35. data/lib/review/book/book_unit.rb +3 -0
  36. data/lib/review/book/chapter.rb +3 -0
  37. data/lib/review/book/index.rb +1 -0
  38. data/lib/review/book/volume.rb +1 -0
  39. data/lib/review/builder.rb +8 -1
  40. data/lib/review/call_hook.rb +20 -0
  41. data/lib/review/catalog.rb +1 -0
  42. data/lib/review/compiler.rb +27 -10
  43. data/lib/review/configure.rb +64 -7
  44. data/lib/review/epubmaker.rb +93 -96
  45. data/lib/review/epubmaker/content.rb +113 -0
  46. data/lib/review/epubmaker/epubcommon.rb +372 -0
  47. data/lib/review/epubmaker/epubv2.rb +178 -0
  48. data/lib/review/epubmaker/epubv3.rb +231 -0
  49. data/lib/review/epubmaker/producer.rb +168 -0
  50. data/lib/review/epubmaker/reviewheaderlistener.rb +12 -2
  51. data/lib/review/epubmaker/zip_exporter.rb +84 -0
  52. data/lib/review/exception.rb +6 -0
  53. data/lib/review/htmlbuilder.rb +36 -49
  54. data/lib/review/htmlutils.rb +1 -1
  55. data/lib/review/i18n.rb +1 -0
  56. data/lib/review/idgxmlbuilder.rb +33 -30
  57. data/lib/review/idgxmlmaker.rb +3 -1
  58. data/lib/review/img_math.rb +245 -0
  59. data/lib/review/index_builder.rb +1 -0
  60. data/lib/review/init.rb +4 -4
  61. data/lib/review/latexbox.rb +58 -0
  62. data/lib/review/latexbuilder.rb +30 -19
  63. data/lib/review/latexutils.rb +9 -1
  64. data/lib/review/lineinput.rb +112 -2
  65. data/lib/review/logger.rb +41 -2
  66. data/lib/review/makerhelper.rb +2 -205
  67. data/lib/review/markdownbuilder.rb +32 -1
  68. data/lib/review/pdfmaker.rb +31 -29
  69. data/lib/review/plaintextbuilder.rb +9 -1
  70. data/lib/review/preprocessor.rb +12 -6
  71. data/lib/review/rstbuilder.rb +1 -1
  72. data/lib/review/sec_counter.rb +1 -0
  73. data/lib/review/template.rb +6 -0
  74. data/lib/review/textmaker.rb +11 -7
  75. data/lib/review/textutils.rb +2 -10
  76. data/lib/review/tocprinter.rb +85 -68
  77. data/lib/review/topbuilder.rb +18 -11
  78. data/lib/review/update.rb +5 -6
  79. data/lib/review/version.rb +1 -1
  80. data/lib/review/volumeprinter.rb +4 -5
  81. data/lib/review/webmaker.rb +18 -13
  82. data/lib/review/webtocprinter.rb +10 -9
  83. data/lib/review/yamlloader.rb +2 -1
  84. data/review.gemspec +5 -3
  85. data/samples/sample-book/src/config-epub2.yml +1 -1
  86. data/samples/sample-book/src/config.yml +1 -1
  87. data/samples/sample-book/src/lib/tasks/review.rake +17 -1
  88. data/samples/syntax-book/ch01.re +1 -1
  89. data/samples/syntax-book/ch02.re +21 -6
  90. data/samples/syntax-book/ch03.re +1 -1
  91. data/samples/syntax-book/images/img3-2.png +0 -0
  92. data/templates/html/_colophon.html.erb +23 -0
  93. data/templates/html/_colophon_history.html.erb +9 -0
  94. data/templates/html/_cover.html.erb +10 -0
  95. data/templates/html/_part_body.html.erb +6 -0
  96. data/templates/html/_titlepage.html.erb +20 -0
  97. data/templates/html/layout-html5.html.erb +6 -0
  98. data/templates/html/layout-xhtml1.html.erb +6 -0
  99. data/templates/latex/config.erb +8 -0
  100. data/templates/latex/review-jlreq/review-base.sty +4 -5
  101. data/templates/latex/review-jlreq/review-jlreq.cls +10 -2
  102. data/templates/latex/review-jlreq/review-style.sty +6 -1
  103. data/templates/latex/review-jlreq/review-tcbox.sty +348 -0
  104. data/templates/latex/review-jlreq/reviewmacro.sty +5 -0
  105. data/templates/latex/review-jsbook/review-base.sty +5 -7
  106. data/templates/latex/review-jsbook/review-jsbook.cls +10 -2
  107. data/templates/latex/review-jsbook/review-style.sty +6 -1
  108. data/templates/latex/review-jsbook/review-tcbox.sty +348 -0
  109. data/templates/latex/review-jsbook/reviewmacro.sty +5 -0
  110. data/templates/opf/epubv2.opf.erb +7 -7
  111. data/templates/opf/epubv3.opf.erb +7 -7
  112. data/templates/opf/opf_manifest_epubv2.opf.erb +10 -0
  113. data/templates/opf/opf_manifest_epubv3.opf.erb +10 -0
  114. data/templates/opf/opf_metainfo_epubv2.opf.erb +17 -0
  115. data/templates/opf/opf_metainfo_epubv3.opf.erb +49 -0
  116. data/templates/opf/opf_tocx_epubv2.opf.erb +9 -0
  117. data/templates/opf/opf_tocx_epubv3.opf.erb +17 -0
  118. data/templates/web/html/layout-html5.html.erb +6 -5
  119. data/templates/web/html/layout-xhtml1.html.erb +6 -0
  120. data/test/assets/header_listener.html +35 -0
  121. data/test/assets/img_math/img1.png +0 -0
  122. data/test/assets/img_math/img2.png +0 -0
  123. data/test/assets/img_math/img3.png +0 -0
  124. data/test/assets/syntax_book_index_detail.txt +58 -0
  125. data/test/assets/test_template.tex +4 -1
  126. data/test/assets/test_template_backmatter.tex +4 -1
  127. data/test/run_test.rb +1 -1
  128. data/test/test_book_chapter.rb +2 -2
  129. data/test/test_catalog_converter_cmd.rb +1 -1
  130. data/test/test_epub3maker.rb +168 -124
  131. data/test/test_epubmaker.rb +243 -131
  132. data/test/test_epubmaker_cmd.rb +2 -2
  133. data/test/test_helper.rb +5 -4
  134. data/test/test_htmlbuilder.rb +64 -6
  135. data/test/test_idgxmlbuilder.rb +13 -0
  136. data/test/test_idgxmlmaker_cmd.rb +7 -3
  137. data/test/test_img_math.rb +111 -0
  138. data/test/test_indexbuilder.rb +5 -5
  139. data/test/test_latexbuilder.rb +107 -4
  140. data/test/test_lineinput.rb +20 -93
  141. data/test/test_markdownbuilder.rb +29 -0
  142. data/test/test_pdfmaker.rb +71 -0
  143. data/test/test_pdfmaker_cmd.rb +2 -2
  144. data/test/test_plaintextbuilder.rb +10 -18
  145. data/test/test_reviewheaderlistener.rb +49 -0
  146. data/test/test_template.rb +12 -2
  147. data/test/test_textmaker_cmd.rb +5 -1
  148. data/test/test_tocprinter.rb +46 -0
  149. data/test/test_topbuilder.rb +6 -1
  150. data/test/test_update.rb +34 -34
  151. data/test/test_zip_exporter.rb +5 -6
  152. metadata +91 -17
  153. data/lib/epubmaker.rb +0 -23
  154. data/lib/epubmaker/content.rb +0 -111
  155. data/lib/epubmaker/epubcommon.rb +0 -449
  156. data/lib/epubmaker/epubv2.rb +0 -142
  157. data/lib/epubmaker/epubv3.rb +0 -235
  158. data/lib/epubmaker/producer.rb +0 -375
  159. data/lib/epubmaker/zip_exporter.rb +0 -81
  160. data/lib/lineinput.rb +0 -155
@@ -1,5 +1,5 @@
1
1
  require 'test_helper'
2
- require 'lineinput'
2
+ require 'review/lineinput'
3
3
  require 'tempfile'
4
4
  require 'stringio'
5
5
 
@@ -9,7 +9,7 @@ class LineInputTest < Test::Unit::TestCase
9
9
  li = LineInput.new(io)
10
10
  assert_equal 0, li.lineno
11
11
  assert !li.eof?
12
- assert_equal "#<LineInput file=#{io.inspect} line=0>", li.inspect
12
+ assert_equal "#<ReVIEW::LineInput file=#{io.inspect} line=0>", li.inspect
13
13
  end
14
14
 
15
15
  def test_gets
@@ -40,21 +40,6 @@ class LineInputTest < Test::Unit::TestCase
40
40
  assert li.eof?
41
41
  end
42
42
 
43
- def test_ungets
44
- io = StringIO.new('abc')
45
- li = LineInput.new(io)
46
-
47
- line = li.gets
48
- assert_equal line, li.ungets(line)
49
- assert_equal 0, li.lineno
50
- assert_equal line, li.gets
51
-
52
- li.ungets('xyz')
53
- assert_equal 0, li.lineno
54
- li.ungets('xyz')
55
- assert_equal(-1, li.lineno) # XXX: OK?
56
- end
57
-
58
43
  def test_peek
59
44
  li = LineInput.new(StringIO.new)
60
45
  assert_equal nil, li.peek
@@ -71,33 +56,6 @@ class LineInputTest < Test::Unit::TestCase
71
56
  assert li.next?
72
57
  end
73
58
 
74
- def test_gets_if
75
- io = StringIO.new
76
- li = LineInput.new(io)
77
- assert_equal nil, li.gets_if(//)
78
-
79
- io = StringIO.new("abc\ndef\nghi")
80
- li = LineInput.new(io)
81
-
82
- assert_equal "abc\n", li.gets_if(//)
83
- assert_equal nil, li.gets_if(/^X/)
84
- assert_equal nil, li.gets_if(/^g/)
85
- assert_equal "def\n", li.gets_if(/^d/)
86
- end
87
-
88
- def test_gets_unless
89
- io = StringIO.new
90
- li = LineInput.new(io)
91
- assert_equal nil, li.gets_unless(//)
92
-
93
- io = StringIO.new("abc\ndef\nghi")
94
- li = LineInput.new(io)
95
-
96
- assert_equal nil, li.gets_unless(//)
97
- assert_equal "abc\n", li.gets_unless(/^X/)
98
- assert_equal nil, li.gets_unless(/^d/)
99
- end
100
-
101
59
  def test_each
102
60
  content = "abc\ndef\nghi"
103
61
  io = StringIO.new(content)
@@ -112,17 +70,9 @@ class LineInputTest < Test::Unit::TestCase
112
70
  io = StringIO.new("abc\ndef\nghi")
113
71
  li = LineInput.new(io)
114
72
 
115
- li.while_match(/^[ad]/) {}
116
- assert_equal 2, li.lineno
117
- assert_equal 'ghi', li.gets
118
- end
119
-
120
- def test_getlines_while
121
- io = StringIO.new("abc\ndef\nghi")
122
- li = LineInput.new(io)
123
-
124
- buf = li.getlines_while(/^[ad]/)
125
- assert_equal ["abc\n", "def\n"], buf
73
+ li.while_match(/^[ad]/) do
74
+ # skip
75
+ end
126
76
  assert_equal 2, li.lineno
127
77
  assert_equal 'ghi', li.gets
128
78
  end
@@ -131,47 +81,24 @@ class LineInputTest < Test::Unit::TestCase
131
81
  io = StringIO.new("abc\ndef\nghi")
132
82
  li = LineInput.new(io)
133
83
 
134
- li.until_match(/^[^a]/) {}
135
- assert_equal 1, li.lineno
136
- assert_equal "def\n", li.gets
137
- end
138
-
139
- def test_getlines_until
140
- io = StringIO.new("abc\ndef\nghi")
141
- li = LineInput.new(io)
142
-
143
- buf = li.getlines_until(/^[^a]/)
144
- assert_equal ["abc\n"], buf
84
+ li.until_match(/^[^a]/) do
85
+ # skip
86
+ end
145
87
  assert_equal 1, li.lineno
146
88
  assert_equal "def\n", li.gets
147
89
  end
148
90
 
149
- def test_until_terminator
150
- io = StringIO.new("abc\n//}\ndef\nghi\n//}\njkl\nmno")
151
- li = LineInput.new(io)
152
-
153
- data = ''
154
- li.until_terminator(%r<\A//\}>) { |l| data << l }
155
- assert_equal "abc\n", data
156
- assert_equal 2, li.lineno
157
-
158
- data = ''
159
- li.until_terminator(%r<\A//\}>) { |l| data << l }
160
- assert_equal "def\nghi\n", data
161
- assert_equal 5, li.lineno
162
-
163
- data = ''
164
- li.until_terminator(%r<\A//\}>) { |l| data << l }
165
- assert_equal "jkl\nmno", data
166
- assert_equal 8, li.lineno
167
- end
168
-
169
- def test_until_terminator2
170
- io = StringIO.new("abc\ndef\n//}\nghi\n//}")
171
- li = LineInput.new(io)
172
-
173
- data = li.getblock(%r<\A//\}>)
174
- assert_equal ["abc\n", "def\n"], data
175
- assert_equal 3, li.lineno
91
+ def test_invalid_control_sequence
92
+ 0.upto(31) do |n|
93
+ content = n.chr
94
+ io = StringIO.new(content)
95
+ li = ReVIEW::LineInput.new(io)
96
+ if [9, 10, 13].include?(n) # TAB, LF, CR
97
+ assert_equal content, li.gets
98
+ else
99
+ e = assert_raise(ReVIEW::SyntaxError) { li.gets }
100
+ assert_match(/found invalid control/, e.message)
101
+ end
102
+ end
176
103
  end
177
104
  end
@@ -106,6 +106,35 @@ EOS
106
106
  assert_equal %Q(test <span class="red">コメント</span> test2), actual
107
107
  end
108
108
 
109
+ def test_inline_hd_chap
110
+ def @chapter.headline_index
111
+ item = Book::Index::Item.new('chap1|test', [1, 1], 'te_st')
112
+ idx = Book::HeadlineIndex.new(self)
113
+ idx.add_item(item)
114
+ idx
115
+ end
116
+
117
+ @config['secnolevel'] = 2
118
+ actual = compile_inline('test @<hd>{chap1|test} test2')
119
+ assert_equal 'test <a href="#h1-1-1">「te_st」</a> test2', actual
120
+
121
+ actual = compile_inline('test @<hd>{test} test2')
122
+ assert_equal 'test <a href="#h1-1-1">「te_st」</a> test2', actual
123
+
124
+ @config['secnolevel'] = 3
125
+ actual = compile_inline('test @<hd>{chap1|test} test2')
126
+ assert_equal 'test <a href="#h1-1-1">「1.1.1 te_st」</a> test2', actual
127
+
128
+ @config['chapterlink'] = nil
129
+ @config['secnolevel'] = 2
130
+ actual = compile_inline('test @<hd>{chap1|test} test2')
131
+ assert_equal 'test 「te_st」 test2', actual
132
+
133
+ @config['secnolevel'] = 3
134
+ actual = compile_inline('test @<hd>{chap1|test} test2')
135
+ assert_equal 'test 「1.1.1 te_st」 test2', actual
136
+ end
137
+
109
138
  def test_ul_nest1
110
139
  src = <<-EOS
111
140
  * AAA
@@ -261,4 +261,75 @@ class PDFMakerTest < Test::Unit::TestCase
261
261
  '2012年1月31日 ver 1.2.1発行']
262
262
  assert_equal expect, history
263
263
  end
264
+
265
+ def test_box_setting_is_defined
266
+ %w[column note memo tip info warning important caution notice].each do |name|
267
+ @config['pdfmaker']['boxsetting'] = {
268
+ name => { 'style' => 'simplebox' }
269
+ }
270
+ assert !ReVIEW::LaTeXBox.new.tcbox(@config).empty?
271
+ end
272
+ @config['pdfmaker']['boxsetting'] = {
273
+ 'invalid' => { 'style' => 'simplebox' }
274
+ }
275
+ assert ReVIEW::LaTeXBox.new.tcbox(@config).empty?
276
+ end
277
+
278
+ def test_box_setting_options
279
+ @config['pdfmaker']['boxsetting'] = {
280
+ 'note' => { 'style' => 'simplebox' },
281
+ 'important' => { 'style' => 'simplebox', 'options' => 'colback=blue,arc=3mm' },
282
+ 'caution' => { 'style' => 'squarecaptionbox', 'options_with_caption' => 'attach boxed title to top bottom' }
283
+ }
284
+
285
+ expected = <<-EOS
286
+ \\renewenvironment{reviewnote}[1][]{%
287
+ \\csdef{rv@tmp@withcaption}{true}
288
+ \\notblank{##1}{
289
+ \\begin{rv@simplebox@caption}{##1}[]
290
+ }{
291
+ \\csundef{rv@tmp@withcaption}
292
+ \\begin{rv@simplebox@nocaption}[]
293
+ }
294
+ }{
295
+ \\ifcsdef{rv@tmp@withcaption}{
296
+ \\end{rv@simplebox@caption}
297
+ }{
298
+ \\end{rv@simplebox@nocaption}
299
+ }
300
+ }
301
+ \\renewenvironment{reviewimportant}[1][]{%
302
+ \\csdef{rv@tmp@withcaption}{true}
303
+ \\notblank{##1}{
304
+ \\begin{rv@simplebox@caption}{##1}[colback=blue,arc=3mm]
305
+ }{
306
+ \\csundef{rv@tmp@withcaption}
307
+ \\begin{rv@simplebox@nocaption}[colback=blue,arc=3mm]
308
+ }
309
+ }{
310
+ \\ifcsdef{rv@tmp@withcaption}{
311
+ \\end{rv@simplebox@caption}
312
+ }{
313
+ \\end{rv@simplebox@nocaption}
314
+ }
315
+ }
316
+ \\renewenvironment{reviewcaution}[1][]{%
317
+ \\csdef{rv@tmp@withcaption}{true}
318
+ \\notblank{##1}{
319
+ \\begin{rv@squarecaptionbox@caption}{##1}[attach boxed title to top bottom]
320
+ }{
321
+ \\csundef{rv@tmp@withcaption}
322
+ \\begin{rv@squarecaptionbox@nocaption}[]
323
+ }
324
+ }{
325
+ \\ifcsdef{rv@tmp@withcaption}{
326
+ \\end{rv@squarecaptionbox@caption}
327
+ }{
328
+ \\end{rv@squarecaptionbox@nocaption}
329
+ }
330
+ }
331
+ EOS
332
+ actual = ReVIEW::LaTeXBox.new.tcbox(@config)
333
+ assert_equal expected, actual
334
+ end
264
335
  end
@@ -5,14 +5,14 @@ require 'yaml'
5
5
  require 'rbconfig'
6
6
  require 'open3'
7
7
 
8
- REVIEW_PDFMAKER = File.expand_path('../bin/review-pdfmaker', File.dirname(__FILE__))
8
+ REVIEW_PDFMAKER = File.expand_path('../bin/review-pdfmaker', __dir__)
9
9
 
10
10
  class PDFMakerCmdTest < Test::Unit::TestCase
11
11
  def setup
12
12
  @tmpdir1 = Dir.mktmpdir
13
13
 
14
14
  @old_rubylib = ENV['RUBYLIB']
15
- ENV['RUBYLIB'] = File.expand_path('../lib', File.dirname(__FILE__))
15
+ ENV['RUBYLIB'] = File.expand_path('../lib', __dir__)
16
16
  end
17
17
 
18
18
  def teardown
@@ -90,9 +90,16 @@ class PLAINTEXTBuidlerTest < Test::Unit::TestCase
90
90
  assert_equal "\n", actual
91
91
  end
92
92
 
93
- def test_inline_i
94
- actual = compile_inline('test @<i>{inline test} test2')
95
- assert_equal 'test inline test test2', actual
93
+ def test_inline_asis
94
+ %w[i b tti ttb bou ami u strong em code ins tcy].each do |tag|
95
+ actual = compile_inline("test @<#{tag}>{inline test} test2")
96
+ assert_equal 'test inline test test2', actual
97
+ end
98
+ end
99
+
100
+ def test_inline_del
101
+ actual = compile_inline('test @<del>{inline test} test2')
102
+ assert_equal 'test test2', actual
96
103
  end
97
104
 
98
105
  def test_inline_i_and_escape
@@ -100,11 +107,6 @@ class PLAINTEXTBuidlerTest < Test::Unit::TestCase
100
107
  assert_equal 'test inline<&;\\ test test2', actual
101
108
  end
102
109
 
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
110
  def test_inline_b_and_escape
109
111
  actual = compile_inline('test @<b>{inline<&;\\ test} test2')
110
112
  assert_equal 'test inline<&;\\ test test2', actual
@@ -115,16 +117,6 @@ class PLAINTEXTBuidlerTest < Test::Unit::TestCase
115
117
  assert_equal 'test inline test test2}', actual
116
118
  end
117
119
 
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
120
  def test_inline_uchar
129
121
  actual = compile_inline('test @<uchar>{2460} test2')
130
122
  assert_equal 'test ① test2', actual
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+ require 'rexml/document'
3
+ require 'rexml/streamlistener'
4
+ require 'review/epubmaker'
5
+
6
+ class ReVIEWHeaderListenerTest < Test::Unit::TestCase
7
+ def setup
8
+ @epubmaker = ReVIEW::EPUBMaker.new
9
+ end
10
+
11
+ def teardown
12
+ end
13
+
14
+ def test_epubmaker_parse_headlines
15
+ # original Re:VIEW source:
16
+ #
17
+ # = first chapter
18
+ # == first section
19
+ # === first @<embed>{<img src="images/icon1.jpg" alt="subsection" />}
20
+ # == second section
21
+ # ==={dummy1} dummy subsection
22
+ # == third section
23
+ # ==[notoc] notoc section
24
+ # ==[notoc]{dummy2} notoc section
25
+ # ==[nodisp] nodisp section
26
+ # ==[nodisp]{dummy3} nodisp section
27
+ # ==[nonum] nonum section
28
+ # ==[nonum]{dummy4} nonum section
29
+ Dir.mktmpdir do |_dir|
30
+ path = File.join(assets_dir, 'header_listener.html')
31
+ headlines = @epubmaker.parse_headlines(path)
32
+
33
+ expected = [{ 'id' => 'h1', 'level' => 1, 'notoc' => nil, 'title' => '第1章 first chapter' },
34
+ { 'id' => 'h1-1', 'level' => 2, 'notoc' => nil, 'title' => '1.1 first section' },
35
+ { 'id' => 'h1-1-1', 'level' => 3, 'notoc' => nil, 'title' => 'first subsection' },
36
+ { 'id' => 'h1-2', 'level' => 2, 'notoc' => nil, 'title' => '1.2 second section' },
37
+ { 'id' => 'h1-2-1', 'level' => 3, 'notoc' => nil, 'title' => 'dummy subsection' },
38
+ { 'id' => 'h1-3', 'level' => 2, 'notoc' => nil, 'title' => '1.3 third section' },
39
+ { 'id' => 'ch01_nonum1', 'level' => 2, 'notoc' => 'true', 'title' => 'notoc section' },
40
+ { 'id' => 'dummy2', 'level' => 2, 'notoc' => 'true', 'title' => 'notoc section' },
41
+ { 'id' => 'ch01_nonum3', 'level' => 2, 'notoc' => nil, 'title' => 'nodisp section' },
42
+ { 'id' => 'dummy3', 'level' => 2, 'notoc' => nil, 'title' => 'nodisp section' },
43
+ { 'id' => 'ch01_nonum5', 'level' => 2, 'notoc' => nil, 'title' => 'nonum section' },
44
+ { 'id' => 'dummy4', 'level' => 2, 'notoc' => nil, 'title' => 'nonum section' }]
45
+
46
+ assert_equal expected, headlines
47
+ end
48
+ end
49
+ end
@@ -9,15 +9,25 @@ class TemplateTest < Test::Unit::TestCase
9
9
  end
10
10
 
11
11
  def test_load
12
- tmplfile = File.expand_path('./assets/test.xml.erb', File.dirname(__FILE__))
12
+ tmplfile = File.expand_path('./assets/test.xml.erb', __dir__)
13
13
  tmpl = ReVIEW::Template.load(tmplfile)
14
14
  assert_equal("<test>\n<name></name>\n</test>\n", tmpl.result(binding))
15
15
  end
16
16
 
17
17
  def test_open_with_value
18
- tmplfile = File.expand_path('./assets/test.xml.erb', File.dirname(__FILE__))
18
+ tmplfile = File.expand_path('./assets/test.xml.erb', __dir__)
19
19
  tmpl = ReVIEW::Template.load(tmplfile)
20
20
  @name = 'test'
21
21
  assert_equal("<test>\n<name>test</name>\n</test>\n", tmpl.result(binding))
22
22
  end
23
+
24
+ def test_generate
25
+ result = ReVIEW::Template.generate(path: './assets/test.xml.erb', binding: binding, template_dir: __dir__)
26
+ assert_equal("<test>\n<name></name>\n</test>\n", result)
27
+ end
28
+
29
+ def test_generate_without_template_dir
30
+ result = ReVIEW::Template.generate(path: '../test/assets/test.xml.erb', binding: binding)
31
+ assert_equal("<test>\n<name></name>\n</test>\n", result)
32
+ end
23
33
  end
@@ -29,7 +29,11 @@ class TEXTMakerCmdTest < Test::Unit::TestCase
29
29
  ruby_cmd = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']) + RbConfig::CONFIG['EXEEXT']
30
30
  Dir.chdir(@tmpdir1) do
31
31
  _o, e, s = Open3.capture3("#{ruby_cmd} -S #{REVIEW_TEXTMAKER} #{option} #{configfile}")
32
- assert_equal '', e
32
+ if defined?(ReVIEW::TTYLogger)
33
+ assert_match(/SUCCESS/, e)
34
+ else
35
+ assert_equal '', e
36
+ end
33
37
  assert s.success?
34
38
  end
35
39
  assert File.exist?(File.join(@tmpdir1, targetfile))
@@ -0,0 +1,46 @@
1
+ require 'test_helper'
2
+ require 'review/tocprinter'
3
+ require 'unicode/eaw'
4
+
5
+ class TOCPrinterTest < Test::Unit::TestCase
6
+ def setup
7
+ @toc_printer = ReVIEW::TOCPrinter.new
8
+ end
9
+
10
+ def teardown
11
+ end
12
+
13
+ def test_calc_linesize
14
+ @toc_printer.calc_char_width = nil
15
+ size = @toc_printer.calc_linesize('あ いうえおABCD')
16
+ assert_equal 10, size
17
+ size = @toc_printer.calc_linesize("あ い\nうえ\nおAB\nCD\n")
18
+ assert_equal 14, size
19
+ end
20
+
21
+ def test_calc_linesize_with_char_width
22
+ @toc_printer.calc_char_width = true
23
+ size = @toc_printer.calc_linesize('あ いうえおABCD')
24
+ assert_equal 7.5, size
25
+ size = @toc_printer.calc_linesize("あ い\nうえ\nおAB\nCD\n")
26
+ assert_equal 9.5, size
27
+ end
28
+
29
+ def test_execute_syntax_book_detail
30
+ Dir.chdir('./samples/syntax-book') do
31
+ stdout = $stdout
32
+ tmp_io = StringIO.new
33
+ $stdout = tmp_io
34
+ begin
35
+ @toc_printer.execute('-d')
36
+ tmp_io.rewind
37
+ result = tmp_io.read
38
+ path = File.join(assets_dir, 'syntax_book_index_detail.txt')
39
+ expected = File.read(path)
40
+ assert_equal expected, result
41
+ ensure
42
+ $stdout = stdout
43
+ end
44
+ end
45
+ end
46
+ end