# -*- Encoding: utf-8 -*-
#
# Copyright 2013 whiteleaf. All rights reserved.
#
require_relative "../lib/html"
html_test_html_path = File.expand_path(File.dirname(__FILE__) + "/data/html_test.html")
html_test_txt_path = File.expand_path(File.dirname(__FILE__) + "/data/html_test.txt")
describe HTML do
before do
@html = HTML.new("")
end
it "rubyタグ → 青空ルビ注記" do
rubies = [
["漢字", "|漢字《かんじ》"],
["八九三", "|八九三《やくざ》"],
["堪能()", "|堪能《たんのう》"],
["漢字", "漢字"],
["この文章の中にルビはない", "この文章の中にルビはない"],
["美食を堪能()した", "美食を|堪能《たんのう》した"],
]
rubies.each do |ruby|
expect(@html.ruby_to_aozora(ruby[0])).to eq(ruby[1])
end
end
it " → 太字" do
expect(@html.b_to_aozora("次の文字は太字に")).to eq("次の文字は[#太字]太字[#太字終わり]に")
end
it " → 斜体" do
expect(@html.i_to_aozora("次の文字は斜体に")).to eq("次の文字は[#斜体]斜体[#斜体終わり]に")
end
it " → 取消線" do
expect(@html.s_to_aozora("次の文字は取消線に")).to eq("次の文字は[#取消線]取消線[#取消線終わり]に")
end
it "
→ 改行" do
expect(@html.br_to_aozora("あいう
かきく
\nさしす
")).to eq("あいう\nかきく\nさしす\n")
end
it " → 挿絵注記" do
expect(@html.img_to_aozora('')).to eq("[#挿絵(./images/100.jpg)入る]")
@html.set_illust_setting(current_url: "http://novel.example.com/10510/")
expect(@html.img_to_aozora('')).to eq(
"[#挿絵(http://novel.example.com/10510/images/100.jpg)入る]"
)
@html.set_illust_setting(current_url: nil)
end
it "HTML#to_aozora" do
test_html = File.read(html_test_html_path, encoding: "utf-8")
test_txt = File.read(html_test_txt_path, encoding: "utf-8")
html = HTML.new(test_html)
expect(html.to_aozora).to eq(test_txt)
end
describe "装飾タグの削除" do
before do
@strip_html = HTML.new
@strip_html.strip_decoration_tag = true
end
it do
@strip_html.string = "太字"
expect(@strip_html.to_aozora).to eq "太字"
end
it do
@strip_html.string = "太字斜体打ち消し"
expect(@strip_html.to_aozora).to eq "太字斜体打ち消し"
end
it do
@strip_html.string = "漢字"
expect(@strip_html.to_aozora).to eq "|漢字《かんじ》"
end
end
end