Skip to content

Commit b7a7a4d

Browse files
committed
End-to-end tests
1 parent e2dec09 commit b7a7a4d

4 files changed

Lines changed: 205 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
require_relative 'helper'
3+
4+
class HeadingTest < XrefTestCase
5+
6+
def test_headings
7+
markup = <<MARKUP
8+
= Section 1
9+
== Section 1.1
10+
=== Section 1.1.1
11+
==== Section 1.1.1.1
12+
===== Section 1.1.1.1.1
13+
====== Section 1.1.1.1.1.1
14+
= Section 2
15+
== Section 2.1
16+
=== Section 2.1.1
17+
==== Section 2.1.1.1
18+
===== Section 2.1.1.1.1
19+
====== Section 2.1.1.1.1.1
20+
MARKUP
21+
Helper.run_rdoc(__method__, markup) do |html_lines|
22+
heading_lines = Helper.select_lines(html_lines, /^<h\d/)
23+
# Check count of headings.
24+
markup_lines = markup.lines
25+
assert_equal(markup_lines.size, heading_lines.size)
26+
# Check each markup line against the corresponding heading line.
27+
markup_lines.each_with_index do |markup_line, index|
28+
heading_line = heading_lines[index]
29+
doc = Document.new(heading_line)
30+
root_ele = doc.root
31+
# Check number of equal signs against the heading level.
32+
equal_signs, section_title = markup_line.chomp.split(' ', 2)
33+
heading_level = equal_signs.size
34+
assert_equal("h#{heading_level}", root_ele.name)
35+
# Check the id attribute.
36+
id_value = root_ele.attribute('id').value
37+
assert_equal("label-#{section_title.gsub(' ', '+')}", id_value)
38+
end
39+
end
40+
end
41+
42+
end

test/rdoc/end_to_end/helper.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
require 'fileutils'
2+
require 'rexml/document'
3+
require_relative '../xref_test_case'
4+
5+
include REXML
6+
7+
class Helper
8+
9+
def self.setup(filestem)
10+
@dirpath = File.join(Dir.tmpdir, 'MarkupTest-' + filestem)
11+
FileUtils.rm_rf(@dirpath)
12+
Dir.mkdir(@dirpath)
13+
end
14+
15+
def self.teardown
16+
FileUtils.rm_rf(@dirpath)
17+
end
18+
19+
def self.select_lines(lines, pattern)
20+
lines.select { |line| line.match(pattern) }
21+
end
22+
23+
def self.run_rdoc(method, markup)
24+
25+
filestem = method.to_s
26+
self.setup(filestem)
27+
28+
# Create the markdown file.
29+
rdoc_filename = filestem + '.rdoc'
30+
rdoc_filepath = File.join(@dirpath, rdoc_filename)
31+
File.write(rdoc_filepath, markup)
32+
33+
# Run rdoc, to create the HTML file.
34+
Dir.chdir(@dirpath) do
35+
command = "rdoc #{rdoc_filepath}"
36+
system(command)
37+
end
38+
39+
# Get the HTML as lines.
40+
html_filename = filestem + '_rdoc.html'
41+
html_filepath = File.join(@dirpath, 'doc', html_filename)
42+
html_lines = File.readlines(html_filepath)
43+
44+
yield html_lines
45+
46+
self.teardown
47+
48+
end
49+
50+
51+
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
require_relative 'helper'
3+
4+
class HorizontalRuleTest < XrefTestCase
5+
6+
def test_horizontal_rule
7+
markup = <<MARKUP
8+
---
9+
10+
--- Not a horizontal rule.
11+
12+
-- Not a horizontal rule.
13+
14+
---
15+
16+
MARKUP
17+
Helper.run_rdoc(__method__, markup) do |html_lines|
18+
# Check count of horizontal rules.
19+
hr_lines = Helper.select_lines(html_lines, '<hr>')
20+
assert_equal(2, hr_lines.size)
21+
# Check count of not horizontal rules.
22+
# One of the above generates an M dash, the other an N dash.
23+
pattern = /<p>(—|–) Not a horizontal rule.<\/p>/
24+
not_hr_lines = html_lines.select {|line| line.match(pattern) }
25+
assert_equal(2, not_hr_lines.size)
26+
end
27+
end
28+
29+
end
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# frozen_string_literal: true
2+
require_relative 'helper'
3+
4+
class TextMarkupTest < XrefTestCase
5+
6+
def test_italic
7+
markup = <<MARKUP
8+
9+
Paragraph containing _italic_word_.
10+
11+
>>>
12+
Block quote containing _italic_word_.
13+
14+
- List item containing _italic_word_.
15+
16+
= Heading containing _italic_word_.
17+
18+
Paragraph containing <i>italic phrase</i>.
19+
20+
>>>
21+
Block quote containing <i>italic phrase</i>.
22+
23+
- List item containing <i>italic phrase</i>.
24+
25+
= Heading containing <i>italic phrase</i>.
26+
27+
Paragraph containing <em>italic phrase</em>.
28+
29+
>>>
30+
Block quote containing <em>italic phrase</em>.
31+
32+
- List item containing <em>italic phrase</em>.
33+
34+
= Heading containing <em>italic phrase</em>.
35+
36+
MARKUP
37+
Helper.run_rdoc(__method__, markup) do |html_lines|
38+
italic_word_lines = Helper.select_lines(html_lines, '<em>italic_word</em>')
39+
# Check count of italic words.
40+
# (Five, not four, b/c the heading generates two.)
41+
assert_equal(5, italic_word_lines.size)
42+
italic_phrase_lines = Helper.select_lines(html_lines, '<em>italic phrase</em>')
43+
# Check count of italic phrases.
44+
# (Ten, not eight, b/c each heading generates two.)
45+
assert_equal(10, italic_phrase_lines.size)
46+
end
47+
end
48+
49+
def test_bold
50+
markup = <<MARKUP
51+
52+
Paragraph containing *bold_word*.
53+
54+
>>>
55+
Block quote containing *bold_word*.
56+
57+
- List item containing *bold_word*.
58+
59+
= Heading containing *bold_word*.
60+
61+
Paragraph containing <tt>bold phrase</tt>.
62+
63+
>>>
64+
Block quote containing <tt>bold phrase</tt>.
65+
66+
- List item containing <tt>bold phrase</tt>.
67+
68+
= Heading containing <tt>bold phrase</tt>.
69+
70+
MARKUP
71+
Helper.run_rdoc(__method__, markup) do |html_lines|
72+
# Check count of bold words.
73+
bold_word_lines = Helper.select_lines(html_lines, '<strong>bold_word</strong>')
74+
# (Five, not four, b/c the heading generates two.)
75+
assert_equal(5, bold_word_lines.size)
76+
# Check count of bold phrases.
77+
bold_phrase_lines = Helper.select_lines(html_lines, '<strong>bold phrase</strong>')
78+
# (Five, not four, b/c the heading generates two.)
79+
assert_equal(5, bold_word_lines.size)
80+
end
81+
end
82+
83+
end

0 commit comments

Comments
 (0)