aozora2html 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/Guardfile +21 -0
- data/README.md +49 -0
- data/Rakefile +12 -0
- data/aozora2html.gemspec +32 -0
- data/bin/aozora2html +44 -0
- data/lib/aozora2html.rb +6 -0
- data/lib/aozora2html/version.rb +3 -0
- data/lib/t2hs.rb +2529 -0
- data/sample/chukiichiran_kinyurei.html +1078 -0
- data/sample/chukiichiran_kinyurei.txt +1034 -0
- data/test/test_aozora2html.rb +88 -0
- data/test/test_aozora_accent_parser.rb +20 -0
- data/test/test_compat.rb +11 -0
- data/test/test_dakuten_katakana_tag.rb +26 -0
- data/test/test_decorate_tag.rb +23 -0
- data/test/test_dir_tag.rb +23 -0
- data/test/test_editor_note_tag.rb +22 -0
- data/test/test_exception.rb +23 -0
- data/test/test_font_size_tag.rb +33 -0
- data/test/test_gaiji_tag.rb +35 -0
- data/test/test_helper.rb +5 -0
- data/test/test_img_tag.rb +22 -0
- data/test/test_inline_caption_tag.rb +23 -0
- data/test/test_inline_font_size_tag.rb +33 -0
- data/test/test_inline_keigakomi_tag.rb +23 -0
- data/test/test_inline_yokogumi_tag.rb +23 -0
- data/test/test_jizume_tag.rb +24 -0
- data/test/test_jstream.rb +57 -0
- data/test/test_kaeriten_tag.rb +23 -0
- data/test/test_keigakomi_tag.rb +30 -0
- data/test/test_multiline_caption_tag.rb +24 -0
- data/test/test_multiline_midashi_tag.rb +38 -0
- data/test/test_multiline_style_tag.rb +24 -0
- data/test/test_multiline_yokogumi_tag.rb +24 -0
- data/test/test_okurigana_tag.rb +23 -0
- data/test/test_ruby_tag.rb +23 -0
- metadata +197 -0
@@ -0,0 +1,88 @@
|
|
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
|
+
end
|
10
|
+
|
11
|
+
def test_aozora2html_new
|
12
|
+
Dir.mktmpdir do |dir|
|
13
|
+
input = File.join(dir,'dummy.txt')
|
14
|
+
output = File.join(dir,'dummy2.txt')
|
15
|
+
File.write(input, "テスト\r\n")
|
16
|
+
parser = Aozora2Html.new(input, output)
|
17
|
+
|
18
|
+
assert_equal Aozora2Html, parser.class
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_scount
|
23
|
+
Dir.mktmpdir do |dir|
|
24
|
+
input = File.join(dir,'dummy.txt')
|
25
|
+
output = File.join(dir,'dummy2.txt')
|
26
|
+
File.write(input, "a\r\nb\r\nc\r\n")
|
27
|
+
parser = Aozora2Html.new(input, output)
|
28
|
+
|
29
|
+
assert_equal 0, parser.scount
|
30
|
+
ch = parser.read_char
|
31
|
+
assert_equal "a",ch
|
32
|
+
assert_equal 1, parser.scount
|
33
|
+
ch = parser.read_char
|
34
|
+
assert_equal "\r\n",ch
|
35
|
+
assert_equal 1, parser.scount
|
36
|
+
ch = parser.read_char
|
37
|
+
assert_equal "b",ch
|
38
|
+
assert_equal 2, parser.scount
|
39
|
+
ch = parser.read_char
|
40
|
+
assert_equal "\r\n",ch
|
41
|
+
assert_equal 2, parser.scount
|
42
|
+
ch = parser.read_char
|
43
|
+
assert_equal "c",ch
|
44
|
+
assert_equal 3, parser.scount
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_read_line
|
49
|
+
Dir.mktmpdir do |dir|
|
50
|
+
input = File.join(dir,'dummy.txt')
|
51
|
+
output = File.join(dir,'dummy2.txt')
|
52
|
+
File.write(input, "ab\r\nc\r\n")
|
53
|
+
parser = Aozora2Html.new(input, output)
|
54
|
+
|
55
|
+
parsed = parser.read_line
|
56
|
+
assert_equal "ab", parsed
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_char_type
|
61
|
+
Dir.mktmpdir do |dir|
|
62
|
+
input = File.join(dir,'dummy.txt')
|
63
|
+
output = File.join(dir,'dummy2.txt')
|
64
|
+
File.write(input, "ab\r\nc\r\n")
|
65
|
+
parser = Aozora2Html.new(input, output)
|
66
|
+
|
67
|
+
assert_equal :kanji, parser.char_type(Embed_Gaiji_tag.new(nil,"foo","1-2-3","name"))
|
68
|
+
assert_equal :kanji, parser.char_type(UnEmbed_Gaiji_tag.new(nil,"foo"))
|
69
|
+
assert_equal :hankaku, parser.char_type(Accent_tag.new(nil,123,"abc"))
|
70
|
+
assert_equal :else, parser.char_type(Okurigana_tag.new(nil,"abc"))
|
71
|
+
assert_equal :else, parser.char_type(Inline_keigakomi_tag.new(nil,"abc"))
|
72
|
+
assert_equal :katakana, parser.char_type(Dakuten_katakana_tag.new(nil,1,"abc"))
|
73
|
+
|
74
|
+
assert_equal :hiragana, parser.char_type("あ".encode("shift_jis"))
|
75
|
+
assert_equal :hiragana, parser.char_type("っ".encode("shift_jis"))
|
76
|
+
assert_equal :katakana, parser.char_type("ヴ".encode("shift_jis"))
|
77
|
+
assert_equal :katakana, parser.char_type("ー".encode("shift_jis"))
|
78
|
+
assert_equal :zenkaku, parser.char_type("w".encode("shift_jis"))
|
79
|
+
assert_equal :hankaku, parser.char_type("z".encode("shift_jis"))
|
80
|
+
assert_equal :kanji, parser.char_type("漢".encode("shift_jis"))
|
81
|
+
assert_equal :hankaku_terminate, parser.char_type("!".encode("shift_jis"))
|
82
|
+
assert_equal :else, parser.char_type("?".encode("shift_jis"))
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def teardown
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
require 'aozora2html'
|
4
|
+
|
5
|
+
class Aozora2HtmlTest < 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 = Aozora_accent_parser.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 teardown
|
19
|
+
end
|
20
|
+
end
|
data/test/test_compat.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
require 'aozora2html'
|
4
|
+
|
5
|
+
class DakutenKatakanaTagTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@orig_gaiji_dir = $gaiji_dir
|
8
|
+
$gaiji_dir = "g_dir"
|
9
|
+
stub(@parser).block_allowed_context?{true}
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_dakuten_katakana_new
|
13
|
+
tag = Dakuten_katakana_tag.new(@parser,1,"ア".encode("shift_jis"))
|
14
|
+
assert_equal Dakuten_katakana_tag, tag.class
|
15
|
+
assert_equal true, tag.kind_of?(Inline_tag)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_to_s
|
19
|
+
tag = Dakuten_katakana_tag.new(@parser,1,"ア".encode("shift_jis"))
|
20
|
+
assert_equal "<img src=\"g_dir/1-07/1-07-81.png\" alt=\"※(濁点付き片仮名「ア」、1-07-81)\" class=\"gaiji\" />", tag.to_s.encode("utf-8")
|
21
|
+
end
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
$gaiji_dir = @orig_gaiji_dir
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
require 'aozora2html'
|
4
|
+
|
5
|
+
class DecorateTagTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
stub(@parser).block_allowed_context?{true}
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_decorate_new
|
11
|
+
tag = Decorate_tag.new(@parser,"aa",1,:dai)
|
12
|
+
assert_equal Decorate_tag, tag.class
|
13
|
+
assert_equal true, tag.kind_of?(Inline_tag)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_to_s
|
17
|
+
tag = Decorate_tag.new(@parser,"テスト".encode("shift_jis"),"foo","span")
|
18
|
+
assert_equal "<span class=\"foo\">テスト</span>", tag.to_s.encode("utf-8")
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
require 'aozora2html'
|
4
|
+
|
5
|
+
class DirTagTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
stub(@parser).block_allowed_context?{true}
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_dir_new
|
11
|
+
tag = Dir_tag.new(@parser,"テスト".encode("shift_jis"))
|
12
|
+
assert_equal Dir_tag, tag.class
|
13
|
+
assert_equal true, tag.kind_of?(Inline_tag)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_to_s
|
17
|
+
tag = Dir_tag.new(@parser,"テスト".encode("shift_jis"))
|
18
|
+
assert_equal "<span dir=\"ltr\">テスト</span>", tag.to_s.encode("utf-8")
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
require 'aozora2html'
|
4
|
+
|
5
|
+
class EditorNoteTagTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_editor_note_new
|
10
|
+
tag = Editor_note_tag.new(nil,"注記のテスト".encode("shift_jis"))
|
11
|
+
assert_equal Editor_note_tag, tag.class
|
12
|
+
assert_equal true, tag.kind_of?(Inline_tag)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_to_s
|
16
|
+
tag = Editor_note_tag.new(nil,"注記のテスト".encode("shift_jis"))
|
17
|
+
assert_equal "<span class=\"notes\">[#注記のテスト]</span>", tag.to_s.encode("utf-8")
|
18
|
+
end
|
19
|
+
|
20
|
+
def teardown
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
require 'aozora2html'
|
4
|
+
|
5
|
+
class ExceptionTest < Test::Unit::TestCase
|
6
|
+
def test_raise_aozora_exception
|
7
|
+
assert_raises(Aozora_Exception) do
|
8
|
+
raise Aozora_Exception, "error!"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_raise_aozora_error
|
13
|
+
error_msg = ""
|
14
|
+
begin
|
15
|
+
raise Aozora_Error, "sample error"
|
16
|
+
rescue Aozora_Error => msg
|
17
|
+
error_msg = msg.message(123)
|
18
|
+
end
|
19
|
+
assert_equal "エラー(123行目):sample error. \r\n処理を停止します",
|
20
|
+
error_msg.encode("utf-8")
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'aozora2html'
|
3
|
+
|
4
|
+
class FontSizeTagTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
stub(@parser).block_allowed_context?{true}
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_font_size_new
|
10
|
+
tag = Font_size_tag.new(@parser,1,:dai)
|
11
|
+
assert_equal Font_size_tag, tag.class
|
12
|
+
assert_equal true, tag.kind_of?(Block_tag)
|
13
|
+
assert_equal true, tag.kind_of?(Multiline_tag)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_to_s
|
17
|
+
tag = Font_size_tag.new(@parser,1,:dai)
|
18
|
+
assert_equal "<div class=\"dai1\" style=\"font-size: large;\">", tag.to_s.encode("utf-8")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_to_s2
|
22
|
+
tag = Font_size_tag.new(@parser,2,:dai)
|
23
|
+
assert_equal "<div class=\"dai2\" style=\"font-size: x-large;\">", tag.to_s.encode("utf-8")
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_to_s3
|
27
|
+
tag = Font_size_tag.new(@parser,3,:sho)
|
28
|
+
assert_equal "<div class=\"sho3\" style=\"font-size: xx-small;\">", tag.to_s.encode("utf-8")
|
29
|
+
end
|
30
|
+
|
31
|
+
def teardown
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
require 'aozora2html'
|
4
|
+
|
5
|
+
class EmbedGaijiTagTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@orig_gaiji_dir = $gaiji_dir
|
8
|
+
$gaiji_dir = "g_dir/"
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_gaiji_new
|
12
|
+
egt = Embed_Gaiji_tag.new(nil,"foo","1-2-3","name")
|
13
|
+
assert_equal "<img src=\"g_dir/foo/1-2-3.png\" alt=\"※(name)\" class=\"gaiji\" />", egt.to_s.encode("utf-8")
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_unembed_gaiji_new
|
17
|
+
egt = UnEmbed_Gaiji_tag.new(nil,"テストtest".encode("Shift_JIS"))
|
18
|
+
assert_equal "<span class=\"notes\">[テストtest]</span>", egt.to_s.encode("utf-8")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_espcaed?
|
22
|
+
egt = UnEmbed_Gaiji_tag.new(nil,"テストtest".encode("Shift_JIS"))
|
23
|
+
assert_equal false, egt.escaped?
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_espcae!
|
27
|
+
egt = UnEmbed_Gaiji_tag.new(nil,"テストtest".encode("Shift_JIS"))
|
28
|
+
egt.escape!
|
29
|
+
assert_equal true, egt.escaped?
|
30
|
+
end
|
31
|
+
|
32
|
+
def teardown
|
33
|
+
$gaiji_dir = @orig_gaiji_dir
|
34
|
+
end
|
35
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'aozora2html'
|
3
|
+
|
4
|
+
class ImgTagTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
stub(@parser).block_allowed_context?{true}
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_img_new
|
10
|
+
tag = Img_tag.new(@parser,"foo.png","img1","alt img1",40,50)
|
11
|
+
assert_equal Img_tag, tag.class
|
12
|
+
assert_equal true, tag.kind_of?(Inline_tag)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_to_s
|
16
|
+
tag = Img_tag.new(@parser,"foo.png","img1","alt img1",40,50)
|
17
|
+
assert_equal "<img class=\"img1\" width=\"40\" height=\"50\" src=\"foo.png\" alt=\"alt img1\" />", tag.to_s.encode("utf-8")
|
18
|
+
end
|
19
|
+
|
20
|
+
def teardown
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
require 'aozora2html'
|
4
|
+
|
5
|
+
class InlineCaptionTagTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
stub(@parser).block_allowed_context?{true}
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_caption_new
|
11
|
+
tag = Inline_caption_tag.new(@parser,"aaa")
|
12
|
+
assert_equal Inline_caption_tag, tag.class
|
13
|
+
assert_equal true, tag.kind_of?(Inline_tag)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_to_s
|
17
|
+
tag = Inline_caption_tag.new(@parser,"テスト".encode("shift_jis"))
|
18
|
+
assert_equal "<span class=\"caption\">テスト</span>", tag.to_s.encode("utf-8")
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
require 'aozora2html'
|
4
|
+
|
5
|
+
class InlineFontSizeTagTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
stub(@parser).block_allowed_context?{true}
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_font_size_new
|
11
|
+
tag = Inline_font_size_tag.new(@parser,"aa",1,:dai)
|
12
|
+
assert_equal Inline_font_size_tag, tag.class
|
13
|
+
assert_equal true, tag.kind_of?(Inline_tag)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_to_s
|
17
|
+
tag = Inline_font_size_tag.new(@parser,"テスト".encode("shift_jis"),1,:dai)
|
18
|
+
assert_equal "<span class=\"dai1\" style=\"font-size: large;\">テスト</span>", tag.to_s.encode("utf-8")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_to_s2
|
22
|
+
tag = Inline_font_size_tag.new(@parser,"テスト".encode("shift_jis"),2,:sho)
|
23
|
+
assert_equal "<span class=\"sho2\" style=\"font-size: x-small;\">テスト</span>", tag.to_s.encode("utf-8")
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_to_s3
|
27
|
+
tag = Inline_font_size_tag.new(@parser,"テスト".encode("shift_jis"),3,:sho)
|
28
|
+
assert_equal "<span class=\"sho3\" style=\"font-size: xx-small;\">テスト</span>", tag.to_s.encode("utf-8")
|
29
|
+
end
|
30
|
+
|
31
|
+
def teardown
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
require 'aozora2html'
|
4
|
+
|
5
|
+
class InlineKeigakomiTagTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
stub(@parser).block_allowed_context?{true}
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_keigakomi_new
|
11
|
+
tag = Inline_keigakomi_tag.new(@parser,"aaa")
|
12
|
+
assert_equal Inline_keigakomi_tag, tag.class
|
13
|
+
assert_equal true, tag.kind_of?(Inline_tag)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_to_s
|
17
|
+
tag = Inline_keigakomi_tag.new(@parser,"テスト".encode("shift_jis"))
|
18
|
+
assert_equal "<span class=\"keigakomi\">テスト</span>", tag.to_s.encode("utf-8")
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
require 'aozora2html'
|
4
|
+
|
5
|
+
class InlineYokogumiTagTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
stub(@parser).block_allowed_context?{true}
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_yokogumi_new
|
11
|
+
tag = Inline_yokogumi_tag.new(@parser,"aaa")
|
12
|
+
assert_equal Inline_yokogumi_tag, tag.class
|
13
|
+
assert_equal true, tag.kind_of?(Inline_tag)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_to_s
|
17
|
+
tag = Inline_yokogumi_tag.new(@parser,"テスト".encode("shift_jis"))
|
18
|
+
assert_equal "<span class=\"yokogumi\">テスト</span>", tag.to_s.encode("utf-8")
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown
|
22
|
+
end
|
23
|
+
end
|