From 79fe84edf5da875daf240c9c11220ba89f3d49af Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 14 Aug 2019 21:12:15 +0900 Subject: Removed test_case files from lib directory. --- test/rdoc/helper.rb | 205 +------ test/rdoc/support/formatter_test_case.rb | 764 ++++++++++++++++++++++++++ test/rdoc/support/test_case.rb | 216 ++++++++ test/rdoc/support/text_formatter_test_case.rb | 115 ++++ 4 files changed, 1098 insertions(+), 202 deletions(-) create mode 100644 test/rdoc/support/formatter_test_case.rb create mode 100644 test/rdoc/support/test_case.rb create mode 100644 test/rdoc/support/text_formatter_test_case.rb (limited to 'test/rdoc') diff --git a/test/rdoc/helper.rb b/test/rdoc/helper.rb index a900491987..2ba26c296b 100644 --- a/test/rdoc/helper.rb +++ b/test/rdoc/helper.rb @@ -1,204 +1,5 @@ # frozen_string_literal: true -require 'bundler/errors' -begin - gem 'test-unit' -rescue NoMethodError, Gem::LoadError, Bundler::GemfileNotFound - # for ruby tests -end -require 'test/unit' - -require 'fileutils' -require 'pp' -require 'tempfile' -require 'tmpdir' -require 'stringio' - -require 'rdoc' - -## -# RDoc::TestCase is an abstract TestCase to provide common setup and teardown -# across all RDoc tests. The test case uses minitest, so all the assertions -# of minitest may be used. -# -# The testcase provides the following: -# -# * A reset code-object tree -# * A reset markup preprocessor (RDoc::Markup::PreProcess) -# * The @RM alias of RDoc::Markup (for less typing) -# * @pwd containing the current working directory -# * FileUtils, pp, Tempfile, Dir.tmpdir and StringIO - -class RDoc::TestCase < Test::Unit::TestCase - - ## - # Abstract test-case setup - - def setup - super - - @top_level = nil - - @RM = RDoc::Markup - - @pwd = Dir.pwd - - @store = RDoc::Store.new - - @rdoc = RDoc::RDoc.new - @rdoc.store = @store - @rdoc.options = RDoc::Options.new - - g = Object.new - def g.class_dir() end - def g.file_dir() end - @rdoc.generator = g - - RDoc::Markup::PreProcess.reset - end - - ## - # Asserts +path+ is a file - - def assert_file path - assert File.file?(path), "#{path} is not a file" - end - - ## - # Asserts +path+ is a directory - - def assert_directory path - assert File.directory?(path), "#{path} is not a directory" - end - - ## - # Refutes +path+ exists - - def refute_file path - refute File.exist?(path), "#{path} exists" - end - - ## - # Shortcut for RDoc::Markup::BlankLine.new - - def blank_line - @RM::BlankLine.new - end - - ## - # Shortcut for RDoc::Markup::BlockQuote.new with +contents+ - - def block *contents - @RM::BlockQuote.new(*contents) - end - - ## - # Creates an RDoc::Comment with +text+ which was defined on +top_level+. - # By default the comment has the 'rdoc' format. - - def comment text, top_level = @top_level, language = nil - comment = RDoc::Comment.new text, top_level, language - comment - end - - ## - # Shortcut for RDoc::Markup::Document.new with +contents+ - - def doc *contents - @RM::Document.new(*contents) - end - - ## - # Shortcut for RDoc::Markup::HardBreak.new - - def hard_break - @RM::HardBreak.new - end - - ## - # Shortcut for RDoc::Markup::Heading.new with +level+ and +text+ - - def head level, text - @RM::Heading.new level, text - end - - ## - # Shortcut for RDoc::Markup::ListItem.new with +label+ and +parts+ - - def item label = nil, *parts - @RM::ListItem.new label, *parts - end - - ## - # Shortcut for RDoc::Markup::List.new with +type+ and +items+ - - def list type = nil, *items - @RM::List.new type, *items - end - - ## - # Enables pretty-print output - - def mu_pp obj # :nodoc: - s = obj.pretty_inspect - s = RDoc::Encoding.change_encoding s, Encoding.default_external - s.chomp - end - - ## - # Shortcut for RDoc::Markup::Paragraph.new with +contents+ - - def para *a - @RM::Paragraph.new(*a) - end - - ## - # Shortcut for RDoc::Markup::Rule.new with +weight+ - - def rule weight - @RM::Rule.new weight - end - - ## - # Shortcut for RDoc::Markup::Raw.new with +contents+ - - def raw *contents - @RM::Raw.new(*contents) - end - - ## - # Creates a temporary directory changes the current directory to it for the - # duration of the block. - # - # Depends upon Dir.mktmpdir - - def temp_dir - Dir.mktmpdir do |temp_dir| - Dir.chdir temp_dir do - yield temp_dir - end - end - end - - ## - # Shortcut for RDoc::Markup::Verbatim.new with +parts+ - - def verb *parts - @RM::Verbatim.new(*parts) - end - - ## - # run capture_output with setting $VERBOSE = true - - def verbose_capture_output - capture_output do - begin - orig_verbose = $VERBOSE - $VERBOSE = true - yield - ensure - $VERBOSE = orig_verbose - end - end - end -end +require_relative './support/test_case' +require_relative './support/formatter_test_case' +require_relative './support/text_formatter_test_case' diff --git a/test/rdoc/support/formatter_test_case.rb b/test/rdoc/support/formatter_test_case.rb new file mode 100644 index 0000000000..9f49dd0897 --- /dev/null +++ b/test/rdoc/support/formatter_test_case.rb @@ -0,0 +1,764 @@ +# frozen_string_literal: true +require 'test/unit' + +## +# Test case for creating new RDoc::Markup formatters. See +# test/test_rdoc_markup_to_*.rb for examples. +# +# This test case adds a variety of tests to your subclass when +# #add_visitor_tests is called. Most tests set up a scenario then call a +# method you will provide to perform the assertion on the output. +# +# Your subclass must instantiate a visitor and assign it to @to. +# +# For example, test_accept_blank_line sets up a RDoc::Markup::BlockLine then +# calls accept_blank_line on your visitor. You are responsible for asserting +# that the output is correct. +# +# Example: +# +# class TestRDocMarkupToNewFormat < RDoc::Markup::FormatterTestCase +# +# add_visitor_tests +# +# def setup +# super +# +# @to = RDoc::Markup::ToNewFormat.new +# end +# +# def accept_blank_line +# assert_equal :junk, @to.res.join +# end +# +# # ... +# +# end + +class RDoc::Markup::FormatterTestCase < RDoc::TestCase + + ## + # Call #setup when inheriting from this test case. + # + # Provides the following instance variables: + # + # +@m+:: RDoc::Markup.new + # +@RM+:: RDoc::Markup # to reduce typing + # +@bullet_list+:: @RM::List.new :BULLET, # ... + # +@label_list+:: @RM::List.new :LABEL, # ... + # +@lalpha_list+:: @RM::List.new :LALPHA, # ... + # +@note_list+:: @RM::List.new :NOTE, # ... + # +@number_list+:: @RM::List.new :NUMBER, # ... + # +@ualpha_list+:: @RM::List.new :UALPHA, # ... + + def setup + super + + @options = RDoc::Options.new + + @m = @RM.new + + @bullet_list = @RM::List.new(:BULLET, + @RM::ListItem.new(nil, @RM::Paragraph.new('l1')), + @RM::ListItem.new(nil, @RM::Paragraph.new('l2'))) + + @label_list = @RM::List.new(:LABEL, + @RM::ListItem.new('cat', @RM::Paragraph.new('cats are cool')), + @RM::ListItem.new('dog', @RM::Paragraph.new('dogs are cool too'))) + + @lalpha_list = @RM::List.new(:LALPHA, + @RM::ListItem.new(nil, @RM::Paragraph.new('l1')), + @RM::ListItem.new(nil, @RM::Paragraph.new('l2'))) + + @note_list = @RM::List.new(:NOTE, + @RM::ListItem.new('cat', @RM::Paragraph.new('cats are cool')), + @RM::ListItem.new('dog', @RM::Paragraph.new('dogs are cool too'))) + + @number_list = @RM::List.new(:NUMBER, + @RM::ListItem.new(nil, @RM::Paragraph.new('l1')), + @RM::ListItem.new(nil, @RM::Paragraph.new('l2'))) + + @ualpha_list = @RM::List.new(:UALPHA, + @RM::ListItem.new(nil, @RM::Paragraph.new('l1')), + @RM::ListItem.new(nil, @RM::Paragraph.new('l2'))) + end + + ## + # Call to add the visitor tests to your test case + + def self.add_visitor_tests + class_eval do + + ## + # Calls start_accepting which needs to verify startup state + + def test_start_accepting + @to.start_accepting + + start_accepting + end + + ## + # Calls end_accepting on your test case which needs to call + # @to.end_accepting and verify document generation + + def test_end_accepting + @to.start_accepting + @to.res << 'hi' + + end_accepting + end + + ## + # Calls accept_blank_line + + def test_accept_blank_line + @to.start_accepting + + @to.accept_blank_line @RM::BlankLine.new + + accept_blank_line + end + + ## + # Calls accept_block_quote + + def test_accept_block_quote + @to.start_accepting + + @to.accept_block_quote block para 'quote' + + accept_block_quote + end + ## + # Test case that calls @to.accept_document + + def test_accept_document + @to.start_accepting + @to.accept_document @RM::Document.new @RM::Paragraph.new 'hello' + + accept_document + end + + ## + # Calls accept_heading with a level 5 RDoc::Markup::Heading + + def test_accept_heading + @to.start_accepting + + @to.accept_heading @RM::Heading.new(5, 'Hello') + + accept_heading + end + + ## + # Calls accept_heading_1 with a level 1 RDoc::Markup::Heading + + def test_accept_heading_1 + @to.start_accepting + + @to.accept_heading @RM::Heading.new(1, 'Hello') + + accept_heading_1 + end + + ## + # Calls accept_heading_2 with a level 2 RDoc::Markup::Heading + + def test_accept_heading_2 + @to.start_accepting + + @to.accept_heading @RM::Heading.new(2, 'Hello') + + accept_heading_2 + end + + ## + # Calls accept_heading_3 with a level 3 RDoc::Markup::Heading + + def test_accept_heading_3 + @to.start_accepting + + @to.accept_heading @RM::Heading.new(3, 'Hello') + + accept_heading_3 + end + + ## + # Calls accept_heading_4 with a level 4 RDoc::Markup::Heading + + def test_accept_heading_4 + @to.start_accepting + + @to.accept_heading @RM::Heading.new(4, 'Hello') + + accept_heading_4 + end + + ## + # Calls accept_heading_b with a bold level 1 RDoc::Markup::Heading + + def test_accept_heading_b + @to.start_accepting + + @to.accept_heading @RM::Heading.new(1, '*Hello*') + + accept_heading_b + end + + ## + # Calls accept_heading_suppressed_crossref with a level 1 + # RDoc::Markup::Heading containing a suppressed crossref + + def test_accept_heading_suppressed_crossref # HACK to_html_crossref test + @to.start_accepting + + @to.accept_heading @RM::Heading.new(1, '\\Hello') + + accept_heading_suppressed_crossref + end + + ## + # Calls accept_paragraph + + def test_accept_paragraph + @to.start_accepting + + @to.accept_paragraph @RM::Paragraph.new('hi') + + accept_paragraph + end + + ## + # Calls accept_paragraph_b with a RDoc::Markup::Paragraph containing + # bold words + + def test_accept_paragraph_b + @to.start_accepting + + @to.accept_paragraph @RM::Paragraph.new('reg bold words reg') + + accept_paragraph_b + end + + ## + # Calls accept_paragraph_br with a RDoc::Markup::Paragraph containing + # a \
+ + def test_accept_paragraph_br + @to.start_accepting + + @to.accept_paragraph para 'one
two' + + accept_paragraph_br + end + + ## + # Calls accept_paragraph with a Paragraph containing a hard break + + def test_accept_paragraph_break + @to.start_accepting + + @to.accept_paragraph para('hello', hard_break, 'world') + + accept_paragraph_break + end + + ## + # Calls accept_paragraph_i with a RDoc::Markup::Paragraph containing + # emphasized words + + def test_accept_paragraph_i + @to.start_accepting + + @to.accept_paragraph @RM::Paragraph.new('reg italic words reg') + + accept_paragraph_i + end + + ## + # Calls accept_paragraph_plus with a RDoc::Markup::Paragraph containing + # teletype words + + def test_accept_paragraph_plus + @to.start_accepting + + @to.accept_paragraph @RM::Paragraph.new('reg +teletype+ reg') + + accept_paragraph_plus + end + + ## + # Calls accept_paragraph_star with a RDoc::Markup::Paragraph containing + # bold words + + def test_accept_paragraph_star + @to.start_accepting + + @to.accept_paragraph @RM::Paragraph.new('reg *bold* reg') + + accept_paragraph_star + end + + ## + # Calls accept_paragraph_underscore with a RDoc::Markup::Paragraph + # containing emphasized words + + def test_accept_paragraph_underscore + @to.start_accepting + + @to.accept_paragraph @RM::Paragraph.new('reg _italic_ reg') + + accept_paragraph_underscore + end + + ## + # Calls accept_verbatim with a RDoc::Markup::Verbatim + + def test_accept_verbatim + @to.start_accepting + + @to.accept_verbatim @RM::Verbatim.new("hi\n", " world\n") + + accept_verbatim + end + + ## + # Calls accept_raw with a RDoc::Markup::Raw + + def test_accept_raw + @to.start_accepting + + @to.accept_raw @RM::Raw.new("", + "
NameCount", + "
a1", + "
b2", + "
") + + accept_raw + end + + ## + # Calls accept_rule with a RDoc::Markup::Rule + + def test_accept_rule + @to.start_accepting + + @to.accept_rule @RM::Rule.new(4) + + accept_rule + end + + ## + # Calls accept_list_item_start_bullet + + def test_accept_list_item_start_bullet + @to.start_accepting + + @to.accept_list_start @bullet_list + + @to.accept_list_item_start @bullet_list.items.first + + accept_list_item_start_bullet + end + + ## + # Calls accept_list_item_start_label + + def test_accept_list_item_start_label + @to.start_accepting + + @to.accept_list_start @label_list + + @to.accept_list_item_start @label_list.items.first + + accept_list_item_start_label + end + + ## + # Calls accept_list_item_start_lalpha + + def test_accept_list_item_start_lalpha + @to.start_accepting + + @to.accept_list_start @lalpha_list + + @to.accept_list_item_start @lalpha_list.items.first + + accept_list_item_start_lalpha + end + + ## + # Calls accept_list_item_start_note + + def test_accept_list_item_start_note + @to.start_accepting + + @to.accept_list_start @note_list + + @to.accept_list_item_start @note_list.items.first + + accept_list_item_start_note + end + + ## + # Calls accept_list_item_start_note_2 + + def test_accept_list_item_start_note_2 + list = list(:NOTE, + item('teletype', + para('teletype description'))) + + @to.start_accepting + + list.accept @to + + @to.end_accepting + + accept_list_item_start_note_2 + end + + ## + # Calls accept_list_item_start_note_multi_description + + def test_accept_list_item_start_note_multi_description + list = list(:NOTE, + item(%w[label], + para('description one')), + item(nil, para('description two'))) + + @to.start_accepting + + list.accept @to + + @to.end_accepting + + accept_list_item_start_note_multi_description + end + + ## + # Calls accept_list_item_start_note_multi_label + + def test_accept_list_item_start_note_multi_label + list = list(:NOTE, + item(%w[one two], + para('two headers'))) + + @to.start_accepting + + list.accept @to + + @to.end_accepting + + accept_list_item_start_note_multi_label + end + + ## + # Calls accept_list_item_start_number + + def test_accept_list_item_start_number + @to.start_accepting + + @to.accept_list_start @number_list + + @to.accept_list_item_start @number_list.items.first + + accept_list_item_start_number + end + + ## + # Calls accept_list_item_start_ualpha + + def test_accept_list_item_start_ualpha + @to.start_accepting + + @to.accept_list_start @ualpha_list + + @to.accept_list_item_start @ualpha_list.items.first + + accept_list_item_start_ualpha + end + + ## + # Calls accept_list_item_end_bullet + + def test_accept_list_item_end_bullet + @to.start_accepting + + @to.accept_list_start @bullet_list + + @to.accept_list_item_start @bullet_list.items.first + + @to.accept_list_item_end @bullet_list.items.first + + accept_list_item_end_bullet + end + + ## + # Calls accept_list_item_end_label + + def test_accept_list_item_end_label + @to.start_accepting + + @to.accept_list_start @label_list + + @to.accept_list_item_start @label_list.items.first + + @to.accept_list_item_end @label_list.items.first + + accept_list_item_end_label + end + + ## + # Calls accept_list_item_end_lalpha + + def test_accept_list_item_end_lalpha + @to.start_accepting + + @to.accept_list_start @lalpha_list + + @to.accept_list_item_start @lalpha_list.items.first + + @to.accept_list_item_end @lalpha_list.items.first + + accept_list_item_end_lalpha + end + + ## + # Calls accept_list_item_end_note + + def test_accept_list_item_end_note + @to.start_accepting + + @to.accept_list_start @note_list + + @to.accept_list_item_start @note_list.items.first + + @to.accept_list_item_end @note_list.items.first + + accept_list_item_end_note + end + + ## + # Calls accept_list_item_end_number + + def test_accept_list_item_end_number + @to.start_accepting + + @to.accept_list_start @number_list + + @to.accept_list_item_start @number_list.items.first + + @to.accept_list_item_end @number_list.items.first + + accept_list_item_end_number + end + + ## + # Calls accept_list_item_end_ualpha + + def test_accept_list_item_end_ualpha + @to.start_accepting + + @to.accept_list_start @ualpha_list + + @to.accept_list_item_start @ualpha_list.items.first + + @to.accept_list_item_end @ualpha_list.items.first + + accept_list_item_end_ualpha + end + + ## + # Calls accept_list_start_bullet + + def test_accept_list_start_bullet + @to.start_accepting + + @to.accept_list_start @bullet_list + + accept_list_start_bullet + end + + ## + # Calls accept_list_start_label + + def test_accept_list_start_label + @to.start_accepting + + @to.accept_list_start @label_list + + accept_list_start_label + end + + ## + # Calls accept_list_start_lalpha + + def test_accept_list_start_lalpha + @to.start_accepting + + @to.accept_list_start @lalpha_list + + accept_list_start_lalpha + end + + ## + # Calls accept_list_start_note + + def test_accept_list_start_note + @to.start_accepting + + @to.accept_list_start @note_list + + accept_list_start_note + end + + ## + # Calls accept_list_start_number + + def test_accept_list_start_number + @to.start_accepting + + @to.accept_list_start @number_list + + accept_list_start_number + end + + ## + # Calls accept_list_start_ualpha + + def test_accept_list_start_ualpha + @to.start_accepting + + @to.accept_list_start @ualpha_list + + accept_list_start_ualpha + end + + ## + # Calls accept_list_end_bullet + + def test_accept_list_end_bullet + @to.start_accepting + + @to.accept_list_start @bullet_list + + @to.accept_list_end @bullet_list + + accept_list_end_bullet + end + + ## + # Calls accept_list_end_label + + def test_accept_list_end_label + @to.start_accepting + + @to.accept_list_start @label_list + + @to.accept_list_end @label_list + + accept_list_end_label + end + + ## + # Calls accept_list_end_lalpha + + def test_accept_list_end_lalpha + @to.start_accepting + + @to.accept_list_start @lalpha_list + + @to.accept_list_end @lalpha_list + + accept_list_end_lalpha + end + + ## + # Calls accept_list_end_number + + def test_accept_list_end_number + @to.start_accepting + + @to.accept_list_start @number_list + + @to.accept_list_end @number_list + + accept_list_end_number + end + + ## + # Calls accept_list_end_note + + def test_accept_list_end_note + @to.start_accepting + + @to.accept_list_start @note_list + + @to.accept_list_end @note_list + + accept_list_end_note + end + + ## + # Calls accept_list_end_ualpha + + def test_accept_list_end_ualpha + @to.start_accepting + + @to.accept_list_start @ualpha_list + + @to.accept_list_end @ualpha_list + + accept_list_end_ualpha + end + + ## + # Calls list_nested with a two-level list + + def test_list_nested + doc = @RM::Document.new( + @RM::List.new(:BULLET, + @RM::ListItem.new(nil, + @RM::Paragraph.new('l1'), + @RM::List.new(:BULLET, + @RM::ListItem.new(nil, + @RM::Paragraph.new('l1.1')))), + @RM::ListItem.new(nil, + @RM::Paragraph.new('l2')))) + + doc.accept @to + + list_nested + end + + ## + # Calls list_verbatim with a list containing a verbatim block + + def test_list_verbatim # HACK overblown + doc = + doc( + list(:BULLET, + item(nil, + para('list stuff'), + blank_line, + verb("* list\n", + " with\n", + "\n", + " second\n", + "\n", + " 1. indented\n", + " 2. numbered\n", + "\n", + " third\n", + "\n", + "* second\n")))) + + doc.accept @to + + list_verbatim + end + end + end + +end diff --git a/test/rdoc/support/test_case.rb b/test/rdoc/support/test_case.rb new file mode 100644 index 0000000000..9a4f04b76e --- /dev/null +++ b/test/rdoc/support/test_case.rb @@ -0,0 +1,216 @@ +## +# RDoc::TestCase is an abstract TestCase to provide common setup and teardown +# across all RDoc tests. The test case uses minitest, so all the assertions +# of minitest may be used. +# +# The testcase provides the following: +# +# * A reset code-object tree +# * A reset markup preprocessor (RDoc::Markup::PreProcess) +# * The @RM alias of RDoc::Markup (for less typing) +# * @pwd containing the current working directory +# * FileUtils, pp, Tempfile, Dir.tmpdir and StringIO + +require 'bundler/errors' +begin + gem 'test-unit' +rescue NoMethodError, Gem::LoadError, Bundler::GemfileNotFound + # for ruby tests +end + +require 'test/unit' + +require 'fileutils' +require 'pp' +require 'tempfile' +require 'tmpdir' +require 'stringio' + +require 'rdoc' + +## +# RDoc::TestCase is an abstract TestCase to provide common setup and teardown +# across all RDoc tests. The test case uses minitest, so all the assertions +# of minitest may be used. +# +# The testcase provides the following: +# +# * A reset code-object tree +# * A reset markup preprocessor (RDoc::Markup::PreProcess) +# * The @RM alias of RDoc::Markup (for less typing) +# * @pwd containing the current working directory +# * FileUtils, pp, Tempfile, Dir.tmpdir and StringIO + +class RDoc::TestCase < Test::Unit::TestCase + + ## + # Abstract test-case setup + + def setup + super + + @top_level = nil + + @RM = RDoc::Markup + + @pwd = Dir.pwd + + @store = RDoc::Store.new + + @rdoc = RDoc::RDoc.new + @rdoc.store = @store + @rdoc.options = RDoc::Options.new + + g = Object.new + def g.class_dir() end + def g.file_dir() end + @rdoc.generator = g + + RDoc::Markup::PreProcess.reset + end + + ## + # Asserts +path+ is a file + + def assert_file path + assert File.file?(path), "#{path} is not a file" + end + + ## + # Asserts +path+ is a directory + + def assert_directory path + assert File.directory?(path), "#{path} is not a directory" + end + + ## + # Refutes +path+ exists + + def refute_file path + refute File.exist?(path), "#{path} exists" + end + + ## + # Shortcut for RDoc::Markup::BlankLine.new + + def blank_line + @RM::BlankLine.new + end + + ## + # Shortcut for RDoc::Markup::BlockQuote.new with +contents+ + + def block *contents + @RM::BlockQuote.new(*contents) + end + + ## + # Creates an RDoc::Comment with +text+ which was defined on +top_level+. + # By default the comment has the 'rdoc' format. + + def comment text, top_level = @top_level, language = nil + comment = RDoc::Comment.new text, top_level, language + comment + end + + ## + # Shortcut for RDoc::Markup::Document.new with +contents+ + + def doc *contents + @RM::Document.new(*contents) + end + + ## + # Shortcut for RDoc::Markup::HardBreak.new + + def hard_break + @RM::HardBreak.new + end + + ## + # Shortcut for RDoc::Markup::Heading.new with +level+ and +text+ + + def head level, text + @RM::Heading.new level, text + end + + ## + # Shortcut for RDoc::Markup::ListItem.new with +label+ and +parts+ + + def item label = nil, *parts + @RM::ListItem.new label, *parts + end + + ## + # Shortcut for RDoc::Markup::List.new with +type+ and +items+ + + def list type = nil, *items + @RM::List.new type, *items + end + + ## + # Enables pretty-print output + + def mu_pp obj # :nodoc: + s = obj.pretty_inspect + s = RDoc::Encoding.change_encoding s, Encoding.default_external + s.chomp + end + + ## + # Shortcut for RDoc::Markup::Paragraph.new with +contents+ + + def para *a + @RM::Paragraph.new(*a) + end + + ## + # Shortcut for RDoc::Markup::Rule.new with +weight+ + + def rule weight + @RM::Rule.new weight + end + + ## + # Shortcut for RDoc::Markup::Raw.new with +contents+ + + def raw *contents + @RM::Raw.new(*contents) + end + + ## + # Creates a temporary directory changes the current directory to it for the + # duration of the block. + # + # Depends upon Dir.mktmpdir + + def temp_dir + Dir.mktmpdir do |temp_dir| + Dir.chdir temp_dir do + yield temp_dir + end + end + end + + ## + # Shortcut for RDoc::Markup::Verbatim.new with +parts+ + + def verb *parts + @RM::Verbatim.new(*parts) + end + + ## + # run capture_io with setting $VERBOSE = true + + def verbose_capture_output + capture_output do + begin + orig_verbose = $VERBOSE + $VERBOSE = true + yield + ensure + $VERBOSE = orig_verbose + end + end + end +end diff --git a/test/rdoc/support/text_formatter_test_case.rb b/test/rdoc/support/text_formatter_test_case.rb new file mode 100644 index 0000000000..22a762b5f0 --- /dev/null +++ b/test/rdoc/support/text_formatter_test_case.rb @@ -0,0 +1,115 @@ +# frozen_string_literal: true +## +# Test case for creating new plain-text RDoc::Markup formatters. See also +# RDoc::Markup::FormatterTestCase +# +# See test_rdoc_markup_to_rdoc.rb for a complete example. +# +# Example: +# +# class TestRDocMarkupToNewTextFormat < RDoc::Markup::TextFormatterTestCase +# +# add_visitor_tests +# add_text_tests +# +# def setup +# super +# +# @to = RDoc::Markup::ToNewTextFormat.new +# end +# +# def accept_blank_line +# assert_equal :junk, @to.res.join +# end +# +# # ... +# +# end + +class RDoc::Markup::TextFormatterTestCase < RDoc::Markup::FormatterTestCase + + ## + # Adds test cases to the calling TestCase. + + def self.add_text_tests + self.class_eval do + + ## + # Test case that calls @to.accept_heading + + def test_accept_heading_indent + @to.start_accepting + @to.indent = 3 + @to.accept_heading @RM::Heading.new(1, 'Hello') + + accept_heading_indent + end + + ## + # Test case that calls @to.accept_rule + + def test_accept_rule_indent + @to.start_accepting + @to.indent = 3 + @to.accept_rule @RM::Rule.new(1) + + accept_rule_indent + end + + ## + # Test case that calls @to.accept_verbatim + + def test_accept_verbatim_indent + @to.start_accepting + @to.indent = 2 + @to.accept_verbatim @RM::Verbatim.new("hi\n", " world\n") + + accept_verbatim_indent + end + + ## + # Test case that calls @to.accept_verbatim with a big indent + + def test_accept_verbatim_big_indent + @to.start_accepting + @to.indent = 2 + @to.accept_verbatim @RM::Verbatim.new("hi\n", "world\n") + + accept_verbatim_big_indent + end + + ## + # Test case that calls @to.accept_paragraph with an indent + + def test_accept_paragraph_indent + @to.start_accepting + @to.indent = 3 + @to.accept_paragraph @RM::Paragraph.new(('words ' * 30).strip) + + accept_paragraph_indent + end + + ## + # Test case that calls @to.accept_paragraph with a long line + + def test_accept_paragraph_wrap + @to.start_accepting + @to.accept_paragraph @RM::Paragraph.new(('words ' * 30).strip) + + accept_paragraph_wrap + end + + ## + # Test case that calls @to.attributes with an escaped + # cross-reference. If this test doesn't pass something may be very + # wrong. + + def test_attributes + assert_equal 'Dog', @to.attributes("\\Dog") + end + + end + end + +end + -- cgit v1.2.3