From b7a7a4d885b3cb0f786df0379ccf1db756dfa345 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Sat, 6 Sep 2025 22:36:03 +0100 Subject: [PATCH 01/10] End-to-end tests --- test/rdoc/end_to_end/heading_test.rb | 42 ++++++++++ test/rdoc/end_to_end/helper.rb | 51 ++++++++++++ test/rdoc/end_to_end/horizontal_rule_test.rb | 29 +++++++ test/rdoc/end_to_end/text_markup_test.rb | 83 ++++++++++++++++++++ 4 files changed, 205 insertions(+) create mode 100644 test/rdoc/end_to_end/heading_test.rb create mode 100644 test/rdoc/end_to_end/helper.rb create mode 100644 test/rdoc/end_to_end/horizontal_rule_test.rb create mode 100644 test/rdoc/end_to_end/text_markup_test.rb diff --git a/test/rdoc/end_to_end/heading_test.rb b/test/rdoc/end_to_end/heading_test.rb new file mode 100644 index 0000000000..42debdc4c4 --- /dev/null +++ b/test/rdoc/end_to_end/heading_test.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true +require_relative 'helper' + +class HeadingTest < XrefTestCase + + def test_headings + markup = <') + 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 = /

(—|–) 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 diff --git a/test/rdoc/end_to_end/text_markup_test.rb b/test/rdoc/end_to_end/text_markup_test.rb new file mode 100644 index 0000000000..8a05f95eec --- /dev/null +++ b/test/rdoc/end_to_end/text_markup_test.rb @@ -0,0 +1,83 @@ +# frozen_string_literal: true +require_relative 'helper' + +class TextMarkupTest < XrefTestCase + + def test_italic + markup = <>> + Block quote containing _italic_word_. + +- List item containing _italic_word_. + += Heading containing _italic_word_. + +Paragraph containing italic phrase. + +>>> + Block quote containing italic phrase. + +- List item containing italic phrase. + += Heading containing italic phrase. + +Paragraph containing italic phrase. + +>>> + Block quote containing italic phrase. + +- List item containing italic phrase. + += Heading containing italic phrase. + +MARKUP + Helper.run_rdoc(__method__, markup) do |html_lines| + italic_word_lines = Helper.select_lines(html_lines, 'italic_word') + # 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, 'italic phrase') + # 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 = <>> + Block quote containing *bold_word*. + +- List item containing *bold_word*. + += Heading containing *bold_word*. + +Paragraph containing bold phrase. + +>>> + Block quote containing bold phrase. + +- List item containing bold phrase. + += Heading containing bold phrase. + +MARKUP + Helper.run_rdoc(__method__, markup) do |html_lines| + # Check count of bold words. + bold_word_lines = Helper.select_lines(html_lines, 'bold_word') + # (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, 'bold phrase') + # (Five, not four, b/c the heading generates two.) + assert_equal(5, bold_word_lines.size) + end + end + +end From a25216cceabc9c011175fe759ffc0cded5b3ba37 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Sat, 6 Sep 2025 23:00:26 +0100 Subject: [PATCH 02/10] More --- test/rdoc/end_to_end/text_markup_test.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/rdoc/end_to_end/text_markup_test.rb b/test/rdoc/end_to_end/text_markup_test.rb index 8a05f95eec..2b6be355f9 100644 --- a/test/rdoc/end_to_end/text_markup_test.rb +++ b/test/rdoc/end_to_end/text_markup_test.rb @@ -58,14 +58,14 @@ def test_bold = Heading containing *bold_word*. -Paragraph containing bold phrase. +Paragraph containing bold phrase. >>> - Block quote containing bold phrase. + Block quote containing bold phrase. -- List item containing bold phrase. +- List item containing bold phrase. -= Heading containing bold phrase. += Heading containing bold phrase. MARKUP Helper.run_rdoc(__method__, markup) do |html_lines| @@ -76,7 +76,7 @@ def test_bold # Check count of bold phrases. bold_phrase_lines = Helper.select_lines(html_lines, 'bold phrase') # (Five, not four, b/c the heading generates two.) - assert_equal(5, bold_word_lines.size) + assert_equal(5, bold_phrase_lines.size) end end From 109374254fdd088a889d8bfaa52fd54d2407caa6 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Sat, 6 Sep 2025 23:29:24 +0100 Subject: [PATCH 03/10] More --- test/rdoc/end_to_end/text_markup_test.rb | 66 ++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/test/rdoc/end_to_end/text_markup_test.rb b/test/rdoc/end_to_end/text_markup_test.rb index 2b6be355f9..69efce8f56 100644 --- a/test/rdoc/end_to_end/text_markup_test.rb +++ b/test/rdoc/end_to_end/text_markup_test.rb @@ -80,4 +80,70 @@ def test_bold end end + def test_monofont + markup = <>> + Block quote containing +monofont_word+. + +- List item containing +monofont_word+. + += Heading containing +monofont_word+. + +Paragraph containing monofont phrase. + +>>> + Block quote containing monofont phrase. + +- List item containing monofont phrase. + += Heading containing monofont phrase. + +Paragraph containing monofont phrase. + +>>> + Block quote containing monofont phrase. + +- List item containing monofont phrase. + += Heading containing monofont phrase. + +MARKUP + Helper.run_rdoc(__method__, markup) do |html_lines| + monofont_word_lines = Helper.select_lines(html_lines, 'monofont_word') + # 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, 'monofont phrase') + # 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 = <>> + Block quote containing #{convertible_characters}. + +- List item containing #{convertible_characters}. + += Heading containing #{convertible_characters}. + +MARKUP + Helper.run_rdoc(__method__, markup) do |html_lines| + converted_character_lines = Helper.select_lines(html_lines, '© ® … – — ‘foo’ “bar”') + # Check count of converted character lines. + # (The heading line contains escapes, and so does not match.) + assert_equal(4, converted_character_lines.size) + end + end + end From 3618b4c548119402d68edf0900a6ca8e082d5b8a Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Sat, 6 Sep 2025 23:30:46 +0100 Subject: [PATCH 04/10] More --- test/rdoc/end_to_end/helper.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/rdoc/end_to_end/helper.rb b/test/rdoc/end_to_end/helper.rb index def52b36f2..f79b9f0b05 100644 --- a/test/rdoc/end_to_end/helper.rb +++ b/test/rdoc/end_to_end/helper.rb @@ -32,8 +32,9 @@ def self.run_rdoc(method, markup) # Run rdoc, to create the HTML file. Dir.chdir(@dirpath) do - command = "rdoc #{rdoc_filepath}" - system(command) + `rdoc #{rdoc_filepath}` + # command = "rdoc #{rdoc_filepath}" + # system(command) end # Get the HTML as lines. From 5f3123c1d23d7f6d6871a4a2f9ade8e4cf8c0f74 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Sat, 6 Sep 2025 23:47:07 +0100 Subject: [PATCH 05/10] More --- test/rdoc/end_to_end/helper.rb | 2 -- test/rdoc/end_to_end/text_markup_test.rb | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/test/rdoc/end_to_end/helper.rb b/test/rdoc/end_to_end/helper.rb index f79b9f0b05..66494606ba 100644 --- a/test/rdoc/end_to_end/helper.rb +++ b/test/rdoc/end_to_end/helper.rb @@ -33,8 +33,6 @@ def self.run_rdoc(method, markup) # Run rdoc, to create the HTML file. Dir.chdir(@dirpath) do `rdoc #{rdoc_filepath}` - # command = "rdoc #{rdoc_filepath}" - # system(command) end # Get the HTML as lines. diff --git a/test/rdoc/end_to_end/text_markup_test.rb b/test/rdoc/end_to_end/text_markup_test.rb index 69efce8f56..fe92b9b74c 100644 --- a/test/rdoc/end_to_end/text_markup_test.rb +++ b/test/rdoc/end_to_end/text_markup_test.rb @@ -141,7 +141,7 @@ def test_character_conversions Helper.run_rdoc(__method__, markup) do |html_lines| converted_character_lines = Helper.select_lines(html_lines, '© ® … – — ‘foo’ “bar”') # Check count of converted character lines. - # (The heading line contains escapes, and so does not match.) + # (The generated heading line contains escapes, and so does not match.) assert_equal(4, converted_character_lines.size) end end From 03a0f0887e5bdcf8d9003625cf1c7e23cc42f8cf Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Sat, 6 Sep 2025 23:58:38 +0100 Subject: [PATCH 06/10] More --- test/rdoc/end_to_end/heading_test.rb | 2 +- test/rdoc/end_to_end/helper.rb | 6 +++++- test/rdoc/end_to_end/horizontal_rule_test.rb | 4 ++-- test/rdoc/end_to_end/text_markup_test.rb | 8 ++++---- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/test/rdoc/end_to_end/heading_test.rb b/test/rdoc/end_to_end/heading_test.rb index 42debdc4c4..132efd3ecc 100644 --- a/test/rdoc/end_to_end/heading_test.rb +++ b/test/rdoc/end_to_end/heading_test.rb @@ -18,7 +18,7 @@ def test_headings ===== Section 2.1.1.1.1 ====== Section 2.1.1.1.1.1 MARKUP - Helper.run_rdoc(__method__, markup) do |html_lines| + Helper.run_rdoc(markup, __method__) do |html_lines| heading_lines = Helper.select_lines(html_lines, /^') 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. + # One of the above generates an M-dash, the other an N-dash. pattern = /

(—|–) Not a horizontal rule.<\/p>/ not_hr_lines = html_lines.select {|line| line.match(pattern) } assert_equal(2, not_hr_lines.size) diff --git a/test/rdoc/end_to_end/text_markup_test.rb b/test/rdoc/end_to_end/text_markup_test.rb index fe92b9b74c..b0ebb55429 100644 --- a/test/rdoc/end_to_end/text_markup_test.rb +++ b/test/rdoc/end_to_end/text_markup_test.rb @@ -34,7 +34,7 @@ def test_italic = Heading containing italic phrase. MARKUP - Helper.run_rdoc(__method__, markup) do |html_lines| + Helper.run_rdoc(markup, __method__) do |html_lines| italic_word_lines = Helper.select_lines(html_lines, 'italic_word') # Check count of italic words. # (Five, not four, b/c the heading generates two.) @@ -68,7 +68,7 @@ def test_bold = Heading containing bold phrase. MARKUP - Helper.run_rdoc(__method__, markup) do |html_lines| + Helper.run_rdoc(markup, __method__) do |html_lines| # Check count of bold words. bold_word_lines = Helper.select_lines(html_lines, 'bold_word') # (Five, not four, b/c the heading generates two.) @@ -111,7 +111,7 @@ def test_monofont = Heading containing monofont phrase. MARKUP - Helper.run_rdoc(__method__, markup) do |html_lines| + Helper.run_rdoc(markup, __method__) do |html_lines| monofont_word_lines = Helper.select_lines(html_lines, 'monofont_word') # Check count of monofont words. # (Five, not four, b/c the heading generates two.) @@ -138,7 +138,7 @@ def test_character_conversions = Heading containing #{convertible_characters}. MARKUP - Helper.run_rdoc(__method__, markup) do |html_lines| + 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.) From 575061f4990271019443dc122274fd2f80589659 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Thu, 11 Sep 2025 22:42:04 +0100 Subject: [PATCH 07/10] Avoid using REXML --- test/rdoc/end_to_end/heading_test.rb | 15 ++++++--------- test/rdoc/end_to_end/helper.rb | 3 --- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/test/rdoc/end_to_end/heading_test.rb b/test/rdoc/end_to_end/heading_test.rb index 132efd3ecc..e7da9940e5 100644 --- a/test/rdoc/end_to_end/heading_test.rb +++ b/test/rdoc/end_to_end/heading_test.rb @@ -26,15 +26,12 @@ def test_headings # Check each markup line against the corresponding heading line. markup_lines.each_with_index do |markup_line, index| heading_line = heading_lines[index] - doc = Document.new(heading_line) - root_ele = doc.root - # Check number of equal signs against the heading level. - equal_signs, section_title = markup_line.chomp.split(' ', 2) - heading_level = equal_signs.size - assert_equal("h#{heading_level}", root_ele.name) - # Check the id attribute. - id_value = root_ele.attribute('id').value - assert_equal("label-#{section_title.gsub(' ', '+')}", id_value) + equal_signs, expected_title = markup_line.chomp.split(' ', 2) + assert(heading_line.include?(expected_title)) + expected_heading_level = equal_signs.size + heading_line.match(/^ Date: Thu, 11 Sep 2025 23:02:51 +0100 Subject: [PATCH 08/10] Fix temp dir permissions for macos --- test/rdoc/end_to_end/helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/rdoc/end_to_end/helper.rb b/test/rdoc/end_to_end/helper.rb index 3b8001451d..21ce788035 100644 --- a/test/rdoc/end_to_end/helper.rb +++ b/test/rdoc/end_to_end/helper.rb @@ -8,6 +8,7 @@ def self.setup(filestem) @dirpath = File.join(Dir.tmpdir, 'MarkupTest-' + filestem) FileUtils.rm_rf(@dirpath) Dir.mkdir(@dirpath) + FileUtils.chmod(0700, @dirpath) end # Remove temporary directory. From 2c049bbb0c2595a561e28cf4e02fd982995a2ddd Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Fri, 12 Sep 2025 03:34:17 +0100 Subject: [PATCH 09/10] More --- test/rdoc/end_to_end/helper.rb | 56 +++++++++++++--------------------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/test/rdoc/end_to_end/helper.rb b/test/rdoc/end_to_end/helper.rb index 21ce788035..3884e5effe 100644 --- a/test/rdoc/end_to_end/helper.rb +++ b/test/rdoc/end_to_end/helper.rb @@ -3,48 +3,36 @@ class Helper - # Create temporary directory. - def self.setup(filestem) - @dirpath = File.join(Dir.tmpdir, 'MarkupTest-' + filestem) - FileUtils.rm_rf(@dirpath) - Dir.mkdir(@dirpath) - FileUtils.chmod(0700, @dirpath) - end - - # Remove temporary directory. - def self.teardown - FileUtils.rm_rf(@dirpath) - end - # 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 used in setup. + # 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 - self.setup(filestem) - - # Create the markdown file. - rdoc_filename = filestem + '.rdoc' - rdoc_filepath = File.join(@dirpath, rdoc_filename) - File.write(rdoc_filepath, markup) - - # Run rdoc, to create the HTML file. - Dir.chdir(@dirpath) do - `rdoc #{rdoc_filepath}` + 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. + html_dirname = 'html' + `rdoc --op html #{rdoc_filename} #{html_dirname}` + # Get the HTML as lines. + html_filename = filestem + '_rdoc.html' + html_filepath = File.join(html_dirname, html_filename) + html_lines = File.readlines(html_filepath) + # Yield them. + yield html_lines end - - # Get the HTML as lines. - html_filename = filestem + '_rdoc.html' - html_filepath = File.join(@dirpath, 'doc', html_filename) - html_lines = File.readlines(html_filepath) - - yield html_lines - - self.teardown + # Clean up. + FileUtils.rm_rf(tmpdirpath) end From 8cccd90b46aa860c9380f95f3398b74734fea07c Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Fri, 12 Sep 2025 04:04:34 +0100 Subject: [PATCH 10/10] More --- test/rdoc/end_to_end/helper.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test/rdoc/end_to_end/helper.rb b/test/rdoc/end_to_end/helper.rb index 3884e5effe..01f483baea 100644 --- a/test/rdoc/end_to_end/helper.rb +++ b/test/rdoc/end_to_end/helper.rb @@ -1,4 +1,5 @@ require 'fileutils' +require 'open3' require_relative '../xref_test_case' class Helper @@ -22,11 +23,17 @@ def self.run_rdoc(markup, method) rdoc_filename = filestem + '.rdoc' File.write(rdoc_filename, markup) # Run rdoc, to create the HTML file. - html_dirname = 'html' - `rdoc --op html #{rdoc_filename} #{html_dirname}` + 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(html_dirname, html_filename) + html_filepath = File.join('doc', html_filename) html_lines = File.readlines(html_filepath) # Yield them. yield html_lines