# frozen_string_literal: true
require 'test_helper'
class TestVariousTocHtml < Minitest::Test
# ref. https://github.com/toshimaru/jekyll-toc/issues/45
ANGLE_BRACKET_HTML = <<-HTML
h1
<base href>
& < >
HTML
NO_TOC_HTML = <<-HTML
h1
no_toc h1
h2
no_toc h2
h3
no_toc h3
h4
no_toc h4
HTML
JAPANESE_HEADINGS_HTML = <<-HTML
あ
い
う
HTML
TAGS_INSIDE_HEADINGS_HTML = <<-HTML
h2
h2
HTML
TEST_HTML_1 = <<-HTML
h1
h3
h6
HTML
TEST_HTML_2 = <<-HTML
h1
h3
h2
h6
HTML
TEST_HTML_3 = <<-HTML
h6
h5
h4
h3
h2
h1
HTML
TEST_HTML_4 = <<-HTML
h1
h3
h2
h4
h5
HTML
def test_nested_toc
parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_1)
doc = Nokogiri::HTML(parser.toc)
expected = <<-HTML
HTML
actual = doc.css('ul.section-nav').to_s
assert_equal(expected, actual)
end
def test_nested_toc_with_min_and_max
parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_1, { "min_level" => 2, "max_level" => 5 })
doc = Nokogiri::HTML(parser.toc)
expected = <<-HTML
HTML
actual = doc.css('ul.section-nav').to_s
assert_equal(expected, actual)
end
def test_complex_nested_toc
parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_2)
doc = Nokogiri::HTML(parser.toc)
expected = <<-HTML
HTML
actual = doc.css('ul.section-nav').to_s
assert_equal(expected, actual)
end
def test_decremental_headings1
parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_3)
doc = Nokogiri::HTML(parser.toc)
expected = <<-HTML
HTML
actual = doc.css('ul.section-nav').to_s
assert_equal(expected, actual)
end
def test_decremental_headings2
parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_4)
doc = Nokogiri::HTML(parser.toc)
expected = <<-HTML
HTML
assert_equal(expected, doc.css('ul.section-nav').to_s)
end
def test_no_toc
parser = Jekyll::TableOfContents::Parser.new(NO_TOC_HTML)
doc = Nokogiri::HTML(parser.toc)
expected = <<-HTML
HTML
actual = doc.css('ul.section-nav').to_s
assert_equal(expected, actual)
end
def test_japanese_toc
parser = Jekyll::TableOfContents::Parser.new(JAPANESE_HEADINGS_HTML)
doc = Nokogiri::HTML(parser.toc)
expected = <<-HTML
HTML
actual = doc.css('ul.section-nav').to_s
assert_equal(expected, actual)
end
def test_angle_bracket
parser = Jekyll::TableOfContents::Parser.new(ANGLE_BRACKET_HTML)
doc = Nokogiri::HTML(parser.toc)
expected = <<-HTML
HTML
actual = doc.css('ul.section-nav').to_s
assert_equal(expected, actual)
end
def test_tags_inside_heading
parser = Jekyll::TableOfContents::Parser.new(TAGS_INSIDE_HEADINGS_HTML)
doc = Nokogiri::HTML(parser.toc)
expected = <<-HTML
HTML
actual = doc.css('ul.section-nav').to_s
assert_equal(expected, actual)
end
end