aozora2html 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -177,19 +177,19 @@ class Aozora2HtmlTest < Test::Unit::TestCase
177
177
 
178
178
  def test_convert_japanese_number
179
179
  assert_equal "3字下げ",
180
- @parser.convert_japanese_number("三字下げ".encode("shift_jis")).encode("utf-8")
180
+ Aozora2Html::Utils.convert_japanese_number("三字下げ".encode("shift_jis")).encode("utf-8")
181
181
  assert_equal "10字下げ",
182
- @parser.convert_japanese_number("十字下げ".encode("shift_jis")).encode("utf-8")
182
+ Aozora2Html::Utils.convert_japanese_number("十字下げ".encode("shift_jis")).encode("utf-8")
183
183
  assert_equal "12字下げ",
184
- @parser.convert_japanese_number("十二字下げ".encode("shift_jis")).encode("utf-8")
184
+ Aozora2Html::Utils.convert_japanese_number("十二字下げ".encode("shift_jis")).encode("utf-8")
185
185
  assert_equal "20字下げ",
186
- @parser.convert_japanese_number("二十字下げ".encode("shift_jis")).encode("utf-8")
186
+ Aozora2Html::Utils.convert_japanese_number("二十字下げ".encode("shift_jis")).encode("utf-8")
187
187
  assert_equal "20字下げ",
188
- @parser.convert_japanese_number("二〇字下げ".encode("shift_jis")).encode("utf-8")
188
+ Aozora2Html::Utils.convert_japanese_number("二〇字下げ".encode("shift_jis")).encode("utf-8")
189
189
  assert_equal "23字下げ",
190
- @parser.convert_japanese_number("二十三字下げ".encode("shift_jis")).encode("utf-8")
190
+ Aozora2Html::Utils.convert_japanese_number("二十三字下げ".encode("shift_jis")).encode("utf-8")
191
191
  assert_equal "2字下げ",
192
- @parser.convert_japanese_number("2字下げ".encode("shift_jis")).encode("utf-8")
192
+ Aozora2Html::Utils.convert_japanese_number("2字下げ".encode("shift_jis")).encode("utf-8")
193
193
 
194
194
  end
195
195
 
@@ -217,6 +217,163 @@ class Aozora2HtmlTest < Test::Unit::TestCase
217
217
  assert_equal true, @parser.terpri?(["a",tag])
218
218
  end
219
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
+
220
377
  def teardown
221
378
  end
222
379
  end
@@ -1,3 +1,4 @@
1
+ # -*- coding:utf-8 -*-
1
2
  require 'test_helper'
2
3
  require 'aozora2html'
3
4
 
@@ -29,6 +30,12 @@ class FontSizeTagTest < Test::Unit::TestCase
29
30
  assert_equal "<div class=\"sho3\" style=\"font-size: xx-small;\">", tag.to_s.encode("utf-8")
30
31
  end
31
32
 
33
+ def test_to_s0
34
+ assert_raise(Aozora2Html::Error.new("文字サイズの指定が不正です".to_sjis)) do
35
+ _tag = Aozora2Html::Tag::FontSize.new(@parser,0,:sho)
36
+ end
37
+ end
38
+
32
39
  def teardown
33
40
  end
34
41
  end
@@ -97,6 +97,20 @@ class RubyParseTest < Test::Unit::TestCase
97
97
  assert_equal expected, parsed
98
98
  end
99
99
 
100
+ def test_parse_ruby12
101
+ src = "大空文庫《あおぞらぶんこ》[#「大空文庫」に「ママ」の注記]\r\n"
102
+ assert_raise(Aozora2Html::Error.new("同じ箇所に2つのルビはつけられません".encode("shift_jis"))) do
103
+ _parsed = parse_text(src)
104
+ end
105
+ end
106
+
107
+ def test_parse_ruby13
108
+ src = "[#注記付き]名※[#二の字点、1-2-22][#「(銘々)」の注記付き終わり]\r\n"
109
+ parsed = parse_text(src)
110
+ expected = %Q|<ruby><rb>名<img src="../../../gaiji/1-02/1-02-22.png" alt="※(二の字点、1-2-22)" class="gaiji" /></rb><rp>(</rp><rt>(銘々)</rt><rp>)</rp></ruby><br />\r\n|
111
+ assert_equal expected, parsed
112
+ end
113
+
100
114
  def parse_text(input_text)
101
115
  input = StringIO.new(input_text.encode("shift_jis"))
102
116
  output = StringIO.new
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aozora2html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - aozorahack team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-10 00:00:00.000000000 Z
11
+ date: 2020-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '12.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '12.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: test-unit
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,34 +80,6 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: guard
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: guard-test
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
83
  description: converter from Aozora Bunko format into xhtml. It's based of t2hs.rb
112
84
  from kumihan.aozora.gr.jp.
113
85
  email:
@@ -117,15 +89,17 @@ executables:
117
89
  extensions: []
118
90
  extra_rdoc_files: []
119
91
  files:
92
+ - ".github/workflows/ruby.yml"
120
93
  - ".gitignore"
94
+ - ".rubocop.yml"
121
95
  - ".travis.yml"
122
96
  - CHANGELOG.md
123
97
  - Gemfile
124
98
  - Guardfile
99
+ - LICENSE
125
100
  - README.md
126
101
  - Rakefile
127
102
  - aozora2html.gemspec
128
- - appveyor.yml
129
103
  - bin/aozora2html
130
104
  - lib/aozora2html.rb
131
105
  - lib/aozora2html/accent_parser.rb
@@ -238,8 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
212
  - !ruby/object:Gem::Version
239
213
  version: '0'
240
214
  requirements: []
241
- rubyforge_project:
242
- rubygems_version: 2.6.8
215
+ rubygems_version: 3.1.2
243
216
  signing_key:
244
217
  specification_version: 4
245
218
  summary: converter from Aozora Bunko format into xhtml. It's based of t2hs.rb from
@@ -1,23 +0,0 @@
1
- ---
2
- install:
3
- - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
4
- - ruby --version
5
- - gem --version
6
- - bundle install
7
- build_script:
8
- - bundle exec rake test
9
-
10
- branches:
11
- only:
12
- - master
13
-
14
- environment:
15
- matrix:
16
- - ruby_version: "200"
17
- - ruby_version: "200-x64"
18
- - ruby_version: "21"
19
- - ruby_version: "21-x64"
20
- - ruby_version: "22"
21
- - ruby_version: "22-x64"
22
- - ruby_version: "23"
23
- - ruby_version: "23-x64"