# encoding: utf-8
require "test_helper"
class HTML::Pipeline::TableOfContentsFilterTest < Test::Unit::TestCase
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 'Dr DreIce Cube
Eazy-E
MC Ren
)
assert_includes '"#dr-dre"', toc
assert_includes '"#ice-cube"', toc
assert_includes '"#eazy-e"', toc
assert_includes '"#mc-ren"', toc
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 '"dopeman"', result
assert_includes '"dopeman-1"', result
end
def test_dupe_headers_have_unique_toc_anchors
@orig = %(Straight Outta Compton
Dopeman
Express Yourself
Dopeman
)
assert_includes '"#dopeman"', toc
assert_includes '"#dopeman-1"', toc
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