# encoding: utf-8
require "test_helper"
class HTML::Pipeline::TableOfContentsFilterTest < Minitest::Test
TocFilter = HTML::Pipeline::TableOfContentsFilter
TocPipeline =
HTML::Pipeline.new [
HTML::Pipeline::TableOfContentsFilter
]
def toc
result = {}
TocPipeline.call(@orig, {}, result)
result[:toc]
end
def test_anchors_are_added_properly
orig = %(
Ice cube
Will swarm on any motherfucker in a blue uniform
)
assert_includes TocFilter.call(orig).to_s, 'Dr DreIce Cube
Eazy-E
MC Ren
)
assert_includes toc, '"#dr-dre"'
assert_includes toc, '"#ice-cube"'
assert_includes toc, '"#eazy-e"'
assert_includes toc, '"#mc-ren"'
end
def test_dupe_headers_have_unique_trailing_identifiers
orig = %(Straight Outta Compton
Dopeman
Express Yourself
Dopeman
)
result = TocFilter.call(orig).to_s
assert_includes result, '"dopeman"'
assert_includes result, '"dopeman-1"'
end
def test_dupe_headers_have_unique_toc_anchors
@orig = %(Straight Outta Compton
Dopeman
Express Yourself
Dopeman
)
assert_includes toc, '"#dopeman"'
assert_includes toc, '"#dopeman-1"'
end
def test_all_header_tags_are_found_when_adding_anchors
orig = %("Funky President" by James Brown
"It's My Thing" by Marva Whitney
"Boogie Back" by Roy Ayers
"Feel Good" by Fancy
"Funky Drummer" by James Brown
"Ruthless Villain" by Eazy-E
"Be Thankful for What You Got" by William DeVaughn)
doc = TocFilter.call(orig)
assert_equal 6, doc.search('a').size
end
def test_toc_is_complete
@orig = %("Funky President" by James Brown
"It's My Thing" by Marva Whitney
"Boogie Back" by Roy Ayers
"Feel Good" by Fancy
"Funky Drummer" by James Brown
"Ruthless Villain" by Eazy-E
"Be Thankful for What You Got" by William DeVaughn)
expected = %Q{}
assert_equal expected, toc
end
if RUBY_VERSION > "1.9" # not sure how to make this work on 1.8.7
def test_anchors_with_utf8_characters
orig = %(日本語
Русский
\n日本語",
rendered_h1s[0]
assert_equal "\nРусский
",
rendered_h1s[1]
end
def test_toc_with_utf8_characters
@orig = %(日本語
Русский
\n日本語\nРусский\n}
assert_equal expected, rendered_toc
end
end
end