aozora2html 2.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +19 -0
  3. data/.github/workflows/ruby.yml +5 -3
  4. data/.gitignore +1 -0
  5. data/.rubocop.yml +38 -151
  6. data/.rubocop_todo.yml +7 -0
  7. data/CHANGELOG.md +41 -0
  8. data/Gemfile +2 -0
  9. data/Guardfile +3 -1
  10. data/HACKING.md +45 -0
  11. data/README.md +14 -6
  12. data/Rakefile +12 -5
  13. data/aozora2html.gemspec +25 -23
  14. data/bin/aozora2html +21 -19
  15. data/lib/aozora2html/accent_parser.rb +62 -54
  16. data/lib/aozora2html/error.rb +5 -4
  17. data/lib/aozora2html/header.rb +20 -18
  18. data/lib/aozora2html/i18n.rb +40 -20
  19. data/lib/aozora2html/midashi_counter.rb +32 -0
  20. data/lib/aozora2html/ruby_buffer.rb +63 -28
  21. data/lib/aozora2html/string_refinements.rb +36 -0
  22. data/lib/aozora2html/style_stack.rb +6 -0
  23. data/lib/aozora2html/tag/accent.rb +10 -12
  24. data/lib/aozora2html/tag/block.rb +11 -9
  25. data/lib/aozora2html/tag/chitsuki.rb +6 -2
  26. data/lib/aozora2html/tag/dakuten_katakana.rb +10 -8
  27. data/lib/aozora2html/tag/decorate.rb +4 -3
  28. data/lib/aozora2html/tag/dir.rb +4 -2
  29. data/lib/aozora2html/tag/editor_note.rb +7 -4
  30. data/lib/aozora2html/tag/embed_gaiji.rb +15 -11
  31. data/lib/aozora2html/tag/font_size.rb +5 -2
  32. data/lib/aozora2html/tag/gaiji.rb +4 -3
  33. data/lib/aozora2html/tag/img.rb +4 -4
  34. data/lib/aozora2html/tag/indent.rb +3 -3
  35. data/lib/aozora2html/tag/inline.rb +10 -7
  36. data/lib/aozora2html/tag/inline_caption.rb +4 -2
  37. data/lib/aozora2html/tag/inline_font_size.rb +4 -3
  38. data/lib/aozora2html/tag/inline_keigakomi.rb +4 -2
  39. data/lib/aozora2html/tag/inline_yokogumi.rb +4 -3
  40. data/lib/aozora2html/tag/jisage.rb +3 -1
  41. data/lib/aozora2html/tag/jizume.rb +3 -0
  42. data/lib/aozora2html/tag/kaeriten.rb +4 -2
  43. data/lib/aozora2html/tag/keigakomi.rb +15 -9
  44. data/lib/aozora2html/tag/kunten.rb +4 -4
  45. data/lib/aozora2html/tag/midashi.rb +3 -1
  46. data/lib/aozora2html/tag/multiline.rb +3 -0
  47. data/lib/aozora2html/tag/multiline_caption.rb +6 -8
  48. data/lib/aozora2html/tag/multiline_chitsuki.rb +3 -1
  49. data/lib/aozora2html/tag/multiline_jisage.rb +3 -1
  50. data/lib/aozora2html/tag/multiline_midashi.rb +6 -3
  51. data/lib/aozora2html/tag/multiline_style.rb +5 -3
  52. data/lib/aozora2html/tag/multiline_yokogumi.rb +6 -9
  53. data/lib/aozora2html/tag/okurigana.rb +4 -2
  54. data/lib/aozora2html/tag/oneline_chitsuki.rb +3 -2
  55. data/lib/aozora2html/tag/oneline_indent.rb +8 -1
  56. data/lib/aozora2html/tag/oneline_jisage.rb +3 -0
  57. data/lib/aozora2html/tag/reference_mentioned.rb +22 -21
  58. data/lib/aozora2html/tag/ruby.rb +174 -70
  59. data/lib/aozora2html/tag/un_embed_gaiji.rb +8 -2
  60. data/lib/aozora2html/tag.rb +40 -38
  61. data/lib/aozora2html/tag_parser.rb +23 -16
  62. data/lib/aozora2html/text_buffer.rb +50 -0
  63. data/lib/aozora2html/utils.rb +113 -50
  64. data/lib/aozora2html/version.rb +3 -1
  65. data/lib/aozora2html/yaml_loader.rb +8 -2
  66. data/lib/aozora2html/zip.rb +4 -0
  67. data/lib/aozora2html.rb +1329 -3
  68. data/lib/extensions.rb +2 -34
  69. data/lib/jstream.rb +96 -25
  70. data/sample/chukiichiran_kinyurei.html +42 -29
  71. data/sample/chukiichiran_kinyurei.txt +16 -3
  72. metadata +80 -83
  73. data/.travis.yml +0 -12
  74. data/lib/t2hs.rb +0 -1607
  75. data/test/test_aozora2html.rb +0 -379
  76. data/test/test_aozora_accent_parser.rb +0 -31
  77. data/test/test_command_parse.rb +0 -213
  78. data/test/test_compat.rb +0 -11
  79. data/test/test_dakuten_katakana_tag.rb +0 -27
  80. data/test/test_decorate_tag.rb +0 -24
  81. data/test/test_dir_tag.rb +0 -24
  82. data/test/test_editor_note_tag.rb +0 -22
  83. data/test/test_exception.rb +0 -23
  84. data/test/test_font_size_tag.rb +0 -41
  85. data/test/test_gaiji_tag.rb +0 -49
  86. data/test/test_header.rb +0 -60
  87. data/test/test_helper.rb +0 -5
  88. data/test/test_i18n.rb +0 -23
  89. data/test/test_img_tag.rb +0 -23
  90. data/test/test_inline_caption_tag.rb +0 -24
  91. data/test/test_inline_font_size_tag.rb +0 -34
  92. data/test/test_inline_keigakomi_tag.rb +0 -24
  93. data/test/test_inline_yokogumi_tag.rb +0 -24
  94. data/test/test_jizume_tag.rb +0 -25
  95. data/test/test_jstream.rb +0 -57
  96. data/test/test_kaeriten_tag.rb +0 -24
  97. data/test/test_keigakomi_tag.rb +0 -31
  98. data/test/test_midashi_tag.rb +0 -38
  99. data/test/test_multiline_caption_tag.rb +0 -25
  100. data/test/test_multiline_midashi_tag.rb +0 -55
  101. data/test/test_multiline_style_tag.rb +0 -25
  102. data/test/test_multiline_yokogumi_tag.rb +0 -25
  103. data/test/test_okurigana_tag.rb +0 -24
  104. data/test/test_ruby_parse.rb +0 -130
  105. data/test/test_ruby_tag.rb +0 -24
  106. data/test/test_tag_parser.rb +0 -80
@@ -1,379 +0,0 @@
1
- # encoding: utf-8
2
- require 'test_helper'
3
- require 'aozora2html'
4
- require 'fileutils'
5
- require 'tmpdir'
6
-
7
- class Aozora2HtmlTest < Test::Unit::TestCase
8
- def setup
9
- input = StringIO.new("abc\r\n")
10
- output = StringIO.new
11
- @parser = Aozora2Html.new(input, output)
12
- end
13
-
14
- def test_aozora2html_new
15
- Dir.mktmpdir do |dir|
16
- input = File.join(dir,'dummy.txt')
17
- output = File.join(dir,'dummy2.txt')
18
- File.binwrite(input, "テスト\r\n")
19
- parser = Aozora2Html.new(input, output)
20
- begin
21
- assert_equal Aozora2Html, parser.class
22
- ensure
23
- parser.close
24
- end
25
- end
26
- end
27
-
28
- def test_line_number
29
- Dir.mktmpdir do |dir|
30
- input = File.join(dir,'dummy.txt')
31
- output = File.join(dir,'dummy2.txt')
32
- File.binwrite(input, "a\r\nb\r\nc\r\n")
33
- parser = Aozora2Html.new(input, output)
34
-
35
- begin
36
- assert_equal 0, parser.line_number
37
- ch = parser.read_char
38
- assert_equal "a",ch
39
- assert_equal 1, parser.line_number
40
- ch = parser.read_char
41
- assert_equal "\r\n",ch
42
- assert_equal 1, parser.line_number
43
- ch = parser.read_char
44
- assert_equal "b",ch
45
- assert_equal 2, parser.line_number
46
- ch = parser.read_char
47
- assert_equal "\r\n",ch
48
- assert_equal 2, parser.line_number
49
- ch = parser.read_char
50
- assert_equal "c",ch
51
- assert_equal 3, parser.line_number
52
- ensure
53
- parser.close
54
- end
55
- end
56
- end
57
-
58
- def test_line_number_2
59
- input = StringIO.new("a\r\nb\r\nc\r\n")
60
- output = StringIO.new
61
- parser = Aozora2Html.new(input, output)
62
- assert_equal 0, parser.line_number
63
- ch = parser.read_char
64
- assert_equal "a",ch
65
- assert_equal 1, parser.line_number
66
- ch = parser.read_char
67
- assert_equal "\r\n",ch
68
- assert_equal 1, parser.line_number
69
- ch = parser.read_char
70
- assert_equal "b",ch
71
- assert_equal 2, parser.line_number
72
- ch = parser.read_char
73
- assert_equal "\r\n",ch
74
- assert_equal 2, parser.line_number
75
- ch = parser.read_char
76
- assert_equal "c",ch
77
- assert_equal 3, parser.line_number
78
- end
79
-
80
- def test_read_line
81
- input = StringIO.new("ab\r\nc\r\n")
82
- output = StringIO.new
83
- parser = Aozora2Html.new(input, output)
84
- parsed = parser.read_line
85
- assert_equal "ab", parsed
86
- end
87
-
88
- 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"))
95
-
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"))
107
- end
108
-
109
- def test_read_char
110
- input = StringIO.new("/\\r\n".encode("shift_jis"))
111
- output = StringIO.new
112
- parser = Aozora2Html.new(input, output)
113
- char = parser.read_char
114
- assert_equal "/".encode("shift_jis"), char
115
- assert_equal Aozora2Html::KU, char
116
- end
117
-
118
- def test_illegal_char_check
119
- input = StringIO.new("abc\r\n")
120
- output = StringIO.new
121
- parser = Aozora2Html.new(input, output)
122
- out = StringIO.new
123
- $stdout = out
124
- begin
125
- parser.illegal_char_check("#", 123)
126
- outstr = out.string
127
- assert_equal "警告(123行目):1バイトの「#」が使われています\n", outstr.encode("utf-8")
128
- ensure
129
- $stdout = STDOUT
130
- end
131
- end
132
-
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
- out = StringIO.new
138
- $stdout = out
139
- begin
140
- parser.illegal_char_check("♯".encode("shift_jis"), 123)
141
- outstr = out.string
142
- assert_equal "警告(123行目):注記記号の誤用の可能性がある、「♯」が使われています\n", outstr.encode("utf-8")
143
- ensure
144
- $stdout = STDOUT
145
- end
146
- end
147
-
148
- def test_illegal_char_check_notjis
149
- input = StringIO.new("abc\r\n")
150
- output = StringIO.new
151
- parser = Aozora2Html.new(input, output)
152
- out = StringIO.new
153
- $stdout = out
154
- begin
155
- parser.illegal_char_check("①".encode("cp932").force_encoding("shift_jis"), 123)
156
- outstr = out.string
157
- assert_equal "警告(123行目):JIS外字「①」が使われています\n", outstr.force_encoding("cp932").encode("utf-8")
158
- ensure
159
- $stdout = STDOUT
160
- end
161
- end
162
-
163
- def test_illegal_char_check_ok
164
- input = StringIO.new("abc\r\n")
165
- output = StringIO.new
166
- parser = Aozora2Html.new(input, output)
167
- out = StringIO.new
168
- $stdout = out
169
- begin
170
- parser.illegal_char_check("あ".encode("shift_jis"), 123)
171
- outstr = output.string
172
- assert_equal "", outstr
173
- ensure
174
- $stdout = STDOUT
175
- end
176
- end
177
-
178
- 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
-
194
- end
195
-
196
- def test_kuten2png
197
- 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")
199
- 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")
201
- 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")
205
- end
206
-
207
- 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])
218
- end
219
-
220
- def test_new_midashi_id
221
- midashi_id = @parser.new_midashi_id(1)
222
- 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"))
226
- assert_raise(Aozora2Html::Error) do
227
- @parser.new_midashi_id("?".encode("shift_jis"))
228
- end
229
- end
230
-
231
- def test_multiply
232
- bouki = @parser.multiply("x", 5)
233
- assert_equal "x&nbsp;x&nbsp;x&nbsp;x&nbsp;x", bouki
234
- end
235
-
236
- 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
241
- end
242
-
243
- def test_detect_command_mode
244
- command = "字下げ終わり".encode("shift_jis")
245
- assert_equal :jisage, @parser.detect_command_mode(command)
246
- command = "地付き終わり".encode("shift_jis")
247
- assert_equal :chitsuki, @parser.detect_command_mode(command)
248
- command = "中見出し終わり".encode("shift_jis")
249
- assert_equal :midashi, @parser.detect_command_mode(command)
250
- command = "ここで太字終わり".encode("shift_jis")
251
- assert_equal :futoji, @parser.detect_command_mode(command)
252
- end
253
-
254
- def test_tcy
255
- input = StringIO.new("[#縦中横](※[#ローマ数字1、1-13-21])\r\n".encode("shift_jis"))
256
- output = StringIO.new
257
- parser = Aozora2Html.new(input, output)
258
- out = StringIO.new
259
- $stdout = out
260
- message = nil
261
- begin
262
- parser.parse_body
263
- parser.general_output
264
- rescue Aozora2Html::Error => e
265
- message = e.message.encode("utf-8")
266
- ensure
267
- $stdout = STDOUT
268
- assert_equal "エラー(0行目):縦中横中に改行されました。改行をまたぐ要素にはブロック表記を用いてください. \r\n処理を停止します", message
269
- end
270
- end
271
-
272
- def test_ensure_close
273
- input = StringIO.new("[#ここから5字下げ]\r\n底本: test\r\n".encode("shift_jis"))
274
- output = StringIO.new
275
- parser = Aozora2Html.new(input, output)
276
- out = StringIO.new
277
- $stdout = out
278
- message = nil
279
- begin
280
- parser.parse_body
281
- parser.parse_body
282
- parser.parse_body
283
- parser.general_output
284
- rescue Aozora2Html::Error => e
285
- message = e.message.encode("utf-8")
286
- ensure
287
- $stdout = STDOUT
288
- assert_equal "エラー(0行目):字下げ中に本文が終了しました. \r\n処理を停止します", message
289
- end
290
- end
291
-
292
- def test_ending_check
293
- input = StringIO.new("本文\r\n\r\n底本:test\r\n".encode("shift_jis"))
294
- output = StringIO.new
295
- parser = Aozora2Html.new(input, output)
296
- out = StringIO.new
297
- $stdout = out
298
- _message = nil
299
- begin
300
- parser.parse_body
301
- parser.parse_body
302
- parser.parse_body
303
- parser.parse_body
304
- parser.parse_body
305
- rescue Aozora2Html::Error => e
306
- _message = e.message.encode("utf-8")
307
- ensure
308
- $stdout = STDOUT
309
- output.seek(0)
310
- out_text = output.read
311
- assert_equal "本文<br />\r\n<br />\r\n</div>\r\n<div class=\"bibliographical_information\">\r\n<hr />\r\n<br />\r\n", out_text
312
- end
313
- end
314
-
315
- def test_invalid_closing
316
- input = StringIO.new("[#ここで太字終わり]\r\n".encode("shift_jis"))
317
- output = StringIO.new
318
- parser = Aozora2Html.new(input, output)
319
- out = StringIO.new
320
- $stdout = out
321
- message = nil
322
- begin
323
- parser.parse_body
324
- rescue Aozora2Html::Error => e
325
- message = e.message.encode("utf-8")
326
- ensure
327
- $stdout = STDOUT
328
- assert_equal "エラー(0行目):太字を閉じようとしましたが、太字中ではありません. \r\n処理を停止します", message
329
- end
330
- end
331
-
332
- def test_invalid_nest
333
- input = StringIO.new("[#太字][#傍線]あ[#太字終わり]\r\n".encode("shift_jis"))
334
- output = StringIO.new
335
- parser = Aozora2Html.new(input, output)
336
- out = StringIO.new
337
- $stdout = out
338
- message = nil
339
- 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
347
- rescue Aozora2Html::Error => e
348
- message = e.message.encode("utf-8")
349
- ensure
350
- $stdout = STDOUT
351
- assert_equal "エラー(0行目):太字を終了しようとしましたが、傍線中です. \r\n処理を停止します", message
352
- end
353
- end
354
-
355
- def test_command_do
356
- input = StringIO.new("[#ここから太字]\r\nテスト。\r\n[#ここで太字終わり]\r\n".encode("shift_jis"))
357
- output = StringIO.new
358
- parser = Aozora2Html.new(input, output)
359
- out = StringIO.new
360
- $stdout = out
361
- _message = nil
362
- begin
363
- 9.times do
364
- parser.parse_body
365
- end
366
- rescue Aozora2Html::Error => e
367
- _message = e.message.encode("utf-8")
368
- ensure
369
- $stdout = STDOUT
370
- output.seek(0)
371
- out_text = output.read
372
- assert_equal "<div class=\"futoji\">\r\nテスト。<br />\r\n</div>\r\n", out_text
373
- end
374
- end
375
-
376
-
377
- def teardown
378
- end
379
- end
@@ -1,31 +0,0 @@
1
- # encoding: utf-8
2
- require 'test_helper'
3
- require 'aozora2html'
4
-
5
- class Aozora2HtmlAccentParserTest < Test::Unit::TestCase
6
- def setup
7
- end
8
-
9
- def test_new
10
- str = "〔e'tiquette〕\r\n".encode("shift_jis")
11
- strio = StringIO.new(str)
12
- 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")
16
- end
17
-
18
- def test_use_jisx0213
19
- Aozora2Html::Tag::Accent.use_jisx0213 = true
20
- str = "〔e'tiquette〕\r\n".encode("shift_jis")
21
- strio = StringIO.new(str)
22
- 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")
26
- end
27
-
28
- def teardown
29
- Aozora2Html::Tag::Accent.use_jisx0213 = nil
30
- end
31
- end
@@ -1,213 +0,0 @@
1
- # encoding: utf-8
2
- require 'test_helper'
3
- require 'aozora2html'
4
-
5
- class CommandParseTest < Test::Unit::TestCase
6
- def setup
7
- end
8
-
9
- def test_parse_command1
10
- src = "デボルド―※[#濁点付き片仮名ワ、1-7-82]ルモオル\r\n"
11
- parsed = parse_text(src)
12
- expected = "デボルド—<img src=\"../../../gaiji/1-07/1-07-82.png\" alt=\"※(濁点付き片仮名ワ、1-7-82)\" class=\"gaiji\" />ルモオル<br />\r\n"
13
- assert_equal expected, parsed
14
- end
15
-
16
- def test_parse_command2
17
- src = "繁雑な日本の 〔e'tiquette〕 も、\r\n"
18
- parsed = parse_text(src)
19
- expected = %Q|繁雑な日本の <img src="../../../gaiji/1-09/1-09-63.png" alt="※(アキュートアクセント付きE小文字)" class="gaiji" />tiquette も、<br />\r\n|
20
- assert_equal expected, parsed
21
- end
22
-
23
- def test_parse_command3
24
- src = "〔Sito^t qu'on le touche il re'sonne.〕\r\n"
25
- parsed = parse_text(src)
26
- expected = %Q|Sit<img src="../../../gaiji/1-09/1-09-74.png" alt="※(サーカムフレックスアクセント付きO小文字)" class="gaiji" />t q<img src="../../../gaiji/1-09/1-09-79.png" alt="※(アキュートアクセント付きU小文字)" class="gaiji" />on le touche il r<img src="../../../gaiji/1-09/1-09-63.png" alt="※(アキュートアクセント付きE小文字)" class="gaiji" />sonne.<br />\r\n|
27
- assert_equal expected, parsed
28
- end
29
-
30
- def test_parse_command4
31
- src = "presqu'〔i^le〕\r\n"
32
- parsed = parse_text(src)
33
- expected = %Q|presqu'<img src="../../../gaiji/1-09/1-09-68.png" alt="※(サーカムフレックスアクセント付きI小文字)" class="gaiji" />le<br />\r\n|
34
- assert_equal expected, parsed
35
- end
36
-
37
- def test_parse_command5
38
- src = "[二十歳の 〔E'tude〕]\r\n"
39
- parsed = parse_text(src)
40
- expected = %Q|[二十歳の <img src="../../../gaiji/1-09/1-09-32.png" alt="※(アキュートアクセント付きE)" class="gaiji" />tude]<br />\r\n|
41
- assert_equal expected, parsed
42
- end
43
-
44
- def test_parse_command6
45
- src = "責[#「責」に白ゴマ傍点]空文庫\r\n"
46
- parsed = parse_text(src)
47
- expected = %Q|<em class="white_sesame_dot">責</em>空文庫<br />\r\n|
48
- assert_equal expected, parsed
49
- end
50
-
51
- def test_parse_command7
52
- src = "[#丸傍点]青空文庫で読書しよう[#丸傍点終わり]。\r\n"
53
- parsed = parse_text(src)
54
- expected = %Q|<em class="black_circle">青空文庫で読書しよう</em>。<br />\r\n|
55
- assert_equal expected, parsed
56
- end
57
-
58
- def test_parse_command8
59
- src = "この形は傍線[#「傍線」に傍線]と書いてください。\r\n"
60
- parsed = parse_text(src)
61
- expected = %Q|この形は<em class="underline_solid">傍線</em>と書いてください。<br />\r\n|
62
- assert_equal expected, parsed
63
- end
64
-
65
- def test_parse_command9
66
- src = "[#左に鎖線]青空文庫で読書しよう[#左に鎖線終わり]。\r\n"
67
- parsed = parse_text(src)
68
- expected = %Q|<em class="overline_dotted">青空文庫で読書しよう</em>。<br />\r\n|
69
- assert_equal expected, parsed
70
- end
71
-
72
- def test_parse_command10
73
- src = "「クリス、宇宙航行委員会が選考[#「選考」は太字]するんだ。きみは志願できない。待つ[#「待つ」は太字]んだ」\r\n"
74
- parsed = parse_text(src)
75
- expected = %Q|「クリス、宇宙航行委員会が<span class="futoji">選考</span>するんだ。きみは志願できない。<span class="futoji">待つ</span>んだ」<br />\r\n|
76
- assert_equal expected, parsed
77
- end
78
-
79
- def test_parse_command11
80
- src = "Which, teaching us, hath this exordium: Nothing from nothing ever yet was born.[#「Nothing from nothing ever yet was born.」は斜体]\r\n"
81
- parsed = parse_text(src)
82
- expected = %Q|Which, teaching us, hath this exordium: <span class="shatai">Nothing from nothing ever yet was born.</span><br />\r\n|
83
- assert_equal expected, parsed
84
- end
85
-
86
- def test_parse_command_warichu
87
- src = "[#割り注]価は四百円であった。[#割り注終わり]\r\n"
88
- parsed = parse_text(src)
89
- expected = %Q|<span class="warichu">(価は四百円であった。)</span><br />\r\n|
90
- assert_equal expected, parsed
91
- end
92
-
93
- def test_parse_command_warichu2
94
- src = "飽海郡南平田村大字飛鳥[#割り注]東は字大林四三七[#改行]西は字神内一一一ノ一[#割り注終わり]\r\n"
95
- parsed = parse_text(src)
96
- expected = %Q|飽海郡南平田村大字飛鳥<span class="warichu">(東は字大林四三七<span class="notes">[#改行]</span>西は字神内一一一ノ一)</span><br />\r\n|
97
- assert_equal expected, parsed
98
- end
99
-
100
- def test_parse_command_unicode
101
- Aozora2Html::Tag::EmbedGaiji.use_unicode = true
102
- src = "※[#「衄のへん+卩」、U+5379、287-2]\r\n"
103
- parsed = parse_text(src)
104
- expected = "&#x5379;<br />\r\n"
105
- assert_equal expected, parsed
106
- end
107
-
108
- def test_parse_command_teisei1
109
- Aozora2Html::Tag::EmbedGaiji.use_unicode = true
110
- src = "吹喋[#「喋」に「ママ」の注記]\r\n"
111
- parsed = parse_text(src)
112
- expected = "吹<ruby><rb>喋</rb><rp>(</rp><rt>ママ</rt><rp>)</rp></ruby><br />\r\n"
113
- assert_equal expected, parsed
114
- end
115
-
116
- def test_parse_command_teisei2
117
- Aozora2Html::Tag::EmbedGaiji.use_unicode = true
118
- src = "紋附だとか[#「紋附だとか」は底本では「絞附だとか」]\r\n"
119
- parsed = parse_text(src)
120
- expected = %Q|紋附だとか<span class="notes">[#「紋附だとか」は底本では「絞附だとか」]</span><br />\r\n|
121
- assert_equal expected, parsed
122
- end
123
-
124
- def test_parse_command_teisei3
125
- Aozora2Html::Tag::EmbedGaiji.use_unicode = true
126
- src = "私は籠《ざる》[#ルビの「ざる」は底本では「さる」]をさげ\r\n"
127
- parsed = parse_text(src)
128
- expected = %Q|私は<ruby><rb>籠</rb><rp>(</rp><rt>ざる</rt><rp>)</rp></ruby><span class="notes">[#ルビの「ざる」は底本では「さる」]</span>をさげ<br />\r\n|
129
- assert_equal expected, parsed
130
- end
131
-
132
- def test_parse_command_teisei4
133
- Aozora2Html::Tag::EmbedGaiji.use_unicode = true
134
- src = "広場へに[#「広場へに」はママ]店でもだそう。\r\n"
135
- parsed = parse_text(src)
136
- expected = %Q|広場へに<span class="notes">[#「広場へに」はママ]</span>店でもだそう。<br />\r\n|
137
- assert_equal expected, parsed
138
- end
139
-
140
- def test_parse_command_teisei5
141
- Aozora2Html::Tag::EmbedGaiji.use_unicode = true
142
- src = "お湯《ゆう》[#ルビの「ゆう」はママ]\r\n"
143
- parsed = parse_text(src)
144
- expected = %Q|お<ruby><rb>湯</rb><rp>(</rp><rt>ゆう</rt><rp>)</rp></ruby><span class="notes">[#ルビの「ゆう」はママ]</span><br />\r\n|
145
- assert_equal expected, parsed
146
- end
147
-
148
- def test_parse_command_tcy
149
- Aozora2Html::Tag::EmbedGaiji.use_unicode = true
150
- src = "米機B29[#「29」は縦中横]の編隊は、\r\n"
151
- parsed = parse_text(src)
152
- expected = %Q|米機B<span dir="ltr">29</span>の編隊は、<br />\r\n|
153
- assert_equal expected, parsed
154
- end
155
-
156
- def test_parse_command_tcy2
157
- Aozora2Html::Tag::EmbedGaiji.use_unicode = true
158
- src = "[#縦中横](※[#ローマ数字1、1-13-21])[#縦中横終わり]\r\n"
159
- parsed = parse_text(src)
160
- expected = %Q|<span dir="ltr">(<img src="../../../gaiji/1-13/1-13-21.png" alt="※(ローマ数字1、1-13-21)" class="gaiji" />)</span><br />\r\n|
161
- assert_equal expected, parsed
162
- end
163
-
164
- def test_parse_command_kogaki
165
- Aozora2Html::Tag::EmbedGaiji.use_unicode = true
166
- src = "それ以上である。(5)[#「(5)」は行右小書き]\r\n"
167
- parsed = parse_text(src)
168
- expected = %Q|それ以上である。<sup class="superscript">(5)</sup><br />\r\n|
169
- assert_equal expected, parsed
170
- end
171
-
172
- def test_parse_command_uetsuki
173
- Aozora2Html::Tag::EmbedGaiji.use_unicode = true
174
- src = "22[#「2」は上付き小文字]\r\n"
175
- parsed = parse_text(src)
176
- expected = %Q|2<sup class="superscript">2</sup><br />\r\n|
177
- assert_equal expected, parsed
178
- end
179
-
180
- def test_parse_command_bouki
181
- Aozora2Html::Tag::EmbedGaiji.use_unicode = true
182
- src = "支部長の顔にさっと血が流れ[#「血が流れ」に「×」の傍記]た\r\n"
183
- parsed = parse_text(src)
184
- expected = %Q|支部長の顔にさっと<ruby><rb>血が流れ</rb><rp>(</rp><rt>×&nbsp;×&nbsp;×&nbsp;×</rt><rp>)</rp></ruby>た<br />\r\n|
185
- assert_equal expected, parsed
186
- end
187
-
188
- def test_parse_command_ruby
189
- Aozora2Html::Tag::EmbedGaiji.use_unicode = true
190
- src = "グリーンランドの中央部八千尺の氷河地帯にあるといわれる、[#横組み]“Ser-mik-Suah《セルミク・シュアー》”[#横組み終わり]の冥路《よみじ》の国。\r\n"
191
- parsed = parse_text(src)
192
- expected = %Q|グリーンランドの中央部八千尺の氷河地帯にあるといわれる、<span class=\"yokogumi\">“<ruby><rb>Ser-mik-Suah</rb><rp>(</rp><rt>セルミク・シュアー</rt><rp>)</rp></ruby>”</span>の<ruby><rb>冥路</rb><rp>(</rp><rt>よみじ</rt><rp>)</rp></ruby>の国。<br />\r\n|
193
- assert_equal expected, parsed
194
- end
195
-
196
- def parse_text(input_text)
197
- input = StringIO.new(input_text.encode("shift_jis"))
198
- output = StringIO.new
199
- parser = Aozora2Html.new(input, output)
200
- parser.instance_eval{@section=:tail}
201
- catch(:terminate) do
202
- loop do
203
- parser.parse
204
- end
205
- end
206
- output.string.encode("utf-8")
207
- end
208
-
209
- def teardown
210
- Aozora2Html::Tag::EmbedGaiji.use_jisx0213 = false
211
- Aozora2Html::Tag::EmbedGaiji.use_unicode = false
212
- end
213
- end
data/test/test_compat.rb DELETED
@@ -1,11 +0,0 @@
1
- require 'test_helper'
2
- require 'aozora2html'
3
-
4
- class CompatTest < Test::Unit::TestCase
5
- def test_array_to_s
6
- assert_equal "abc", ["a", "b", "c"].join
7
- end
8
- end
9
-
10
-
11
-
@@ -1,27 +0,0 @@
1
- # encoding: utf-8
2
- require 'test_helper'
3
- require 'aozora2html'
4
-
5
- class DakutenKatakanaTagTest < Test::Unit::TestCase
6
- def setup
7
- @parser = Object.new
8
- @orig_gaiji_dir = $gaiji_dir
9
- $gaiji_dir = "g_dir"
10
- stub(@parser).block_allowed_context?{true}
11
- end
12
-
13
- def test_dakuten_katakana_new
14
- tag = Aozora2Html::Tag::DakutenKatakana.new(@parser,1,"ア".encode("shift_jis"))
15
- assert_equal Aozora2Html::Tag::DakutenKatakana, tag.class
16
- assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
17
- end
18
-
19
- def test_to_s
20
- tag = Aozora2Html::Tag::DakutenKatakana.new(@parser,1,"ア".encode("shift_jis"))
21
- assert_equal "<img src=\"g_dir/1-07/1-07-81.png\" alt=\"※(濁点付き片仮名「ア」、1-07-81)\" class=\"gaiji\" />", tag.to_s.encode("utf-8")
22
- end
23
-
24
- def teardown
25
- $gaiji_dir = @orig_gaiji_dir
26
- end
27
- end
@@ -1,24 +0,0 @@
1
- # encoding: utf-8
2
- require 'test_helper'
3
- require 'aozora2html'
4
-
5
- class DecorateTagTest < Test::Unit::TestCase
6
- def setup
7
- @parser = Object.new
8
- stub(@parser).block_allowed_context?{true}
9
- end
10
-
11
- def test_decorate_new
12
- tag = Aozora2Html::Tag::Decorate.new(@parser,"aa",1,:dai)
13
- assert_equal Aozora2Html::Tag::Decorate, tag.class
14
- assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
15
- end
16
-
17
- def test_to_s
18
- tag = Aozora2Html::Tag::Decorate.new(@parser,"テスト".encode("shift_jis"),"foo","span")
19
- assert_equal "<span class=\"foo\">テスト</span>", tag.to_s.encode("utf-8")
20
- end
21
-
22
- def teardown
23
- end
24
- end