aozora2html 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rubocop.yml +19 -0
- data/.github/workflows/ruby.yml +4 -1
- data/.rubocop.yml +36 -152
- data/.rubocop_todo.yml +7 -0
- data/CHANGELOG.md +26 -0
- data/Gemfile +2 -0
- data/Guardfile +3 -1
- data/HACKING.md +45 -0
- data/README.md +14 -6
- data/Rakefile +12 -5
- data/aozora2html.gemspec +24 -22
- data/bin/aozora2html +21 -19
- data/lib/aozora2html/accent_parser.rb +62 -54
- data/lib/aozora2html/error.rb +5 -4
- data/lib/aozora2html/header.rb +20 -18
- data/lib/aozora2html/i18n.rb +40 -20
- data/lib/aozora2html/ruby_buffer.rb +63 -28
- data/lib/aozora2html/string_refinements.rb +36 -0
- data/lib/aozora2html/style_stack.rb +6 -0
- data/lib/aozora2html/tag/accent.rb +10 -12
- data/lib/aozora2html/tag/block.rb +11 -9
- data/lib/aozora2html/tag/chitsuki.rb +6 -2
- data/lib/aozora2html/tag/dakuten_katakana.rb +10 -8
- data/lib/aozora2html/tag/decorate.rb +4 -3
- data/lib/aozora2html/tag/dir.rb +4 -2
- data/lib/aozora2html/tag/editor_note.rb +7 -4
- data/lib/aozora2html/tag/embed_gaiji.rb +15 -11
- data/lib/aozora2html/tag/font_size.rb +5 -2
- data/lib/aozora2html/tag/gaiji.rb +4 -3
- data/lib/aozora2html/tag/img.rb +4 -4
- data/lib/aozora2html/tag/indent.rb +3 -3
- data/lib/aozora2html/tag/inline.rb +10 -7
- data/lib/aozora2html/tag/inline_caption.rb +4 -2
- data/lib/aozora2html/tag/inline_font_size.rb +4 -3
- data/lib/aozora2html/tag/inline_keigakomi.rb +4 -2
- data/lib/aozora2html/tag/inline_yokogumi.rb +4 -3
- data/lib/aozora2html/tag/jisage.rb +3 -1
- data/lib/aozora2html/tag/jizume.rb +3 -0
- data/lib/aozora2html/tag/kaeriten.rb +4 -2
- data/lib/aozora2html/tag/keigakomi.rb +15 -9
- data/lib/aozora2html/tag/kunten.rb +4 -4
- data/lib/aozora2html/tag/midashi.rb +3 -1
- data/lib/aozora2html/tag/multiline.rb +3 -0
- data/lib/aozora2html/tag/multiline_caption.rb +6 -8
- data/lib/aozora2html/tag/multiline_chitsuki.rb +3 -1
- data/lib/aozora2html/tag/multiline_jisage.rb +3 -1
- data/lib/aozora2html/tag/multiline_midashi.rb +6 -3
- data/lib/aozora2html/tag/multiline_style.rb +5 -3
- data/lib/aozora2html/tag/multiline_yokogumi.rb +6 -9
- data/lib/aozora2html/tag/okurigana.rb +4 -2
- data/lib/aozora2html/tag/oneline_chitsuki.rb +3 -2
- data/lib/aozora2html/tag/oneline_indent.rb +8 -1
- data/lib/aozora2html/tag/oneline_jisage.rb +3 -0
- data/lib/aozora2html/tag/reference_mentioned.rb +22 -21
- data/lib/aozora2html/tag/ruby.rb +174 -70
- data/lib/aozora2html/tag/un_embed_gaiji.rb +8 -2
- data/lib/aozora2html/tag.rb +40 -38
- data/lib/aozora2html/tag_parser.rb +23 -16
- data/lib/aozora2html/text_buffer.rb +50 -0
- data/lib/aozora2html/utils.rb +113 -50
- data/lib/aozora2html/version.rb +3 -1
- data/lib/aozora2html/yaml_loader.rb +8 -2
- data/lib/aozora2html/zip.rb +4 -0
- data/lib/aozora2html.rb +1358 -3
- data/lib/extensions.rb +2 -34
- data/lib/jstream.rb +96 -25
- data/sample/chukiichiran_kinyurei.html +15 -2
- data/sample/chukiichiran_kinyurei.txt +15 -2
- data/test/test_aozora2html.rb +137 -148
- data/test/test_aozora_accent_parser.rb +26 -9
- data/test/test_command_parse.rb +25 -22
- data/test/test_compat.rb +3 -4
- data/test/test_dakuten_katakana_tag.rb +10 -12
- data/test/test_decorate_tag.rb +9 -6
- data/test/test_dir_tag.rb +9 -6
- data/test/test_editor_note_tag.rb +8 -5
- data/test/test_exception.rb +10 -8
- data/test/test_font_size_tag.rb +16 -13
- data/test/test_gaiji_tag.rb +15 -14
- data/test/test_header.rb +25 -40
- data/test/test_helper.rb +3 -1
- data/test/test_i18n.rb +22 -6
- data/test/test_img_tag.rb +9 -5
- data/test/test_inline_caption_tag.rb +9 -6
- data/test/test_inline_font_size_tag.rb +13 -10
- data/test/test_inline_keigakomi_tag.rb +9 -6
- data/test/test_inline_yokogumi_tag.rb +9 -6
- data/test/test_jizume_tag.rb +9 -7
- data/test/test_jstream.rb +33 -30
- data/test/test_kaeriten_tag.rb +9 -6
- data/test/test_keigakomi_tag.rb +11 -9
- data/test/test_midashi_tag.rb +15 -14
- data/test/test_multiline_caption_tag.rb +7 -5
- data/test/test_multiline_midashi_tag.rb +24 -25
- data/test/test_multiline_style_tag.rb +9 -7
- data/test/test_multiline_yokogumi_tag.rb +7 -5
- data/test/test_okurigana_tag.rb +9 -6
- data/test/test_ruby_parse.rb +14 -14
- data/test/test_ruby_tag.rb +9 -6
- data/test/test_tag_parser.rb +28 -26
- metadata +60 -14
- data/.travis.yml +0 -12
- data/lib/t2hs.rb +0 -1607
data/test/test_command_parse.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'test_helper'
|
3
4
|
require 'aozora2html'
|
4
5
|
|
@@ -44,56 +45,56 @@ class CommandParseTest < Test::Unit::TestCase
|
|
44
45
|
def test_parse_command6
|
45
46
|
src = "責[#「責」に白ゴマ傍点]空文庫\r\n"
|
46
47
|
parsed = parse_text(src)
|
47
|
-
expected = %Q
|
48
|
+
expected = %Q(<em class="white_sesame_dot">責</em>空文庫<br />\r\n)
|
48
49
|
assert_equal expected, parsed
|
49
50
|
end
|
50
51
|
|
51
52
|
def test_parse_command7
|
52
53
|
src = "[#丸傍点]青空文庫で読書しよう[#丸傍点終わり]。\r\n"
|
53
54
|
parsed = parse_text(src)
|
54
|
-
expected = %Q
|
55
|
+
expected = %Q(<em class="black_circle">青空文庫で読書しよう</em>。<br />\r\n)
|
55
56
|
assert_equal expected, parsed
|
56
57
|
end
|
57
58
|
|
58
59
|
def test_parse_command8
|
59
60
|
src = "この形は傍線[#「傍線」に傍線]と書いてください。\r\n"
|
60
61
|
parsed = parse_text(src)
|
61
|
-
expected = %Q
|
62
|
+
expected = %Q(この形は<em class="underline_solid">傍線</em>と書いてください。<br />\r\n)
|
62
63
|
assert_equal expected, parsed
|
63
64
|
end
|
64
65
|
|
65
66
|
def test_parse_command9
|
66
67
|
src = "[#左に鎖線]青空文庫で読書しよう[#左に鎖線終わり]。\r\n"
|
67
68
|
parsed = parse_text(src)
|
68
|
-
expected = %Q
|
69
|
+
expected = %Q(<em class="overline_dotted">青空文庫で読書しよう</em>。<br />\r\n)
|
69
70
|
assert_equal expected, parsed
|
70
71
|
end
|
71
72
|
|
72
73
|
def test_parse_command10
|
73
74
|
src = "「クリス、宇宙航行委員会が選考[#「選考」は太字]するんだ。きみは志願できない。待つ[#「待つ」は太字]んだ」\r\n"
|
74
75
|
parsed = parse_text(src)
|
75
|
-
expected = %Q
|
76
|
+
expected = %Q(「クリス、宇宙航行委員会が<span class="futoji">選考</span>するんだ。きみは志願できない。<span class="futoji">待つ</span>んだ」<br />\r\n)
|
76
77
|
assert_equal expected, parsed
|
77
78
|
end
|
78
79
|
|
79
80
|
def test_parse_command11
|
80
81
|
src = "Which, teaching us, hath this exordium: Nothing from nothing ever yet was born.[#「Nothing from nothing ever yet was born.」は斜体]\r\n"
|
81
82
|
parsed = parse_text(src)
|
82
|
-
expected = %Q
|
83
|
+
expected = %Q(Which, teaching us, hath this exordium: <span class="shatai">Nothing from nothing ever yet was born.</span><br />\r\n)
|
83
84
|
assert_equal expected, parsed
|
84
85
|
end
|
85
86
|
|
86
87
|
def test_parse_command_warichu
|
87
88
|
src = "[#割り注]価は四百円であった。[#割り注終わり]\r\n"
|
88
89
|
parsed = parse_text(src)
|
89
|
-
expected = %Q
|
90
|
+
expected = %Q(<span class="warichu">(価は四百円であった。)</span><br />\r\n)
|
90
91
|
assert_equal expected, parsed
|
91
92
|
end
|
92
93
|
|
93
94
|
def test_parse_command_warichu2
|
94
95
|
src = "飽海郡南平田村大字飛鳥[#割り注]東は字大林四三七[#改行]西は字神内一一一ノ一[#割り注終わり]\r\n"
|
95
96
|
parsed = parse_text(src)
|
96
|
-
expected = %Q
|
97
|
+
expected = %Q(飽海郡南平田村大字飛鳥<span class="warichu">(東は字大林四三七<span class="notes">[#改行]</span>西は字神内一一一ノ一)</span><br />\r\n)
|
97
98
|
assert_equal expected, parsed
|
98
99
|
end
|
99
100
|
|
@@ -117,7 +118,7 @@ class CommandParseTest < Test::Unit::TestCase
|
|
117
118
|
Aozora2Html::Tag::EmbedGaiji.use_unicode = true
|
118
119
|
src = "紋附だとか[#「紋附だとか」は底本では「絞附だとか」]\r\n"
|
119
120
|
parsed = parse_text(src)
|
120
|
-
expected = %Q
|
121
|
+
expected = %Q(紋附だとか<span class="notes">[#「紋附だとか」は底本では「絞附だとか」]</span><br />\r\n)
|
121
122
|
assert_equal expected, parsed
|
122
123
|
end
|
123
124
|
|
@@ -125,7 +126,7 @@ class CommandParseTest < Test::Unit::TestCase
|
|
125
126
|
Aozora2Html::Tag::EmbedGaiji.use_unicode = true
|
126
127
|
src = "私は籠《ざる》[#ルビの「ざる」は底本では「さる」]をさげ\r\n"
|
127
128
|
parsed = parse_text(src)
|
128
|
-
expected = %Q
|
129
|
+
expected = %Q(私は<ruby><rb>籠</rb><rp>(</rp><rt>ざる</rt><rp>)</rp></ruby><span class="notes">[#ルビの「ざる」は底本では「さる」]</span>をさげ<br />\r\n)
|
129
130
|
assert_equal expected, parsed
|
130
131
|
end
|
131
132
|
|
@@ -133,7 +134,7 @@ class CommandParseTest < Test::Unit::TestCase
|
|
133
134
|
Aozora2Html::Tag::EmbedGaiji.use_unicode = true
|
134
135
|
src = "広場へに[#「広場へに」はママ]店でもだそう。\r\n"
|
135
136
|
parsed = parse_text(src)
|
136
|
-
expected = %Q
|
137
|
+
expected = %Q(広場へに<span class="notes">[#「広場へに」はママ]</span>店でもだそう。<br />\r\n)
|
137
138
|
assert_equal expected, parsed
|
138
139
|
end
|
139
140
|
|
@@ -141,7 +142,7 @@ class CommandParseTest < Test::Unit::TestCase
|
|
141
142
|
Aozora2Html::Tag::EmbedGaiji.use_unicode = true
|
142
143
|
src = "お湯《ゆう》[#ルビの「ゆう」はママ]\r\n"
|
143
144
|
parsed = parse_text(src)
|
144
|
-
expected = %Q
|
145
|
+
expected = %Q(お<ruby><rb>湯</rb><rp>(</rp><rt>ゆう</rt><rp>)</rp></ruby><span class="notes">[#ルビの「ゆう」はママ]</span><br />\r\n)
|
145
146
|
assert_equal expected, parsed
|
146
147
|
end
|
147
148
|
|
@@ -149,7 +150,7 @@ class CommandParseTest < Test::Unit::TestCase
|
|
149
150
|
Aozora2Html::Tag::EmbedGaiji.use_unicode = true
|
150
151
|
src = "米機B29[#「29」は縦中横]の編隊は、\r\n"
|
151
152
|
parsed = parse_text(src)
|
152
|
-
expected = %Q
|
153
|
+
expected = %Q(米機B<span dir="ltr">29</span>の編隊は、<br />\r\n)
|
153
154
|
assert_equal expected, parsed
|
154
155
|
end
|
155
156
|
|
@@ -165,7 +166,7 @@ class CommandParseTest < Test::Unit::TestCase
|
|
165
166
|
Aozora2Html::Tag::EmbedGaiji.use_unicode = true
|
166
167
|
src = "それ以上である。(5)[#「(5)」は行右小書き]\r\n"
|
167
168
|
parsed = parse_text(src)
|
168
|
-
expected = %Q
|
169
|
+
expected = %Q(それ以上である。<sup class="superscript">(5)</sup><br />\r\n)
|
169
170
|
assert_equal expected, parsed
|
170
171
|
end
|
171
172
|
|
@@ -173,7 +174,7 @@ class CommandParseTest < Test::Unit::TestCase
|
|
173
174
|
Aozora2Html::Tag::EmbedGaiji.use_unicode = true
|
174
175
|
src = "22[#「2」は上付き小文字]\r\n"
|
175
176
|
parsed = parse_text(src)
|
176
|
-
expected = %Q
|
177
|
+
expected = %Q(2<sup class="superscript">2</sup><br />\r\n)
|
177
178
|
assert_equal expected, parsed
|
178
179
|
end
|
179
180
|
|
@@ -181,7 +182,7 @@ class CommandParseTest < Test::Unit::TestCase
|
|
181
182
|
Aozora2Html::Tag::EmbedGaiji.use_unicode = true
|
182
183
|
src = "支部長の顔にさっと血が流れ[#「血が流れ」に「×」の傍記]た\r\n"
|
183
184
|
parsed = parse_text(src)
|
184
|
-
expected = %Q
|
185
|
+
expected = %Q(支部長の顔にさっと<ruby><rb>血が流れ</rb><rp>(</rp><rt>× × × ×</rt><rp>)</rp></ruby>た<br />\r\n)
|
185
186
|
assert_equal expected, parsed
|
186
187
|
end
|
187
188
|
|
@@ -189,21 +190,23 @@ class CommandParseTest < Test::Unit::TestCase
|
|
189
190
|
Aozora2Html::Tag::EmbedGaiji.use_unicode = true
|
190
191
|
src = "グリーンランドの中央部八千尺の氷河地帯にあるといわれる、[#横組み]“Ser-mik-Suah《セルミク・シュアー》”[#横組み終わり]の冥路《よみじ》の国。\r\n"
|
191
192
|
parsed = parse_text(src)
|
192
|
-
expected = %Q
|
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)
|
193
194
|
assert_equal expected, parsed
|
194
195
|
end
|
195
196
|
|
197
|
+
using Aozora2Html::StringRefinements
|
198
|
+
|
196
199
|
def parse_text(input_text)
|
197
|
-
input = StringIO.new(input_text.
|
200
|
+
input = StringIO.new(input_text.to_sjis)
|
198
201
|
output = StringIO.new
|
199
202
|
parser = Aozora2Html.new(input, output)
|
200
|
-
parser.instance_eval{@section
|
203
|
+
parser.instance_eval { @section = :tail }
|
201
204
|
catch(:terminate) do
|
202
205
|
loop do
|
203
|
-
parser.parse
|
206
|
+
parser.__send__(:parse)
|
204
207
|
end
|
205
208
|
end
|
206
|
-
output.string.
|
209
|
+
output.string.to_utf8
|
207
210
|
end
|
208
211
|
|
209
212
|
def teardown
|
data/test/test_compat.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
require 'aozora2html'
|
3
5
|
|
4
6
|
class CompatTest < Test::Unit::TestCase
|
5
7
|
def test_array_to_s
|
6
|
-
assert_equal
|
8
|
+
assert_equal 'abc', ['a', 'b', 'c'].join
|
7
9
|
end
|
8
10
|
end
|
9
|
-
|
10
|
-
|
11
|
-
|
@@ -1,27 +1,25 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'test_helper'
|
3
4
|
require 'aozora2html'
|
4
5
|
|
5
6
|
class DakutenKatakanaTagTest < Test::Unit::TestCase
|
6
7
|
def setup
|
7
8
|
@parser = Object.new
|
8
|
-
@
|
9
|
-
|
10
|
-
stub(@parser).block_allowed_context?{true}
|
9
|
+
@gaiji_dir = 'g_dir'
|
10
|
+
stub(@parser).block_allowed_context? { true }
|
11
11
|
end
|
12
12
|
|
13
|
+
using Aozora2Html::StringRefinements
|
14
|
+
|
13
15
|
def test_dakuten_katakana_new
|
14
|
-
tag = Aozora2Html::Tag::DakutenKatakana.new(@parser,1,
|
16
|
+
tag = Aozora2Html::Tag::DakutenKatakana.new(@parser, 1, 'ア'.to_sjis, gaiji_dir: @gaiji_dir)
|
15
17
|
assert_equal Aozora2Html::Tag::DakutenKatakana, tag.class
|
16
|
-
assert_equal true, tag.
|
18
|
+
assert_equal true, tag.is_a?(Aozora2Html::Tag::Inline)
|
17
19
|
end
|
18
20
|
|
19
21
|
def test_to_s
|
20
|
-
tag = Aozora2Html::Tag::DakutenKatakana.new(@parser,1,
|
21
|
-
assert_equal
|
22
|
-
end
|
23
|
-
|
24
|
-
def teardown
|
25
|
-
$gaiji_dir = @orig_gaiji_dir
|
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
|
26
24
|
end
|
27
25
|
end
|
data/test/test_decorate_tag.rb
CHANGED
@@ -1,22 +1,25 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'test_helper'
|
3
4
|
require 'aozora2html'
|
4
5
|
|
5
6
|
class DecorateTagTest < Test::Unit::TestCase
|
6
7
|
def setup
|
7
8
|
@parser = Object.new
|
8
|
-
stub(@parser).block_allowed_context?{true}
|
9
|
+
stub(@parser).block_allowed_context? { true }
|
9
10
|
end
|
10
11
|
|
11
12
|
def test_decorate_new
|
12
|
-
tag = Aozora2Html::Tag::Decorate.new(@parser,
|
13
|
+
tag = Aozora2Html::Tag::Decorate.new(@parser, 'aa', 1, :dai)
|
13
14
|
assert_equal Aozora2Html::Tag::Decorate, tag.class
|
14
|
-
assert_equal true, tag.
|
15
|
+
assert_equal true, tag.is_a?(Aozora2Html::Tag::Inline)
|
15
16
|
end
|
16
17
|
|
18
|
+
using Aozora2Html::StringRefinements
|
19
|
+
|
17
20
|
def test_to_s
|
18
|
-
tag = Aozora2Html::Tag::Decorate.new(@parser,
|
19
|
-
assert_equal
|
21
|
+
tag = Aozora2Html::Tag::Decorate.new(@parser, 'テスト'.to_sjis, 'foo', 'span')
|
22
|
+
assert_equal '<span class="foo">テスト</span>', tag.to_s.to_utf8
|
20
23
|
end
|
21
24
|
|
22
25
|
def teardown
|
data/test/test_dir_tag.rb
CHANGED
@@ -1,22 +1,25 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'test_helper'
|
3
4
|
require 'aozora2html'
|
4
5
|
|
5
6
|
class DirTagTest < Test::Unit::TestCase
|
6
7
|
def setup
|
7
8
|
@parser = Object.new
|
8
|
-
stub(@parser).block_allowed_context?{true}
|
9
|
+
stub(@parser).block_allowed_context? { true }
|
9
10
|
end
|
10
11
|
|
12
|
+
using Aozora2Html::StringRefinements
|
13
|
+
|
11
14
|
def test_dir_new
|
12
|
-
tag = Aozora2Html::Tag::Dir.new(@parser,
|
15
|
+
tag = Aozora2Html::Tag::Dir.new(@parser, 'テスト'.to_sjis)
|
13
16
|
assert_equal Aozora2Html::Tag::Dir, tag.class
|
14
|
-
assert_equal true, tag.
|
17
|
+
assert_equal true, tag.is_a?(Aozora2Html::Tag::Inline)
|
15
18
|
end
|
16
19
|
|
17
20
|
def test_to_s
|
18
|
-
tag = Aozora2Html::Tag::Dir.new(@parser,
|
19
|
-
assert_equal
|
21
|
+
tag = Aozora2Html::Tag::Dir.new(@parser, 'テスト'.to_sjis)
|
22
|
+
assert_equal '<span dir="ltr">テスト</span>', tag.to_s.to_utf8
|
20
23
|
end
|
21
24
|
|
22
25
|
def teardown
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'test_helper'
|
3
4
|
require 'aozora2html'
|
4
5
|
|
@@ -6,15 +7,17 @@ class EditorNoteTagTest < Test::Unit::TestCase
|
|
6
7
|
def setup
|
7
8
|
end
|
8
9
|
|
10
|
+
using Aozora2Html::StringRefinements
|
11
|
+
|
9
12
|
def test_editor_note_new
|
10
|
-
tag = Aozora2Html::Tag::EditorNote.new(nil,
|
13
|
+
tag = Aozora2Html::Tag::EditorNote.new(nil, '注記のテスト'.to_sjis)
|
11
14
|
assert_equal Aozora2Html::Tag::EditorNote, tag.class
|
12
|
-
assert_equal true, tag.
|
15
|
+
assert_equal true, tag.is_a?(Aozora2Html::Tag::Inline)
|
13
16
|
end
|
14
17
|
|
15
18
|
def test_to_s
|
16
|
-
tag = Aozora2Html::Tag::EditorNote.new(nil,
|
17
|
-
assert_equal
|
19
|
+
tag = Aozora2Html::Tag::EditorNote.new(nil, '注記のテスト'.to_sjis)
|
20
|
+
assert_equal '<span class="notes">[#注記のテスト]</span>', tag.to_s.to_utf8
|
18
21
|
end
|
19
22
|
|
20
23
|
def teardown
|
data/test/test_exception.rb
CHANGED
@@ -1,23 +1,25 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'test_helper'
|
3
4
|
require 'aozora2html'
|
4
5
|
|
5
6
|
class ExceptionTest < Test::Unit::TestCase
|
6
7
|
def test_raise_aozora_exception
|
7
8
|
assert_raises(Aozora2Html::Error) do
|
8
|
-
raise Aozora2Html::Error,
|
9
|
+
raise Aozora2Html::Error, 'error!'
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
13
|
+
using Aozora2Html::StringRefinements
|
14
|
+
|
12
15
|
def test_raise_aozora_error
|
13
|
-
error_msg =
|
16
|
+
error_msg = ''
|
14
17
|
begin
|
15
|
-
raise Aozora2Html::Error,
|
16
|
-
rescue Aozora2Html::Error =>
|
17
|
-
error_msg =
|
18
|
+
raise Aozora2Html::Error, 'sample error'
|
19
|
+
rescue Aozora2Html::Error => e
|
20
|
+
error_msg = e.message(123)
|
18
21
|
end
|
19
22
|
assert_equal "エラー(123行目):sample error. \r\n処理を停止します",
|
20
|
-
error_msg.
|
21
|
-
|
23
|
+
error_msg.to_utf8
|
22
24
|
end
|
23
25
|
end
|
data/test/test_font_size_tag.rb
CHANGED
@@ -1,38 +1,41 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'test_helper'
|
3
4
|
require 'aozora2html'
|
4
5
|
|
5
6
|
class FontSizeTagTest < Test::Unit::TestCase
|
6
7
|
def setup
|
7
8
|
@parser = Object.new
|
8
|
-
stub(@parser).block_allowed_context?{true}
|
9
|
+
stub(@parser).block_allowed_context? { true }
|
9
10
|
end
|
10
11
|
|
11
12
|
def test_font_size_new
|
12
|
-
tag = Aozora2Html::Tag::FontSize.new(@parser,1
|
13
|
+
tag = Aozora2Html::Tag::FontSize.new(@parser, 1, :dai)
|
13
14
|
assert_equal Aozora2Html::Tag::FontSize, tag.class
|
14
|
-
assert_equal true, tag.
|
15
|
-
assert_equal true, tag.
|
15
|
+
assert_equal true, tag.is_a?(Aozora2Html::Tag::Block)
|
16
|
+
assert_equal true, tag.is_a?(Aozora2Html::Tag::Multiline)
|
16
17
|
end
|
17
18
|
|
19
|
+
using Aozora2Html::StringRefinements
|
20
|
+
|
18
21
|
def test_to_s
|
19
|
-
tag = Aozora2Html::Tag::FontSize.new(@parser,1
|
20
|
-
assert_equal
|
22
|
+
tag = Aozora2Html::Tag::FontSize.new(@parser, 1, :dai)
|
23
|
+
assert_equal '<div class="dai1" style="font-size: large;">', tag.to_s.to_utf8
|
21
24
|
end
|
22
25
|
|
23
26
|
def test_to_s2
|
24
|
-
tag = Aozora2Html::Tag::FontSize.new(@parser,2
|
25
|
-
assert_equal
|
27
|
+
tag = Aozora2Html::Tag::FontSize.new(@parser, 2, :dai)
|
28
|
+
assert_equal '<div class="dai2" style="font-size: x-large;">', tag.to_s.to_utf8
|
26
29
|
end
|
27
30
|
|
28
31
|
def test_to_s3
|
29
|
-
tag = Aozora2Html::Tag::FontSize.new(@parser,3
|
30
|
-
assert_equal
|
32
|
+
tag = Aozora2Html::Tag::FontSize.new(@parser, 3, :sho)
|
33
|
+
assert_equal '<div class="sho3" style="font-size: xx-small;">', tag.to_s.to_utf8
|
31
34
|
end
|
32
35
|
|
33
36
|
def test_to_s0
|
34
|
-
assert_raise(Aozora2Html::Error.new(
|
35
|
-
_tag = Aozora2Html::Tag::FontSize.new(@parser,0
|
37
|
+
assert_raise(Aozora2Html::Error.new('文字サイズの指定が不正です'.to_sjis)) do
|
38
|
+
_tag = Aozora2Html::Tag::FontSize.new(@parser, 0, :sho)
|
36
39
|
end
|
37
40
|
end
|
38
41
|
|
data/test/test_gaiji_tag.rb
CHANGED
@@ -1,49 +1,50 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'test_helper'
|
3
4
|
require 'aozora2html'
|
4
5
|
|
5
6
|
class EmbedGaijiTagTest < Test::Unit::TestCase
|
6
7
|
def setup
|
7
|
-
@
|
8
|
-
$gaiji_dir = "g_dir/"
|
8
|
+
@gaiji_dir = 'g_dir/'
|
9
9
|
end
|
10
10
|
|
11
|
+
using Aozora2Html::StringRefinements
|
12
|
+
|
11
13
|
def test_gaiji_new
|
12
|
-
egt = Aozora2Html::Tag::EmbedGaiji.new(nil,
|
13
|
-
assert_equal
|
14
|
+
egt = Aozora2Html::Tag::EmbedGaiji.new(nil, 'foo', '1-2-3', 'name', gaiji_dir: @gaiji_dir)
|
15
|
+
assert_equal '<img src="g_dir/foo/1-2-3.png" alt="※(name)" class="gaiji" />', egt.to_s.to_utf8
|
14
16
|
end
|
15
17
|
|
16
18
|
def test_unembed_gaiji_new
|
17
|
-
egt = Aozora2Html::Tag::UnEmbedGaiji.new(nil,
|
18
|
-
assert_equal
|
19
|
+
egt = Aozora2Html::Tag::UnEmbedGaiji.new(nil, 'テストtest'.to_sjis)
|
20
|
+
assert_equal '<span class="notes">[テストtest]</span>', egt.to_s.to_utf8
|
19
21
|
end
|
20
22
|
|
21
23
|
def test_espcaed?
|
22
|
-
egt = Aozora2Html::Tag::UnEmbedGaiji.new(nil,
|
24
|
+
egt = Aozora2Html::Tag::UnEmbedGaiji.new(nil, 'テストtest'.to_sjis)
|
23
25
|
assert_equal false, egt.escaped?
|
24
26
|
end
|
25
27
|
|
26
28
|
def test_espcae!
|
27
|
-
egt = Aozora2Html::Tag::UnEmbedGaiji.new(nil,
|
29
|
+
egt = Aozora2Html::Tag::UnEmbedGaiji.new(nil, 'テストtest'.to_sjis)
|
28
30
|
egt.escape!
|
29
31
|
assert_equal true, egt.escaped?
|
30
32
|
end
|
31
33
|
|
32
34
|
def test_jisx0213
|
33
35
|
Aozora2Html::Tag::EmbedGaiji.use_jisx0213 = true
|
34
|
-
egt = Aozora2Html::Tag::EmbedGaiji.new(nil,
|
35
|
-
assert_equal
|
36
|
+
egt = Aozora2Html::Tag::EmbedGaiji.new(nil, 'foo', '1-06-75', 'snowman', gaiji_dir: @gaiji_dir)
|
37
|
+
assert_equal '☃', egt.to_s.to_utf8
|
36
38
|
end
|
37
39
|
|
38
40
|
def test_use_unicode
|
39
41
|
Aozora2Html::Tag::EmbedGaiji.use_unicode = true
|
40
|
-
egt = Aozora2Html::Tag::EmbedGaiji.new(nil,
|
41
|
-
assert_equal
|
42
|
+
egt = Aozora2Html::Tag::EmbedGaiji.new(nil, 'foo', '1-06-75', 'snowman', '2603', gaiji_dir: @gaiji_dir)
|
43
|
+
assert_equal '☃', egt.to_s.to_utf8
|
42
44
|
end
|
43
45
|
|
44
46
|
def teardown
|
45
47
|
Aozora2Html::Tag::EmbedGaiji.use_jisx0213 = false
|
46
48
|
Aozora2Html::Tag::EmbedGaiji.use_unicode = false
|
47
|
-
$gaiji_dir = @orig_gaiji_dir
|
48
49
|
end
|
49
50
|
end
|
data/test/test_header.rb
CHANGED
@@ -1,60 +1,45 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'test_helper'
|
3
4
|
require 'aozora2html'
|
4
5
|
|
5
6
|
class HeaderTest < Test::Unit::TestCase
|
6
7
|
def setup
|
7
|
-
@header = Aozora2Html::Header.new
|
8
|
+
@header = Aozora2Html::Header.new(css_files: Array['../../aozora.css'])
|
8
9
|
end
|
9
10
|
|
11
|
+
using Aozora2Html::StringRefinements
|
12
|
+
|
10
13
|
def test_header_to_html
|
11
|
-
@header.push(
|
12
|
-
@header.push(
|
13
|
-
actual = @header.to_html.
|
14
|
+
@header.push('武装せる市街'.to_sjis)
|
15
|
+
@header.push('黒島伝治'.to_sjis)
|
16
|
+
actual = @header.to_html.to_utf8
|
17
|
+
|
18
|
+
# rubocop:disable Layout/LineLength
|
14
19
|
expected =
|
15
|
-
"<?xml version=\"1.0\" encoding=\"Shift_JIS\"?>\r\n"
|
16
|
-
|
17
|
-
|
18
|
-
"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"ja\" >\r\n" +
|
19
|
-
"<head>\r\n" +
|
20
|
-
"\t<meta http-equiv=\"Content-Type\" content=\"text/html;charset=Shift_JIS\" />\r\n" +
|
21
|
-
"\t<meta http-equiv=\"content-style-type\" content=\"text/css\" />\r\n" +
|
22
|
-
"\t<link rel=\"stylesheet\" type=\"text/css\" href=\"../../aozora.css\" />\r\n" +
|
23
|
-
"\t<title>黒島伝治 武装せる市街</title>\r\n" +
|
24
|
-
"\t<script type=\"text/javascript\" src=\"../../jquery-1.4.2.min.js\"></script>\r\n" +
|
25
|
-
" <link rel=\"Schema.DC\" href=\"http://purl.org/dc/elements/1.1/\" />\r\n" +
|
26
|
-
"\t<meta name=\"DC.Title\" content=\"武装せる市街\" />\r\n" +
|
27
|
-
"\t<meta name=\"DC.Creator\" content=\"黒島伝治\" />\r\n" +
|
28
|
-
"\t<meta name=\"DC.Publisher\" content=\"青空文庫\" />\r\n" +
|
29
|
-
"</head>\r\n" +
|
30
|
-
"<body>\r\n" +
|
31
|
-
"<div class=\"metadata\">\r\n" +
|
32
|
-
"<h1 class=\"title\">武装せる市街</h1>\r\n" +
|
33
|
-
"<h2 class=\"author\">黒島伝治</h2>\r\n" +
|
34
|
-
"<br />\r\n" +
|
35
|
-
"<br />\r\n" +
|
36
|
-
"</div>\r\n" +
|
37
|
-
"<div id=\"contents\" style=\"display:none\"></div><div class=\"main_text\">"
|
20
|
+
"<?xml version=\"1.0\" encoding=\"Shift_JIS\"?>\r\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\r\n \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"ja\" >\r\n<head>\r\n\t<meta http-equiv=\"Content-Type\" content=\"text/html;charset=Shift_JIS\" />\r\n\t<meta http-equiv=\"content-style-type\" content=\"text/css\" />\r\n\t<link rel=\"stylesheet\" type=\"text/css\" href=\"../../aozora.css\" />\r\n\t<title>黒島伝治 武装せる市街</title>\r\n\t<script type=\"text/javascript\" src=\"../../jquery-1.4.2.min.js\"></script>\r\n <link rel=\"Schema.DC\" href=\"http://purl.org/dc/elements/1.1/\" />\r\n\t<meta name=\"DC.Title\" content=\"武装せる市街\" />\r\n\t<meta name=\"DC.Creator\" content=\"黒島伝治\" />\r\n\t<meta name=\"DC.Publisher\" content=\"青空文庫\" />\r\n</head>\r\n<body>\r\n<div class=\"metadata\">\r\n<h1 class=\"title\">武装せる市街</h1>\r\n<h2 class=\"author\">黒島伝治</h2>\r\n<br />\r\n<br />\r\n</div>\r\n<div id=\"contents\" style=\"display:none\"></div><div class=\"main_text\">"
|
21
|
+
# rubocop:enable Layout/LineLength
|
22
|
+
|
38
23
|
assert_equal(expected, actual)
|
39
24
|
end
|
40
25
|
|
41
26
|
def test_build_title
|
42
|
-
@header.push(
|
43
|
-
@header.push(
|
44
|
-
header_info = @header.build_header_info
|
45
|
-
actual = @header.build_title(header_info).
|
46
|
-
expected =
|
27
|
+
@header.push('武装せる市街'.to_sjis)
|
28
|
+
@header.push('黒島伝治'.to_sjis)
|
29
|
+
header_info = @header.build_header_info
|
30
|
+
actual = @header.build_title(header_info).to_utf8
|
31
|
+
expected = '<title>黒島伝治 武装せる市街</title>'
|
47
32
|
assert_equal(expected, actual)
|
48
33
|
end
|
49
34
|
|
50
35
|
def test_build_title2
|
51
|
-
@header.push(
|
52
|
-
@header.push(
|
53
|
-
@header.push(
|
54
|
-
@header.push(
|
55
|
-
header_info = @header.build_header_info
|
56
|
-
actual = @header.build_title(header_info).
|
57
|
-
expected =
|
36
|
+
@header.push('スリーピー・ホローの伝説'.to_sjis)
|
37
|
+
@header.push('故ディードリッヒ・ニッカボッカーの遺稿より'.to_sjis)
|
38
|
+
@header.push('ワシントン・アーヴィング Washington Irving'.to_sjis)
|
39
|
+
@header.push('吉田甲子太郎訳'.to_sjis)
|
40
|
+
header_info = @header.build_header_info
|
41
|
+
actual = @header.build_title(header_info).to_utf8
|
42
|
+
expected = '<title>ワシントン・アーヴィング Washington Irving 吉田甲子太郎訳 スリーピー・ホローの伝説 故ディードリッヒ・ニッカボッカーの遺稿より</title>'
|
58
43
|
assert_equal(expected, actual)
|
59
44
|
end
|
60
45
|
end
|
data/test/test_helper.rb
CHANGED
data/test/test_i18n.rb
CHANGED
@@ -1,21 +1,37 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'test_helper'
|
3
4
|
require 'aozora2html'
|
4
5
|
|
5
6
|
class I18nTest < Test::Unit::TestCase
|
7
|
+
using Aozora2Html::StringRefinements
|
8
|
+
|
6
9
|
def test_t
|
7
|
-
|
10
|
+
assert_equal '警告(123行目):JIS外字「①」が使われています',
|
11
|
+
Aozora2Html::I18n.t(:warn_jis_gaiji,
|
12
|
+
123,
|
13
|
+
'①'.encode('cp932').force_encoding('shift_jis'))
|
14
|
+
.force_encoding('cp932').to_utf8
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_error_utf8
|
18
|
+
orig_value = Aozora2Html::I18n.use_utf8
|
19
|
+
Aozora2Html::I18n.use_utf8 = true
|
20
|
+
begin
|
21
|
+
assert_equal '警告(123行目):JIS外字「①」が使われています',
|
8
22
|
Aozora2Html::I18n.t(:warn_jis_gaiji,
|
9
23
|
123,
|
10
|
-
|
11
|
-
|
24
|
+
'①'.encode('cp932').force_encoding('shift_jis'))
|
25
|
+
ensure
|
26
|
+
Aozora2Html::I18n.use_utf8 = orig_value
|
27
|
+
end
|
12
28
|
end
|
13
29
|
|
14
30
|
def test_ruby_puts_behavior
|
15
31
|
$stdout = StringIO.new
|
16
32
|
begin
|
17
|
-
puts
|
18
|
-
assert_equal "①\n", $stdout.string.force_encoding(
|
33
|
+
puts '①'.encode('cp932').force_encoding('shift_jis')
|
34
|
+
assert_equal "①\n", $stdout.string.force_encoding('cp932').to_utf8
|
19
35
|
ensure
|
20
36
|
$stdout = STDOUT
|
21
37
|
end
|