Sha256: e96ce83b713f816d0f9760f8bfc6f7c1383fbe186fd0ffcd315ad76908262ca9

Contents?: true

Size: 1.37 KB

Versions: 5

Compression:

Stored size: 1.37 KB

Contents

# coding: UTF-8
require 'test_helper'

class HTMLTOCRenderTest < Redcarpet::TestCase
  def setup
    @render = Redcarpet::Render::HTML_TOC
    @markdown = "# A title \n## A __nice__ subtitle\n## Another one \n### A sub-sub-title"
  end

  def test_simple_toc_render
    renderer = Redcarpet::Markdown.new(@render)
    output = renderer.render(@markdown).strip

    assert output.start_with?("<ul>")
    assert output.end_with?("</ul>")

    assert_equal 3, output.scan("<ul>").length
    assert_equal 4, output.scan("<li>").length
  end

  def test_granular_toc_render
    renderer = Redcarpet::Markdown.new(@render.new(nesting_level: 2))
    output = renderer.render(@markdown).strip

    assert output.start_with?("<ul>")
    assert output.end_with?("</ul>")

    assert_equal 3, output.scan("<li>").length
    assert !output.include?("A sub-sub title")
  end

  def test_toc_heading_id
    renderer = Redcarpet::Markdown.new(@render)
    output = renderer.render(@markdown)

    assert_match /a-title/, output
    assert_match /a-nice-subtitle/, output
    assert_match /another-one/, output
    assert_match /a-sub-sub-title/, output
  end

  def test_toc_heading_with_hyphen_and_equal
    renderer = Redcarpet::Markdown.new(@render)
    output = renderer.render("# Hello World\n\n-\n\n=")

    assert_equal 1, output.scan("<li>").length
    assert !output.include?('<a href=\"#\"></a>')
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
redcarpet-3.2.3 test/html_toc_render_test.rb
redcarpet-3.2.2 test/html_toc_render_test.rb
redcarpet-3.2.1 test/html_toc_render_test.rb
redcarpet-3.2.0 test/html_toc_render_test.rb
tight-redcarpet-3.1.1 test/html_toc_render_test.rb