aozora2html 0.7.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/rubocop.yml +19 -0
  3. data/.github/workflows/ruby.yml +37 -0
  4. data/.gitignore +8 -3
  5. data/.rubocop.yml +111 -0
  6. data/.rubocop_todo.yml +7 -0
  7. data/CHANGELOG.md +59 -0
  8. data/Gemfile +2 -0
  9. data/Guardfile +3 -1
  10. data/HACKING.md +45 -0
  11. data/LICENSE +116 -0
  12. data/README.md +29 -16
  13. data/Rakefile +12 -5
  14. data/aozora2html.gemspec +24 -24
  15. data/bin/aozora2html +25 -71
  16. data/lib/aozora2html/accent_parser.rb +99 -0
  17. data/lib/aozora2html/error.rb +17 -0
  18. data/lib/aozora2html/header.rb +141 -0
  19. data/lib/aozora2html/i18n.rb +48 -0
  20. data/lib/aozora2html/ruby_buffer.rb +116 -0
  21. data/lib/aozora2html/string_refinements.rb +36 -0
  22. data/lib/aozora2html/style_stack.rb +33 -0
  23. data/lib/aozora2html/tag/accent.rb +37 -0
  24. data/lib/aozora2html/tag/block.rb +21 -0
  25. data/lib/aozora2html/tag/chitsuki.rb +19 -0
  26. data/lib/aozora2html/tag/dakuten_katakana.rb +25 -0
  27. data/lib/aozora2html/tag/decorate.rb +19 -0
  28. data/lib/aozora2html/tag/dir.rb +17 -0
  29. data/lib/aozora2html/tag/editor_note.rb +19 -0
  30. data/lib/aozora2html/tag/embed_gaiji.rb +52 -0
  31. data/lib/aozora2html/tag/font_size.rb +20 -0
  32. data/lib/aozora2html/tag/gaiji.rb +12 -0
  33. data/lib/aozora2html/tag/img.rb +21 -0
  34. data/lib/aozora2html/tag/indent.rb +8 -0
  35. data/lib/aozora2html/tag/inline.rb +16 -0
  36. data/lib/aozora2html/tag/inline_caption.rb +17 -0
  37. data/lib/aozora2html/tag/inline_font_size.rb +19 -0
  38. data/lib/aozora2html/tag/inline_keigakomi.rb +17 -0
  39. data/lib/aozora2html/tag/inline_yokogumi.rb +17 -0
  40. data/lib/aozora2html/tag/jisage.rb +17 -0
  41. data/lib/aozora2html/tag/jizume.rb +19 -0
  42. data/lib/aozora2html/tag/kaeriten.rb +17 -0
  43. data/lib/aozora2html/tag/keigakomi.rb +19 -0
  44. data/lib/aozora2html/tag/kunten.rb +12 -0
  45. data/lib/aozora2html/tag/midashi.rb +20 -0
  46. data/lib/aozora2html/tag/multiline.rb +9 -0
  47. data/lib/aozora2html/tag/multiline_caption.rb +13 -0
  48. data/lib/aozora2html/tag/multiline_chitsuki.rb +10 -0
  49. data/lib/aozora2html/tag/multiline_jisage.rb +10 -0
  50. data/lib/aozora2html/tag/multiline_midashi.rb +25 -0
  51. data/lib/aozora2html/tag/multiline_style.rb +19 -0
  52. data/lib/aozora2html/tag/multiline_yokogumi.rb +14 -0
  53. data/lib/aozora2html/tag/okurigana.rb +17 -0
  54. data/lib/aozora2html/tag/oneline_chitsuki.rb +10 -0
  55. data/lib/aozora2html/tag/oneline_indent.rb +9 -0
  56. data/lib/aozora2html/tag/oneline_jisage.rb +10 -0
  57. data/lib/aozora2html/tag/reference_mentioned.rb +47 -0
  58. data/lib/aozora2html/tag/ruby.rb +202 -0
  59. data/lib/aozora2html/tag/un_embed_gaiji.rb +30 -0
  60. data/lib/aozora2html/tag.rb +57 -0
  61. data/lib/aozora2html/tag_parser.rb +60 -0
  62. data/lib/aozora2html/text_buffer.rb +50 -0
  63. data/lib/aozora2html/utils.rb +156 -0
  64. data/lib/aozora2html/version.rb +3 -1
  65. data/lib/aozora2html/yaml_loader.rb +37 -0
  66. data/lib/aozora2html/zip.rb +4 -0
  67. data/lib/aozora2html.rb +1359 -8
  68. data/lib/extensions.rb +12 -0
  69. data/lib/jstream.rb +139 -0
  70. data/sample/chukiichiran_kinyurei.html +15 -2
  71. data/sample/chukiichiran_kinyurei.txt +15 -2
  72. data/test/test_aozora2html.rb +323 -73
  73. data/test/test_aozora_accent_parser.rb +34 -6
  74. data/test/test_command_parse.rb +216 -0
  75. data/test/test_compat.rb +3 -4
  76. data/test/test_dakuten_katakana_tag.rb +12 -13
  77. data/test/test_decorate_tag.rb +11 -7
  78. data/test/test_dir_tag.rb +11 -7
  79. data/test/test_editor_note_tag.rb +9 -6
  80. data/test/test_exception.rb +11 -9
  81. data/test/test_font_size_tag.rb +22 -11
  82. data/test/test_gaiji_tag.rb +22 -14
  83. data/test/test_header.rb +45 -0
  84. data/test/test_helper.rb +3 -1
  85. data/test/test_i18n.rb +39 -0
  86. data/test/test_img_tag.rb +11 -6
  87. data/test/test_inline_caption_tag.rb +11 -7
  88. data/test/test_inline_font_size_tag.rb +15 -11
  89. data/test/test_inline_keigakomi_tag.rb +11 -7
  90. data/test/test_inline_yokogumi_tag.rb +11 -7
  91. data/test/test_jizume_tag.rb +11 -8
  92. data/test/test_jstream.rb +33 -30
  93. data/test/test_kaeriten_tag.rb +11 -7
  94. data/test/test_keigakomi_tag.rb +14 -11
  95. data/test/test_midashi_tag.rb +39 -0
  96. data/test/test_multiline_caption_tag.rb +11 -8
  97. data/test/test_multiline_midashi_tag.rb +26 -26
  98. data/test/test_multiline_style_tag.rb +11 -8
  99. data/test/test_multiline_yokogumi_tag.rb +11 -8
  100. data/test/test_okurigana_tag.rb +11 -7
  101. data/test/test_ruby_parse.rb +130 -0
  102. data/test/test_ruby_tag.rb +11 -7
  103. data/test/test_tag_parser.rb +31 -29
  104. data/vendor/jis2ucs/README.md +3 -6
  105. data/yml/accent_table.yml +240 -0
  106. data/yml/command_table.yml +61 -0
  107. data/yml/jis2ucs.yml +11234 -0
  108. metadata +99 -21
  109. data/.travis.yml +0 -12
  110. data/appveyor.yml +0 -23
  111. data/lib/accent_tag.rb +0 -23
  112. data/lib/aozora2html/jis2ucs.rb +0 -11237
  113. data/lib/embed_gaiji_tag.rb +0 -34
  114. data/lib/t2hs.rb +0 -2535
@@ -1,21 +1,25 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
  require 'aozora2html'
4
5
 
5
6
  class InlineCaptionTagTest < Test::Unit::TestCase
6
7
  def setup
7
- stub(@parser).block_allowed_context?{true}
8
+ @parser = Object.new
9
+ stub(@parser).block_allowed_context? { true }
8
10
  end
9
11
 
10
12
  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)
13
+ tag = Aozora2Html::Tag::InlineCaption.new(@parser, 'aaa')
14
+ assert_equal Aozora2Html::Tag::InlineCaption, tag.class
15
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Inline)
14
16
  end
15
17
 
18
+ using Aozora2Html::StringRefinements
19
+
16
20
  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")
21
+ tag = Aozora2Html::Tag::InlineCaption.new(@parser, 'テスト'.to_sjis)
22
+ assert_equal '<span class="caption">テスト</span>', tag.to_s.to_utf8
19
23
  end
20
24
 
21
25
  def teardown
@@ -1,31 +1,35 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
  require 'aozora2html'
4
5
 
5
6
  class InlineFontSizeTagTest < Test::Unit::TestCase
6
7
  def setup
7
- stub(@parser).block_allowed_context?{true}
8
+ @parser = Object.new
9
+ stub(@parser).block_allowed_context? { true }
8
10
  end
9
11
 
10
12
  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)
13
+ tag = Aozora2Html::Tag::InlineFontSize.new(@parser, 'aa', 1, :dai)
14
+ assert_equal Aozora2Html::Tag::InlineFontSize, tag.class
15
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Inline)
14
16
  end
15
17
 
18
+ using Aozora2Html::StringRefinements
19
+
16
20
  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")
21
+ tag = Aozora2Html::Tag::InlineFontSize.new(@parser, 'テスト'.to_sjis, 1, :dai)
22
+ assert_equal '<span class="dai1" style="font-size: large;">テスト</span>', tag.to_s.to_utf8
19
23
  end
20
24
 
21
25
  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")
26
+ tag = Aozora2Html::Tag::InlineFontSize.new(@parser, 'テスト'.to_sjis, 2, :sho)
27
+ assert_equal '<span class="sho2" style="font-size: x-small;">テスト</span>', tag.to_s.to_utf8
24
28
  end
25
29
 
26
30
  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")
31
+ tag = Aozora2Html::Tag::InlineFontSize.new(@parser, 'テスト'.to_sjis, 3, :sho)
32
+ assert_equal '<span class="sho3" style="font-size: xx-small;">テスト</span>', tag.to_s.to_utf8
29
33
  end
30
34
 
31
35
  def teardown
@@ -1,21 +1,25 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
  require 'aozora2html'
4
5
 
5
6
  class InlineKeigakomiTagTest < Test::Unit::TestCase
6
7
  def setup
7
- stub(@parser).block_allowed_context?{true}
8
+ @parser = Object.new
9
+ stub(@parser).block_allowed_context? { true }
8
10
  end
9
11
 
10
12
  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)
13
+ tag = Aozora2Html::Tag::InlineKeigakomi.new(@parser, 'aaa')
14
+ assert_equal Aozora2Html::Tag::InlineKeigakomi, tag.class
15
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Inline)
14
16
  end
15
17
 
18
+ using Aozora2Html::StringRefinements
19
+
16
20
  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")
21
+ tag = Aozora2Html::Tag::InlineKeigakomi.new(@parser, 'テスト'.to_sjis)
22
+ assert_equal '<span class="keigakomi">テスト</span>', tag.to_s.to_utf8
19
23
  end
20
24
 
21
25
  def teardown
@@ -1,21 +1,25 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
  require 'aozora2html'
4
5
 
5
6
  class InlineYokogumiTagTest < Test::Unit::TestCase
6
7
  def setup
7
- stub(@parser).block_allowed_context?{true}
8
+ @parser = Object.new
9
+ stub(@parser).block_allowed_context? { true }
8
10
  end
9
11
 
10
12
  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)
13
+ tag = Aozora2Html::Tag::InlineYokogumi.new(@parser, 'aaa')
14
+ assert_equal Aozora2Html::Tag::InlineYokogumi, tag.class
15
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Inline)
14
16
  end
15
17
 
18
+ using Aozora2Html::StringRefinements
19
+
16
20
  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")
21
+ tag = Aozora2Html::Tag::InlineYokogumi.new(@parser, 'テスト'.to_sjis)
22
+ assert_equal '<span class="yokogumi">テスト</span>', tag.to_s.to_utf8
19
23
  end
20
24
 
21
25
  def teardown
@@ -1,22 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
  require 'aozora2html'
3
5
 
4
6
  class JizumeTagTest < Test::Unit::TestCase
5
7
  def setup
6
- stub(@parser).block_allowed_context?{true}
8
+ @parser = Object.new
9
+ stub(@parser).block_allowed_context? { true }
7
10
  end
8
11
 
9
12
  def test_jizume_new
10
- tag = Jizume_tag.new(@parser,50)
11
- assert_equal Jizume_tag, tag.class
12
- assert_equal true, tag.kind_of?(Block_tag)
13
- assert_equal true, tag.kind_of?(Multiline_tag)
13
+ tag = Aozora2Html::Tag::Jizume.new(@parser, 50)
14
+ assert_equal Aozora2Html::Tag::Jizume, tag.class
15
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Block)
16
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Multiline)
14
17
  end
15
18
 
16
19
  def test_to_s
17
- tag = Jizume_tag.new(@parser,50)
18
- assert_equal "<div class=\"jizume_50\" style=\"width: 50em\">", tag.to_s
19
- assert_equal "</div>", tag.close_tag
20
+ tag = Aozora2Html::Tag::Jizume.new(@parser, 50)
21
+ assert_equal '<div class="jizume_50" style="width: 50em">', tag.to_s
22
+ assert_equal '</div>', tag.close_tag
20
23
  end
21
24
 
22
25
  def teardown
data/test/test_jstream.rb CHANGED
@@ -1,9 +1,12 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
  require 'aozora2html'
4
5
  require 'stringio'
5
6
 
6
7
  class JstreamTest < Test::Unit::TestCase
8
+ using Aozora2Html::StringRefinements
9
+
7
10
  def test_new_error
8
11
  strio = StringIO.new("aaa\nbbb\n")
9
12
  orig_stdout = $stdout
@@ -13,45 +16,45 @@ class JstreamTest < Test::Unit::TestCase
13
16
  Jstream.new(strio)
14
17
  end
15
18
  $stdout = orig_stdout
16
- assert_equal "エラー(1行目):改行コードを、「CR+LF」にあらためてください. \r\n処理を停止します\n", out.string.encode("utf-8")
19
+ assert_equal "エラー(1行目):改行コードを、「CR+LF」にあらためてください. \r\n処理を停止します\n", out.string.to_utf8
17
20
  end
18
21
 
19
22
  def test_read_char
20
- strio = StringIO.new("aあ5\r\n%\\b\r\n".encode("Shift_JIS"))
23
+ strio = StringIO.new("aあ5\r\n%\\b\r\n".to_sjis)
21
24
  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 "", 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")
25
+ assert_equal 'a', stm.read_char.to_utf8
26
+ assert_equal '', stm.read_char.to_utf8
27
+ assert_equal '', stm.read_char.to_utf8
28
+ assert_equal "\r\n", stm.read_char.to_utf8
29
+ assert_equal '', stm.read_char.to_utf8
30
+ assert_equal '\\', stm.read_char.to_utf8
31
+ assert_equal 'b', stm.read_char.to_utf8
32
+ assert_equal "\r\n", stm.read_char.to_utf8
30
33
  assert_equal :eof, stm.read_char
31
- assert_equal "\r\n", stm.read_char # XXX ??
32
- assert_equal :eof, stm.read_char # XXX ??
34
+ # assert_equal "\r\n", stm.read_char # :eof以降は正しい値を保証しない
35
+ assert_equal :eof, stm.read_char # 何度もread_charすると:eofが複数回出る
33
36
  end
34
37
 
35
38
  def test_peek_char
36
- strio = StringIO.new("aあ5\r\n%\\b\r\n".encode("Shift_JIS"))
39
+ strio = StringIO.new("aあ5\r\n%\\b\r\n".to_sjis)
37
40
  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 "", 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") # XXX ??
43
- assert_equal "\r\n", stm.peek_char(5).encode("utf-8") # XXX ??
44
- assert_equal "\r\n", stm.peek_char(100).encode("utf-8") # XXX ??
45
- assert_equal "a", stm.read_char.encode("utf-8")
41
+ assert_equal 'a', stm.peek_char(0).to_utf8
42
+ assert_equal '', stm.peek_char(1).to_utf8
43
+ assert_equal '', stm.peek_char(2).to_utf8
44
+ assert_equal "\r\n", stm.peek_char(3).to_utf8
45
+ # assert_equal "\r\n", stm.peek_char(4).to_utf8 # 改行文字以降は正しい値を保証しない
46
+ # assert_equal "\r\n", stm.peek_char(5).to_utf8 # 同上
47
+ # assert_equal "\r\n", stm.peek_char(100).to_utf8 # 同上
48
+ assert_equal 'a', stm.read_char.to_utf8
46
49
 
47
- assert_equal "", stm.peek_char(0).encode("utf-8")
48
- assert_equal "", stm.read_char.encode("utf-8")
49
- assert_equal "", stm.read_char.encode("utf-8")
50
- assert_equal "\r\n", stm.read_char.encode("utf-8")
50
+ assert_equal '', stm.peek_char(0).to_utf8
51
+ assert_equal '', stm.read_char.to_utf8
52
+ assert_equal '', stm.read_char.to_utf8
53
+ assert_equal "\r\n", stm.read_char.to_utf8
51
54
 
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")
55
+ assert_equal '', stm.peek_char(0).to_utf8
56
+ assert_equal '\\', stm.peek_char(1).to_utf8
57
+ assert_equal 'b', stm.peek_char(2).to_utf8
58
+ assert_equal "\r\n", stm.peek_char(3).to_utf8
56
59
  end
57
60
  end
@@ -1,21 +1,25 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
  require 'aozora2html'
4
5
 
5
6
  class KaeritenTagTest < Test::Unit::TestCase
6
7
  def setup
7
- stub(@parser).block_allowed_context?{true}
8
+ @parser = Object.new
9
+ stub(@parser).block_allowed_context? { true }
8
10
  end
9
11
 
10
12
  def test_kaeriten_new
11
- tag = Kaeriten_tag.new(@parser,"aaa")
12
- assert_equal Kaeriten_tag, tag.class
13
- assert_equal true, tag.kind_of?(Inline_tag)
13
+ tag = Aozora2Html::Tag::Kaeriten.new(@parser, 'aaa')
14
+ assert_equal Aozora2Html::Tag::Kaeriten, tag.class
15
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Inline)
14
16
  end
15
17
 
18
+ using Aozora2Html::StringRefinements
19
+
16
20
  def test_to_s
17
- tag = Kaeriten_tag.new(@parser,"テスト".encode("shift_jis"))
18
- assert_equal "<sub class=\"kaeriten\">テスト</sub>", tag.to_s.encode("utf-8")
21
+ tag = Aozora2Html::Tag::Kaeriten.new(@parser, 'テスト'.to_sjis)
22
+ assert_equal '<sub class="kaeriten">テスト</sub>', tag.to_s.to_utf8
19
23
  end
20
24
 
21
25
  def teardown
@@ -1,28 +1,31 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
  require 'aozora2html'
3
5
 
4
6
  class KeigakomiTagTest < Test::Unit::TestCase
5
7
  def setup
6
- stub(@parser).block_allowed_context?{true}
8
+ @parser = Object.new
9
+ stub(@parser).block_allowed_context? { true }
7
10
  end
8
11
 
9
12
  def test_keigakomi_new
10
- tag = Keigakomi_tag.new(@parser,2)
11
- assert_equal Keigakomi_tag, tag.class
12
- assert_equal true, tag.kind_of?(Block_tag)
13
- assert_equal true, tag.kind_of?(Multiline_tag)
13
+ tag = Aozora2Html::Tag::Keigakomi.new(@parser, 2)
14
+ assert_equal Aozora2Html::Tag::Keigakomi, tag.class
15
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Block)
16
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Multiline)
14
17
  end
15
18
 
16
19
  def test_to_s
17
- tag = Keigakomi_tag.new(@parser)
18
- assert_equal "<div class=\"keigakomi\" style=\"border: solid 1px\">", tag.to_s
19
- assert_equal "</div>", tag.close_tag
20
+ tag = Aozora2Html::Tag::Keigakomi.new(@parser)
21
+ assert_equal '<div class="keigakomi" style="border: solid 1px">', tag.to_s
22
+ assert_equal '</div>', tag.close_tag
20
23
  end
21
24
 
22
25
  def test_to_s2
23
- tag = Keigakomi_tag.new(@parser,2)
24
- assert_equal "<div class=\"keigakomi\" style=\"border: solid 2px\">", tag.to_s
25
- assert_equal "</div>", tag.close_tag
26
+ tag = Aozora2Html::Tag::Keigakomi.new(@parser, 2)
27
+ assert_equal '<div class="keigakomi" style="border: solid 2px">', tag.to_s
28
+ assert_equal '</div>', tag.close_tag
26
29
  end
27
30
 
28
31
  def teardown
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+ require 'aozora2html'
5
+
6
+ class MidashiTagTest < Test::Unit::TestCase
7
+ def setup
8
+ @parser = Object.new
9
+ stub(@parser).block_allowed_context? { true }
10
+ stub(@parser).new_midashi_id { 2 }
11
+ end
12
+
13
+ using Aozora2Html::StringRefinements
14
+
15
+ def test_midashi_new
16
+ tag = Aozora2Html::Tag::Midashi.new(@parser, 'テスト見出し'.to_sjis, '小'.to_sjis, :normal)
17
+ assert_equal Aozora2Html::Tag::Midashi, tag.class
18
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Inline)
19
+ end
20
+
21
+ def test_to_s
22
+ tag = Aozora2Html::Tag::Midashi.new(@parser, 'テスト見出し'.to_sjis, '小'.to_sjis, :normal)
23
+ assert_equal "<h5 class=\"ko-midashi\"><a class=\"midashi_anchor\" id=\"midashi2\">#{'テスト見出し'.to_sjis}</a></h5>", tag.to_s
24
+ end
25
+
26
+ def test_to_s_mado
27
+ tag = Aozora2Html::Tag::Midashi.new(@parser, 'テスト見出し'.to_sjis, '小'.to_sjis, :mado)
28
+ assert_equal "<h5 class=\"mado-ko-midashi\"><a class=\"midashi_anchor\" id=\"midashi2\">#{'テスト見出し'.to_sjis}</a></h5>", tag.to_s
29
+ end
30
+
31
+ def test_undeined_midashi
32
+ Aozora2Html::Tag::Midashi.new(@parser, 'テスト見出し'.to_sjis, 'あ'.to_sjis, :normal)
33
+ rescue Aozora2Html::Error => e
34
+ assert_equal e.message(123).to_utf8, "エラー(123行目):未定義な見出しです. \r\n処理を停止します"
35
+ end
36
+
37
+ def teardown
38
+ end
39
+ end
@@ -1,22 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
  require 'aozora2html'
3
5
 
4
6
  class MultilineCaptionTagTest < Test::Unit::TestCase
5
7
  def setup
6
- stub(@parser).block_allowed_context?{true}
8
+ @parser = Object.new
9
+ stub(@parser).block_allowed_context? { true }
7
10
  end
8
11
 
9
12
  def test_multiline_caption_new
10
- tag = Multiline_caption_tag.new(@parser0)
11
- assert_equal Multiline_caption_tag, tag.class
12
- assert_equal true, tag.kind_of?(Block_tag)
13
- assert_equal true, tag.kind_of?(Multiline_tag)
13
+ tag = Aozora2Html::Tag::MultilineCaption.new(@parser)
14
+ assert_equal Aozora2Html::Tag::MultilineCaption, tag.class
15
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Block)
16
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Multiline)
14
17
  end
15
18
 
16
19
  def test_to_s
17
- tag = Multiline_caption_tag.new(@parser)
18
- assert_equal "<div class=\"caption\">", tag.to_s
19
- assert_equal "</div>", tag.close_tag
20
+ tag = Aozora2Html::Tag::MultilineCaption.new(@parser)
21
+ assert_equal '<div class="caption">', tag.to_s
22
+ assert_equal '</div>', tag.close_tag
20
23
  end
21
24
 
22
25
  def teardown
@@ -1,52 +1,52 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
  require 'aozora2html'
4
5
 
5
6
  class MultilineMidashiTagTest < Test::Unit::TestCase
6
7
  def setup
7
- stub(@parser).block_allowed_context?{true}
8
- stub(@parser).new_midashi_id{2}
8
+ @parser = Object.new
9
+ stub(@parser).block_allowed_context? { true }
10
+ stub(@parser).new_midashi_id { 2 }
9
11
  end
10
12
 
13
+ using Aozora2Html::StringRefinements
14
+
11
15
  def test_multiline_midashi_new
12
- tag = Multiline_midashi_tag.new(@parser,"".encode("shift_jis"),:normal)
13
- assert_equal Multiline_midashi_tag, tag.class
14
- assert_equal true, tag.kind_of?(Block_tag)
15
- assert_equal true, tag.kind_of?(Multiline_tag)
16
+ tag = Aozora2Html::Tag::MultilineMidashi.new(@parser, ''.to_sjis, :normal)
17
+ assert_equal Aozora2Html::Tag::MultilineMidashi, tag.class
18
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Block)
19
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Multiline)
16
20
  end
17
21
 
18
22
  def test_to_s
19
- tag = Multiline_midashi_tag.new(@parser,"".encode("shift_jis"),:normal)
20
- assert_equal "<h5 class=\"ko-midashi\"><a class=\"midashi_anchor\" id=\"midashi2\">", tag.to_s
21
- assert_equal "</a></h5>", tag.close_tag
23
+ tag = Aozora2Html::Tag::MultilineMidashi.new(@parser, ''.to_sjis, :normal)
24
+ assert_equal '<h5 class="ko-midashi"><a class="midashi_anchor" id="midashi2">', tag.to_s
25
+ assert_equal '</a></h5>', tag.close_tag
22
26
  end
23
27
 
24
28
  def test_to_s_chu
25
- tag = Multiline_midashi_tag.new(@parser,"".encode("shift_jis"),:dogyo)
26
- assert_equal "<h4 class=\"dogyo-naka-midashi\"><a class=\"midashi_anchor\" id=\"midashi2\">", tag.to_s
27
- assert_equal "</a></h4>", tag.close_tag
29
+ tag = Aozora2Html::Tag::MultilineMidashi.new(@parser, ''.to_sjis, :dogyo)
30
+ assert_equal '<h4 class="dogyo-naka-midashi"><a class="midashi_anchor" id="midashi2">', tag.to_s
31
+ assert_equal '</a></h4>', tag.close_tag
28
32
  end
29
33
 
30
34
  def test_to_s_dai
31
- tag = Multiline_midashi_tag.new(@parser,"".encode("shift_jis"),:mado)
32
- assert_equal "<h3 class=\"mado-o-midashi\"><a class=\"midashi_anchor\" id=\"midashi2\">", tag.to_s
33
- assert_equal "</a></h3>", tag.close_tag
35
+ tag = Aozora2Html::Tag::MultilineMidashi.new(@parser, ''.to_sjis, :mado)
36
+ assert_equal '<h3 class="mado-o-midashi"><a class="midashi_anchor" id="midashi2">', tag.to_s
37
+ assert_equal '</a></h3>', tag.close_tag
34
38
  end
35
39
 
36
40
  def test_undeined_midashi
37
- begin
38
- Multiline_midashi_tag.new(@parser,"あ".encode("shift_jis"),:mado)
39
- rescue Aozora_Error => e
40
- assert_equal e.message(123).encode("utf-8"), "エラー(123行目):未定義な見出しです. \r\n処理を停止します"
41
- end
41
+ Aozora2Html::Tag::MultilineMidashi.new(@parser, 'あ'.to_sjis, :mado)
42
+ rescue Aozora2Html::Error => e
43
+ assert_equal e.message(123).to_utf8, "エラー(123行目):未定義な見出しです. \r\n処理を停止します"
42
44
  end
43
45
 
44
46
  def test_undeined_midashi2
45
- begin
46
- Multiline_midashi_tag.new(@parser,"大".encode("shift_jis"),:madoo)
47
- rescue Aozora_Error => e
48
- assert_equal e.message(123).encode("utf-8"), "エラー(123行目):未定義な見出しです. \r\n処理を停止します"
49
- end
47
+ Aozora2Html::Tag::MultilineMidashi.new(@parser, '大'.to_sjis, :madoo)
48
+ rescue Aozora2Html::Error => e
49
+ assert_equal e.message(123).to_utf8, "エラー(123行目):未定義な見出しです. \r\n処理を停止します"
50
50
  end
51
51
 
52
52
  def teardown
@@ -1,22 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
  require 'aozora2html'
3
5
 
4
6
  class MultilineStyleTagTest < Test::Unit::TestCase
5
7
  def setup
6
- stub(@parser).block_allowed_context?{true}
8
+ @parser = Object.new
9
+ stub(@parser).block_allowed_context? { true }
7
10
  end
8
11
 
9
12
  def test_multiline_style_new
10
- tag = Multiline_style_tag.new(@parser,"style1")
11
- assert_equal Multiline_style_tag, tag.class
12
- assert_equal true, tag.kind_of?(Block_tag)
13
- assert_equal true, tag.kind_of?(Multiline_tag)
13
+ tag = Aozora2Html::Tag::MultilineStyle.new(@parser, 'style1')
14
+ assert_equal Aozora2Html::Tag::MultilineStyle, tag.class
15
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Block)
16
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Multiline)
14
17
  end
15
18
 
16
19
  def test_to_s
17
- tag = Multiline_style_tag.new(@parser,"s1")
18
- assert_equal "<div class=\"s1\">", tag.to_s
19
- assert_equal "</div>", tag.close_tag
20
+ tag = Aozora2Html::Tag::MultilineStyle.new(@parser, 's1')
21
+ assert_equal '<div class="s1">', tag.to_s
22
+ assert_equal '</div>', tag.close_tag
20
23
  end
21
24
 
22
25
  def teardown
@@ -1,22 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
  require 'aozora2html'
3
5
 
4
6
  class MultilineYokogumiTagTest < Test::Unit::TestCase
5
7
  def setup
6
- stub(@parser).block_allowed_context?{true}
8
+ @parser = Object.new
9
+ stub(@parser).block_allowed_context? { true }
7
10
  end
8
11
 
9
12
  def test_multiline_yokogumi_new
10
- tag = Multiline_yokogumi_tag.new(@parser0)
11
- assert_equal Multiline_yokogumi_tag, tag.class
12
- assert_equal true, tag.kind_of?(Block_tag)
13
- assert_equal true, tag.kind_of?(Multiline_tag)
13
+ tag = Aozora2Html::Tag::MultilineYokogumi.new(@parser)
14
+ assert_equal Aozora2Html::Tag::MultilineYokogumi, tag.class
15
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Block)
16
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Multiline)
14
17
  end
15
18
 
16
19
  def test_to_s
17
- tag = Multiline_yokogumi_tag.new(@parser)
18
- assert_equal "<div class=\"yokogumi\">", tag.to_s
19
- assert_equal "</div>", tag.close_tag
20
+ tag = Aozora2Html::Tag::MultilineYokogumi.new(@parser)
21
+ assert_equal '<div class="yokogumi">', tag.to_s
22
+ assert_equal '</div>', tag.close_tag
20
23
  end
21
24
 
22
25
  def teardown
@@ -1,21 +1,25 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
  require 'aozora2html'
4
5
 
5
6
  class OkuriganaTagTest < Test::Unit::TestCase
6
7
  def setup
7
- stub(@parser).block_allowed_context?{true}
8
+ @parser = Object.new
9
+ stub(@parser).block_allowed_context? { true }
8
10
  end
9
11
 
10
12
  def test_okurigana_new
11
- tag = Okurigana_tag.new(@parser,"aaa")
12
- assert_equal Okurigana_tag, tag.class
13
- assert_equal true, tag.kind_of?(Inline_tag)
13
+ tag = Aozora2Html::Tag::Okurigana.new(@parser, 'aaa')
14
+ assert_equal Aozora2Html::Tag::Okurigana, tag.class
15
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Inline)
14
16
  end
15
17
 
18
+ using Aozora2Html::StringRefinements
19
+
16
20
  def test_to_s
17
- tag = Okurigana_tag.new(@parser,"テスト".encode("shift_jis"))
18
- assert_equal "<sup class=\"okurigana\">テスト</sup>", tag.to_s.encode("utf-8")
21
+ tag = Aozora2Html::Tag::Okurigana.new(@parser, 'テスト'.to_sjis)
22
+ assert_equal '<sup class="okurigana">テスト</sup>', tag.to_s.to_utf8
19
23
  end
20
24
 
21
25
  def teardown