aozora2html 2.0.0 → 3.0.1
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 +5 -3
- data/.gitignore +1 -0
- data/.rubocop.yml +38 -151
- data/.rubocop_todo.yml +7 -0
- data/CHANGELOG.md +41 -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 +25 -23
- 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/midashi_counter.rb +32 -0
- 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 +1329 -3
- data/lib/extensions.rb +2 -34
- data/lib/jstream.rb +96 -25
- data/sample/chukiichiran_kinyurei.html +42 -29
- data/sample/chukiichiran_kinyurei.txt +16 -3
- metadata +80 -83
- data/.travis.yml +0 -12
- data/lib/t2hs.rb +0 -1607
- data/test/test_aozora2html.rb +0 -379
- data/test/test_aozora_accent_parser.rb +0 -31
- data/test/test_command_parse.rb +0 -213
- data/test/test_compat.rb +0 -11
- data/test/test_dakuten_katakana_tag.rb +0 -27
- data/test/test_decorate_tag.rb +0 -24
- data/test/test_dir_tag.rb +0 -24
- data/test/test_editor_note_tag.rb +0 -22
- data/test/test_exception.rb +0 -23
- data/test/test_font_size_tag.rb +0 -41
- data/test/test_gaiji_tag.rb +0 -49
- data/test/test_header.rb +0 -60
- data/test/test_helper.rb +0 -5
- data/test/test_i18n.rb +0 -23
- data/test/test_img_tag.rb +0 -23
- data/test/test_inline_caption_tag.rb +0 -24
- data/test/test_inline_font_size_tag.rb +0 -34
- data/test/test_inline_keigakomi_tag.rb +0 -24
- data/test/test_inline_yokogumi_tag.rb +0 -24
- data/test/test_jizume_tag.rb +0 -25
- data/test/test_jstream.rb +0 -57
- data/test/test_kaeriten_tag.rb +0 -24
- data/test/test_keigakomi_tag.rb +0 -31
- data/test/test_midashi_tag.rb +0 -38
- data/test/test_multiline_caption_tag.rb +0 -25
- data/test/test_multiline_midashi_tag.rb +0 -55
- data/test/test_multiline_style_tag.rb +0 -25
- data/test/test_multiline_yokogumi_tag.rb +0 -25
- data/test/test_okurigana_tag.rb +0 -24
- data/test/test_ruby_parse.rb +0 -130
- data/test/test_ruby_tag.rb +0 -24
- data/test/test_tag_parser.rb +0 -80
data/test/test_dir_tag.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'test_helper'
|
3
|
-
require 'aozora2html'
|
4
|
-
|
5
|
-
class DirTagTest < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
@parser = Object.new
|
8
|
-
stub(@parser).block_allowed_context?{true}
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_dir_new
|
12
|
-
tag = Aozora2Html::Tag::Dir.new(@parser,"テスト".encode("shift_jis"))
|
13
|
-
assert_equal Aozora2Html::Tag::Dir, tag.class
|
14
|
-
assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_to_s
|
18
|
-
tag = Aozora2Html::Tag::Dir.new(@parser,"テスト".encode("shift_jis"))
|
19
|
-
assert_equal "<span dir=\"ltr\">テスト</span>", tag.to_s.encode("utf-8")
|
20
|
-
end
|
21
|
-
|
22
|
-
def teardown
|
23
|
-
end
|
24
|
-
end
|
@@ -1,22 +0,0 @@
|
|
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 = Aozora2Html::Tag::EditorNote.new(nil,"注記のテスト".encode("shift_jis"))
|
11
|
-
assert_equal Aozora2Html::Tag::EditorNote, tag.class
|
12
|
-
assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_to_s
|
16
|
-
tag = Aozora2Html::Tag::EditorNote.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
|
data/test/test_exception.rb
DELETED
@@ -1,23 +0,0 @@
|
|
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(Aozora2Html::Error) do
|
8
|
-
raise Aozora2Html::Error, "error!"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_raise_aozora_error
|
13
|
-
error_msg = ""
|
14
|
-
begin
|
15
|
-
raise Aozora2Html::Error, "sample error"
|
16
|
-
rescue Aozora2Html::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
|
data/test/test_font_size_tag.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# -*- coding:utf-8 -*-
|
2
|
-
require 'test_helper'
|
3
|
-
require 'aozora2html'
|
4
|
-
|
5
|
-
class FontSizeTagTest < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
@parser = Object.new
|
8
|
-
stub(@parser).block_allowed_context?{true}
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_font_size_new
|
12
|
-
tag = Aozora2Html::Tag::FontSize.new(@parser,1,:dai)
|
13
|
-
assert_equal Aozora2Html::Tag::FontSize, tag.class
|
14
|
-
assert_equal true, tag.kind_of?(Aozora2Html::Tag::Block)
|
15
|
-
assert_equal true, tag.kind_of?(Aozora2Html::Tag::Multiline)
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_to_s
|
19
|
-
tag = Aozora2Html::Tag::FontSize.new(@parser,1,:dai)
|
20
|
-
assert_equal "<div class=\"dai1\" style=\"font-size: large;\">", tag.to_s.encode("utf-8")
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_to_s2
|
24
|
-
tag = Aozora2Html::Tag::FontSize.new(@parser,2,:dai)
|
25
|
-
assert_equal "<div class=\"dai2\" style=\"font-size: x-large;\">", tag.to_s.encode("utf-8")
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_to_s3
|
29
|
-
tag = Aozora2Html::Tag::FontSize.new(@parser,3,:sho)
|
30
|
-
assert_equal "<div class=\"sho3\" style=\"font-size: xx-small;\">", tag.to_s.encode("utf-8")
|
31
|
-
end
|
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
|
-
|
39
|
-
def teardown
|
40
|
-
end
|
41
|
-
end
|
data/test/test_gaiji_tag.rb
DELETED
@@ -1,49 +0,0 @@
|
|
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 = Aozora2Html::Tag::EmbedGaiji.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 = Aozora2Html::Tag::UnEmbedGaiji.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 = Aozora2Html::Tag::UnEmbedGaiji.new(nil,"テストtest".encode("Shift_JIS"))
|
23
|
-
assert_equal false, egt.escaped?
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_espcae!
|
27
|
-
egt = Aozora2Html::Tag::UnEmbedGaiji.new(nil,"テストtest".encode("Shift_JIS"))
|
28
|
-
egt.escape!
|
29
|
-
assert_equal true, egt.escaped?
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_jisx0213
|
33
|
-
Aozora2Html::Tag::EmbedGaiji.use_jisx0213 = true
|
34
|
-
egt = Aozora2Html::Tag::EmbedGaiji.new(nil,"foo","1-06-75","snowman")
|
35
|
-
assert_equal "☃", egt.to_s.encode("utf-8")
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_use_unicode
|
39
|
-
Aozora2Html::Tag::EmbedGaiji.use_unicode = true
|
40
|
-
egt = Aozora2Html::Tag::EmbedGaiji.new(nil,"foo","1-06-75","snowman","2603")
|
41
|
-
assert_equal "☃", egt.to_s.encode("utf-8")
|
42
|
-
end
|
43
|
-
|
44
|
-
def teardown
|
45
|
-
Aozora2Html::Tag::EmbedGaiji.use_jisx0213 = false
|
46
|
-
Aozora2Html::Tag::EmbedGaiji.use_unicode = false
|
47
|
-
$gaiji_dir = @orig_gaiji_dir
|
48
|
-
end
|
49
|
-
end
|
data/test/test_header.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'test_helper'
|
3
|
-
require 'aozora2html'
|
4
|
-
|
5
|
-
class HeaderTest < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
@header = Aozora2Html::Header.new
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_header_to_html
|
11
|
-
@header.push("武装せる市街".encode("shift_jis"))
|
12
|
-
@header.push("黒島伝治".encode("shift_jis"))
|
13
|
-
actual = @header.to_html.encode("utf-8")
|
14
|
-
expected =
|
15
|
-
"<?xml version=\"1.0\" encoding=\"Shift_JIS\"?>\r\n" +
|
16
|
-
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\r\n" +
|
17
|
-
" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\r\n" +
|
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\">"
|
38
|
-
assert_equal(expected, actual)
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_build_title
|
42
|
-
@header.push("武装せる市街".encode("shift_jis"))
|
43
|
-
@header.push("黒島伝治".encode("shift_jis"))
|
44
|
-
header_info = @header.build_header_info()
|
45
|
-
actual = @header.build_title(header_info).encode("utf-8")
|
46
|
-
expected = "<title>黒島伝治 武装せる市街</title>"
|
47
|
-
assert_equal(expected, actual)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_build_title2
|
51
|
-
@header.push("スリーピー・ホローの伝説".encode("shift_jis"))
|
52
|
-
@header.push("故ディードリッヒ・ニッカボッカーの遺稿より".encode("shift_jis"))
|
53
|
-
@header.push("ワシントン・アーヴィング Washington Irving".encode("shift_jis"))
|
54
|
-
@header.push("吉田甲子太郎訳".encode("shift_jis"))
|
55
|
-
header_info = @header.build_header_info()
|
56
|
-
actual = @header.build_title(header_info).encode("utf-8")
|
57
|
-
expected = "<title>ワシントン・アーヴィング Washington Irving 吉田甲子太郎訳 スリーピー・ホローの伝説 故ディードリッヒ・ニッカボッカーの遺稿より</title>"
|
58
|
-
assert_equal(expected, actual)
|
59
|
-
end
|
60
|
-
end
|
data/test/test_helper.rb
DELETED
data/test/test_i18n.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'test_helper'
|
3
|
-
require 'aozora2html'
|
4
|
-
|
5
|
-
class I18nTest < Test::Unit::TestCase
|
6
|
-
def test_t
|
7
|
-
assert_equal "警告(123行目):JIS外字「①」が使われています",
|
8
|
-
Aozora2Html::I18n.t(:warn_jis_gaiji,
|
9
|
-
123,
|
10
|
-
"①".encode("cp932").force_encoding("shift_jis"))
|
11
|
-
.force_encoding("cp932").encode("utf-8")
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_ruby_puts_behavior
|
15
|
-
$stdout = StringIO.new
|
16
|
-
begin
|
17
|
-
puts "①".encode("cp932").force_encoding("shift_jis")
|
18
|
-
assert_equal "①\n", $stdout.string.force_encoding("cp932").encode("utf-8")
|
19
|
-
ensure
|
20
|
-
$stdout = STDOUT
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/test/test_img_tag.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'aozora2html'
|
3
|
-
|
4
|
-
class ImgTagTest < Test::Unit::TestCase
|
5
|
-
def setup
|
6
|
-
@parser = Object.new
|
7
|
-
stub(@parser).block_allowed_context?{true}
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_img_new
|
11
|
-
tag = Aozora2Html::Tag::Img.new(@parser,"foo.png","img1","alt img1",40,50)
|
12
|
-
assert_equal Aozora2Html::Tag::Img, tag.class
|
13
|
-
assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_to_s
|
17
|
-
tag = Aozora2Html::Tag::Img.new(@parser,"foo.png","img1","alt img1",40,50)
|
18
|
-
assert_equal "<img class=\"img1\" width=\"40\" height=\"50\" src=\"foo.png\" alt=\"alt img1\" />", tag.to_s.encode("utf-8")
|
19
|
-
end
|
20
|
-
|
21
|
-
def teardown
|
22
|
-
end
|
23
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'test_helper'
|
3
|
-
require 'aozora2html'
|
4
|
-
|
5
|
-
class InlineCaptionTagTest < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
@parser = Object.new
|
8
|
-
stub(@parser).block_allowed_context?{true}
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_caption_new
|
12
|
-
tag = Aozora2Html::Tag::InlineCaption.new(@parser,"aaa")
|
13
|
-
assert_equal Aozora2Html::Tag::InlineCaption, tag.class
|
14
|
-
assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_to_s
|
18
|
-
tag = Aozora2Html::Tag::InlineCaption.new(@parser,"テスト".encode("shift_jis"))
|
19
|
-
assert_equal "<span class=\"caption\">テスト</span>", tag.to_s.encode("utf-8")
|
20
|
-
end
|
21
|
-
|
22
|
-
def teardown
|
23
|
-
end
|
24
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'test_helper'
|
3
|
-
require 'aozora2html'
|
4
|
-
|
5
|
-
class InlineFontSizeTagTest < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
@parser = Object.new
|
8
|
-
stub(@parser).block_allowed_context?{true}
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_font_size_new
|
12
|
-
tag = Aozora2Html::Tag::InlineFontSize.new(@parser,"aa",1,:dai)
|
13
|
-
assert_equal Aozora2Html::Tag::InlineFontSize, tag.class
|
14
|
-
assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_to_s
|
18
|
-
tag = Aozora2Html::Tag::InlineFontSize.new(@parser,"テスト".encode("shift_jis"),1,:dai)
|
19
|
-
assert_equal "<span class=\"dai1\" style=\"font-size: large;\">テスト</span>", tag.to_s.encode("utf-8")
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_to_s2
|
23
|
-
tag = Aozora2Html::Tag::InlineFontSize.new(@parser,"テスト".encode("shift_jis"),2,:sho)
|
24
|
-
assert_equal "<span class=\"sho2\" style=\"font-size: x-small;\">テスト</span>", tag.to_s.encode("utf-8")
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_to_s3
|
28
|
-
tag = Aozora2Html::Tag::InlineFontSize.new(@parser,"テスト".encode("shift_jis"),3,:sho)
|
29
|
-
assert_equal "<span class=\"sho3\" style=\"font-size: xx-small;\">テスト</span>", tag.to_s.encode("utf-8")
|
30
|
-
end
|
31
|
-
|
32
|
-
def teardown
|
33
|
-
end
|
34
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'test_helper'
|
3
|
-
require 'aozora2html'
|
4
|
-
|
5
|
-
class InlineKeigakomiTagTest < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
@parser = Object.new
|
8
|
-
stub(@parser).block_allowed_context?{true}
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_keigakomi_new
|
12
|
-
tag = Aozora2Html::Tag::InlineKeigakomi.new(@parser,"aaa")
|
13
|
-
assert_equal Aozora2Html::Tag::InlineKeigakomi, tag.class
|
14
|
-
assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_to_s
|
18
|
-
tag = Aozora2Html::Tag::InlineKeigakomi.new(@parser,"テスト".encode("shift_jis"))
|
19
|
-
assert_equal "<span class=\"keigakomi\">テスト</span>", tag.to_s.encode("utf-8")
|
20
|
-
end
|
21
|
-
|
22
|
-
def teardown
|
23
|
-
end
|
24
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'test_helper'
|
3
|
-
require 'aozora2html'
|
4
|
-
|
5
|
-
class InlineYokogumiTagTest < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
@parser = Object.new
|
8
|
-
stub(@parser).block_allowed_context?{true}
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_yokogumi_new
|
12
|
-
tag = Aozora2Html::Tag::InlineYokogumi.new(@parser,"aaa")
|
13
|
-
assert_equal Aozora2Html::Tag::InlineYokogumi, tag.class
|
14
|
-
assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_to_s
|
18
|
-
tag = Aozora2Html::Tag::InlineYokogumi.new(@parser,"テスト".encode("shift_jis"))
|
19
|
-
assert_equal "<span class=\"yokogumi\">テスト</span>", tag.to_s.encode("utf-8")
|
20
|
-
end
|
21
|
-
|
22
|
-
def teardown
|
23
|
-
end
|
24
|
-
end
|
data/test/test_jizume_tag.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'aozora2html'
|
3
|
-
|
4
|
-
class JizumeTagTest < Test::Unit::TestCase
|
5
|
-
def setup
|
6
|
-
@parser = Object.new
|
7
|
-
stub(@parser).block_allowed_context?{true}
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_jizume_new
|
11
|
-
tag = Aozora2Html::Tag::Jizume.new(@parser,50)
|
12
|
-
assert_equal Aozora2Html::Tag::Jizume, tag.class
|
13
|
-
assert_equal true, tag.kind_of?(Aozora2Html::Tag::Block)
|
14
|
-
assert_equal true, tag.kind_of?(Aozora2Html::Tag::Multiline)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_to_s
|
18
|
-
tag = Aozora2Html::Tag::Jizume.new(@parser,50)
|
19
|
-
assert_equal "<div class=\"jizume_50\" style=\"width: 50em\">", tag.to_s
|
20
|
-
assert_equal "</div>", tag.close_tag
|
21
|
-
end
|
22
|
-
|
23
|
-
def teardown
|
24
|
-
end
|
25
|
-
end
|
data/test/test_jstream.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'test_helper'
|
3
|
-
require 'aozora2html'
|
4
|
-
require 'stringio'
|
5
|
-
|
6
|
-
class JstreamTest < Test::Unit::TestCase
|
7
|
-
def test_new_error
|
8
|
-
strio = StringIO.new("aaa\nbbb\n")
|
9
|
-
orig_stdout = $stdout
|
10
|
-
out = StringIO.new
|
11
|
-
$stdout = out
|
12
|
-
assert_raises(SystemExit) do
|
13
|
-
Jstream.new(strio)
|
14
|
-
end
|
15
|
-
$stdout = orig_stdout
|
16
|
-
assert_equal "エラー(1行目):改行コードを、「CR+LF」にあらためてください. \r\n処理を停止します\n", out.string.encode("utf-8")
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_read_char
|
20
|
-
strio = StringIO.new("aあ5\r\n%\\b\r\n".encode("Shift_JIS"))
|
21
|
-
stm = Jstream.new(strio)
|
22
|
-
assert_equal "a", stm.read_char.encode("utf-8")
|
23
|
-
assert_equal "あ", stm.read_char.encode("utf-8")
|
24
|
-
assert_equal "5", stm.read_char.encode("utf-8")
|
25
|
-
assert_equal "\r\n", stm.read_char.encode("utf-8")
|
26
|
-
assert_equal "%", stm.read_char.encode("utf-8")
|
27
|
-
assert_equal "\\", stm.read_char.encode("utf-8")
|
28
|
-
assert_equal "b", stm.read_char.encode("utf-8")
|
29
|
-
assert_equal "\r\n", stm.read_char.encode("utf-8")
|
30
|
-
assert_equal :eof, stm.read_char
|
31
|
-
assert_equal "\r\n", stm.read_char # :eof以降は正しい値を保証しない
|
32
|
-
assert_equal :eof, stm.read_char # 何度もread_charすると:eofが複数回出る
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_peek_char
|
36
|
-
strio = StringIO.new("aあ5\r\n%\\b\r\n".encode("Shift_JIS"))
|
37
|
-
stm = Jstream.new(strio)
|
38
|
-
assert_equal "a", stm.peek_char(0).encode("utf-8")
|
39
|
-
assert_equal "あ", stm.peek_char(1).encode("utf-8")
|
40
|
-
assert_equal "5", stm.peek_char(2).encode("utf-8")
|
41
|
-
assert_equal "\r\n", stm.peek_char(3).encode("utf-8")
|
42
|
-
assert_equal "\r\n", stm.peek_char(4).encode("utf-8") # 改行文字以降は正しい値を保証しない
|
43
|
-
assert_equal "\r\n", stm.peek_char(5).encode("utf-8") # 同上
|
44
|
-
assert_equal "\r\n", stm.peek_char(100).encode("utf-8") # 同上
|
45
|
-
assert_equal "a", stm.read_char.encode("utf-8")
|
46
|
-
|
47
|
-
assert_equal "あ", stm.peek_char(0).encode("utf-8")
|
48
|
-
assert_equal "あ", stm.read_char.encode("utf-8")
|
49
|
-
assert_equal "5", stm.read_char.encode("utf-8")
|
50
|
-
assert_equal "\r\n", stm.read_char.encode("utf-8")
|
51
|
-
|
52
|
-
assert_equal "%", stm.peek_char(0).encode("utf-8")
|
53
|
-
assert_equal "\\", stm.peek_char(1).encode("utf-8")
|
54
|
-
assert_equal "b", stm.peek_char(2).encode("utf-8")
|
55
|
-
assert_equal "\r\n", stm.peek_char(3).encode("utf-8")
|
56
|
-
end
|
57
|
-
end
|
data/test/test_kaeriten_tag.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'test_helper'
|
3
|
-
require 'aozora2html'
|
4
|
-
|
5
|
-
class KaeritenTagTest < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
@parser = Object.new
|
8
|
-
stub(@parser).block_allowed_context?{true}
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_kaeriten_new
|
12
|
-
tag = Aozora2Html::Tag::Kaeriten.new(@parser,"aaa")
|
13
|
-
assert_equal Aozora2Html::Tag::Kaeriten, tag.class
|
14
|
-
assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_to_s
|
18
|
-
tag = Aozora2Html::Tag::Kaeriten.new(@parser,"テスト".encode("shift_jis"))
|
19
|
-
assert_equal "<sub class=\"kaeriten\">テスト</sub>", tag.to_s.encode("utf-8")
|
20
|
-
end
|
21
|
-
|
22
|
-
def teardown
|
23
|
-
end
|
24
|
-
end
|
data/test/test_keigakomi_tag.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'aozora2html'
|
3
|
-
|
4
|
-
class KeigakomiTagTest < Test::Unit::TestCase
|
5
|
-
def setup
|
6
|
-
@parser = Object.new
|
7
|
-
stub(@parser).block_allowed_context?{true}
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_keigakomi_new
|
11
|
-
tag = Aozora2Html::Tag::Keigakomi.new(@parser,2)
|
12
|
-
assert_equal Aozora2Html::Tag::Keigakomi, tag.class
|
13
|
-
assert_equal true, tag.kind_of?(Aozora2Html::Tag::Block)
|
14
|
-
assert_equal true, tag.kind_of?(Aozora2Html::Tag::Multiline)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_to_s
|
18
|
-
tag = Aozora2Html::Tag::Keigakomi.new(@parser)
|
19
|
-
assert_equal "<div class=\"keigakomi\" style=\"border: solid 1px\">", tag.to_s
|
20
|
-
assert_equal "</div>", tag.close_tag
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_to_s2
|
24
|
-
tag = Aozora2Html::Tag::Keigakomi.new(@parser,2)
|
25
|
-
assert_equal "<div class=\"keigakomi\" style=\"border: solid 2px\">", tag.to_s
|
26
|
-
assert_equal "</div>", tag.close_tag
|
27
|
-
end
|
28
|
-
|
29
|
-
def teardown
|
30
|
-
end
|
31
|
-
end
|
data/test/test_midashi_tag.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'test_helper'
|
3
|
-
require 'aozora2html'
|
4
|
-
|
5
|
-
class MidashiTagTest < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
@parser = Object.new
|
8
|
-
stub(@parser).block_allowed_context?{true}
|
9
|
-
stub(@parser).new_midashi_id{2}
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_midashi_new
|
13
|
-
tag = Aozora2Html::Tag::Midashi.new(@parser, "テスト見出し".encode("shift_jis"), "小".encode("shift_jis"), :normal)
|
14
|
-
assert_equal Aozora2Html::Tag::Midashi, tag.class
|
15
|
-
assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_to_s
|
19
|
-
tag = Aozora2Html::Tag::Midashi.new(@parser, "テスト見出し".encode("shift_jis"), "小".encode("shift_jis"), :normal)
|
20
|
-
assert_equal "<h5 class=\"ko-midashi\"><a class=\"midashi_anchor\" id=\"midashi2\">"+"テスト見出し".encode("shift_jis")+"</a></h5>", tag.to_s
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_to_s_mado
|
24
|
-
tag = Aozora2Html::Tag::Midashi.new(@parser, "テスト見出し".encode("shift_jis"), "小".encode("shift_jis"), :mado)
|
25
|
-
assert_equal "<h5 class=\"mado-ko-midashi\"><a class=\"midashi_anchor\" id=\"midashi2\">"+"テスト見出し".encode("shift_jis")+"</a></h5>", tag.to_s
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_undeined_midashi
|
29
|
-
begin
|
30
|
-
Aozora2Html::Tag::Midashi.new(@parser, "テスト見出し".encode("shift_jis"), "あ".encode("shift_jis"), :normal)
|
31
|
-
rescue Aozora2Html::Error => e
|
32
|
-
assert_equal e.message(123).encode("utf-8"), "エラー(123行目):未定義な見出しです. \r\n処理を停止します"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def teardown
|
37
|
-
end
|
38
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'aozora2html'
|
3
|
-
|
4
|
-
class MultilineCaptionTagTest < Test::Unit::TestCase
|
5
|
-
def setup
|
6
|
-
@parser = Object.new
|
7
|
-
stub(@parser).block_allowed_context?{true}
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_multiline_caption_new
|
11
|
-
tag = Aozora2Html::Tag::MultilineCaption.new(@parser)
|
12
|
-
assert_equal Aozora2Html::Tag::MultilineCaption, tag.class
|
13
|
-
assert_equal true, tag.kind_of?(Aozora2Html::Tag::Block)
|
14
|
-
assert_equal true, tag.kind_of?(Aozora2Html::Tag::Multiline)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_to_s
|
18
|
-
tag = Aozora2Html::Tag::MultilineCaption.new(@parser)
|
19
|
-
assert_equal "<div class=\"caption\">", tag.to_s
|
20
|
-
assert_equal "</div>", tag.close_tag
|
21
|
-
end
|
22
|
-
|
23
|
-
def teardown
|
24
|
-
end
|
25
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'test_helper'
|
3
|
-
require 'aozora2html'
|
4
|
-
|
5
|
-
class MultilineMidashiTagTest < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
@parser = Object.new
|
8
|
-
stub(@parser).block_allowed_context?{true}
|
9
|
-
stub(@parser).new_midashi_id{2}
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_multiline_midashi_new
|
13
|
-
tag = Aozora2Html::Tag::MultilineMidashi.new(@parser,"小".encode("shift_jis"),:normal)
|
14
|
-
assert_equal Aozora2Html::Tag::MultilineMidashi, tag.class
|
15
|
-
assert_equal true, tag.kind_of?(Aozora2Html::Tag::Block)
|
16
|
-
assert_equal true, tag.kind_of?(Aozora2Html::Tag::Multiline)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_to_s
|
20
|
-
tag = Aozora2Html::Tag::MultilineMidashi.new(@parser,"小".encode("shift_jis"),:normal)
|
21
|
-
assert_equal "<h5 class=\"ko-midashi\"><a class=\"midashi_anchor\" id=\"midashi2\">", tag.to_s
|
22
|
-
assert_equal "</a></h5>", tag.close_tag
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_to_s_chu
|
26
|
-
tag = Aozora2Html::Tag::MultilineMidashi.new(@parser,"中".encode("shift_jis"),:dogyo)
|
27
|
-
assert_equal "<h4 class=\"dogyo-naka-midashi\"><a class=\"midashi_anchor\" id=\"midashi2\">", tag.to_s
|
28
|
-
assert_equal "</a></h4>", tag.close_tag
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_to_s_dai
|
32
|
-
tag = Aozora2Html::Tag::MultilineMidashi.new(@parser,"大".encode("shift_jis"),:mado)
|
33
|
-
assert_equal "<h3 class=\"mado-o-midashi\"><a class=\"midashi_anchor\" id=\"midashi2\">", tag.to_s
|
34
|
-
assert_equal "</a></h3>", tag.close_tag
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_undeined_midashi
|
38
|
-
begin
|
39
|
-
Aozora2Html::Tag::MultilineMidashi.new(@parser,"あ".encode("shift_jis"),:mado)
|
40
|
-
rescue Aozora2Html::Error => e
|
41
|
-
assert_equal e.message(123).encode("utf-8"), "エラー(123行目):未定義な見出しです. \r\n処理を停止します"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_undeined_midashi2
|
46
|
-
begin
|
47
|
-
Aozora2Html::Tag::MultilineMidashi.new(@parser,"大".encode("shift_jis"),:madoo)
|
48
|
-
rescue Aozora2Html::Error => e
|
49
|
-
assert_equal e.message(123).encode("utf-8"), "エラー(123行目):未定義な見出しです. \r\n処理を停止します"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def teardown
|
54
|
-
end
|
55
|
-
end
|