aozora2html 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +19 -0
  3. data/.github/workflows/ruby.yml +4 -1
  4. data/.rubocop.yml +36 -152
  5. data/.rubocop_todo.yml +7 -0
  6. data/CHANGELOG.md +26 -0
  7. data/Gemfile +2 -0
  8. data/Guardfile +3 -1
  9. data/HACKING.md +45 -0
  10. data/README.md +14 -6
  11. data/Rakefile +12 -5
  12. data/aozora2html.gemspec +24 -22
  13. data/bin/aozora2html +21 -19
  14. data/lib/aozora2html/accent_parser.rb +62 -54
  15. data/lib/aozora2html/error.rb +5 -4
  16. data/lib/aozora2html/header.rb +20 -18
  17. data/lib/aozora2html/i18n.rb +40 -20
  18. data/lib/aozora2html/ruby_buffer.rb +63 -28
  19. data/lib/aozora2html/string_refinements.rb +36 -0
  20. data/lib/aozora2html/style_stack.rb +6 -0
  21. data/lib/aozora2html/tag/accent.rb +10 -12
  22. data/lib/aozora2html/tag/block.rb +11 -9
  23. data/lib/aozora2html/tag/chitsuki.rb +6 -2
  24. data/lib/aozora2html/tag/dakuten_katakana.rb +10 -8
  25. data/lib/aozora2html/tag/decorate.rb +4 -3
  26. data/lib/aozora2html/tag/dir.rb +4 -2
  27. data/lib/aozora2html/tag/editor_note.rb +7 -4
  28. data/lib/aozora2html/tag/embed_gaiji.rb +15 -11
  29. data/lib/aozora2html/tag/font_size.rb +5 -2
  30. data/lib/aozora2html/tag/gaiji.rb +4 -3
  31. data/lib/aozora2html/tag/img.rb +4 -4
  32. data/lib/aozora2html/tag/indent.rb +3 -3
  33. data/lib/aozora2html/tag/inline.rb +10 -7
  34. data/lib/aozora2html/tag/inline_caption.rb +4 -2
  35. data/lib/aozora2html/tag/inline_font_size.rb +4 -3
  36. data/lib/aozora2html/tag/inline_keigakomi.rb +4 -2
  37. data/lib/aozora2html/tag/inline_yokogumi.rb +4 -3
  38. data/lib/aozora2html/tag/jisage.rb +3 -1
  39. data/lib/aozora2html/tag/jizume.rb +3 -0
  40. data/lib/aozora2html/tag/kaeriten.rb +4 -2
  41. data/lib/aozora2html/tag/keigakomi.rb +15 -9
  42. data/lib/aozora2html/tag/kunten.rb +4 -4
  43. data/lib/aozora2html/tag/midashi.rb +3 -1
  44. data/lib/aozora2html/tag/multiline.rb +3 -0
  45. data/lib/aozora2html/tag/multiline_caption.rb +6 -8
  46. data/lib/aozora2html/tag/multiline_chitsuki.rb +3 -1
  47. data/lib/aozora2html/tag/multiline_jisage.rb +3 -1
  48. data/lib/aozora2html/tag/multiline_midashi.rb +6 -3
  49. data/lib/aozora2html/tag/multiline_style.rb +5 -3
  50. data/lib/aozora2html/tag/multiline_yokogumi.rb +6 -9
  51. data/lib/aozora2html/tag/okurigana.rb +4 -2
  52. data/lib/aozora2html/tag/oneline_chitsuki.rb +3 -2
  53. data/lib/aozora2html/tag/oneline_indent.rb +8 -1
  54. data/lib/aozora2html/tag/oneline_jisage.rb +3 -0
  55. data/lib/aozora2html/tag/reference_mentioned.rb +22 -21
  56. data/lib/aozora2html/tag/ruby.rb +174 -70
  57. data/lib/aozora2html/tag/un_embed_gaiji.rb +8 -2
  58. data/lib/aozora2html/tag.rb +40 -38
  59. data/lib/aozora2html/tag_parser.rb +23 -16
  60. data/lib/aozora2html/text_buffer.rb +50 -0
  61. data/lib/aozora2html/utils.rb +113 -50
  62. data/lib/aozora2html/version.rb +3 -1
  63. data/lib/aozora2html/yaml_loader.rb +8 -2
  64. data/lib/aozora2html/zip.rb +4 -0
  65. data/lib/aozora2html.rb +1358 -3
  66. data/lib/extensions.rb +2 -34
  67. data/lib/jstream.rb +96 -25
  68. data/sample/chukiichiran_kinyurei.html +15 -2
  69. data/sample/chukiichiran_kinyurei.txt +15 -2
  70. data/test/test_aozora2html.rb +137 -148
  71. data/test/test_aozora_accent_parser.rb +26 -9
  72. data/test/test_command_parse.rb +25 -22
  73. data/test/test_compat.rb +3 -4
  74. data/test/test_dakuten_katakana_tag.rb +10 -12
  75. data/test/test_decorate_tag.rb +9 -6
  76. data/test/test_dir_tag.rb +9 -6
  77. data/test/test_editor_note_tag.rb +8 -5
  78. data/test/test_exception.rb +10 -8
  79. data/test/test_font_size_tag.rb +16 -13
  80. data/test/test_gaiji_tag.rb +15 -14
  81. data/test/test_header.rb +25 -40
  82. data/test/test_helper.rb +3 -1
  83. data/test/test_i18n.rb +22 -6
  84. data/test/test_img_tag.rb +9 -5
  85. data/test/test_inline_caption_tag.rb +9 -6
  86. data/test/test_inline_font_size_tag.rb +13 -10
  87. data/test/test_inline_keigakomi_tag.rb +9 -6
  88. data/test/test_inline_yokogumi_tag.rb +9 -6
  89. data/test/test_jizume_tag.rb +9 -7
  90. data/test/test_jstream.rb +33 -30
  91. data/test/test_kaeriten_tag.rb +9 -6
  92. data/test/test_keigakomi_tag.rb +11 -9
  93. data/test/test_midashi_tag.rb +15 -14
  94. data/test/test_multiline_caption_tag.rb +7 -5
  95. data/test/test_multiline_midashi_tag.rb +24 -25
  96. data/test/test_multiline_style_tag.rb +9 -7
  97. data/test/test_multiline_yokogumi_tag.rb +7 -5
  98. data/test/test_okurigana_tag.rb +9 -6
  99. data/test/test_ruby_parse.rb +14 -14
  100. data/test/test_ruby_tag.rb +9 -6
  101. data/test/test_tag_parser.rb +28 -26
  102. metadata +60 -14
  103. data/.travis.yml +0 -12
  104. data/lib/t2hs.rb +0 -1607
data/test/test_img_tag.rb CHANGED
@@ -1,21 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
  require 'aozora2html'
3
5
 
4
6
  class ImgTagTest < Test::Unit::TestCase
5
7
  def setup
6
8
  @parser = Object.new
7
- stub(@parser).block_allowed_context?{true}
9
+ stub(@parser).block_allowed_context? { true }
8
10
  end
9
11
 
10
12
  def test_img_new
11
- tag = Aozora2Html::Tag::Img.new(@parser,"foo.png","img1","alt img1",40,50)
13
+ tag = Aozora2Html::Tag::Img.new(@parser, 'foo.png', 'img1', 'alt img1', 40, 50)
12
14
  assert_equal Aozora2Html::Tag::Img, tag.class
13
- assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
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 = 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")
21
+ tag = Aozora2Html::Tag::Img.new(@parser, 'foo.png', 'img1', 'alt img1', 40, 50)
22
+ assert_equal '<img class="img1" width="40" height="50" src="foo.png" alt="alt img1" />', tag.to_s.to_utf8
19
23
  end
20
24
 
21
25
  def teardown
@@ -1,22 +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
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_caption_new
12
- tag = Aozora2Html::Tag::InlineCaption.new(@parser,"aaa")
13
+ tag = Aozora2Html::Tag::InlineCaption.new(@parser, 'aaa')
13
14
  assert_equal Aozora2Html::Tag::InlineCaption, tag.class
14
- assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
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::InlineCaption.new(@parser,"テスト".encode("shift_jis"))
19
- 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
20
23
  end
21
24
 
22
25
  def teardown
@@ -1,32 +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
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::InlineFontSize.new(@parser,"aa",1,:dai)
13
+ tag = Aozora2Html::Tag::InlineFontSize.new(@parser, 'aa', 1, :dai)
13
14
  assert_equal Aozora2Html::Tag::InlineFontSize, tag.class
14
- assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
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::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")
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
20
23
  end
21
24
 
22
25
  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")
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
25
28
  end
26
29
 
27
30
  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")
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
30
33
  end
31
34
 
32
35
  def teardown
@@ -1,22 +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
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_keigakomi_new
12
- tag = Aozora2Html::Tag::InlineKeigakomi.new(@parser,"aaa")
13
+ tag = Aozora2Html::Tag::InlineKeigakomi.new(@parser, 'aaa')
13
14
  assert_equal Aozora2Html::Tag::InlineKeigakomi, tag.class
14
- assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
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::InlineKeigakomi.new(@parser,"テスト".encode("shift_jis"))
19
- 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
20
23
  end
21
24
 
22
25
  def teardown
@@ -1,22 +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
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_yokogumi_new
12
- tag = Aozora2Html::Tag::InlineYokogumi.new(@parser,"aaa")
13
+ tag = Aozora2Html::Tag::InlineYokogumi.new(@parser, 'aaa')
13
14
  assert_equal Aozora2Html::Tag::InlineYokogumi, tag.class
14
- assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
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::InlineYokogumi.new(@parser,"テスト".encode("shift_jis"))
19
- 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
20
23
  end
21
24
 
22
25
  def teardown
@@ -1,23 +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
8
  @parser = Object.new
7
- stub(@parser).block_allowed_context?{true}
9
+ stub(@parser).block_allowed_context? { true }
8
10
  end
9
11
 
10
12
  def test_jizume_new
11
- tag = Aozora2Html::Tag::Jizume.new(@parser,50)
13
+ tag = Aozora2Html::Tag::Jizume.new(@parser, 50)
12
14
  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
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Block)
16
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Multiline)
15
17
  end
16
18
 
17
19
  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
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
21
23
  end
22
24
 
23
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 # :eof以降は正しい値を保証しない
32
- assert_equal :eof, stm.read_char # 何度もread_charすると:eofが複数回出る
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") # 改行文字以降は正しい値を保証しない
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")
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,22 +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
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_kaeriten_new
12
- tag = Aozora2Html::Tag::Kaeriten.new(@parser,"aaa")
13
+ tag = Aozora2Html::Tag::Kaeriten.new(@parser, 'aaa')
13
14
  assert_equal Aozora2Html::Tag::Kaeriten, tag.class
14
- assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
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::Kaeriten.new(@parser,"テスト".encode("shift_jis"))
19
- 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
20
23
  end
21
24
 
22
25
  def teardown
@@ -1,29 +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
8
  @parser = Object.new
7
- stub(@parser).block_allowed_context?{true}
9
+ stub(@parser).block_allowed_context? { true }
8
10
  end
9
11
 
10
12
  def test_keigakomi_new
11
- tag = Aozora2Html::Tag::Keigakomi.new(@parser,2)
13
+ tag = Aozora2Html::Tag::Keigakomi.new(@parser, 2)
12
14
  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
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Block)
16
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Multiline)
15
17
  end
16
18
 
17
19
  def test_to_s
18
20
  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
+ assert_equal '<div class="keigakomi" style="border: solid 1px">', tag.to_s
22
+ assert_equal '</div>', tag.close_tag
21
23
  end
22
24
 
23
25
  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
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
27
29
  end
28
30
 
29
31
  def teardown
@@ -1,36 +1,37 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
  require 'aozora2html'
4
5
 
5
6
  class MidashiTagTest < Test::Unit::TestCase
6
7
  def setup
7
8
  @parser = Object.new
8
- stub(@parser).block_allowed_context?{true}
9
- stub(@parser).new_midashi_id{2}
9
+ stub(@parser).block_allowed_context? { true }
10
+ stub(@parser).new_midashi_id { 2 }
10
11
  end
11
12
 
13
+ using Aozora2Html::StringRefinements
14
+
12
15
  def test_midashi_new
13
- tag = Aozora2Html::Tag::Midashi.new(@parser, "テスト見出し".encode("shift_jis"), "".encode("shift_jis"), :normal)
16
+ tag = Aozora2Html::Tag::Midashi.new(@parser, 'テスト見出し'.to_sjis, ''.to_sjis, :normal)
14
17
  assert_equal Aozora2Html::Tag::Midashi, tag.class
15
- assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
18
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Inline)
16
19
  end
17
20
 
18
21
  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
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
21
24
  end
22
25
 
23
26
  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
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
26
29
  end
27
30
 
28
31
  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
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処理を停止します"
34
35
  end
35
36
 
36
37
  def teardown
@@ -1,23 +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
8
  @parser = Object.new
7
- stub(@parser).block_allowed_context?{true}
9
+ stub(@parser).block_allowed_context? { true }
8
10
  end
9
11
 
10
12
  def test_multiline_caption_new
11
13
  tag = Aozora2Html::Tag::MultilineCaption.new(@parser)
12
14
  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
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Block)
16
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Multiline)
15
17
  end
16
18
 
17
19
  def test_to_s
18
20
  tag = Aozora2Html::Tag::MultilineCaption.new(@parser)
19
- assert_equal "<div class=\"caption\">", tag.to_s
20
- assert_equal "</div>", tag.close_tag
21
+ assert_equal '<div class="caption">', tag.to_s
22
+ assert_equal '</div>', tag.close_tag
21
23
  end
22
24
 
23
25
  def teardown
@@ -1,53 +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
8
  @parser = Object.new
8
- stub(@parser).block_allowed_context?{true}
9
- stub(@parser).new_midashi_id{2}
9
+ stub(@parser).block_allowed_context? { true }
10
+ stub(@parser).new_midashi_id { 2 }
10
11
  end
11
12
 
13
+ using Aozora2Html::StringRefinements
14
+
12
15
  def test_multiline_midashi_new
13
- tag = Aozora2Html::Tag::MultilineMidashi.new(@parser,"".encode("shift_jis"),:normal)
16
+ tag = Aozora2Html::Tag::MultilineMidashi.new(@parser, ''.to_sjis, :normal)
14
17
  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)
18
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Block)
19
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Multiline)
17
20
  end
18
21
 
19
22
  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
+ 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
23
26
  end
24
27
 
25
28
  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
+ 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
29
32
  end
30
33
 
31
34
  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
+ 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
35
38
  end
36
39
 
37
40
  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
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処理を停止します"
43
44
  end
44
45
 
45
46
  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
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処理を停止します"
51
50
  end
52
51
 
53
52
  def teardown
@@ -1,23 +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
8
  @parser = Object.new
7
- stub(@parser).block_allowed_context?{true}
9
+ stub(@parser).block_allowed_context? { true }
8
10
  end
9
11
 
10
12
  def test_multiline_style_new
11
- tag = Aozora2Html::Tag::MultilineStyle.new(@parser,"style1")
13
+ tag = Aozora2Html::Tag::MultilineStyle.new(@parser, 'style1')
12
14
  assert_equal Aozora2Html::Tag::MultilineStyle, tag.class
13
- assert_equal true, tag.kind_of?(Aozora2Html::Tag::Block)
14
- assert_equal true, tag.kind_of?(Aozora2Html::Tag::Multiline)
15
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Block)
16
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Multiline)
15
17
  end
16
18
 
17
19
  def test_to_s
18
- tag = Aozora2Html::Tag::MultilineStyle.new(@parser,"s1")
19
- assert_equal "<div class=\"s1\">", tag.to_s
20
- 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
21
23
  end
22
24
 
23
25
  def teardown
@@ -1,23 +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
8
  @parser = Object.new
7
- stub(@parser).block_allowed_context?{true}
9
+ stub(@parser).block_allowed_context? { true }
8
10
  end
9
11
 
10
12
  def test_multiline_yokogumi_new
11
13
  tag = Aozora2Html::Tag::MultilineYokogumi.new(@parser)
12
14
  assert_equal Aozora2Html::Tag::MultilineYokogumi, tag.class
13
- assert_equal true, tag.kind_of?(Aozora2Html::Tag::Block)
14
- assert_equal true, tag.kind_of?(Aozora2Html::Tag::Multiline)
15
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Block)
16
+ assert_equal true, tag.is_a?(Aozora2Html::Tag::Multiline)
15
17
  end
16
18
 
17
19
  def test_to_s
18
20
  tag = Aozora2Html::Tag::MultilineYokogumi.new(@parser)
19
- assert_equal "<div class=\"yokogumi\">", tag.to_s
20
- assert_equal "</div>", tag.close_tag
21
+ assert_equal '<div class="yokogumi">', tag.to_s
22
+ assert_equal '</div>', tag.close_tag
21
23
  end
22
24
 
23
25
  def teardown
@@ -1,22 +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
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_okurigana_new
12
- tag = Aozora2Html::Tag::Okurigana.new(@parser,"aaa")
13
+ tag = Aozora2Html::Tag::Okurigana.new(@parser, 'aaa')
13
14
  assert_equal Aozora2Html::Tag::Okurigana, tag.class
14
- assert_equal true, tag.kind_of?(Aozora2Html::Tag::Inline)
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::Okurigana.new(@parser,"テスト".encode("shift_jis"))
19
- 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
20
23
  end
21
24
 
22
25
  def teardown