Sha256: 617fc9c549cbcb4bfeab70ead4520c3907e4b171b9bfcd62b0aa196af4a23687

Contents?: true

Size: 1.57 KB

Versions: 15

Compression:

Stored size: 1.57 KB

Contents

require "test_helper"

class HTML::Pipeline::TableOfContentsFilterTest < Test::Unit::TestCase
  TocFilter = HTML::Pipeline::TableOfContentsFilter
  CONTEXT = { toc_minimal_length: 1, toc_header: 'Table of contents' }

  def test_anchors_are_added_properly
    orig = %(<h2>Ice cube</h2><p>Will swarm on any motherfucker in a blue uniform</p>)
    assert_includes '<h2 id=', TocFilter.call(orig, CONTEXT).to_s
  end

  def test_anchors_have_sane_names
    orig = %(<h2>Dr Dre</h2><h2>Ice Cube</h2><h2>Eazy-E</h2><h2>MC Ren</h2>)
    result = TocFilter.call(orig, CONTEXT).to_s

    assert_includes '"dr-dre"', result
    assert_includes '"ice-cube"', result
    assert_includes '"eazy-e"', result
    assert_includes '"mc-ren"', result
  end

  def test_dupe_headers_have_unique_trailing_identifiers
    orig = %(<h2>Straight Outta Compton</h2>
             <h3>Dopeman</h3>
             <h4>Express Yourself</h4>
             <h2>Dopeman</h2>)

    result = TocFilter.call(orig, CONTEXT).to_s

    assert_includes '"dopeman"', result
    assert_includes '"dopeman-1"', result
  end

  def test_all_header_tags_are_found_when_adding_anchors
    orig = %(<h2>"Funky President" by James Brown</h2>
             <h3>"It's My Thing" by Marva Whitney</h3>
             <h4>"Boogie Back" by Roy Ayers</h4>
             <h5>"Feel Good" by Fancy</h5>
             <h6>"Funky Drummer" by James Brown</h6>
             <h7>"Ruthless Villain" by Eazy-E</h7>
             <h8>"Be Thankful for What You Got" by William DeVaughn</h8>)

    doc = TocFilter.call(orig, CONTEXT)
    assert_equal 5, doc.search('a').size
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
html-pipeline-linuxfr-0.15.7 test/html/pipeline/toc_filter_test.rb
html-pipeline-linuxfr-0.15.6 test/html/pipeline/toc_filter_test.rb
html-pipeline-linuxfr-0.15.5 test/html/pipeline/toc_filter_test.rb
html-pipeline-linuxfr-0.15.4 test/html/pipeline/toc_filter_test.rb
html-pipeline-linuxfr-0.15.3 test/html/pipeline/toc_filter_test.rb
html-pipeline-linuxfr-0.14.30 test/html/pipeline/toc_filter_test.rb
html-pipeline-linuxfr-0.15.2 test/html/pipeline/toc_filter_test.rb
html-pipeline-linuxfr-0.15.1 test/html/pipeline/toc_filter_test.rb
html-pipeline-linuxfr-0.14.29 test/html/pipeline/toc_filter_test.rb
html-pipeline-linuxfr-0.15.0 test/html/pipeline/toc_filter_test.rb
html-pipeline-linuxfr-0.14.28 test/html/pipeline/toc_filter_test.rb
html-pipeline-linuxfr-0.14.27 test/html/pipeline/toc_filter_test.rb
html-pipeline-linuxfr-0.14.26 test/html/pipeline/toc_filter_test.rb
html-pipeline-linuxfr-0.14.25 test/html/pipeline/toc_filter_test.rb
html-pipeline-linuxfr-0.14.24 test/html/pipeline/toc_filter_test.rb