# frozen_string_literal: true require 'test_helper' class TestVariousTocHtml < Minitest::Test TEST_HTML = <<~HTML

h1

h3

h6
HTML def test_nested_toc parser = Jekyll::TableOfContents::Parser.new(TEST_HTML) expected = <<~HTML.chomp HTML assert_equal(expected, parser.build_toc) end def test_nested_toc_with_min_and_max parser = Jekyll::TableOfContents::Parser.new(TEST_HTML, 'min_level' => 2, 'max_level' => 5) expected = <<~HTML.chomp HTML assert_equal(expected, parser.build_toc) end def test_complex_nested_toc parser = Jekyll::TableOfContents::Parser.new(<<~HTML)

h1

h3

h2

h6
HTML expected = <<~HTML.chomp HTML assert_equal(expected, parser.build_toc) end def test_decremental_headings1 parser = Jekyll::TableOfContents::Parser.new(<<~HTML)
h6
h5

h4

h3

h2

h1

HTML expected = <<~HTML.chomp HTML assert_equal(expected, parser.build_toc) end def test_decremental_headings2 parser = Jekyll::TableOfContents::Parser.new(<<~HTML)

h1

h3

h2

h4

h5
HTML expected = <<~HTML.chomp HTML assert_equal(expected, parser.build_toc) end def test_no_toc parser = Jekyll::TableOfContents::Parser.new(<<~HTML)

h1

no_toc h1

h2

no_toc h2

h3

no_toc h3

h4

no_toc h4

HTML expected = <<~HTML.chomp HTML assert_equal(expected, parser.build_toc) end def test_japanese_toc parser = Jekyll::TableOfContents::Parser.new(<<~HTML)

HTML expected = <<~HTML.chomp HTML assert_equal(expected, parser.build_toc) html_with_anchors = parser.inject_anchors_into_html assert_match(%r{あ}, html_with_anchors) assert_match(%r{い}, html_with_anchors) assert_match(%r{う}, html_with_anchors) end # ref. https://github.com/toshimaru/jekyll-toc/issues/45 def test_angle_bracket parser = Jekyll::TableOfContents::Parser.new(<<~HTML)

h1

<base href>

& < >

HTML expected = <<~HTML.chomp HTML assert_equal(expected, parser.build_toc) end def test_tags_inside_heading parser = Jekyll::TableOfContents::Parser.new(<<~HTML)

h2

h2

HTML expected = <<~HTML.chomp HTML assert_equal(expected, parser.build_toc) end def test_nested_toc_with_no_toc_section_class parser = Jekyll::TableOfContents::Parser.new(<<~HTML)

h1

h2

h3

h6
HTML expected = <<~HTML.chomp HTML assert_equal(expected, parser.build_toc) html = parser.inject_anchors_into_html assert_match(%r{

.+

}m, html) assert_match(%r{

.+

}m, html) assert_match(%r{
.+
}m, html) assert_includes(html, '

h2

') end def test_nested_toc_with_no_toc_section_class_option parser = Jekyll::TableOfContents::Parser.new(<<~HTML, 'no_toc_section_class' => 'exclude')

h1

h2

h3

h4

h5
h6
HTML expected = <<~HTML.chomp HTML assert_equal(expected, parser.build_toc) html = parser.inject_anchors_into_html assert_match(%r{

.+

}m, html) assert_match(%r{

.+

}m, html) assert_match(%r{
.+
}m, html) assert_includes(html, '

h2

') assert_includes(html, '

h4

') assert_includes(html, '
h5
') end def test_multiple_no_toc_section_classes parser = Jekyll::TableOfContents::Parser.new(<<~HTML, 'no_toc_section_class' => ['no_toc_section', 'exclude'])

h1

h2

h3

h4

h5
h6
HTML expected = <<~HTML.chomp HTML assert_equal(expected, parser.build_toc) html = parser.inject_anchors_into_html assert_match(%r{

.+

}m, html) assert_match(%r{

.+

}m, html) assert_match(%r{
.+
}m, html) assert_includes(html, '

h2

') assert_includes(html, '

h4

') assert_includes(html, '
h5
') end def test_toc_with_explicit_id parser = Jekyll::TableOfContents::Parser.new(<<~HTML)

h1

h2

h3

HTML expected = <<~HTML.chomp HTML assert_equal(expected, parser.build_toc) html = parser.inject_anchors_into_html assert_includes(html, %( HTML assert_equal(expected, parser.build_toc) end def test_custom_css_classes parser = Jekyll::TableOfContents::Parser.new( TEST_HTML, 'item_class' => 'custom-item', 'list_class' => 'custom-list', 'sublist_class' => 'custom-sublist', 'item_prefix' => 'custom-prefix-' ) expected = <<~HTML.chomp HTML assert_equal(expected, parser.build_toc) end end