From 12b092523d9f967b9e61ec20cdb3d40658ad6eee Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Sat, 4 Oct 2025 17:59:30 +0100 Subject: [PATCH 1/5] Integration tests --- test/integration/lib/integration_test_case.rb | 48 ++++++ test/integration/rdoc/heading_test.rb | 39 +++++ test/integration/rdoc/horizontal_rule_test.rb | 29 ++++ test/integration/rdoc/text_markup_test.rb | 149 ++++++++++++++++++ 4 files changed, 265 insertions(+) create mode 100644 test/integration/lib/integration_test_case.rb create mode 100644 test/integration/rdoc/heading_test.rb create mode 100644 test/integration/rdoc/horizontal_rule_test.rb create mode 100644 test/integration/rdoc/text_markup_test.rb diff --git a/test/integration/lib/integration_test_case.rb b/test/integration/lib/integration_test_case.rb new file mode 100644 index 0000000000..10602230e0 --- /dev/null +++ b/test/integration/lib/integration_test_case.rb @@ -0,0 +1,48 @@ +require 'fileutils' +require 'open3' +require 'test/unit' +require 'tmpdir' + +class IntegrationTestCase < Test::Unit::TestCase + + # Run rdoc with the given markup as input; suffix is used for temp dirname uniqueness. + def run_rdoc(markup, suffix = nil) + # Default suffix is the name of the calling test, extracted from caller array. + suffix ||= caller[0].split('#').last.sub("'", '') + # Make the temp dirpath. + filestem = suffix.to_s + tmpdirpath = File.join(Dir.tmpdir, 'MarkupTest-' + filestem) + # Remove the dir and re-create it (belt and suspenders). + 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'}" + 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 + + # Convenience method for selecting lines. + def select_lines(lines, pattern) + lines.select {|line| line.match(pattern) } + end + +end diff --git a/test/integration/rdoc/heading_test.rb b/test/integration/rdoc/heading_test.rb new file mode 100644 index 0000000000..2414941cec --- /dev/null +++ b/test/integration/rdoc/heading_test.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true +require_relative '../lib/integration_test_case' + +class HeadingTest < IntegrationTestCase + + 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/integration/rdoc/text_markup_test.rb b/test/integration/rdoc/text_markup_test.rb new file mode 100644 index 0000000000..d8eeca1e77 --- /dev/null +++ b/test/integration/rdoc/text_markup_test.rb @@ -0,0 +1,149 @@ +# frozen_string_literal: true +require_relative '../lib/integration_test_case' + +class TextMarkupTest < IntegrationTestCase + + 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 + run_rdoc(markup) do |html_lines| + italic_word_lines = 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 = 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 + run_rdoc(markup) do |html_lines| + # Check count of bold words. + bold_word_lines = 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 = select_lines(html_lines, 'bold phrase') + # (Five, not four, b/c the heading generates two.) + assert_equal(5, bold_phrase_lines.size) + 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 + run_rdoc(markup) do |html_lines| + monofont_word_lines = 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 = 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 + run_rdoc(markup) do |html_lines| + converted_character_lines = 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 From 90b2891e0295932d45587bbbb3986522a603a567 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Sat, 4 Oct 2025 19:21:01 +0100 Subject: [PATCH 2/5] Fix bug (to work in all Ruby versions --- test/integration/lib/integration_test_case.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/lib/integration_test_case.rb b/test/integration/lib/integration_test_case.rb index 10602230e0..b8204163a2 100644 --- a/test/integration/lib/integration_test_case.rb +++ b/test/integration/lib/integration_test_case.rb @@ -8,7 +8,7 @@ class IntegrationTestCase < Test::Unit::TestCase # Run rdoc with the given markup as input; suffix is used for temp dirname uniqueness. def run_rdoc(markup, suffix = nil) # Default suffix is the name of the calling test, extracted from caller array. - suffix ||= caller[0].split('#').last.sub("'", '') + suffix ||= caller[0].split('#').last.chop # Make the temp dirpath. filestem = suffix.to_s tmpdirpath = File.join(Dir.tmpdir, 'MarkupTest-' + filestem) From 3feae8857afc15cc46cf4556468e5ca1ae69c3d8 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Sat, 4 Oct 2025 19:30:58 +0100 Subject: [PATCH 3/5] Another attempted fix --- test/integration/lib/integration_test_case.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/integration/lib/integration_test_case.rb b/test/integration/lib/integration_test_case.rb index b8204163a2..7e65944855 100644 --- a/test/integration/lib/integration_test_case.rb +++ b/test/integration/lib/integration_test_case.rb @@ -8,7 +8,8 @@ class IntegrationTestCase < Test::Unit::TestCase # Run rdoc with the given markup as input; suffix is used for temp dirname uniqueness. def run_rdoc(markup, suffix = nil) # Default suffix is the name of the calling test, extracted from caller array. - suffix ||= caller[0].split('#').last.chop + suffix ||= caller[0].partition(/test\w+/)[1] + p suffix # Make the temp dirpath. filestem = suffix.to_s tmpdirpath = File.join(Dir.tmpdir, 'MarkupTest-' + filestem) From 9cc905924cfbb0bdbc3fccdbaa9e7a47d7f73e05 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Sat, 4 Oct 2025 19:50:09 +0100 Subject: [PATCH 4/5] Another attempted fix --- test/integration/lib/integration_test_case.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/test/integration/lib/integration_test_case.rb b/test/integration/lib/integration_test_case.rb index 7e65944855..30d52dca90 100644 --- a/test/integration/lib/integration_test_case.rb +++ b/test/integration/lib/integration_test_case.rb @@ -6,12 +6,9 @@ class IntegrationTestCase < Test::Unit::TestCase # Run rdoc with the given markup as input; suffix is used for temp dirname uniqueness. - def run_rdoc(markup, suffix = nil) - # Default suffix is the name of the calling test, extracted from caller array. - suffix ||= caller[0].partition(/test\w+/)[1] - p suffix + def run_rdoc(markup) # Make the temp dirpath. - filestem = suffix.to_s + filestem = get_test_name tmpdirpath = File.join(Dir.tmpdir, 'MarkupTest-' + filestem) # Remove the dir and re-create it (belt and suspenders). FileUtils.rm_rf(tmpdirpath) @@ -41,6 +38,15 @@ def run_rdoc(markup, suffix = nil) FileUtils.rm_rf(tmpdirpath) end + # Get the test name from the caller array. + def get_test_name + caller.each do |entry| + entry.match(/#(test\w+)/) + return $1 if $1 + end + fail 'Could not determine test name.' + end + # Convenience method for selecting lines. def select_lines(lines, pattern) lines.select {|line| line.match(pattern) } From be6a8d099d33daf9a4ff5ec6f7d6bc1b9eb19967 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Sat, 4 Oct 2025 19:54:56 +0100 Subject: [PATCH 5/5] Another attempted fix --- test/integration/lib/integration_test_case.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/lib/integration_test_case.rb b/test/integration/lib/integration_test_case.rb index 30d52dca90..9b90ddecea 100644 --- a/test/integration/lib/integration_test_case.rb +++ b/test/integration/lib/integration_test_case.rb @@ -41,7 +41,7 @@ def run_rdoc(markup) # Get the test name from the caller array. def get_test_name caller.each do |entry| - entry.match(/#(test\w+)/) + entry.match(/\W(test\w+)/) return $1 if $1 end fail 'Could not determine test name.'