aozora2html 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +19 -0
  3. data/.github/workflows/ruby.yml +4 -1
  4. data/.rubocop.yml +36 -152
  5. data/.rubocop_todo.yml +7 -0
  6. data/CHANGELOG.md +26 -0
  7. data/Gemfile +2 -0
  8. data/Guardfile +3 -1
  9. data/HACKING.md +45 -0
  10. data/README.md +14 -6
  11. data/Rakefile +12 -5
  12. data/aozora2html.gemspec +24 -22
  13. data/bin/aozora2html +21 -19
  14. data/lib/aozora2html/accent_parser.rb +62 -54
  15. data/lib/aozora2html/error.rb +5 -4
  16. data/lib/aozora2html/header.rb +20 -18
  17. data/lib/aozora2html/i18n.rb +40 -20
  18. data/lib/aozora2html/ruby_buffer.rb +63 -28
  19. data/lib/aozora2html/string_refinements.rb +36 -0
  20. data/lib/aozora2html/style_stack.rb +6 -0
  21. data/lib/aozora2html/tag/accent.rb +10 -12
  22. data/lib/aozora2html/tag/block.rb +11 -9
  23. data/lib/aozora2html/tag/chitsuki.rb +6 -2
  24. data/lib/aozora2html/tag/dakuten_katakana.rb +10 -8
  25. data/lib/aozora2html/tag/decorate.rb +4 -3
  26. data/lib/aozora2html/tag/dir.rb +4 -2
  27. data/lib/aozora2html/tag/editor_note.rb +7 -4
  28. data/lib/aozora2html/tag/embed_gaiji.rb +15 -11
  29. data/lib/aozora2html/tag/font_size.rb +5 -2
  30. data/lib/aozora2html/tag/gaiji.rb +4 -3
  31. data/lib/aozora2html/tag/img.rb +4 -4
  32. data/lib/aozora2html/tag/indent.rb +3 -3
  33. data/lib/aozora2html/tag/inline.rb +10 -7
  34. data/lib/aozora2html/tag/inline_caption.rb +4 -2
  35. data/lib/aozora2html/tag/inline_font_size.rb +4 -3
  36. data/lib/aozora2html/tag/inline_keigakomi.rb +4 -2
  37. data/lib/aozora2html/tag/inline_yokogumi.rb +4 -3
  38. data/lib/aozora2html/tag/jisage.rb +3 -1
  39. data/lib/aozora2html/tag/jizume.rb +3 -0
  40. data/lib/aozora2html/tag/kaeriten.rb +4 -2
  41. data/lib/aozora2html/tag/keigakomi.rb +15 -9
  42. data/lib/aozora2html/tag/kunten.rb +4 -4
  43. data/lib/aozora2html/tag/midashi.rb +3 -1
  44. data/lib/aozora2html/tag/multiline.rb +3 -0
  45. data/lib/aozora2html/tag/multiline_caption.rb +6 -8
  46. data/lib/aozora2html/tag/multiline_chitsuki.rb +3 -1
  47. data/lib/aozora2html/tag/multiline_jisage.rb +3 -1
  48. data/lib/aozora2html/tag/multiline_midashi.rb +6 -3
  49. data/lib/aozora2html/tag/multiline_style.rb +5 -3
  50. data/lib/aozora2html/tag/multiline_yokogumi.rb +6 -9
  51. data/lib/aozora2html/tag/okurigana.rb +4 -2
  52. data/lib/aozora2html/tag/oneline_chitsuki.rb +3 -2
  53. data/lib/aozora2html/tag/oneline_indent.rb +8 -1
  54. data/lib/aozora2html/tag/oneline_jisage.rb +3 -0
  55. data/lib/aozora2html/tag/reference_mentioned.rb +22 -21
  56. data/lib/aozora2html/tag/ruby.rb +174 -70
  57. data/lib/aozora2html/tag/un_embed_gaiji.rb +8 -2
  58. data/lib/aozora2html/tag.rb +40 -38
  59. data/lib/aozora2html/tag_parser.rb +23 -16
  60. data/lib/aozora2html/text_buffer.rb +50 -0
  61. data/lib/aozora2html/utils.rb +113 -50
  62. data/lib/aozora2html/version.rb +3 -1
  63. data/lib/aozora2html/yaml_loader.rb +8 -2
  64. data/lib/aozora2html/zip.rb +4 -0
  65. data/lib/aozora2html.rb +1358 -3
  66. data/lib/extensions.rb +2 -34
  67. data/lib/jstream.rb +96 -25
  68. data/sample/chukiichiran_kinyurei.html +15 -2
  69. data/sample/chukiichiran_kinyurei.txt +15 -2
  70. data/test/test_aozora2html.rb +137 -148
  71. data/test/test_aozora_accent_parser.rb +26 -9
  72. data/test/test_command_parse.rb +25 -22
  73. data/test/test_compat.rb +3 -4
  74. data/test/test_dakuten_katakana_tag.rb +10 -12
  75. data/test/test_decorate_tag.rb +9 -6
  76. data/test/test_dir_tag.rb +9 -6
  77. data/test/test_editor_note_tag.rb +8 -5
  78. data/test/test_exception.rb +10 -8
  79. data/test/test_font_size_tag.rb +16 -13
  80. data/test/test_gaiji_tag.rb +15 -14
  81. data/test/test_header.rb +25 -40
  82. data/test/test_helper.rb +3 -1
  83. data/test/test_i18n.rb +22 -6
  84. data/test/test_img_tag.rb +9 -5
  85. data/test/test_inline_caption_tag.rb +9 -6
  86. data/test/test_inline_font_size_tag.rb +13 -10
  87. data/test/test_inline_keigakomi_tag.rb +9 -6
  88. data/test/test_inline_yokogumi_tag.rb +9 -6
  89. data/test/test_jizume_tag.rb +9 -7
  90. data/test/test_jstream.rb +33 -30
  91. data/test/test_kaeriten_tag.rb +9 -6
  92. data/test/test_keigakomi_tag.rb +11 -9
  93. data/test/test_midashi_tag.rb +15 -14
  94. data/test/test_multiline_caption_tag.rb +7 -5
  95. data/test/test_multiline_midashi_tag.rb +24 -25
  96. data/test/test_multiline_style_tag.rb +9 -7
  97. data/test/test_multiline_yokogumi_tag.rb +7 -5
  98. data/test/test_okurigana_tag.rb +9 -6
  99. data/test/test_ruby_parse.rb +14 -14
  100. data/test/test_ruby_tag.rb +9 -6
  101. data/test/test_tag_parser.rb +28 -26
  102. metadata +60 -14
  103. data/.travis.yml +0 -12
  104. data/lib/t2hs.rb +0 -1607
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
  require 'aozora2html'
4
5
  require 'fileutils'
@@ -13,67 +14,67 @@ class Aozora2HtmlTest < Test::Unit::TestCase
13
14
 
14
15
  def test_aozora2html_new
15
16
  Dir.mktmpdir do |dir|
16
- input = File.join(dir,'dummy.txt')
17
- output = File.join(dir,'dummy2.txt')
17
+ input = File.join(dir, 'dummy.txt')
18
+ output = File.join(dir, 'dummy2.txt')
18
19
  File.binwrite(input, "テスト\r\n")
19
20
  parser = Aozora2Html.new(input, output)
20
21
  begin
21
22
  assert_equal Aozora2Html, parser.class
22
23
  ensure
23
- parser.close
24
+ parser.__send__(:close)
24
25
  end
25
26
  end
26
27
  end
27
28
 
28
29
  def test_line_number
29
30
  Dir.mktmpdir do |dir|
30
- input = File.join(dir,'dummy.txt')
31
- output = File.join(dir,'dummy2.txt')
31
+ input = File.join(dir, 'dummy.txt')
32
+ output = File.join(dir, 'dummy2.txt')
32
33
  File.binwrite(input, "a\r\nb\r\nc\r\n")
33
34
  parser = Aozora2Html.new(input, output)
34
35
 
35
36
  begin
36
37
  assert_equal 0, parser.line_number
37
- ch = parser.read_char
38
- assert_equal "a",ch
38
+ ch = parser.__send__(:read_char)
39
+ assert_equal 'a', ch
39
40
  assert_equal 1, parser.line_number
40
- ch = parser.read_char
41
- assert_equal "\r\n",ch
41
+ ch = parser.__send__(:read_char)
42
+ assert_equal "\r\n", ch
42
43
  assert_equal 1, parser.line_number
43
- ch = parser.read_char
44
- assert_equal "b",ch
44
+ ch = parser.__send__(:read_char)
45
+ assert_equal 'b', ch
45
46
  assert_equal 2, parser.line_number
46
- ch = parser.read_char
47
- assert_equal "\r\n",ch
47
+ ch = parser.__send__(:read_char)
48
+ assert_equal "\r\n", ch
48
49
  assert_equal 2, parser.line_number
49
- ch = parser.read_char
50
- assert_equal "c",ch
50
+ ch = parser.__send__(:read_char)
51
+ assert_equal 'c', ch
51
52
  assert_equal 3, parser.line_number
52
53
  ensure
53
- parser.close
54
+ parser.__send__(:close)
54
55
  end
55
56
  end
56
57
  end
57
58
 
58
- def test_line_number_2
59
+ def test_line_number2
59
60
  input = StringIO.new("a\r\nb\r\nc\r\n")
60
61
  output = StringIO.new
61
62
  parser = Aozora2Html.new(input, output)
62
63
  assert_equal 0, parser.line_number
63
- ch = parser.read_char
64
- assert_equal "a",ch
64
+ ch = parser.__send__(:read_char)
65
+ assert_equal 'a', ch
65
66
  assert_equal 1, parser.line_number
66
- ch = parser.read_char
67
- assert_equal "\r\n",ch
67
+ ch = parser.__send__(:read_char)
68
+ assert_equal "\r\n", ch
68
69
  assert_equal 1, parser.line_number
69
- ch = parser.read_char
70
- assert_equal "b",ch
70
+ ch = parser.__send__(:read_char)
71
+ assert_equal 'b', ch
71
72
  assert_equal 2, parser.line_number
72
- ch = parser.read_char
73
- assert_equal "\r\n",ch
73
+ ch = parser.__send__(:read_char)
74
+ assert_equal "\r\n", ch
74
75
  assert_equal 2, parser.line_number
75
- ch = parser.read_char
76
- assert_equal "c",ch
76
+ ch = parser.__send__(:read_char)
77
+ assert_equal 'c', ch
77
78
  assert_equal 3, parser.line_number
78
79
  end
79
80
 
@@ -81,188 +82,177 @@ class Aozora2HtmlTest < Test::Unit::TestCase
81
82
  input = StringIO.new("ab\r\nc\r\n")
82
83
  output = StringIO.new
83
84
  parser = Aozora2Html.new(input, output)
84
- parsed = parser.read_line
85
- assert_equal "ab", parsed
85
+ parsed = parser.__send__(:read_line)
86
+ assert_equal 'ab', parsed
86
87
  end
87
88
 
89
+ using Aozora2Html::StringRefinements
90
+
88
91
  def test_char_type
89
- assert_equal :kanji, @parser.char_type(Aozora2Html::Tag::EmbedGaiji.new(nil,"foo","1-2-3","name"))
90
- assert_equal :kanji, @parser.char_type(Aozora2Html::Tag::UnEmbedGaiji.new(nil,"foo"))
91
- assert_equal :hankaku, @parser.char_type(Aozora2Html::Tag::Accent.new(nil,123,"abc"))
92
- assert_equal :else, @parser.char_type(Aozora2Html::Tag::Okurigana.new(nil,"abc"))
93
- assert_equal :else, @parser.char_type(Aozora2Html::Tag::InlineKeigakomi.new(nil,"abc"))
94
- assert_equal :katakana, @parser.char_type(Aozora2Html::Tag::DakutenKatakana.new(nil,1,"abc"))
92
+ assert_equal :kanji, Aozora2Html::Tag::EmbedGaiji.new(nil, 'foo', '1-2-3', 'name', gaiji_dir: nil).char_type
93
+ assert_equal :kanji, Aozora2Html::Tag::UnEmbedGaiji.new(nil, 'foo').char_type
94
+ assert_equal :hankaku, Aozora2Html::Tag::Accent.new(nil, 123, 'abc', gaiji_dir: nil).char_type
95
+ assert_equal :else, Aozora2Html::Tag::Okurigana.new(nil, 'abc').char_type
96
+ assert_equal :else, Aozora2Html::Tag::InlineKeigakomi.new(nil, 'abc').char_type
97
+ assert_equal :katakana, Aozora2Html::Tag::DakutenKatakana.new(nil, 1, 'abc', gaiji_dir: nil).char_type
95
98
 
96
- assert_equal :hiragana, @parser.char_type("あ".encode("shift_jis"))
97
- assert_equal :hiragana, @parser.char_type("っ".encode("shift_jis"))
98
- assert_equal :katakana, @parser.char_type("ヴ".encode("shift_jis"))
99
- assert_equal :katakana, @parser.char_type("ー".encode("shift_jis"))
100
- assert_equal :zenkaku, @parser.char_type("A".encode("shift_jis"))
101
- assert_equal :zenkaku, @parser.char_type("w".encode("shift_jis"))
102
- assert_equal :hankaku, @parser.char_type("z".encode("shift_jis"))
103
- assert_equal :kanji, @parser.char_type("漢".encode("shift_jis"))
104
- assert_equal :hankaku_terminate, @parser.char_type("!".encode("shift_jis"))
105
- assert_equal :else, @parser.char_type("?".encode("shift_jis"))
106
- assert_equal :else, @parser.char_type("Å".encode("shift_jis"))
99
+ assert_equal :hiragana, 'あ'.to_sjis.char_type
100
+ assert_equal :hiragana, 'っ'.to_sjis.char_type
101
+ assert_equal :katakana, 'ヴ'.to_sjis.char_type
102
+ assert_equal :katakana, 'ー'.to_sjis.char_type
103
+ assert_equal :zenkaku, 'A'.to_sjis.char_type
104
+ assert_equal :zenkaku, 'w'.to_sjis.char_type
105
+ assert_equal :hankaku, 'z'.to_sjis.char_type
106
+ assert_equal :kanji, '漢'.to_sjis.char_type
107
+ assert_equal :hankaku_terminate, '!'.to_sjis.char_type
108
+ assert_equal :else, '?'.to_sjis.char_type
109
+ assert_equal :else, 'Å'.to_sjis.char_type
107
110
  end
108
111
 
109
112
  def test_read_char
110
- input = StringIO.new("/\\r\n".encode("shift_jis"))
113
+ input = StringIO.new("/\\r\n".to_sjis)
111
114
  output = StringIO.new
112
115
  parser = Aozora2Html.new(input, output)
113
- char = parser.read_char
114
- assert_equal "".encode("shift_jis"), char
116
+ char = parser.__send__(:read_char)
117
+ assert_equal ''.to_sjis, char
115
118
  assert_equal Aozora2Html::KU, char
116
119
  end
117
120
 
118
121
  def test_illegal_char_check
119
- input = StringIO.new("abc\r\n")
120
- output = StringIO.new
121
- parser = Aozora2Html.new(input, output)
122
122
  out = StringIO.new
123
123
  $stdout = out
124
124
  begin
125
- parser.illegal_char_check("#", 123)
125
+ Aozora2Html::Utils.illegal_char_check('#', 123)
126
126
  outstr = out.string
127
- assert_equal "警告(123行目):1バイトの「#」が使われています\n", outstr.encode("utf-8")
127
+ assert_equal "警告(123行目):1バイトの「#」が使われています\n", outstr.to_utf8
128
128
  ensure
129
129
  $stdout = STDOUT
130
130
  end
131
131
  end
132
132
 
133
133
  def test_illegal_char_check_sharp
134
- input = StringIO.new("abc\r\n")
135
- output = StringIO.new
136
- parser = Aozora2Html.new(input, output)
137
134
  out = StringIO.new
138
135
  $stdout = out
139
136
  begin
140
- parser.illegal_char_check("".encode("shift_jis"), 123)
137
+ Aozora2Html::Utils.illegal_char_check(''.to_sjis, 123)
141
138
  outstr = out.string
142
- assert_equal "警告(123行目):注記記号の誤用の可能性がある、「♯」が使われています\n", outstr.encode("utf-8")
139
+ assert_equal "警告(123行目):注記記号の誤用の可能性がある、「♯」が使われています\n", outstr.to_utf8
143
140
  ensure
144
141
  $stdout = STDOUT
145
142
  end
146
143
  end
147
144
 
148
145
  def test_illegal_char_check_notjis
149
- input = StringIO.new("abc\r\n")
150
- output = StringIO.new
151
- parser = Aozora2Html.new(input, output)
152
146
  out = StringIO.new
153
147
  $stdout = out
154
148
  begin
155
- parser.illegal_char_check("".encode("cp932").force_encoding("shift_jis"), 123)
149
+ Aozora2Html::Utils.illegal_char_check(''.encode('cp932').force_encoding('shift_jis'), 123)
156
150
  outstr = out.string
157
- assert_equal "警告(123行目):JIS外字「①」が使われています\n", outstr.force_encoding("cp932").encode("utf-8")
151
+ assert_equal "警告(123行目):JIS外字「①」が使われています\n", outstr.force_encoding('cp932').to_utf8
158
152
  ensure
159
153
  $stdout = STDOUT
160
154
  end
161
155
  end
162
156
 
163
157
  def test_illegal_char_check_ok
164
- input = StringIO.new("abc\r\n")
165
- output = StringIO.new
166
- parser = Aozora2Html.new(input, output)
167
158
  out = StringIO.new
168
159
  $stdout = out
169
160
  begin
170
- parser.illegal_char_check("".encode("shift_jis"), 123)
171
- outstr = output.string
172
- assert_equal "", outstr
161
+ Aozora2Html::Utils.illegal_char_check(''.to_sjis, 123)
162
+ outstr = out.string
163
+ assert_equal '', outstr
173
164
  ensure
174
165
  $stdout = STDOUT
175
166
  end
176
167
  end
177
168
 
178
169
  def test_convert_japanese_number
179
- assert_equal "3字下げ",
180
- Aozora2Html::Utils.convert_japanese_number("三字下げ".encode("shift_jis")).encode("utf-8")
181
- assert_equal "10字下げ",
182
- Aozora2Html::Utils.convert_japanese_number("十字下げ".encode("shift_jis")).encode("utf-8")
183
- assert_equal "12字下げ",
184
- Aozora2Html::Utils.convert_japanese_number("十二字下げ".encode("shift_jis")).encode("utf-8")
185
- assert_equal "20字下げ",
186
- Aozora2Html::Utils.convert_japanese_number("二十字下げ".encode("shift_jis")).encode("utf-8")
187
- assert_equal "20字下げ",
188
- Aozora2Html::Utils.convert_japanese_number("二〇字下げ".encode("shift_jis")).encode("utf-8")
189
- assert_equal "23字下げ",
190
- Aozora2Html::Utils.convert_japanese_number("二十三字下げ".encode("shift_jis")).encode("utf-8")
191
- assert_equal "2字下げ",
192
- Aozora2Html::Utils.convert_japanese_number("2字下げ".encode("shift_jis")).encode("utf-8")
193
-
170
+ assert_equal '3字下げ',
171
+ Aozora2Html::Utils.convert_japanese_number('三字下げ'.to_sjis).to_utf8
172
+ assert_equal '10字下げ',
173
+ Aozora2Html::Utils.convert_japanese_number('十字下げ'.to_sjis).to_utf8
174
+ assert_equal '12字下げ',
175
+ Aozora2Html::Utils.convert_japanese_number('十二字下げ'.to_sjis).to_utf8
176
+ assert_equal '20字下げ',
177
+ Aozora2Html::Utils.convert_japanese_number('二十字下げ'.to_sjis).to_utf8
178
+ assert_equal '20字下げ',
179
+ Aozora2Html::Utils.convert_japanese_number('二〇字下げ'.to_sjis).to_utf8
180
+ assert_equal '23字下げ',
181
+ Aozora2Html::Utils.convert_japanese_number('二十三字下げ'.to_sjis).to_utf8
182
+ assert_equal '2字下げ',
183
+ Aozora2Html::Utils.convert_japanese_number('2字下げ'.to_sjis).to_utf8
194
184
  end
195
185
 
196
186
  def test_kuten2png
197
187
  assert_equal %q|<img src="../../../gaiji/1-84/1-84-77.png" alt="※(「てへん+劣」、第3水準1-84-77)" class="gaiji" />|,
198
- @parser.kuten2png("#「てへん+劣」、第3水準1-84-77".encode("shift_jis")).to_s.encode("utf-8")
188
+ @parser.kuten2png('#「てへん+劣」、第3水準1-84-77'.to_sjis).to_s.to_utf8
199
189
  assert_equal %q|<img src="../../../gaiji/1-02/1-02-22.png" alt="※(二の字点、1-2-22)" class="gaiji" />|,
200
- @parser.kuten2png("#二の字点、1-2-22".encode("shift_jis")).to_s.encode("utf-8")
190
+ @parser.kuten2png('#二の字点、1-2-22'.to_sjis).to_s.to_utf8
201
191
  assert_equal %q|<img src="../../../gaiji/1-06/1-06-57.png" alt="※(ファイナルシグマ、1-6-57)" class="gaiji" />|,
202
- @parser.kuten2png("#ファイナルシグマ、1-6-57".encode("shift_jis")).to_s.encode("utf-8")
203
- assert_equal %q|#「口+世」、151-23|,
204
- @parser.kuten2png("#「口+世」、151-23".encode("shift_jis")).to_s.encode("utf-8")
192
+ @parser.kuten2png('#ファイナルシグマ、1-6-57'.to_sjis).to_s.to_utf8
193
+ assert_equal %q(#「口+世」、151-23),
194
+ @parser.kuten2png('#「口+世」、151-23'.to_sjis).to_s.to_utf8
205
195
  end
206
196
 
207
197
  def test_terpri?
208
- assert_equal true, @parser.terpri?([])
209
- assert_equal true, @parser.terpri?([""])
210
- assert_equal true, @parser.terpri?(["a"])
211
- tag = Aozora2Html::Tag::MultilineMidashi.new(@parser,"".encode("shift_jis"),:normal)
212
- assert_equal false, @parser.terpri?([tag])
213
- assert_equal false, @parser.terpri?([tag,tag])
214
- assert_equal false, @parser.terpri?([tag,"",""])
215
- assert_equal false, @parser.terpri?(["",tag,""])
216
- assert_equal true, @parser.terpri?([tag,"a"])
217
- assert_equal true, @parser.terpri?(["a",tag])
198
+ assert_equal true, Aozora2Html::TextBuffer.new.terpri?
199
+ assert_equal true, Aozora2Html::TextBuffer.new(['']).terpri?
200
+ assert_equal true, Aozora2Html::TextBuffer.new(['a']).terpri?
201
+ tag = Aozora2Html::Tag::MultilineMidashi.new(@parser, ''.to_sjis, :normal)
202
+ assert_equal false, Aozora2Html::TextBuffer.new([tag]).terpri?
203
+ assert_equal false, Aozora2Html::TextBuffer.new([tag, tag]).terpri?
204
+ assert_equal false, Aozora2Html::TextBuffer.new([tag, '', '']).terpri?
205
+ assert_equal false, Aozora2Html::TextBuffer.new(['', tag, '']).terpri?
206
+ assert_equal true, Aozora2Html::TextBuffer.new([tag, 'a']).terpri?
207
+ assert_equal true, Aozora2Html::TextBuffer.new(['a', tag]).terpri?
218
208
  end
219
209
 
220
210
  def test_new_midashi_id
221
211
  midashi_id = @parser.new_midashi_id(1)
222
212
  assert_equal midashi_id + 1, @parser.new_midashi_id(1)
223
- assert_equal midashi_id + 2, @parser.new_midashi_id("".encode("shift_jis"))
224
- assert_equal midashi_id + 12, @parser.new_midashi_id("".encode("shift_jis"))
225
- assert_equal midashi_id + 112, @parser.new_midashi_id("".encode("shift_jis"))
213
+ assert_equal midashi_id + 2, @parser.new_midashi_id(''.to_sjis)
214
+ assert_equal midashi_id + 12, @parser.new_midashi_id(''.to_sjis)
215
+ assert_equal midashi_id + 112, @parser.new_midashi_id(''.to_sjis)
226
216
  assert_raise(Aozora2Html::Error) do
227
- @parser.new_midashi_id("".encode("shift_jis"))
217
+ @parser.new_midashi_id(''.to_sjis)
228
218
  end
229
219
  end
230
220
 
231
221
  def test_multiply
232
- bouki = @parser.multiply("x", 5)
233
- assert_equal "x&nbsp;x&nbsp;x&nbsp;x&nbsp;x", bouki
222
+ bouki = @parser.__send__(:multiply, 'x', 5)
223
+ assert_equal 'x&nbsp;x&nbsp;x&nbsp;x&nbsp;x', bouki
234
224
  end
235
225
 
236
226
  def test_apply_midashi
237
- midashi = @parser.apply_midashi("中見出し".encode("shift_jis"))
238
- assert_equal %Q|<h4 class="naka-midashi"><a class="midashi_anchor" id="midashi10">|, midashi.to_s
239
- midashi = @parser.apply_midashi("大見出し".encode("shift_jis"))
240
- assert_equal %Q|<h3 class="o-midashi"><a class="midashi_anchor" id="midashi110">|, midashi.to_s
227
+ midashi = @parser.__send__(:apply_midashi, '中見出し'.to_sjis)
228
+ assert_equal %Q(<h4 class="naka-midashi"><a class="midashi_anchor" id="midashi10">), midashi.to_s
229
+ midashi = @parser.__send__(:apply_midashi, '大見出し'.to_sjis)
230
+ assert_equal %Q(<h3 class="o-midashi"><a class="midashi_anchor" id="midashi110">), midashi.to_s
241
231
  end
242
232
 
243
233
  def test_detect_command_mode
244
- command = "字下げ終わり".encode("shift_jis")
234
+ command = '字下げ終わり'.to_sjis
245
235
  assert_equal :jisage, @parser.detect_command_mode(command)
246
- command = "地付き終わり".encode("shift_jis")
236
+ command = '地付き終わり'.to_sjis
247
237
  assert_equal :chitsuki, @parser.detect_command_mode(command)
248
- command = "中見出し終わり".encode("shift_jis")
238
+ command = '中見出し終わり'.to_sjis
249
239
  assert_equal :midashi, @parser.detect_command_mode(command)
250
- command = "ここで太字終わり".encode("shift_jis")
240
+ command = 'ここで太字終わり'.to_sjis
251
241
  assert_equal :futoji, @parser.detect_command_mode(command)
252
242
  end
253
243
 
254
244
  def test_tcy
255
- input = StringIO.new("[#縦中横](※[#ローマ数字1、1-13-21])\r\n".encode("shift_jis"))
245
+ input = StringIO.new("[#縦中横](※[#ローマ数字1、1-13-21])\r\n".to_sjis)
256
246
  output = StringIO.new
257
247
  parser = Aozora2Html.new(input, output)
258
248
  out = StringIO.new
259
249
  $stdout = out
260
250
  message = nil
261
251
  begin
262
- parser.parse_body
263
- parser.general_output
252
+ parser.__send__(:parse_body)
253
+ parser.__send__(:general_output)
264
254
  rescue Aozora2Html::Error => e
265
- message = e.message.encode("utf-8")
255
+ message = e.message.to_utf8
266
256
  ensure
267
257
  $stdout = STDOUT
268
258
  assert_equal "エラー(0行目):縦中横中に改行されました。改行をまたぐ要素にはブロック表記を用いてください. \r\n処理を停止します", message
@@ -270,19 +260,19 @@ class Aozora2HtmlTest < Test::Unit::TestCase
270
260
  end
271
261
 
272
262
  def test_ensure_close
273
- input = StringIO.new("[#ここから5字下げ]\r\n底本: test\r\n".encode("shift_jis"))
263
+ input = StringIO.new("[#ここから5字下げ]\r\n底本: test\r\n".to_sjis)
274
264
  output = StringIO.new
275
265
  parser = Aozora2Html.new(input, output)
276
266
  out = StringIO.new
277
267
  $stdout = out
278
268
  message = nil
279
269
  begin
280
- parser.parse_body
281
- parser.parse_body
282
- parser.parse_body
283
- parser.general_output
270
+ parser.__send__(:parse_body)
271
+ parser.__send__(:parse_body)
272
+ parser.__send__(:parse_body)
273
+ parser.__send__(:general_output)
284
274
  rescue Aozora2Html::Error => e
285
- message = e.message.encode("utf-8")
275
+ message = e.message.to_utf8
286
276
  ensure
287
277
  $stdout = STDOUT
288
278
  assert_equal "エラー(0行目):字下げ中に本文が終了しました. \r\n処理を停止します", message
@@ -290,20 +280,20 @@ class Aozora2HtmlTest < Test::Unit::TestCase
290
280
  end
291
281
 
292
282
  def test_ending_check
293
- input = StringIO.new("本文\r\n\r\n底本:test\r\n".encode("shift_jis"))
283
+ input = StringIO.new("本文\r\n\r\n底本:test\r\n".to_sjis)
294
284
  output = StringIO.new
295
285
  parser = Aozora2Html.new(input, output)
296
286
  out = StringIO.new
297
287
  $stdout = out
298
288
  _message = nil
299
289
  begin
300
- parser.parse_body
301
- parser.parse_body
302
- parser.parse_body
303
- parser.parse_body
304
- parser.parse_body
290
+ parser.__send__(:parse_body)
291
+ parser.__send__(:parse_body)
292
+ parser.__send__(:parse_body)
293
+ parser.__send__(:parse_body)
294
+ parser.__send__(:parse_body)
305
295
  rescue Aozora2Html::Error => e
306
- _message = e.message.encode("utf-8")
296
+ _message = e.message.to_utf8
307
297
  ensure
308
298
  $stdout = STDOUT
309
299
  output.seek(0)
@@ -313,16 +303,16 @@ class Aozora2HtmlTest < Test::Unit::TestCase
313
303
  end
314
304
 
315
305
  def test_invalid_closing
316
- input = StringIO.new("[#ここで太字終わり]\r\n".encode("shift_jis"))
306
+ input = StringIO.new("[#ここで太字終わり]\r\n".to_sjis)
317
307
  output = StringIO.new
318
308
  parser = Aozora2Html.new(input, output)
319
309
  out = StringIO.new
320
310
  $stdout = out
321
311
  message = nil
322
312
  begin
323
- parser.parse_body
313
+ parser.__send__(:parse_body)
324
314
  rescue Aozora2Html::Error => e
325
- message = e.message.encode("utf-8")
315
+ message = e.message.to_utf8
326
316
  ensure
327
317
  $stdout = STDOUT
328
318
  assert_equal "エラー(0行目):太字を閉じようとしましたが、太字中ではありません. \r\n処理を停止します", message
@@ -330,22 +320,22 @@ class Aozora2HtmlTest < Test::Unit::TestCase
330
320
  end
331
321
 
332
322
  def test_invalid_nest
333
- input = StringIO.new("[#太字][#傍線]あ[#太字終わり]\r\n".encode("shift_jis"))
323
+ input = StringIO.new("[#太字][#傍線]あ[#太字終わり]\r\n".to_sjis)
334
324
  output = StringIO.new
335
325
  parser = Aozora2Html.new(input, output)
336
326
  out = StringIO.new
337
327
  $stdout = out
338
328
  message = nil
339
329
  begin
340
- parser.parse_body
341
- parser.parse_body
342
- parser.parse_body
343
- parser.parse_body
344
- parser.parse_body
345
- parser.parse_body
346
- parser.parse_body
330
+ parser.__send__(:parse_body)
331
+ parser.__send__(:parse_body)
332
+ parser.__send__(:parse_body)
333
+ parser.__send__(:parse_body)
334
+ parser.__send__(:parse_body)
335
+ parser.__send__(:parse_body)
336
+ parser.__send__(:parse_body)
347
337
  rescue Aozora2Html::Error => e
348
- message = e.message.encode("utf-8")
338
+ message = e.message.to_utf8
349
339
  ensure
350
340
  $stdout = STDOUT
351
341
  assert_equal "エラー(0行目):太字を終了しようとしましたが、傍線中です. \r\n処理を停止します", message
@@ -353,7 +343,7 @@ class Aozora2HtmlTest < Test::Unit::TestCase
353
343
  end
354
344
 
355
345
  def test_command_do
356
- input = StringIO.new("[#ここから太字]\r\nテスト。\r\n[#ここで太字終わり]\r\n".encode("shift_jis"))
346
+ input = StringIO.new("[#ここから太字]\r\nテスト。\r\n[#ここで太字終わり]\r\n".to_sjis)
357
347
  output = StringIO.new
358
348
  parser = Aozora2Html.new(input, output)
359
349
  out = StringIO.new
@@ -361,10 +351,10 @@ class Aozora2HtmlTest < Test::Unit::TestCase
361
351
  _message = nil
362
352
  begin
363
353
  9.times do
364
- parser.parse_body
354
+ parser.__send__(:parse_body)
365
355
  end
366
356
  rescue Aozora2Html::Error => e
367
- _message = e.message.encode("utf-8")
357
+ _message = e.message.to_utf8
368
358
  ensure
369
359
  $stdout = STDOUT
370
360
  output.seek(0)
@@ -373,7 +363,6 @@ class Aozora2HtmlTest < Test::Unit::TestCase
373
363
  end
374
364
  end
375
365
 
376
-
377
366
  def teardown
378
367
  end
379
368
  end
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
  require 'aozora2html'
4
5
 
@@ -6,23 +7,39 @@ class Aozora2HtmlAccentParserTest < Test::Unit::TestCase
6
7
  def setup
7
8
  end
8
9
 
10
+ using Aozora2Html::StringRefinements
11
+
9
12
  def test_new
10
- str = "〔e'tiquette〕\r\n".encode("shift_jis")
13
+ str = "〔e'tiquette〕\r\n".to_sjis
14
+ strio = StringIO.new(str)
15
+ stream = Jstream.new(strio)
16
+ parsed = Aozora2Html::AccentParser.new(stream, '〕'.to_sjis, {}, [], gaiji_dir: 'g_dir/').process
17
+ expected = '〔<img src="g_dir/1-09/1-09-63.png" alt="※(アキュートアクセント付きE小文字)" class="gaiji" />tiquette'
18
+ assert_equal expected, parsed.to_s.to_utf8
19
+ end
20
+
21
+ def test_invalid
22
+ str = "〔e'tiquette\r\n".to_sjis
11
23
  strio = StringIO.new(str)
12
24
  stream = Jstream.new(strio)
13
- parsed = Aozora2Html::AccentParser.new(stream,"〕".encode("shift_jis"),{},[]).process
14
- expected = "〔<img src=\"../../../gaiji/1-09/1-09-63.png\" alt=\"※(アキュートアクセント付きE小文字)\" class=\"gaiji\" />tiquette"
15
- assert_equal expected, parsed.to_s.encode("utf-8")
25
+ $stdout = StringIO.new
26
+ begin
27
+ _parsed = Aozora2Html::AccentParser.new(stream, '〕'.to_sjis, {}, [], gaiji_dir: 'g_dir/').process
28
+ out_str = $stdout.string
29
+ assert_equal "警告(1行目):アクセント分解の亀甲括弧の始めと終わりが、行中で揃っていません\n", out_str.to_utf8
30
+ ensure
31
+ $stdout = STDOUT
32
+ end
16
33
  end
17
34
 
18
35
  def test_use_jisx0213
19
36
  Aozora2Html::Tag::Accent.use_jisx0213 = true
20
- str = "〔e'tiquette〕\r\n".encode("shift_jis")
37
+ str = "〔e'tiquette〕\r\n".to_sjis
21
38
  strio = StringIO.new(str)
22
39
  stream = Jstream.new(strio)
23
- parsed = Aozora2Html::AccentParser.new(stream,"".encode("shift_jis"),{},[]).process
24
- expected = "〔&#x00E9;tiquette"
25
- assert_equal expected, parsed.to_s.encode("utf-8")
40
+ parsed = Aozora2Html::AccentParser.new(stream, ''.to_sjis, {}, [], gaiji_dir: 'g_dir/').process
41
+ expected = '〔&#x00E9;tiquette'
42
+ assert_equal expected, parsed.to_s.to_utf8
26
43
  end
27
44
 
28
45
  def teardown