defmodule Readability.TitleFinderTest do
use ExUnit.Case, async: true
doctest Readability.TitleFinder
@html """
Tag title - test
h1 title
h2 title
"""
test "extract most proper title" do
title = Readability.TitleFinder.title(@html)
assert title == "og title"
end
test "extract og title" do
title = Readability.TitleFinder.og_title(@html)
assert title == "og title"
end
test "does not merge multiple matching og:title tags" do
html = """
"""
title = Readability.TitleFinder.og_title(html)
assert title == "og title 1"
end
test "extract tag title" do
title = Readability.TitleFinder.tag_title(@html)
assert title == "Tag title"
html = """
Tag title :: test
"""
title = Readability.TitleFinder.tag_title(html)
assert title == "Tag title"
html = """
Tag title | test
"""
title = Readability.TitleFinder.tag_title(html)
assert title == "Tag title"
html = """
Tag title-tag
"""
title = Readability.TitleFinder.tag_title(html)
assert title == "Tag title-tag"
html = """
Tag title-tag-title - test
"""
title = Readability.TitleFinder.tag_title(html)
assert title == "Tag title-tag-title"
html = """
Tag title
"""
title = Readability.TitleFinder.tag_title(html)
assert title == "Tag title"
end
test "does not merge multiple title tags" do
html = """
tag title 1tag title 2
"""
title = Readability.TitleFinder.tag_title(html)
assert title == "tag title 1"
end
test "extract h1 tag title" do
title = Readability.TitleFinder.h_tag_title(@html)
assert title == "h1 title"
end
test "extract h2 tag title" do
title = Readability.TitleFinder.h_tag_title(@html, "h2")
assert title == "h2 title"
end
test "does not merge multile header tags" do
html = """
header 1
header 2
"""
title = Readability.TitleFinder.h_tag_title(html)
assert title == "header 1"
end
test "returns an empty string when no title tag can be found" do
assert Readability.TitleFinder.tag_title("") == ""
end
test "returns an empty string when no og:title tag can be found" do
assert Readability.TitleFinder.og_title("") == ""
end
test "returns an empty string when no header tag can be found" do
assert Readability.TitleFinder.h_tag_title("") == ""
end
end