aozora2html 3.0.0 → 3.0.1

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