Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions test/rdoc/end_to_end/heading_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true
require_relative 'helper'

class HeadingTest < XrefTestCase

def test_headings
markup = <<MARKUP
= Section 1
== Section 1.1
=== Section 1.1.1
==== Section 1.1.1.1
===== Section 1.1.1.1.1
====== Section 1.1.1.1.1.1
= Section 2
== Section 2.1
=== Section 2.1.1
==== Section 2.1.1.1
===== Section 2.1.1.1.1
====== Section 2.1.1.1.1.1
MARKUP
Helper.run_rdoc(markup, __method__) do |html_lines|
heading_lines = Helper.select_lines(html_lines, /^<h\d/)
# Check count of headings.
markup_lines = markup.lines
assert_equal(markup_lines.size, heading_lines.size)
# Check each markup line against the corresponding heading line.
markup_lines.each_with_index do |markup_line, index|
heading_line = heading_lines[index]
equal_signs, expected_title = markup_line.chomp.split(' ', 2)
assert(heading_line.include?(expected_title))
expected_heading_level = equal_signs.size
heading_line.match(/^<h(\d)/)
actual_heading_level = $1.to_i
assert_equal(expected_heading_level, actual_heading_level)
end
end
end

end
47 changes: 47 additions & 0 deletions test/rdoc/end_to_end/helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require 'fileutils'
require 'open3'
require_relative '../xref_test_case'

class Helper

# Convenience method for selecting lines.
def self.select_lines(lines, pattern)
lines.select { |line| line.match(pattern) }
end

# Run rdoc for given markup; method is the caller's __method__, used for filename uniqueness.
def self.run_rdoc(markup, method)
# Make the temp dirpath; remove the dir and re-create it.
filestem = method.to_s
tmpdirpath = File.join(Dir.tmpdir, 'MarkupTest-' + filestem)
FileUtils.rm_rf(tmpdirpath)
Dir.mkdir(tmpdirpath)
FileUtils.chmod(0700, tmpdirpath)
# Do all the work in the temporary directory.
Dir.chdir(tmpdirpath) do
# Create the markdown file.
rdoc_filename = filestem + '.rdoc'
File.write(rdoc_filename, markup)
# Run rdoc, to create the HTML file.
command = "rdoc #{rdoc_filename + 'xxx'}"
puts command
Open3.popen3(command) do |_, stdout, stderr|
stdout_s = stdout.read
raise RuntimeError.new(stdout_s) unless stdout_s.match('Parsing')
stderr_s = stderr.read
raise RuntimeError.new(stderr_s) unless stderr_s.match('Generating')
end
# Get the HTML as lines.
html_filename = filestem + '_rdoc.html'
html_filepath = File.join('doc', html_filename)
html_lines = File.readlines(html_filepath)
# Yield them.
yield html_lines
end
# Clean up.
FileUtils.rm_rf(tmpdirpath)

end


end
29 changes: 29 additions & 0 deletions test/rdoc/end_to_end/horizontal_rule_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true
require_relative 'helper'

class HorizontalRuleTest < XrefTestCase

def test_horizontal_rule
markup = <<MARKUP
---

--- Not a horizontal rule.

-- Not a horizontal rule.

---

MARKUP
Helper.run_rdoc(markup, __method__) do |html_lines|
# Check count of horizontal rules.
hr_lines = Helper.select_lines(html_lines, '<hr>')
assert_equal(2, hr_lines.size)
# Check count of not horizontal rules.
# One of the above generates an M-dash, the other an N-dash.
pattern = /<p>(—|–) Not a horizontal rule.<\/p>/
not_hr_lines = html_lines.select {|line| line.match(pattern) }
assert_equal(2, not_hr_lines.size)
end
end

end
149 changes: 149 additions & 0 deletions test/rdoc/end_to_end/text_markup_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# frozen_string_literal: true
require_relative 'helper'

class TextMarkupTest < XrefTestCase

def test_italic
markup = <<MARKUP

Paragraph containing _italic_word_.

>>>
Block quote containing _italic_word_.

- List item containing _italic_word_.

= Heading containing _italic_word_.

Paragraph containing <i>italic phrase</i>.

>>>
Block quote containing <i>italic phrase</i>.

- List item containing <i>italic phrase</i>.

= Heading containing <i>italic phrase</i>.

Paragraph containing <em>italic phrase</em>.

>>>
Block quote containing <em>italic phrase</em>.

- List item containing <em>italic phrase</em>.

= Heading containing <em>italic phrase</em>.

MARKUP
Helper.run_rdoc(markup, __method__) do |html_lines|
italic_word_lines = Helper.select_lines(html_lines, '<em>italic_word</em>')
# Check count of italic words.
# (Five, not four, b/c the heading generates two.)
assert_equal(5, italic_word_lines.size)
italic_phrase_lines = Helper.select_lines(html_lines, '<em>italic phrase</em>')
# Check count of italic phrases.
# (Ten, not eight, b/c each heading generates two.)
assert_equal(10, italic_phrase_lines.size)
end
end

def test_bold
markup = <<MARKUP

Paragraph containing *bold_word*.

>>>
Block quote containing *bold_word*.

- List item containing *bold_word*.

= Heading containing *bold_word*.

Paragraph containing <b>bold phrase</b>.

>>>
Block quote containing <b>bold phrase</b>.

- List item containing <b>bold phrase</b>.

= Heading containing <b>bold phrase</b>.

MARKUP
Helper.run_rdoc(markup, __method__) do |html_lines|
# Check count of bold words.
bold_word_lines = Helper.select_lines(html_lines, '<strong>bold_word</strong>')
# (Five, not four, b/c the heading generates two.)
assert_equal(5, bold_word_lines.size)
# Check count of bold phrases.
bold_phrase_lines = Helper.select_lines(html_lines, '<strong>bold phrase</strong>')
# (Five, not four, b/c the heading generates two.)
assert_equal(5, bold_phrase_lines.size)
end
end

def test_monofont
markup = <<MARKUP

Paragraph containing +monofont_word+.

>>>
Block quote containing +monofont_word+.

- List item containing +monofont_word+.

= Heading containing +monofont_word+.

Paragraph containing <tt>monofont phrase</tt>.

>>>
Block quote containing <tt>monofont phrase</tt>.

- List item containing <tt>monofont phrase</tt>.

= Heading containing <tt>monofont phrase</tt>.

Paragraph containing <code>monofont phrase</code>.

>>>
Block quote containing <code>monofont phrase</code>.

- List item containing <code>monofont phrase</code>.

= Heading containing <code>monofont phrase</code>.

MARKUP
Helper.run_rdoc(markup, __method__) do |html_lines|
monofont_word_lines = Helper.select_lines(html_lines, '<code>monofont_word</code>')
# Check count of monofont words.
# (Five, not four, b/c the heading generates two.)
assert_equal(5, monofont_word_lines.size)
monofont_phrase_lines = Helper.select_lines(html_lines, '<code>monofont phrase</code>')
# Check count of monofont phrases.
# (Ten, not eight, b/c each heading generates two.)
assert_equal(10, monofont_phrase_lines.size)
end
end

def test_character_conversions
convertible_characters = %w[(c) (r) ... -- --- 'foo' "bar"].join(' ')

markup = <<MARKUP

Paragraph containing #{convertible_characters}.

>>>
Block quote containing #{convertible_characters}.

- List item containing #{convertible_characters}.

= Heading containing #{convertible_characters}.

MARKUP
Helper.run_rdoc(markup, __method__) do |html_lines|
converted_character_lines = Helper.select_lines(html_lines, '© ® … – — ‘foo’ “bar”')
# Check count of converted character lines.
# (The generated heading line contains escapes, and so does not match.)
assert_equal(4, converted_character_lines.size)
end
end

end
Loading