From 46580b51477355fece514573c88cb67030f4a502 Mon Sep 17 00:00:00 2001 From: drbrain Date: Thu, 1 Apr 2010 07:45:16 +0000 Subject: Import RDoc 2.5 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27147 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rdoc/empty.dat | 0 test/rdoc/hidden.zip.txt | 1 + .../rdoc/rdoc_markup_to_html_crossref_reference.rb | 31 - test/rdoc/test.ja.rdoc | 8 + test/rdoc/test.ja.txt | 8 + test/rdoc/test.txt | 1 + test/rdoc/test_attribute_manager.rb | 25 +- test/rdoc/test_rdoc_any_method.rb | 33 + test/rdoc/test_rdoc_attr.rb | 40 + test/rdoc/test_rdoc_class_module.rb | 100 ++ test/rdoc/test_rdoc_code_object.rb | 96 ++ test/rdoc/test_rdoc_constant.rb | 15 + test/rdoc/test_rdoc_context.rb | 291 +++++ test/rdoc/test_rdoc_generator_ri.rb | 56 + test/rdoc/test_rdoc_include.rb | 17 + test/rdoc/test_rdoc_info_formatting.rb | 179 --- test/rdoc/test_rdoc_info_sections.rb | 139 -- test/rdoc/test_rdoc_markup.rb | 620 +-------- test/rdoc/test_rdoc_markup_attribute_manager.rb | 40 +- test/rdoc/test_rdoc_markup_document.rb | 51 + test/rdoc/test_rdoc_markup_paragraph.rb | 27 + test/rdoc/test_rdoc_markup_parser.rb | 1327 ++++++++++++++++++++ test/rdoc/test_rdoc_markup_to_ansi.rb | 426 +++++++ test/rdoc/test_rdoc_markup_to_bs.rb | 443 +++++++ test/rdoc/test_rdoc_markup_to_html.rb | 225 +++- test/rdoc/test_rdoc_markup_to_html_crossref.rb | 408 ++---- test/rdoc/test_rdoc_markup_to_rdoc.rb | 426 +++++++ test/rdoc/test_rdoc_normal_class.rb | 17 + test/rdoc/test_rdoc_normal_module.rb | 26 + test/rdoc/test_rdoc_options.rb | 41 + test/rdoc/test_rdoc_parser.rb | 79 +- test/rdoc/test_rdoc_parser_c.rb | 253 +++- test/rdoc/test_rdoc_parser_perl.rb | 5 +- test/rdoc/test_rdoc_parser_ruby.rb | 672 +++++++++- test/rdoc/test_rdoc_parser_simple.rb | 48 + test/rdoc/test_rdoc_rdoc.rb | 66 + test/rdoc/test_rdoc_require.rb | 25 + test/rdoc/test_rdoc_ri_attribute_formatter.rb | 44 - test/rdoc/test_rdoc_ri_default_display.rb | 301 ----- test/rdoc/test_rdoc_ri_driver.rb | 790 +++++++++++- test/rdoc/test_rdoc_ri_formatter.rb | 320 ----- test/rdoc/test_rdoc_ri_overstrike_formatter.rb | 71 -- test/rdoc/test_rdoc_ri_paths.rb | 43 + test/rdoc/test_rdoc_ri_store.rb | 309 +++++ test/rdoc/test_rdoc_task.rb | 64 + test/rdoc/test_rdoc_text.rb | 157 +++ test/rdoc/test_rdoc_top_level.rb | 111 ++ test/rdoc/xref_data.rb | 54 + test/rdoc/xref_test_case.rb | 53 + 49 files changed, 6423 insertions(+), 2159 deletions(-) delete mode 100644 test/rdoc/empty.dat create mode 100644 test/rdoc/hidden.zip.txt delete mode 100644 test/rdoc/rdoc_markup_to_html_crossref_reference.rb create mode 100644 test/rdoc/test.ja.rdoc create mode 100644 test/rdoc/test.ja.txt create mode 100644 test/rdoc/test.txt create mode 100644 test/rdoc/test_rdoc_any_method.rb create mode 100644 test/rdoc/test_rdoc_attr.rb create mode 100644 test/rdoc/test_rdoc_class_module.rb create mode 100644 test/rdoc/test_rdoc_code_object.rb create mode 100644 test/rdoc/test_rdoc_constant.rb create mode 100644 test/rdoc/test_rdoc_context.rb create mode 100644 test/rdoc/test_rdoc_generator_ri.rb create mode 100644 test/rdoc/test_rdoc_include.rb delete mode 100644 test/rdoc/test_rdoc_info_formatting.rb delete mode 100644 test/rdoc/test_rdoc_info_sections.rb create mode 100644 test/rdoc/test_rdoc_markup_document.rb create mode 100644 test/rdoc/test_rdoc_markup_paragraph.rb create mode 100644 test/rdoc/test_rdoc_markup_parser.rb create mode 100644 test/rdoc/test_rdoc_markup_to_ansi.rb create mode 100644 test/rdoc/test_rdoc_markup_to_bs.rb create mode 100644 test/rdoc/test_rdoc_markup_to_rdoc.rb create mode 100644 test/rdoc/test_rdoc_normal_class.rb create mode 100644 test/rdoc/test_rdoc_normal_module.rb create mode 100644 test/rdoc/test_rdoc_options.rb create mode 100644 test/rdoc/test_rdoc_parser_simple.rb create mode 100644 test/rdoc/test_rdoc_rdoc.rb create mode 100644 test/rdoc/test_rdoc_require.rb delete mode 100644 test/rdoc/test_rdoc_ri_attribute_formatter.rb delete mode 100644 test/rdoc/test_rdoc_ri_default_display.rb delete mode 100644 test/rdoc/test_rdoc_ri_formatter.rb delete mode 100644 test/rdoc/test_rdoc_ri_overstrike_formatter.rb create mode 100644 test/rdoc/test_rdoc_ri_paths.rb create mode 100644 test/rdoc/test_rdoc_ri_store.rb create mode 100644 test/rdoc/test_rdoc_task.rb create mode 100644 test/rdoc/test_rdoc_text.rb create mode 100644 test/rdoc/test_rdoc_top_level.rb create mode 100644 test/rdoc/xref_data.rb create mode 100644 test/rdoc/xref_test_case.rb (limited to 'test') diff --git a/test/rdoc/empty.dat b/test/rdoc/empty.dat deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/rdoc/hidden.zip.txt b/test/rdoc/hidden.zip.txt new file mode 100644 index 0000000000..2400e38b7d --- /dev/null +++ b/test/rdoc/hidden.zip.txt @@ -0,0 +1 @@ +PK diff --git a/test/rdoc/rdoc_markup_to_html_crossref_reference.rb b/test/rdoc/rdoc_markup_to_html_crossref_reference.rb deleted file mode 100644 index cbf6734b28..0000000000 --- a/test/rdoc/rdoc_markup_to_html_crossref_reference.rb +++ /dev/null @@ -1,31 +0,0 @@ -# -# This file is parsed by test_rdoc_markup_to_html_crossref.rb -# during its tests. -# -class Ref_Class1 -end - -class Ref_Class2 - class Ref_Class3 - def method - end - - class Helper1 - def method? - end - end - end -end - -class Ref_Class3 - class Helper1 - end - - class Helper2 - end -end - -class Ref_Class4 - class Ref_Class4 - end -end diff --git a/test/rdoc/test.ja.rdoc b/test/rdoc/test.ja.rdoc new file mode 100644 index 0000000000..96e1db93d3 --- /dev/null +++ b/test/rdoc/test.ja.rdoc @@ -0,0 +1,8 @@ +こんにちは! + +初めまして。アーロンと申します。 + +どんな食べ物が好きですか?私はフランスの料理が大好きです。 +日本の料理も大好きです。 + +食べ物を食べるのが大好きだけど、お皿を洗うのが大嫌いです。 diff --git a/test/rdoc/test.ja.txt b/test/rdoc/test.ja.txt new file mode 100644 index 0000000000..96e1db93d3 --- /dev/null +++ b/test/rdoc/test.ja.txt @@ -0,0 +1,8 @@ +こんにちは! + +初めまして。アーロンと申します。 + +どんな食べ物が好きですか?私はフランスの料理が大好きです。 +日本の料理も大好きです。 + +食べ物を食べるのが大好きだけど、お皿を洗うのが大嫌いです。 diff --git a/test/rdoc/test.txt b/test/rdoc/test.txt new file mode 100644 index 0000000000..16b14f5da9 --- /dev/null +++ b/test/rdoc/test.txt @@ -0,0 +1 @@ +test file diff --git a/test/rdoc/test_attribute_manager.rb b/test/rdoc/test_attribute_manager.rb index ee45c0596f..9506f3b40f 100644 --- a/test/rdoc/test_attribute_manager.rb +++ b/test/rdoc/test_attribute_manager.rb @@ -1,5 +1,7 @@ require 'rubygems' -require 'minitest/unit' +require 'minitest/autorun' +require 'rdoc' +require 'rdoc/markup' require 'rdoc/markup/attribute_manager' class TestAttributeManager < MiniTest::Unit::TestCase @@ -9,29 +11,21 @@ class TestAttributeManager < MiniTest::Unit::TestCase @klass = RDoc::Markup::AttributeManager end - def teardown - silently do - @klass.const_set(:MATCHING_WORD_PAIRS, {}) - @klass.const_set(:WORD_PAIR_MAP, {}) - @klass.const_set(:HTML_TAGS, {}) - end - end - def test_initial_word_pairs - word_pairs = @klass::MATCHING_WORD_PAIRS + word_pairs = @am.matching_word_pairs assert word_pairs.is_a?(Hash) assert_equal(3, word_pairs.size) end def test_initial_html - html_tags = @klass::HTML_TAGS + html_tags = @am.html_tags assert html_tags.is_a?(Hash) assert_equal(5, html_tags.size) end def test_add_matching_word_pair @am.add_word_pair("x","x", :TEST) - word_pairs = @klass::MATCHING_WORD_PAIRS + word_pairs = @am.matching_word_pairs assert_equal(4,word_pairs.size) assert(word_pairs.has_key?("x")) end @@ -44,21 +38,21 @@ class TestAttributeManager < MiniTest::Unit::TestCase def test_add_word_pair_map @am.add_word_pair("x", "y", :TEST) - word_pair_map = @klass::WORD_PAIR_MAP + word_pair_map = @am.word_pair_map assert_equal(1,word_pair_map.size) assert_equal(word_pair_map. keys.first.source, "(x)(\\S+)(y)") end def test_add_html_tag @am.add_html("Test", :TEST) - tags = @klass::HTML_TAGS + tags = @am.html_tags assert_equal(6, tags.size) assert(tags.has_key?("test")) end def test_add_special @am.add_special("WikiWord", :WIKIWORD) - specials = @klass::SPECIAL + specials = @am.special assert_equal(1,specials.size) assert(specials.has_key?("WikiWord")) end @@ -73,4 +67,3 @@ class TestAttributeManager < MiniTest::Unit::TestCase end -MiniTest::Unit.autorun diff --git a/test/rdoc/test_rdoc_any_method.rb b/test/rdoc/test_rdoc_any_method.rb new file mode 100644 index 0000000000..00af7703e5 --- /dev/null +++ b/test/rdoc/test_rdoc_any_method.rb @@ -0,0 +1,33 @@ +require File.expand_path '../xref_test_case', __FILE__ + +class RDocAnyMethodTest < XrefTestCase + + def test_full_name + assert_equal 'C1::m', @c1.method_list.first.full_name + end + + def test_parent_name + assert_equal 'C1', @c1.method_list.first.parent_name + assert_equal 'C1', @c1.method_list.last.parent_name + end + + def test_marshal_load + instance_method = Marshal.load Marshal.dump(@c1.method_list.last) + + assert_equal 'C1#m', instance_method.full_name + assert_equal 'C1', instance_method.parent_name + + class_method = Marshal.load Marshal.dump(@c1.method_list.first) + + assert_equal 'C1::m', class_method.full_name + assert_equal 'C1', class_method.parent_name + end + + def test_name + m = RDoc::AnyMethod.new nil, nil + + assert_nil m.name + end + +end + diff --git a/test/rdoc/test_rdoc_attr.rb b/test/rdoc/test_rdoc_attr.rb new file mode 100644 index 0000000000..362326186b --- /dev/null +++ b/test/rdoc/test_rdoc_attr.rb @@ -0,0 +1,40 @@ +require 'rubygems' +require 'minitest/autorun' +require 'rdoc/rdoc' + +class TestRDocAttr < MiniTest::Unit::TestCase + + def setup + @a = RDoc::Attr.new nil, 'attr', 'RW', '' + end + + def test_block_params + assert_nil @a.block_params + end + + def test_call_seq + assert_nil @a.call_seq + end + + def test_full_name + assert_equal '(unknown)#attr', @a.full_name + end + + def test_singleton + refute @a.singleton + end + + def test_type + assert_equal 'attr_accessor', @a.type + + @a.rw = 'R' + + assert_equal 'attr_reader', @a.type + + @a.rw = 'W' + + assert_equal 'attr_writer', @a.type + end + +end + diff --git a/test/rdoc/test_rdoc_class_module.rb b/test/rdoc/test_rdoc_class_module.rb new file mode 100644 index 0000000000..23291b969e --- /dev/null +++ b/test/rdoc/test_rdoc_class_module.rb @@ -0,0 +1,100 @@ +require File.expand_path '../xref_test_case', __FILE__ + +class TestRDocClassModule < XrefTestCase + + def setup + super + + @RM = RDoc::Markup + end + + def test_comment_equals + cm = RDoc::ClassModule.new 'Klass' + cm.comment = '# comment 1' + + assert_equal 'comment 1', cm.comment + + cm.comment = '# comment 2' + + assert_equal "comment 1\n---\ncomment 2", cm.comment + + cm.comment = "# * comment 3" + + assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment + end + + # handle making a short module alias of yourself + + def test_find_class_named + @c2.classes_hash['C2'] = @c2 + + assert_nil @c2.find_class_named('C1') + end + + def test_merge + cm1 = RDoc::ClassModule.new 'Klass' + cm1.comment = 'klass 1' + cm1.add_attribute RDoc::Attr.new(nil, 'a1', 'RW', '') + cm1.add_attribute RDoc::Attr.new(nil, 'a3', 'R', '') + cm1.add_constant RDoc::Constant.new('C1', nil, '') + cm1.add_include RDoc::Include.new('I1', '') + cm1.add_method RDoc::AnyMethod.new(nil, 'm1') + + cm2 = RDoc::ClassModule.new 'Klass' + cm2.instance_variable_set(:@comment, + @RM::Document.new( + @RM::Paragraph.new('klass 2'))) + cm2.add_attribute RDoc::Attr.new(nil, 'a2', 'RW', '') + cm2.add_attribute RDoc::Attr.new(nil, 'a3', 'W', '') + cm2.add_constant RDoc::Constant.new('C2', nil, '') + cm2.add_include RDoc::Include.new('I2', '') + cm2.add_method RDoc::AnyMethod.new(nil, 'm2') + + cm1.merge cm2 + + document = @RM::Document.new( + @RM::Paragraph.new('klass 2'), + @RM::Paragraph.new('klass 1')) + + assert_equal document, cm1.comment + + expected = [ + RDoc::Attr.new(nil, 'a1', 'RW', ''), + RDoc::Attr.new(nil, 'a2', 'RW', ''), + RDoc::Attr.new(nil, 'a3', 'RW', ''), + ] + + expected.each do |a| a.parent = cm1 end + assert_equal expected, cm1.attributes.sort + + expected = [ + RDoc::Constant.new('C1', nil, ''), + RDoc::Constant.new('C2', nil, ''), + ] + + expected.each do |c| c.parent = cm1 end + assert_equal expected, cm1.constants.sort + + expected = [ + RDoc::Include.new('I1', ''), + RDoc::Include.new('I2', ''), + ] + + expected.each do |i| i.parent = cm1 end + assert_equal expected, cm1.includes.sort + + expected = [ + RDoc::AnyMethod.new(nil, 'm1'), + RDoc::AnyMethod.new(nil, 'm2'), + ] + + expected.each do |m| m.parent = cm1 end + assert_equal expected, cm1.method_list.sort + end + + def test_superclass + assert_equal @c3_h1, @c3_h2.superclass + end + +end + diff --git a/test/rdoc/test_rdoc_code_object.rb b/test/rdoc/test_rdoc_code_object.rb new file mode 100644 index 0000000000..7e6098460f --- /dev/null +++ b/test/rdoc/test_rdoc_code_object.rb @@ -0,0 +1,96 @@ +require 'rubygems' +require 'minitest/autorun' +require File.expand_path '../xref_test_case', __FILE__ +require 'rdoc/code_object' + +class TestRDocCodeObject < XrefTestCase + + def setup + super + + @co = RDoc::CodeObject.new + end + + def test_initialize + assert @co.document_self, 'document_self' + assert @co.document_children, 'document_children' + refute @co.force_documentation, 'force_documentation' + refute @co.done_documenting, 'done_documenting' + assert_equal '', @co.comment, 'comment is empty' + end + + def test_comment_equals + @co.comment = '' + + assert_equal '', @co.comment + + @co.comment = 'I am a comment' + + assert_equal 'I am a comment', @co.comment + end + + def test_document_children_equals + @co.document_children = false + refute @co.document_children + + @c2.document_children = false + assert_empty @c2.classes + end + + def test_document_self_equals + @co.document_self = false + refute @co.document_self + + @c1.document_self = false + assert_empty @c1.method_list + end + + def test_documented_eh + refute @co.documented? + + @co.comment = 'hi' + + assert @co.documented? + + @co.comment.replace '' + + refute @co.documented? + + @co.document_self = false + + assert @co.documented? + end + + def test_parent_file_name + assert_equal '(unknown)', @co.parent_file_name + assert_equal 'xref_data.rb', @c1.parent_file_name + end + + def test_parent_name + assert_equal '(unknown)', @co.parent_name + assert_equal 'xref_data.rb', @c1.parent_name + assert_equal 'C2', @c2_c3.parent_name + end + + def test_start_doc + @co.document_self = false + @co.document_children = false + + @co.start_doc + + assert @co.document_self + assert @co.document_children + end + + def test_stop_doc + @co.document_self = true + @co.document_children = true + + @co.stop_doc + + refute @co.document_self + refute @co.document_children + end + +end + diff --git a/test/rdoc/test_rdoc_constant.rb b/test/rdoc/test_rdoc_constant.rb new file mode 100644 index 0000000000..b915f5cc7a --- /dev/null +++ b/test/rdoc/test_rdoc_constant.rb @@ -0,0 +1,15 @@ +require File.expand_path '../xref_test_case', __FILE__ + +class TestRDocConstant < XrefTestCase + + def setup + super + + @const = @c1.constants.first + end + + def test_path + assert_equal 'C1.html#CONST', @const.path + end + +end diff --git a/test/rdoc/test_rdoc_context.rb b/test/rdoc/test_rdoc_context.rb new file mode 100644 index 0000000000..7de5691a22 --- /dev/null +++ b/test/rdoc/test_rdoc_context.rb @@ -0,0 +1,291 @@ +require 'rubygems' +require 'minitest/autorun' +require File.expand_path '../xref_test_case', __FILE__ + +class TestRDocContext < XrefTestCase + + def setup + super + + @context = RDoc::Context.new + end + + def test_initialize + assert_empty @context.in_files + assert_equal 'unknown', @context.name + assert_equal '', @context.comment + assert_equal nil, @context.parent + assert_equal :public, @context.visibility + assert_equal 1, @context.sections.length + + assert_empty @context.classes_hash + assert_empty @context.modules_hash + + assert_empty @context.method_list + assert_empty @context.attributes + assert_empty @context.aliases + assert_empty @context.requires + assert_empty @context.includes + assert_empty @context.constants + end + + def test_add_alias + as = RDoc::Alias.new nil, 'old_name', 'new_name', 'comment' + + @context.add_alias as + + assert_equal [as], @context.aliases + assert_equal [as], @context.unmatched_alias_lists['old_name'] + end + + def test_add_alias_method + meth = RDoc::AnyMethod.new nil, 'old_name' + as = RDoc::Alias.new nil, 'old_name', 'new_name', 'comment' + as.parent = @context + + @context.add_method meth + @context.add_alias as + + assert_empty @context.aliases + assert_empty @context.unmatched_alias_lists + assert_equal %w[old_name new_name], @context.method_list.map { |m| m.name } + end + + def test_add_alias_impl + meth = RDoc::AnyMethod.new nil, 'old_name' + meth.comment = 'old comment' + meth.singleton = false + meth.visibility = :private + + alas = RDoc::Alias.new nil, 'old_name', 'new_name', 'new comment' + + @context.add_alias_impl alas, meth + + assert_equal 1, @context.method_list.length + + alas_meth = @context.method_list.first + assert_equal 'new_name', alas_meth.name + assert_equal 'new comment', alas_meth.comment + assert_equal false, alas_meth.singleton + assert_equal meth, alas_meth.is_alias_for + assert_equal :private, alas_meth.visibility + + assert_equal [alas_meth], meth.aliases + end + + def test_add_class + @c1.add_class RDoc::NormalClass, 'Klass', 'Object' + + assert_includes @c1.classes.map { |k| k.full_name }, 'C1::Klass' + assert_includes RDoc::TopLevel.classes.map { |k| k.full_name }, 'C1::Klass' + end + + def test_add_class_superclass + @c1.add_class RDoc::NormalClass, 'Klass', 'Object' + @c1.add_class RDoc::NormalClass, 'Klass', 'Other' + @c1.add_class RDoc::NormalClass, 'Klass', 'Object' + + klass = @c1.find_module_named 'Klass' + assert_equal 'Other', klass.superclass + end + + def test_add_class_upgrade + @c1.add_module RDoc::NormalModule, 'Klass' + @c1.add_class RDoc::NormalClass, 'Klass', nil + + assert_includes @c1.classes.map { |k| k.full_name }, 'C1::Klass', + 'c1 classes' + refute_includes @c1.modules.map { |k| k.full_name }, 'C1::Klass', + 'c1 modules' + + assert_includes RDoc::TopLevel.classes.map { |k| k.full_name }, 'C1::Klass', + 'TopLevel classes' + refute_includes RDoc::TopLevel.modules.map { |k| k.full_name }, 'C1::Klass', + 'TopLevel modules' + end + + def test_add_constant + const = RDoc::Constant.new 'NAME', 'value', 'comment' + @context.add_constant const + + assert_equal [const], @context.constants + end + + def test_add_include + incl = RDoc::Include.new 'Name', 'comment' + @context.add_include incl + + assert_equal [incl], @context.includes + end + + def test_add_method + meth = RDoc::AnyMethod.new nil, 'old_name' + meth.visibility = nil + + @context.add_method meth + + assert_equal [meth], @context.method_list + assert_equal :public, meth.visibility + end + + def test_add_method_alias + as = RDoc::Alias.new nil, 'old_name', 'new_name', 'comment' + meth = RDoc::AnyMethod.new nil, 'old_name' + + @context.add_alias as + refute_empty @context.aliases + + @context.add_method meth + + assert_empty @context.aliases + assert_empty @context.unmatched_alias_lists + assert_equal %w[old_name new_name], @context.method_list.map { |m| m.name } + end + + def test_add_module + @c1.add_module RDoc::NormalModule, 'Mod' + + assert_includes @c1.modules.map { |m| m.full_name }, 'C1::Mod' + end + + def test_add_module_alias + c3_c4 = @c2.add_module_alias @c2_c3, 'C4' + + assert_equal @c2.find_module_named('C4'), c3_c4 + end + + def test_add_module_class + k = @c1.add_class RDoc::NormalClass, 'Klass', nil + m = @c1.add_module RDoc::NormalModule, 'Klass' + + assert_equal k, m, 'returns class' + assert_empty @c1.modules + end + + def test_add_require + req = RDoc::Require.new 'require', 'comment' + @c1.add_require req + + assert_empty @c1.requires + assert_includes @c1.top_level.requires, req + end + + def test_add_to + incl = RDoc::Include.new 'Name', 'comment' + arr = [] + @context.add_to arr, incl + + assert_includes arr, incl + assert_equal @context, incl.parent + assert_equal @context.current_section, incl.section + end + + def test_add_to_no_document_self + incl = RDoc::Include.new 'Name', 'comment' + arr = [] + @context.document_self = false + @context.add_to arr, incl + + refute_includes arr, incl + end + + def test_add_to_done_documenting + incl = RDoc::Include.new 'Name', 'comment' + arr = [] + @context.done_documenting = true + @context.add_to arr, incl + + refute_includes arr, incl + end + + def test_child_name + assert_equal 'C1::C1', @c1.child_name('C1') + end + + def test_classes + assert_equal %w[C2::C3], @c2.classes.map { |k| k.full_name } + assert_equal %w[C3::H1 C3::H2], @c3.classes.map { |k| k.full_name } + end + + def test_defined_in_eh + assert @c1.defined_in?(@c1.top_level) + + refute @c1.defined_in?(RDoc::TopLevel.new('name.rb')) + end + + def test_equals2 + assert_equal @c3, @c3 + refute_equal @c2, @c3 + refute_equal @c2_c3, @c3 + end + + def test_find_attribute_named + assert_equal nil, @c1.find_attribute_named('none') + assert_equal 'R', @c1.find_attribute_named('attr').rw + assert_equal 'R', @c1.find_attribute_named('attr_reader').rw + assert_equal 'W', @c1.find_attribute_named('attr_writer').rw + assert_equal 'RW', @c1.find_attribute_named('attr_accessor').rw + end + + def test_find_constant_named + assert_equal nil, @c1.find_constant_named('NONE') + assert_equal ':const', @c1.find_constant_named('CONST').value + end + + def test_find_enclosing_module_named + assert_equal nil, @c2_c3.find_enclosing_module_named('NONE') + assert_equal @c1, @c2_c3.find_enclosing_module_named('C1') + assert_equal @c2, @c2_c3.find_enclosing_module_named('C2') + end + + def test_find_file_named + assert_equal nil, @c1.find_file_named('nonexistent.rb') + assert_equal @xref_data, @c1.find_file_named(@file_name) + end + + def test_find_instance_method_named + assert_equal nil, @c1.find_instance_method_named('none') + + m = @c1.find_instance_method_named('m') + assert_instance_of RDoc::AnyMethod, m + assert_equal false, m.singleton + end + + def test_find_local_symbol + assert_equal true, @c1.find_local_symbol('m').singleton + assert_equal ':const', @c1.find_local_symbol('CONST').value + assert_equal 'R', @c1.find_local_symbol('attr').rw + assert_equal @xref_data, @c1.find_local_symbol(@file_name) + assert_equal @c2_c3, @c2.find_local_symbol('C3') + end + + def test_find_method_named + assert_equal true, @c1.find_method_named('m').singleton + end + + def test_find_module_named + assert_equal @c2_c3, @c2.find_module_named('C3') + assert_equal @c2, @c2.find_module_named('C2') + assert_equal @c1, @c2.find_module_named('C1') + + assert_equal 'C2::C3', @c2.find_module_named('C3').full_name + end + + def test_find_symbol + c3 = @xref_data.find_module_named('C3') + assert_equal c3, @xref_data.find_symbol('C3') + assert_equal c3, @c2.find_symbol('::C3') + assert_equal @c2_c3, @c2.find_symbol('C3') + end + + def test_spaceship + assert_equal(-1, @c2.<=>(@c3)) + assert_equal 0, @c2.<=>(@c2) + assert_equal 1, @c3.<=>(@c2) + + assert_equal 1, @c2_c3.<=>(@c2) + assert_equal(-1, @c2_c3.<=>(@c3)) + end + +end + diff --git a/test/rdoc/test_rdoc_generator_ri.rb b/test/rdoc/test_rdoc_generator_ri.rb new file mode 100644 index 0000000000..7027080c9b --- /dev/null +++ b/test/rdoc/test_rdoc_generator_ri.rb @@ -0,0 +1,56 @@ +require 'rubygems' +require 'minitest/autorun' +require 'rdoc/rdoc' +require 'tmpdir' +require 'fileutils' + +class TestRDocGeneratorRI < MiniTest::Unit::TestCase + + def setup + @pwd = Dir.pwd + RDoc::TopLevel.reset + + @tmpdir = File.join Dir.tmpdir, "test_rdoc_generator_ri_#{$$}" + FileUtils.mkdir_p @tmpdir + Dir.chdir @tmpdir + options = RDoc::Options.new + + @g = RDoc::Generator::RI.new options + + @top_level = RDoc::TopLevel.new 'file.rb' + @klass = @top_level.add_class RDoc::NormalClass, 'Object' + @meth = RDoc::AnyMethod.new nil, 'method' + @meth_bang = RDoc::AnyMethod.new nil, 'method!' + @attr = RDoc::Attr.new nil, 'attr', 'RW', '' + + @klass.add_method @meth + @klass.add_method @meth_bang + @klass.add_attribute @attr + end + + def teardown + Dir.chdir @pwd + FileUtils.rm_rf @tmpdir + end + + def assert_file path + assert File.file?(path), "#{path} is not a file" + end + + def test_generate + top_level = RDoc::TopLevel.new 'file.rb' + top_level.add_class @klass.class, @klass.name + + @g.generate nil + + assert_file File.join(@tmpdir, 'cache.ri') + + assert_file File.join(@tmpdir, 'Object', 'cdesc-Object.ri') + + assert_file File.join(@tmpdir, 'Object', 'attr-i.ri') + assert_file File.join(@tmpdir, 'Object', 'method-i.ri') + assert_file File.join(@tmpdir, 'Object', 'method%21-i.ri') + end + +end + diff --git a/test/rdoc/test_rdoc_include.rb b/test/rdoc/test_rdoc_include.rb new file mode 100644 index 0000000000..e4a44b4358 --- /dev/null +++ b/test/rdoc/test_rdoc_include.rb @@ -0,0 +1,17 @@ +require File.expand_path '../xref_test_case', __FILE__ + +class TestRDocInclude < XrefTestCase + + def setup + super + + @inc = RDoc::Include.new 'M1', 'comment' + end + + def test_module + assert_equal @m1, @inc.module + assert_equal 'Unknown', RDoc::Include.new('Unknown', 'comment').module + end + +end + diff --git a/test/rdoc/test_rdoc_info_formatting.rb b/test/rdoc/test_rdoc_info_formatting.rb deleted file mode 100644 index 110c84b2d1..0000000000 --- a/test/rdoc/test_rdoc_info_formatting.rb +++ /dev/null @@ -1,179 +0,0 @@ -require 'fileutils' -require 'tmpdir' -require 'rubygems' -require 'minitest/unit' - -require 'rdoc/generator/texinfo' - -# From chapter 18 of the Pickaxe 3rd ed. and the TexInfo manual. -class TestRDocInfoFormatting < MiniTest::Unit::TestCase - def setup - @output_dir = File.join Dir.mktmpdir("test_rdoc_"), "info_formatting" - @output_file = File.join @output_dir, 'rdoc.texinfo' - - RDoc::RDoc.new.document(['--fmt=texinfo', '--quiet', - File.expand_path(__FILE__), - "--op=#{@output_dir}"]) - @text = File.read @output_file - - # File.open('rdoc.texinfo', 'w') { |f| f.puts @text } - end - - def teardown - FileUtils.rm_rf File.dirname(@output_dir) - end - - # Make sure tags like *this* do not make HTML - def test_descriptions_are_not_html - refute_match Regexp.new("\this\<\/b\>"), @text, - "We had some HTML; icky!" - end - - # Ensure we get a reasonable amount - # - # of space in between paragraphs. - def test_paragraphs_are_spaced - assert_match(/amount\n\n\nof space/, @text) - end - - # @ and {} should be at-sign-prefixed - def test_escaping - assert_match(/@@ and @\{@\} should be at-sign-prefixed/) - end - - # This tests that *bold* and bold me become @strong{bolded} - def test_bold - # Seems like a limitation of the Info format: @strong{bold} - # becomes *bold* when read in Info or M-x info. highly lame! - assert_match(/@strong\{bold\}/) - assert_match(/@strong\{bold me\}/) - end - - # Test that _italics_ and italicize me becomes @emph{italicized} - def test_italics - assert_match(/@emph\{italics\}/) - assert_match(/@emph\{italicize me\}/) - end - - # And that typewriter +text+ and typewriter me becomes @code{typewriter} - def test_tt - assert_match(/@code\{text\}/) - assert_match(/@code\{typewriter me\}/) - end - - # Check that - # anything indented is - # verbatim @verb{|foo bar baz|} - def test_literal_code - assert_match("@verb{| anything indented is - verbatim @@verb@{|foo bar baz|@} -|}") - end - - # = Huge heading should be a @majorheading - # == There is also @chapheading - # === Everything deeper becomes a regular @heading - # ====== Regardless of its nesting level - def test_headings - assert_match(/@majorheading Huge heading should be a @@majorheading/) - assert_match(/@chapheading There is also @@chapheading/) - assert_match(/@heading Everything deeper becomes a regular @@heading/) - assert_match(/@heading Regardless of its nesting level/) - end - - # * list item - # * list item2 - # - # with a paragraph in between - # - # - hyphen lists - # - are also allowed - # and items may flow over lines - def test_bullet_lists - assert_match("@itemize @bullet -@item -list item -@item -list item2 -@end itemize") - assert_match("@itemize @bullet -@item -hyphen lists -@item -are also allowed and items may flow over lines -@end itemize") - end - - # 2. numbered lists - # 8. are made by - # 9. a digit followed by a period - def test_numbered_lists - end - - # a. alpha lists - # b. should be parsed too - def test_alpha_lists - end - - # [cat] small domestic animal - # [+cat+] command to copy standard input - # to standard output - def test_labelled_lists - end - - # * First item. - # * Inner item. - # * Second inner item. - # * Second outer item. - def test_nested_lists - assert_match("@itemize @bullet -@item -First item. -@itemize @bullet -@item -Inner item. -@item -Second inner item. -@end itemize -@item -Second outer item. -@end itemize") - end - - def test_internal_hyperlinks - # be sure to test multi-word hyperlinks as well. - end - - def test_hyperlink_targets - end - - def test_web_links - # An example of the two-argument form: The official - # @uref{ftp://ftp.gnu.org/gnu, GNU ftp site} holds programs and texts. - - # produces: - # The official GNU ftp site (ftp://ftp.gnu.org/gnu) - # holds programs and texts. - # and the HTML output is this: - # The official GNU ftp site - # holds programs and texts. - end - - # three or more hyphens - # ---- - # should produce a horizontal rule - def test_horizontal_rule - # gah; not sure texinfo supports horizontal rules - end - - private - - # We don't want the whole string inspected if we pass our own - # message in. - def assert_match(regex, string = @text, - message = "Didn't find #{regex.inspect} in #{string}.") - assert string[regex] #, message - end -end - -MiniTest::Unit.autorun diff --git a/test/rdoc/test_rdoc_info_sections.rb b/test/rdoc/test_rdoc_info_sections.rb deleted file mode 100644 index 9571cd611e..0000000000 --- a/test/rdoc/test_rdoc_info_sections.rb +++ /dev/null @@ -1,139 +0,0 @@ -require 'fileutils' -require 'tempfile' -require 'rubygems' -require 'minitest/unit' -require 'tmpdir' - -require 'rdoc/generator/texinfo' - -# give us access to check this stuff before it's rendered -class RDoc::Generator::TEXINFO; attr_reader :files, :classes; end -class RDoc::RDoc; attr_reader :options; attr_reader :gen; end - -class TestRDocInfoSections < MiniTest::Unit::TestCase - - def setup - @output_dir = File.join Dir.tmpdir, "test_rdoc_info_sections_#{$$}" - @output_file = File.join @output_dir, 'rdoc.texinfo' - - @input_file = Tempfile.new 'my_file.rb' - - open @input_file.path, 'w' do |io| - io.write TEST_DOC - end - - RDoc::Parser.alias_extension '.rb', File.extname(@input_file.path) - - @rdoc = RDoc::RDoc.new - @rdoc.document(['--fmt=texinfo', '--quiet', @input_file.path, - "--op=#{@output_dir}"]) - - @text = File.read @output_file - end - - def teardown - @input_file.close - FileUtils.rm_rf @output_dir - end - - def test_output_exists - assert ! @text.empty? - end - - def test_each_class_has_a_chapter - assert_section "Class MyClass", '@chapter' - end - - def test_class_descriptions_are_given - assert_match(/Documentation for my class/, @text.gsub("\n", ' ')) - end - - def test_included_modules_are_given - assert_match(/Includes.* MyModule/m, @text) - end - - def test_class_methods_are_given - assert_match(/my_class_method\(my_first_argument\)/, @text) - end - - def test_classes_instance_methods_are_given - assert_section 'Class MyClass#my_method' - assert_match(/my_method\(my_first_argument\)/, @text) - end - - def test_each_module_has_a_chapter - assert_section 'MyModule', '@chapter' - end - - def test_methods_are_shown_only_once - methods = @rdoc.gen.classes.map do |c| - c.methods.map do |m| - c.name + '#' + m.name - end - end.flatten - - assert_equal methods, methods.uniq - end - -# if system "makeinfo --version > /dev/null" -# def test_compiles_to_info -# makeinfo_output = `cd #{@output_dir} && makeinfo rdoc.texinfo` -# assert(File.exist?(File.join(@output_dir, 'rdoc.info')), -# "Info file was not compiled: #{makeinfo_output}") -# end -# end - -# def test_constants_are_documented_somehow -# assert_section 'DEFAULT_FILENAME' # what kind of section? -# assert_section 'DEFAULT_INFO_FILENAME' -# end - -# def test_oh_yeah_dont_forget_files -# end - - def assert_section(name, command = '@section') - assert_match Regexp.new("^#{command}.*#{Regexp.escape name}"), @text, "Could not find a #{command} #{name}" - end - - TEST_DOC = <<-DOC -## -# Documentation for my module - -module MyModule - - ## - # Documentation for my included method - - def my_included_method() end - -end - -## -# Documentation for my class - -class MyClass - - include MyModule - - ## - # Documentation for my constant - - MY_CONSTANT = 'my value' - - ## - # Documentation for my class method - - def self.my_class_method(my_first_argument) end - - ## - # Documentation for my method - - def my_method(my_first_argument) end - -end - - DOC - -end - -MiniTest::Unit.autorun diff --git a/test/rdoc/test_rdoc_markup.rb b/test/rdoc/test_rdoc_markup.rb index 7004fe50ec..9f7866fb5a 100644 --- a/test/rdoc/test_rdoc_markup.rb +++ b/test/rdoc/test_rdoc_markup.rb @@ -1,615 +1,37 @@ require 'rubygems' -require 'minitest/unit' +require 'minitest/autorun' require 'rdoc/markup' require 'rdoc/markup/to_test' class TestRDocMarkup < MiniTest::Unit::TestCase - def basic_conv(str) - sm = RDoc::Markup.new - mock = RDoc::Markup::ToTest.new - sm.convert(str, mock) - sm.content - end - - def line_groups(str, expected) - m = RDoc::Markup.new - mock = RDoc::Markup::ToTest.new - - block = m.convert(str, mock) + def test_convert + str = <<-STR +now is +the time - if block != expected - rows = (0...([expected.size, block.size].max)).collect{|i| - [expected[i]||"nil", block[i]||"nil"] - } - printf "\n\n%35s %35s\n", "Expected", "Got" - rows.each {|e,g| printf "%35s %35s\n", e.dump, g.dump } - end + hello + dave - assert_equal(expected, block) - end +1. l1 +2. l2 + STR - def line_types(str, expected) m = RDoc::Markup.new - mock = RDoc::Markup::ToTest.new - m.convert(str, mock) - assert_equal(expected, m.get_line_types.map{|type| type.to_s[0,1]}.join('')) - end - - def test_groups - str = "now is the time" - line_groups(str, ["L0: Paragraph\nnow is the time"] ) - - str = "now is the time\nfor all good men" - line_groups(str, ["L0: Paragraph\nnow is the time for all good men"] ) - - str = %{\ - now is the time - code _line_ here - for all good men} - - line_groups(str, - [ "L0: Paragraph\nnow is the time", - "L0: Verbatim\n code _line_ here\n", - "L0: Paragraph\nfor all good men" - ] ) - - str = "now is the time\n code\n more code\nfor all good men" - line_groups(str, - [ "L0: Paragraph\nnow is the time", - "L0: Verbatim\n code\n more code\n", - "L0: Paragraph\nfor all good men" - ] ) - - str = %{\ - now is - * l1 - * l2 - the time} - line_groups(str, - [ "L0: Paragraph\nnow is", - "L1: ListStart\n", - "L1: BULLET ListItem\nl1", - "L1: BULLET ListItem\nl2", - "L1: ListEnd\n", - "L0: Paragraph\nthe time" - ]) - - str = %{\ - now is - * l1 - l1+ - * l2 - the time} - line_groups(str, - [ "L0: Paragraph\nnow is", - "L1: ListStart\n", - "L1: BULLET ListItem\nl1 l1+", - "L1: BULLET ListItem\nl2", - "L1: ListEnd\n", - "L0: Paragraph\nthe time" - ]) - - str = %{\ - now is - * l1 - * l1.1 - * l2 - the time} - line_groups(str, - [ "L0: Paragraph\nnow is", - "L1: ListStart\n", - "L1: BULLET ListItem\nl1", - "L2: ListStart\n", - "L2: BULLET ListItem\nl1.1", - "L2: ListEnd\n", - "L1: BULLET ListItem\nl2", - "L1: ListEnd\n", - "L0: Paragraph\nthe time" - ]) - - - str = %{\ - now is - * l1 - * l1.1 - text - code - code - - text - * l2 - the time} - line_groups(str, - [ "L0: Paragraph\nnow is", - "L1: ListStart\n", - "L1: BULLET ListItem\nl1", - "L2: ListStart\n", - "L2: BULLET ListItem\nl1.1 text", - "L2: Verbatim\n code\n code\n", - "L2: Paragraph\ntext", - "L2: ListEnd\n", - "L1: BULLET ListItem\nl2", - "L1: ListEnd\n", - "L0: Paragraph\nthe time" - ]) - - - str = %{\ - now is - 1. l1 - * l1.1 - 2. l2 - the time} - line_groups(str, - [ "L0: Paragraph\nnow is", - "L1: ListStart\n", - "L1: NUMBER ListItem\nl1", - "L2: ListStart\n", - "L2: BULLET ListItem\nl1.1", - "L2: ListEnd\n", - "L1: NUMBER ListItem\nl2", - "L1: ListEnd\n", - "L0: Paragraph\nthe time" - ]) - - str = %{\ - now is - [cat] l1 - * l1.1 - [dog] l2 - the time} - line_groups(str, - [ "L0: Paragraph\nnow is", - "L1: ListStart\n", - "L1: LABELED ListItem\ncat: l1", - "L2: ListStart\n", - "L2: BULLET ListItem\nl1.1", - "L2: ListEnd\n", - "L1: LABELED ListItem\ndog: l2", - "L1: ListEnd\n", - "L0: Paragraph\nthe time" - ]) - - str = %{\ - now is - [cat] l1 - continuation - [dog] l2 - the time} - line_groups(str, - [ "L0: Paragraph\nnow is", - "L1: ListStart\n", - "L1: LABELED ListItem\ncat: l1 continuation", - "L1: LABELED ListItem\ndog: l2", - "L1: ListEnd\n", - "L0: Paragraph\nthe time" - ]) - end - - def test_headings - str = "= heading one" - line_groups(str, - [ "L0: Heading\nheading one" - ]) - - str = "=== heading three" - line_groups(str, - [ "L0: Heading\nheading three" - ]) - - str = "text\n === heading three" - line_groups(str, - [ "L0: Paragraph\ntext", - "L0: Verbatim\n === heading three\n" - ]) - - str = "text\n code\n === heading three" - line_groups(str, - [ "L0: Paragraph\ntext", - "L0: Verbatim\n code\n === heading three\n" - ]) - - str = "text\n code\n=== heading three" - line_groups(str, - [ "L0: Paragraph\ntext", - "L0: Verbatim\n code\n", - "L0: Heading\nheading three" - ]) - - end - - def test_list_alpha - str = "a. alpha\nb. baker\nB. ALPHA\nA. BAKER" - - line_groups(str, - [ "L1: ListStart\n", - "L1: LOWERALPHA ListItem\nalpha", - "L1: LOWERALPHA ListItem\nbaker", - "L1: ListEnd\n", - "L1: ListStart\n", - "L1: UPPERALPHA ListItem\nALPHA", - "L1: UPPERALPHA ListItem\nBAKER", - "L1: ListEnd\n" ]) - end - - def test_list_bullet_dash - str = "- one\n- two\n" - - line_groups(str, - [ "L1: ListStart\n", - "L1: BULLET ListItem\none", - "L1: BULLET ListItem\ntwo", - "L1: ListEnd\n" ]) - end - - def test_list_bullet_star - str = "* one\n* two\n" - - line_groups(str, - [ "L1: ListStart\n", - "L1: BULLET ListItem\none", - "L1: BULLET ListItem\ntwo", - "L1: ListEnd\n" ]) - end - - def test_list_labeled_bracket - str = "[one] item one\n[two] item two" - - line_groups(str, - [ "L1: ListStart\n", - "L1: LABELED ListItem\none: item one", - "L1: LABELED ListItem\ntwo: item two", - "L1: ListEnd\n" ]) - end - - def test_list_labeled_bracket_continued - str = "[one]\n item one\n[two]\n item two" - - line_groups(str, - [ "L1: ListStart\n", - "L1: LABELED ListItem\none: item one", - "L1: LABELED ListItem\ntwo: item two", - "L1: ListEnd\n" ]) - end - - def test_list_labeled_colon - str = "one:: item one\ntwo:: item two" - - line_groups(str, - [ "L1: ListStart\n", - "L1: NOTE ListItem\none:: item one", - "L1: NOTE ListItem\ntwo:: item two", - "L1: ListEnd\n" ]) - end - - def test_list_labeled_colon_continued - str = "one::\n item one\ntwo::\n item two" - - line_groups(str, - [ "L1: ListStart\n", - "L1: NOTE ListItem\none:: item one", - "L1: NOTE ListItem\ntwo:: item two", - "L1: ListEnd\n" ]) - end - - def test_list_nested_bullet_bullet - str = "* one\n* two\n * cat\n * dog" - - line_groups(str, - [ "L1: ListStart\n", - "L1: BULLET ListItem\none", - "L1: BULLET ListItem\ntwo", - "L2: ListStart\n", - "L2: BULLET ListItem\ncat", - "L2: BULLET ListItem\ndog", - "L2: ListEnd\n", - "L1: ListEnd\n" ]) - end - - def test_list_nested_labeled_bullet - str = "[one]\n * cat\n * dog" - - line_groups(str, - [ "L1: ListStart\n", - "L1: LABELED ListItem\none: ", - "L2: ListStart\n", - "L2: BULLET ListItem\ncat", - "L2: BULLET ListItem\ndog", - "L2: ListEnd\n", - "L1: ListEnd\n" ]) - end - - def test_list_nested_labeled_bullet_bullet - str = "[one]\n * cat\n * dog" - - line_groups(str, - [ "L1: ListStart\n", - "L1: LABELED ListItem\none: ", - "L2: ListStart\n", - "L2: BULLET ListItem\ncat", - "L3: ListStart\n", - "L3: BULLET ListItem\ndog", - "L3: ListEnd\n", - "L2: ListEnd\n", - "L1: ListEnd\n" ]) - end - - def test_list_nested_number_number - str = "1. one\n1. two\n 1. cat\n 1. dog" - - line_groups(str, - [ "L1: ListStart\n", - "L1: NUMBER ListItem\none", - "L1: NUMBER ListItem\ntwo", - "L2: ListStart\n", - "L2: NUMBER ListItem\ncat", - "L2: NUMBER ListItem\ndog", - "L2: ListEnd\n", - "L1: ListEnd\n" ]) - end - - def test_list_number - str = "1. one\n2. two\n1. three" - - line_groups(str, - [ "L1: ListStart\n", - "L1: NUMBER ListItem\none", - "L1: NUMBER ListItem\ntwo", - "L1: NUMBER ListItem\nthree", - "L1: ListEnd\n" ]) - end - - def test_list_split - str = %{\ - now is - * l1 - 1. n1 - 2. n2 - * l2 - the time} - line_groups(str, - [ "L0: Paragraph\nnow is", - "L1: ListStart\n", - "L1: BULLET ListItem\nl1", - "L1: ListEnd\n", - "L1: ListStart\n", - "L1: NUMBER ListItem\nn1", - "L1: NUMBER ListItem\nn2", - "L1: ListEnd\n", - "L1: ListStart\n", - "L1: BULLET ListItem\nl2", - "L1: ListEnd\n", - "L0: Paragraph\nthe time" - ]) - - end - - def test_paragraph - str = "paragraph\n\n*bold* paragraph\n" - - line_groups str, [ - "L0: Paragraph\nparagraph", - "L0: BlankLine\n", - "L0: Paragraph\n*bold* paragraph" + out = m.convert str, RDoc::Markup::ToTest.new + + expected = [ + "now is the time", + "\n", + " hello\n dave\n", + "1: ", + "l1", + "1: ", + "l2", ] - end - - def test_tabs - str = "hello\n dave" - assert_equal(str, basic_conv(str)) - str = "hello\n\tdave" - assert_equal("hello\n dave", basic_conv(str)) - str = "hello\n \tdave" - assert_equal("hello\n dave", basic_conv(str)) - str = "hello\n \tdave" - assert_equal("hello\n dave", basic_conv(str)) - str = "hello\n \tdave" - assert_equal("hello\n dave", basic_conv(str)) - str = "hello\n \tdave" - assert_equal("hello\n dave", basic_conv(str)) - str = "hello\n \tdave" - assert_equal("hello\n dave", basic_conv(str)) - str = "hello\n \tdave" - assert_equal("hello\n dave", basic_conv(str)) - str = "hello\n \tdave" - assert_equal("hello\n dave", basic_conv(str)) - str = "hello\n \tdave" - assert_equal("hello\n dave", basic_conv(str)) - str = ".\t\t." - assert_equal(". .", basic_conv(str)) - end - - def test_types - str = "now is the time" - line_types(str, 'P') - - str = "now is the time\nfor all good men" - line_types(str, 'PP') - - str = "now is the time\n code\nfor all good men" - line_types(str, 'PVP') - - str = "now is the time\n code\n more code\nfor all good men" - line_types(str, 'PVVP') - - str = "now is\n---\nthe time" - line_types(str, 'PRP') - - str = %{\ - now is - * l1 - * l2 - the time} - line_types(str, 'PLLP') - - str = %{\ - now is - * l1 - l1+ - * l2 - the time} - line_types(str, 'PLPLP') - - str = %{\ - now is - * l1 - * l1.1 - * l2 - the time} - line_types(str, 'PLLLP') - - str = %{\ - now is - * l1 - * l1.1 - text - code - code - - text - * l2 - the time} - line_types(str, 'PLLPVVBPLP') - - str = %{\ - now is - 1. l1 - * l1.1 - 2. l2 - the time} - line_types(str, 'PLLLP') - - str = %{\ - now is - [cat] l1 - * l1.1 - [dog] l2 - the time} - line_types(str, 'PLLLP') - - str = %{\ - now is - [cat] l1 - continuation - [dog] l2 - the time} - line_types(str, 'PLPLP') - end - - def test_verbatim - str = "paragraph\n *bold* verbatim\n" - - line_groups str, [ - "L0: Paragraph\nparagraph", - "L0: Verbatim\n *bold* verbatim\n" - ] - end - - def test_verbatim_merge - str = %{\ - now is - code - the time} - - line_groups(str, - [ "L0: Paragraph\nnow is", - "L0: Verbatim\n code\n", - "L0: Paragraph\nthe time" - ]) - - - str = %{\ - now is - code - code1 - the time} - - line_groups(str, - [ "L0: Paragraph\nnow is", - "L0: Verbatim\n code\n code1\n", - "L0: Paragraph\nthe time" - ]) - - - str = %{\ - now is - code - - code1 - the time} - - line_groups(str, - [ "L0: Paragraph\nnow is", - "L0: Verbatim\n code\n\n code1\n", - "L0: Paragraph\nthe time" - ]) - - - str = %{\ - now is - code - - code1 - - the time} - - line_groups(str, - [ "L0: Paragraph\nnow is", - "L0: Verbatim\n code\n\n code1\n", - "L0: Paragraph\nthe time" - ]) - - - str = %{\ - now is - code - - code1 - - code2 - the time} - - line_groups(str, - [ "L0: Paragraph\nnow is", - "L0: Verbatim\n code\n\n code1\n\n code2\n", - "L0: Paragraph\nthe time" - ]) - - - # Folds multiple blank lines - str = %{\ - now is - code - - - code1 - - the time} - - line_groups(str, - [ "L0: Paragraph\nnow is", - "L0: Verbatim\n code\n\n code1\n", - "L0: Paragraph\nthe time" - ]) - - - end - - def test_whitespace - assert_equal("hello", basic_conv("hello")) - assert_equal("hello", basic_conv(" hello ")) - assert_equal("hello", basic_conv(" \t \t hello\t\t")) - - assert_equal("1\n 2\n 3", basic_conv("1\n 2\n 3")) - assert_equal("1\n 2\n 3", basic_conv(" 1\n 2\n 3")) - - assert_equal("1\n 2\n 3\n1\n 2", basic_conv("1\n 2\n 3\n1\n 2")) - assert_equal("1\n 2\n 3\n1\n 2", basic_conv(" 1\n 2\n 3\n 1\n 2")) - assert_equal("1\n 2\n\n 3", basic_conv(" 1\n 2\n\n 3")) + assert_equal expected, out end end -MiniTest::Unit.autorun diff --git a/test/rdoc/test_rdoc_markup_attribute_manager.rb b/test/rdoc/test_rdoc_markup_attribute_manager.rb index 520470a8cc..f6b1b6cf17 100644 --- a/test/rdoc/test_rdoc_markup_attribute_manager.rb +++ b/test/rdoc/test_rdoc_markup_attribute_manager.rb @@ -1,14 +1,13 @@ require "rubygems" -require "minitest/unit" +require "minitest/autorun" +require 'rdoc' +require 'rdoc/markup' require "rdoc/markup/inline" require "rdoc/markup/to_html_crossref" class TestRDocMarkupAttributeManager < MiniTest::Unit::TestCase def setup - @orig_special = RDoc::Markup::AttributeManager::SPECIAL - RDoc::Markup::AttributeManager::SPECIAL.replace Hash.new - @am = RDoc::Markup::AttributeManager.new @bold_on = @am.changed_attribute_by_name([], [:BOLD]) @@ -32,10 +31,6 @@ class TestRDocMarkupAttributeManager < MiniTest::Unit::TestCase @wombat_off = @am.changed_attribute_by_name([:WOMBAT], []) end - def teardown - RDoc::Markup::AttributeManager::SPECIAL.replace @orig_special - end - def crossref(text) crossref_bitmap = RDoc::Markup::Attribute.bitmap_for(:_SPECIAL_) | RDoc::Markup::Attribute.bitmap_for(:CROSSREF) @@ -55,9 +50,9 @@ class TestRDocMarkupAttributeManager < MiniTest::Unit::TestCase def test_add_word_pair @am.add_word_pair '%', '&', 'percent and' - assert RDoc::Markup::AttributeManager::WORD_PAIR_MAP.include?(/(%)(\S+)(&)/) - assert RDoc::Markup::AttributeManager::PROTECTABLE.include?('%') - assert !RDoc::Markup::AttributeManager::PROTECTABLE.include?('&') + assert @am.word_pair_map.include?(/(%)(\S+)(&)/) + assert @am.protectable.include?('%') + assert !@am.protectable.include?('&') end def test_add_word_pair_angle @@ -71,8 +66,8 @@ class TestRDocMarkupAttributeManager < MiniTest::Unit::TestCase def test_add_word_pair_matching @am.add_word_pair '^', '^', 'caret' - assert RDoc::Markup::AttributeManager::MATCHING_WORD_PAIRS.include?('^') - assert RDoc::Markup::AttributeManager::PROTECTABLE.include?('^') + assert @am.matching_word_pairs.include?('^') + assert @am.protectable.include?('^') end def test_basic @@ -124,6 +119,10 @@ class TestRDocMarkupAttributeManager < MiniTest::Unit::TestCase @am.flow("*\\bold*") end + def test_bold_html_escaped + assert_equal ['cat dog'], @am.flow('cat \dog') + end + def test_combined assert_equal(["cat ", @em_on, "and", @em_off, " ", @bold_on, "dog", @bold_off], @am.flow("cat _and_ *dog*")) @@ -196,14 +195,17 @@ class TestRDocMarkupAttributeManager < MiniTest::Unit::TestCase end def test_protect - assert_equal(['cat \\ dog'], @am.flow('cat \\ dog')) + assert_equal(['cat \\ dog'], + @am.flow('cat \\ dog')) - assert_equal(["cat dog"], @am.flow("cat \\dog")) + assert_equal(["cat dog"], + @am.flow("cat \\dog")) assert_equal(["cat ", @em_on, "and", @em_off, " dog"], @am.flow("cat and \\dog")) - assert_equal(["*word* or text"], @am.flow("\\*word* or \\text")) + assert_equal(["*word* or text"], + @am.flow("\\*word* or \\text")) assert_equal(["_cat_", @em_on, "dog", @em_off], @am.flow("\\_cat_dog")) @@ -229,6 +231,10 @@ class TestRDocMarkupAttributeManager < MiniTest::Unit::TestCase assert_equal(["cats' ", crossref("#fred")].flatten, @am.flow("cats' #fred")) end + def test_tt_html + assert_equal [@tt_on, '"\n"', @tt_off], + @am.flow('"\n"') + end + end -MiniTest::Unit.autorun diff --git a/test/rdoc/test_rdoc_markup_document.rb b/test/rdoc/test_rdoc_markup_document.rb new file mode 100644 index 0000000000..ab2f1c2362 --- /dev/null +++ b/test/rdoc/test_rdoc_markup_document.rb @@ -0,0 +1,51 @@ +require 'pp' +require 'rubygems' +require 'minitest/autorun' +require 'rdoc/markup' + +class TestRDocMarkupDocument < MiniTest::Unit::TestCase + + def setup + @RM = RDoc::Markup + @d = @RM::Document.new + end + + def mu_pp obj + s = '' + s = PP.pp obj, s + s.force_encoding Encoding.default_external if defined? Encoding + s.chomp + end + + def test_append + @d << @RM::Paragraph.new('hi') + + expected = @RM::Document.new @RM::Paragraph.new('hi') + + assert_equal expected, @d + end + + def test_append_document + @d << @RM::Document.new + + assert_empty @d + + @d << @RM::Document.new(@RM::Paragraph.new('hi')) + + expected = @RM::Document.new @RM::Paragraph.new('hi'), @RM::BlankLine.new + + assert_equal expected, @d + end + + def test_append_string + @d << '' + + assert_empty @d + + assert_raises ArgumentError do + @d << 'hi' + end + end + +end + diff --git a/test/rdoc/test_rdoc_markup_paragraph.rb b/test/rdoc/test_rdoc_markup_paragraph.rb new file mode 100644 index 0000000000..15f3b5f849 --- /dev/null +++ b/test/rdoc/test_rdoc_markup_paragraph.rb @@ -0,0 +1,27 @@ +require 'pp' +require 'rubygems' +require 'minitest/autorun' +require 'rdoc/markup' + +class TestRDocMarkupParagraph < MiniTest::Unit::TestCase + + def setup + @RM = RDoc::Markup + @p = @RM::Paragraph.new + end + + def mu_pp obj + s = '' + s = PP.pp obj, s + s.force_encoding Encoding.default_external if defined? Encoding + s.chomp + end + + def test_push + @p.push 'hi', 'there' + + assert_equal @RM::Paragraph.new('hi', 'there'), @p + end + +end + diff --git a/test/rdoc/test_rdoc_markup_parser.rb b/test/rdoc/test_rdoc_markup_parser.rb new file mode 100644 index 0000000000..656e2c9831 --- /dev/null +++ b/test/rdoc/test_rdoc_markup_parser.rb @@ -0,0 +1,1327 @@ +require 'pp' +require 'rubygems' +require 'minitest/autorun' +require 'rdoc/markup' +require 'rdoc/markup/to_test' + +class TestRDocMarkupParser < MiniTest::Unit::TestCase + + def setup + @RM = RDoc::Markup + @RMP = @RM::Parser + end + + def mu_pp(obj) + s = '' + s = PP.pp obj, s + s = s.force_encoding(Encoding.default_external) if defined? Encoding + s.chomp + end + + def test_build_heading + parser = @RMP.new + + parser.tokens.replace [ + [:TEXT, 'heading three', 4, 0], + [:NEWLINE, "\n", 17, 0], + ] + + assert_equal @RM::Heading.new(3, 'heading three'), parser.build_heading(3) + end + + def test_get + parser = util_parser + + assert_equal [:HEADER, 1, 0, 0], parser.get + + assert_equal 7, parser.tokens.length + end + + def test_parse_bullet + str = <<-STR +* l1 +* l2 + STR + + expected = [ + @RM::List.new(:BULLET, *[ + @RM::ListItem.new(nil, + @RM::Paragraph.new('l1')), + @RM::ListItem.new(nil, + @RM::Paragraph.new('l2'))])] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_bullet_verbatim_heading + str = <<-STR +* l1 + v + += H + STR + + expected = [ + @RM::List.new(:BULLET, *[ + @RM::ListItem.new(nil, + @RM::Paragraph.new('l1'), + @RM::Verbatim.new(' ', 'v', "\n"))]), + @RM::Heading.new(1, 'H')] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_bullet_heading + str = <<-STR +* = l1 + STR + + expected = [ + @RM::List.new(:BULLET, *[ + @RM::ListItem.new(nil, + @RM::Heading.new(1, 'l1'))])] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_bullet_indent + str = <<-STR +* l1 + * l1.1 +* l2 + STR + + expected = [ + @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'))])] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_bullet_paragraph + str = <<-STR +now is +* l1 +* l2 +the time + STR + + expected = [ + @RM::Paragraph.new('now is'), + @RM::List.new(:BULLET, *[ + @RM::ListItem.new(nil, + @RM::Paragraph.new('l1')), + @RM::ListItem.new(nil, + @RM::Paragraph.new('l2')), + ]), + @RM::Paragraph.new('the time'), + ] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_bullet_multiline + str = <<-STR +* l1 + l1+ +* l2 + STR + + expected = [ + @RM::List.new(:BULLET, *[ + @RM::ListItem.new(nil, + @RM::Paragraph.new('l1', 'l1+')), + @RM::ListItem.new(nil, + @RM::Paragraph.new('l2')), + ]), + ] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_bullet_multiparagraph + str = <<-STR +* l1 + + l1+ + STR + + expected = [ + @RM::List.new(:BULLET, *[ + @RM::ListItem.new(nil, + @RM::Paragraph.new('l1'), + @RM::BlankLine.new, + @RM::Paragraph.new('l1+')), + ]), + ] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_bullet_indent_verbatim + str = <<-STR +* l1 + * l1.1 + text + code + code + + text +* l2 + STR + + expected = [ + @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', 'text'), + @RM::Verbatim.new(' ', 'code', "\n", + ' ', 'code', "\n"), + @RM::Paragraph.new('text'))])), + @RM::ListItem.new(nil, + @RM::Paragraph.new('l2'))])] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_dash + str = <<-STR +- one +- two + STR + + expected = [ + @RM::List.new(:BULLET, *[ + @RM::ListItem.new(nil, + @RM::Paragraph.new('one')), + @RM::ListItem.new(nil, + @RM::Paragraph.new('two'))])] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_heading + str = '= heading one' + + expected = [ + @RM::Heading.new(1, 'heading one')] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_heading_three + str = '=== heading three' + + expected = [ + @RM::Heading.new(3, 'heading three')] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_heading_bullet + str = '= * heading one' + + expected = [ + @RM::Heading.new(1, '* heading one')] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_heading_heading + str = '= =' + + expected = [ + @RM::Heading.new(1, '=')] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_heading_lalpha + str = '= b. heading one' + + expected = [ + @RM::Heading.new(1, 'b. heading one')] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_heading_label + str = '= [heading one]' + + expected = [ + @RM::Heading.new(1, '[heading one]')] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_heading_note + str = '= heading one::' + + expected = [ + @RM::Heading.new(1, 'heading one::')] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_heading_number + str = '= 5. heading one' + + expected = [ + @RM::Heading.new(1, '5. heading one')] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_heading_ualpha + str = '= B. heading one' + + expected = [ + @RM::Heading.new(1, 'B. heading one')] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_label + str = <<-STR +[one] item one +[two] item two + STR + + expected = [ + @RM::List.new(:LABEL, *[ + @RM::ListItem.new('one', + @RM::Paragraph.new('item one')), + @RM::ListItem.new('two', + @RM::Paragraph.new('item two'))])] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_label_bullet + str = <<-STR +[cat] l1 + * l1.1 +[dog] l2 + STR + + expected = [ + @RM::List.new(:LABEL, *[ + @RM::ListItem.new('cat', + @RM::Paragraph.new('l1'), + @RM::List.new(:BULLET, *[ + @RM::ListItem.new(nil, + @RM::Paragraph.new('l1.1'))])), + @RM::ListItem.new('dog', + @RM::Paragraph.new('l2'))])] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_label_multiline + str = <<-STR +[cat] l1 + continuation +[dog] l2 + STR + + expected = [ + @RM::List.new(:LABEL, *[ + @RM::ListItem.new('cat', + @RM::Paragraph.new('l1', 'continuation')), + @RM::ListItem.new('dog', + @RM::Paragraph.new('l2'))])] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_label_newline + str = <<-STR +[one] + item one +[two] + item two + STR + + expected = [ + @RM::List.new(:LABEL, *[ + @RM::ListItem.new('one', + @RM::Paragraph.new('item one')), + @RM::ListItem.new('two', + @RM::Paragraph.new('item two')), + ])] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_lalpha + str = <<-STR +a. l1 +b. l2 + STR + + expected = [ + @RM::List.new(:LALPHA, *[ + @RM::ListItem.new(nil, + @RM::Paragraph.new('l1')), + @RM::ListItem.new(nil, + @RM::Paragraph.new('l2'))])] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_lalpha_ualpha + str = <<-STR +a. l1 +b. l2 +A. l3 +A. l4 + STR + + expected = [ + @RM::List.new(:LALPHA, *[ + @RM::ListItem.new(nil, + @RM::Paragraph.new('l1')), + @RM::ListItem.new(nil, + @RM::Paragraph.new('l2'))]), + @RM::List.new(:UALPHA, *[ + @RM::ListItem.new(nil, + @RM::Paragraph.new('l3')), + @RM::ListItem.new(nil, + @RM::Paragraph.new('l4'))])] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_list_verbatim + str = <<-STR +* one + verb1 + verb2 +* two + STR + + expected = [ + @RM::List.new(:BULLET, *[ + @RM::ListItem.new(nil, + @RM::Paragraph.new('one'), + @RM::Verbatim.new(' ', 'verb1', "\n", + ' ', 'verb2', "\n")), + @RM::ListItem.new(nil, + @RM::Paragraph.new('two'))])] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_lists + str = <<-STR +now is +* l1 +1. n1 +2. n2 +* l2 +the time + STR + + expected = [ + @RM::Paragraph.new('now is'), + @RM::List.new(:BULLET, *[ + @RM::ListItem.new(nil, + @RM::Paragraph.new('l1'))]), + @RM::List.new(:NUMBER, *[ + @RM::ListItem.new(nil, + @RM::Paragraph.new('n1')), + @RM::ListItem.new(nil, + @RM::Paragraph.new('n2'))]), + @RM::List.new(:BULLET, *[ + @RM::ListItem.new(nil, + @RM::Paragraph.new('l2'))]), + @RM::Paragraph.new('the time')] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_note + str = <<-STR +one:: item one +two:: item two + STR + + expected = [ + @RM::List.new(:NOTE, *[ + @RM::ListItem.new('one', + @RM::Paragraph.new('item one')), + @RM::ListItem.new('two', + @RM::Paragraph.new('item two'))])] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_note_empty + str = <<-STR +one:: +two:: + STR + + expected = [ + @RM::List.new(:NOTE, *[ + @RM::ListItem.new('one', + @RM::BlankLine.new), + @RM::ListItem.new('two', + @RM::BlankLine.new)])] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_note_note + str = <<-STR +one:: two:: + STR + + expected = [ + @RM::List.new(:NOTE, *[ + @RM::ListItem.new('one', + @RM::List.new(:NOTE, *[ + @RM::ListItem.new('two', + @RM::BlankLine.new)]))])] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_number_bullet + str = <<-STR +1. l1 + * l1.1 +2. l2 + STR + + expected = [ + @RM::List.new(:NUMBER, *[ + @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'))])] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_paragraph + str = <<-STR +now is the time + +for all good men + STR + + expected = [ + @RM::Paragraph.new('now is the time'), + @RM::BlankLine.new, + @RM::Paragraph.new('for all good men')] + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_paragraph_multiline + str = "now is the time\nfor all good men" + + expected = @RM::Paragraph.new 'now is the time for all good men' + assert_equal [expected], @RMP.parse(str).parts + end + + def test_parse_paragraph_verbatim + str = <<-STR +now is the time + code _line_ here +for all good men + STR + + expected = [ + @RM::Paragraph.new('now is the time'), + @RM::Verbatim.new(' ', 'code _line_ here', "\n"), + @RM::Paragraph.new('for all good men'), + ] + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_ualpha + str = <<-STR +A. l1 +B. l2 + STR + + expected = [ + @RM::List.new(:UALPHA, *[ + @RM::ListItem.new(nil, + @RM::Paragraph.new('l1')), + @RM::ListItem.new(nil, + @RM::Paragraph.new('l2'))])] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_verbatim + str = <<-STR +now is + code +the time + STR + + expected = [ + @RM::Paragraph.new('now is'), + @RM::Verbatim.new(' ', 'code', "\n"), + @RM::Paragraph.new('the time'), + ] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_verbatim_bullet + str = <<-STR + * blah + STR + + expected = [ + @RM::Verbatim.new(' ', '*', ' ', 'blah', "\n")] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_verbatim_fold + str = <<-STR +now is + code + + + code1 + +the time + STR + + expected = [ + @RM::Paragraph.new('now is'), + @RM::Verbatim.new(' ', 'code', "\n", + "\n", + ' ', 'code1', "\n"), + @RM::Paragraph.new('the time'), + ] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_verbatim_heading + str = <<-STR +text + === heading three + STR + + expected = [ + @RM::Paragraph.new('text'), + @RM::Verbatim.new(' ', '===', ' ', 'heading three', "\n")] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_verbatim_heading2 + str = "text\n code\n=== heading three" + + expected = [ + @RM::Paragraph.new('text'), + @RM::Verbatim.new(' ', 'code', "\n"), + @RM::Heading.new(3, 'heading three')] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_verbatim_label + str = <<-STR + [blah] blah + STR + + expected = [ + @RM::Verbatim.new(' ', '[blah]', ' ', 'blah', "\n")] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_verbatim_lalpha + str = <<-STR + b. blah + STR + + expected = [ + @RM::Verbatim.new(' ', 'b.', ' ', 'blah', "\n")] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_verbatim_markup_example + str = <<-STR +text + code + === heading three + STR + + expected = [ + @RM::Paragraph.new('text'), + @RM::Verbatim.new(' ', 'code', "\n", + ' ', '===', ' ', 'heading three', "\n")] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_verbatim_merge + str = <<-STR +now is + code + + code1 +the time + STR + + expected = [ + @RM::Paragraph.new('now is'), + @RM::Verbatim.new(' ', 'code', "\n", + "\n", + ' ', 'code1', "\n"), + @RM::Paragraph.new('the time'), + ] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_verbatim_merge2 + str = <<-STR +now is + code + + code1 + + code2 +the time + STR + + expected = [ + @RM::Paragraph.new('now is'), + @RM::Verbatim.new(' ', 'code', "\n", + "\n", + ' ', 'code1', "\n", + "\n", + ' ', 'code2', "\n"), + @RM::Paragraph.new('the time'), + ] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_verbatim_multiline + str = <<-STR +now is + code + code1 +the time + STR + + expected = [ + @RM::Paragraph.new('now is'), + @RM::Verbatim.new(' ', 'code', "\n", + ' ', 'code1', "\n"), + @RM::Paragraph.new('the time'), + ] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_verbatim_multilevel + str = <<-STR +now is the time + code + more code +for all good men + STR + + expected = [ + @RM::Paragraph.new('now is the time'), + @RM::Verbatim.new(' ', 'code', "\n", + ' ', 'more code', "\n"), + @RM::Paragraph.new('for all good men'), + ] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_verbatim_note + str = <<-STR + blah:: blah + STR + + expected = [ + @RM::Verbatim.new(' ', 'blah::', ' ', 'blah', "\n")] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_verbatim_number + str = <<-STR + 2. blah + STR + + expected = [ + @RM::Verbatim.new(' ', '2.', ' ', 'blah', "\n")] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_verbatim_rule + str = <<-STR +text + + --- lib/blah.rb.orig + +++ lib/blah.rb + STR + + expected = [ + @RM::Paragraph.new('text'), + @RM::BlankLine.new, + @RM::Verbatim.new(' ', '---', ' ', 'lib/blah.rb.orig', "\n", + ' ', '+++', ' ', 'lib/blah.rb', "\n")] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_verbatim_rule2 + str = <<-STR.chomp +text + + --- + STR + + expected = [ + @RM::Paragraph.new('text'), + @RM::BlankLine.new, + @RM::Verbatim.new(' ', '---', '')] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_verbatim_trim + str = <<-STR +now is + code + + code1 + +the time + STR + + expected = [ + @RM::Paragraph.new('now is'), + @RM::Verbatim.new(' ', 'code', "\n", + "\n", + ' ', 'code1', "\n"), + @RM::Paragraph.new('the time'), + ] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_verbatim_ualpha + str = <<-STR + B. blah + STR + + expected = [ + @RM::Verbatim.new(' ', 'B.', ' ', 'blah', "\n")] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_whitespace + expected = [ + @RM::Paragraph.new('hello'), + ] + + assert_equal expected, @RMP.parse('hello').parts + + expected = [ + @RM::Verbatim.new(' ', 'hello '), + ] + + assert_equal expected, @RMP.parse(' hello ').parts + + expected = [ + @RM::Verbatim.new(' ', 'hello '), + ] + + assert_equal expected, @RMP.parse(" hello ").parts + + expected = [ + @RM::Paragraph.new('1'), + @RM::Verbatim.new(' ', '2', "\n", + ' ', '3'), + ] + + assert_equal expected, @RMP.parse("1\n 2\n 3").parts + + expected = [ + @RM::Verbatim.new(' ', '1', "\n", + ' ', '2', "\n", + ' ', '3'), + ] + + assert_equal expected, @RMP.parse(" 1\n 2\n 3").parts + + expected = [ + @RM::Paragraph.new('1'), + @RM::Verbatim.new(' ', '2', "\n", + ' ', '3', "\n"), + @RM::Paragraph.new('1'), + @RM::Verbatim.new(' ', '2'), + ] + + assert_equal expected, @RMP.parse("1\n 2\n 3\n1\n 2").parts + + expected = [ + @RM::Verbatim.new(' ', '1', "\n", + ' ', '2', "\n", + ' ', '3', "\n", + ' ', '1', "\n", + ' ', '2'), + ] + + assert_equal expected, @RMP.parse(" 1\n 2\n 3\n 1\n 2").parts + + expected = [ + @RM::Verbatim.new(' ', '1', "\n", + ' ', '2', "\n", + "\n", + ' ', '3'), + ] + + assert_equal expected, @RMP.parse(" 1\n 2\n\n 3").parts + end + + def test_peek_token + parser = util_parser + + assert_equal [:HEADER, 1, 0, 0], parser.peek_token + + assert_equal 8, parser.tokens.length + end + + def test_skip + parser = util_parser + + assert_equal [:HEADER, 1, 0, 0], parser.skip(:HEADER) + + assert_equal [:TEXT, 'Heading', 2, 0], parser.get + + assert_equal [:NEWLINE, "\n", 9, 0], parser.peek_token + + assert_raises RDoc::Markup::Parser::ParseError do + parser.skip :NONE + end + + assert_equal [:NEWLINE, "\n", 9, 0], parser.peek_token + + assert_equal nil, parser.skip(:NONE, false) + + assert_equal [:NEWLINE, "\n", 9, 0], parser.peek_token + end + + def test_tokenize_bullet + str = <<-STR +* l1 + STR + + expected = [ + [:BULLET, :BULLET, 0, 0], + [:SPACE, 2, 0, 0], + [:TEXT, 'l1', 2, 0], + [:NEWLINE, "\n", 4, 0], + ] + + assert_equal expected, @RMP.tokenize(str) + end + + def test_tokenize_bullet_indent + str = <<-STR +* l1 + * l1.1 + STR + + expected = [ + [:BULLET, :BULLET, 0, 0], + [:SPACE, 2, 0, 0], + [:TEXT, 'l1', 2, 0], + [:NEWLINE, "\n", 4, 0], + [:INDENT, 2, 0, 1], + [:BULLET, :BULLET, 2, 1], + [:SPACE, 2, 2, 1], + [:TEXT, 'l1.1', 4, 1], + [:NEWLINE, "\n", 8, 1], + ] + + assert_equal expected, @RMP.tokenize(str) + end + + def test_tokenize_heading + str = <<-STR += Heading +== Heading 2 + STR + + expected = [ + [:HEADER, 1, 0, 0], + [:TEXT, 'Heading', 2, 0], + [:NEWLINE, "\n", 9, 0], + [:HEADER, 2, 0, 1], + [:TEXT, 'Heading 2', 3, 1], + [:NEWLINE, "\n", 12, 1], + ] + + assert_equal expected, @RMP.tokenize(str) + end + + def test_tokenize_heading_heading + str = <<-STR += = + STR + + expected = [ + [:HEADER, 1, 0, 0], + [:TEXT, '=', 2, 0], + [:NEWLINE, "\n", 3, 0], + ] + + assert_equal expected, @RMP.tokenize(str) + end + + def test_tokenize_label + str = <<-STR +[cat] l1 +[dog] l1.1 + STR + + expected = [ + [:LABEL, 'cat', 0, 0], + [:SPACE, 6, 0, 0], + [:TEXT, 'l1', 6, 0], + [:NEWLINE, "\n", 8, 0], + [:LABEL, 'dog', 0, 1], + [:SPACE, 6, 0, 1], + [:TEXT, 'l1.1', 6, 1], + [:NEWLINE, "\n", 10, 1], + ] + + assert_equal expected, @RMP.tokenize(str) + end + + def test_tokenize_label_note + str = <<-STR +[label] + note:: + STR + + expected = [ + [:LABEL, 'label', 0, 0], + [:SPACE, 7, 0, 0], + [:NEWLINE, "\n", 7, 0], + [:INDENT, 2, 0, 1], + [:NOTE, 'note', 2, 1], + [:SPACE, 6, 2, 1], + [:NEWLINE, "\n", 8, 1], + ] + + assert_equal expected, @RMP.tokenize(str) + end + + def test_tokenize_lalpha + str = <<-STR +a. l1 +b. l1.1 + STR + + expected = [ + [:LALPHA, 'a', 0, 0], + [:SPACE, 3, 0, 0], + [:TEXT, 'l1', 3, 0], + [:NEWLINE, "\n", 5, 0], + [:LALPHA, 'b', 0, 1], + [:SPACE, 3, 0, 1], + [:TEXT, 'l1.1', 3, 1], + [:NEWLINE, "\n", 7, 1], + ] + + assert_equal expected, @RMP.tokenize(str) + end + + def test_tokenize_note + str = <<-STR +cat:: l1 +dog:: l1.1 + STR + + expected = [ + [:NOTE, 'cat', 0, 0], + [:SPACE, 6, 0, 0], + [:TEXT, 'l1', 6, 0], + [:NEWLINE, "\n", 8, 0], + [:NOTE, 'dog', 0, 1], + [:SPACE, 6, 0, 1], + [:TEXT, 'l1.1', 6, 1], + [:NEWLINE, "\n", 10, 1], + ] + + assert_equal expected, @RMP.tokenize(str) + end + + def test_tokenize_note_empty + str = <<-STR +cat:: +dog:: + STR + + expected = [ + [:NOTE, 'cat', 0, 0], + [:SPACE, 5, 0, 0], + [:NEWLINE, "\n", 5, 0], + [:NOTE, 'dog', 0, 1], + [:SPACE, 5, 0, 1], + [:NEWLINE, "\n", 5, 1], + ] + + assert_equal expected, @RMP.tokenize(str) + end + + def test_tokenize_note_not + str = <<-STR +Cat::Dog + STR + + expected = [ + [:TEXT, 'Cat::Dog', 0, 0], + [:NEWLINE, "\n", 8, 0], + ] + + assert_equal expected, @RMP.tokenize(str) + end + + def test_tokenize_number + str = <<-STR +1. l1 +2. l1.1 + STR + + expected = [ + [:NUMBER, '1', 0, 0], + [:SPACE, 3, 0, 0], + [:TEXT, 'l1', 3, 0], + [:NEWLINE, "\n", 5, 0], + [:NUMBER, '2', 0, 1], + [:SPACE, 3, 0, 1], + [:TEXT, 'l1.1', 3, 1], + [:NEWLINE, "\n", 7, 1], + ] + + assert_equal expected, @RMP.tokenize(str) + end + + def test_tokenize_number_period + str = <<-STR +1. blah blah blah + l. +2. blah blah blah blah + d. + STR + + expected = [ + [:NUMBER, "1", 0, 0], + [:SPACE, 3, 0, 0], + [:TEXT, "blah blah blah", 3, 0], + [:NEWLINE, "\n", 17, 0], + + [:INDENT, 3, 0, 1], + [:TEXT, "l.", 3, 1], + [:NEWLINE, "\n", 5, 1], + + [:NUMBER, "2", 0, 2], + [:SPACE, 3, 0, 2], + [:TEXT, "blah blah blah blah", 3, 2], + [:NEWLINE, "\n", 22, 2], + + [:INDENT, 3, 0, 3], + [:TEXT, "d.", 3, 3], + [:NEWLINE, "\n", 5, 3] + ] + + assert_equal expected, @RMP.tokenize(str) + end + + def test_tokenize_number_period_continue + str = <<-STR +1. blah blah blah + l. more stuff +2. blah blah blah blah + d. other stuff + STR + + expected = [ + [:NUMBER, "1", 0, 0], + [:SPACE, 3, 0, 0], + [:TEXT, "blah blah blah", 3, 0], + [:NEWLINE, "\n", 17, 0], + + [:INDENT, 3, 0, 1], + [:LALPHA, "l", 3, 1], + [:SPACE, 4, 3, 1], + [:TEXT, "more stuff", 7, 1], + [:NEWLINE, "\n", 17, 1], + + [:NUMBER, "2", 0, 2], + [:SPACE, 3, 0, 2], + [:TEXT, "blah blah blah blah", 3, 2], + [:NEWLINE, "\n", 22, 2], + + [:INDENT, 3, 0, 3], + [:LALPHA, "d", 3, 3], + [:SPACE, 3, 3, 3], + [:TEXT, "other stuff", 6, 3], + [:NEWLINE, "\n", 17, 3] + ] + + assert_equal expected, @RMP.tokenize(str) + end + + def test_tokenize_paragraphs + str = <<-STR +now is +the time + +for all + STR + + expected = [ + [:TEXT, 'now is', 0, 0], + [:NEWLINE, "\n", 6, 0], + [:TEXT, 'the time', 0, 1], + [:NEWLINE, "\n", 8, 1], + [:NEWLINE, "\n", 0, 2], + [:TEXT, 'for all', 0, 3], + [:NEWLINE, "\n", 7, 3], + ] + + assert_equal expected, @RMP.tokenize(str) + end + + def test_tokenize_rule + str = <<-STR +--- + +--- blah --- + STR + + expected = [ + [:RULE, 1, 0, 0], + [:NEWLINE, "\n", 4, 0], + [:NEWLINE, "\n", 0, 1], + [:TEXT, "--- blah ---", 0, 2], + [:NEWLINE, "\n", 12, 2], + ] + + assert_equal expected, @RMP.tokenize(str) + end + + def test_tokenize_ualpha + str = <<-STR +A. l1 +B. l1.1 + STR + + expected = [ + [:UALPHA, 'A', 0, 0], + [:SPACE, 3, 0, 0], + [:TEXT, 'l1', 3, 0], + [:NEWLINE, "\n", 5, 0], + [:UALPHA, 'B', 0, 1], + [:SPACE, 3, 0, 1], + [:TEXT, 'l1.1', 3, 1], + [:NEWLINE, "\n", 7, 1], + ] + + assert_equal expected, @RMP.tokenize(str) + end + + def test_tokenize_verbatim_heading + str = <<-STR +Example heading: + + === heading three + STR + + expected = [ + [:TEXT, 'Example heading:', 0, 0], + [:NEWLINE, "\n", 16, 0], + [:NEWLINE, "\n", 0, 1], + [:INDENT, 3, 0, 2], + [:HEADER, 3, 3, 2], + [:TEXT, 'heading three', 7, 2], + [:NEWLINE, "\n", 20, 2], + ] + + assert_equal expected, @RMP.tokenize(str) + end + + # HACK move to Verbatim test case + def test_verbatim_normalize + v = @RM::Verbatim.new ' ', 'foo', "\n", "\n", "\n", ' ', 'bar', "\n" + + v.normalize + + assert_equal [' ', 'foo', "\n", "\n", ' ', 'bar', "\n"], v.parts + + v = @RM::Verbatim.new ' ', 'foo', "\n", "\n" + + v.normalize + + assert_equal [' ', 'foo', "\n"], v.parts + end + + def test_unget + parser = util_parser + + parser.get + + parser.unget + + assert_equal [:HEADER, 1, 0, 0], parser.peek_token + + assert_raises @RMP::Error do + parser.unget + end + + assert_equal 8, parser.tokens.length + end + + def util_parser + str = <<-STR += Heading + +Some text here +some more text over here + STR + + @parser = @RMP.new + @parser.tokenize str + @parser + end + +end + diff --git a/test/rdoc/test_rdoc_markup_to_ansi.rb b/test/rdoc/test_rdoc_markup_to_ansi.rb new file mode 100644 index 0000000000..195226a4e3 --- /dev/null +++ b/test/rdoc/test_rdoc_markup_to_ansi.rb @@ -0,0 +1,426 @@ +require 'rubygems' +require 'rdoc/markup/formatter_test_case' +require 'rdoc/markup/to_ansi' +require 'minitest/autorun' + +class TestRDocMarkupToAnsi < RDoc::Markup::FormatterTestCase + + add_visitor_tests + + def setup + super + + @to = RDoc::Markup::ToAnsi.new + end + + def accept_blank_line + assert_equal "\e[0m\n", @to.res.join + end + + def accept_heading + assert_equal "\e[0mHello\n", @to.res.join + end + + def accept_list_end_bullet + assert_empty @to.list_index + assert_empty @to.list_type + assert_empty @to.list_width + end + + def accept_list_end_label + assert_empty @to.list_index + assert_empty @to.list_type + assert_empty @to.list_width + end + + def accept_list_end_lalpha + assert_empty @to.list_index + assert_empty @to.list_type + assert_empty @to.list_width + end + + def accept_list_end_note + assert_empty @to.list_index + assert_empty @to.list_type + assert_empty @to.list_width + end + + def accept_list_end_number + assert_empty @to.list_index + assert_empty @to.list_type + assert_empty @to.list_width + end + + def accept_list_end_ualpha + assert_empty @to.list_index + assert_empty @to.list_type + assert_empty @to.list_width + end + + def accept_list_item_end_bullet + assert_equal 0, @to.indent, 'indent' + end + + def accept_list_item_end_label + assert_equal "\e[0m\n", @to.res.join + assert_equal 0, @to.indent, 'indent' + end + + def accept_list_item_end_lalpha + assert_equal 0, @to.indent, 'indent' + assert_equal 'b', @to.list_index.last + end + + def accept_list_item_end_note + assert_equal "\e[0m\n", @to.res.join + assert_equal 0, @to.indent, 'indent' + end + + def accept_list_item_end_number + assert_equal 0, @to.indent, 'indent' + assert_equal 2, @to.list_index.last + end + + def accept_list_item_end_ualpha + assert_equal 0, @to.indent, 'indent' + assert_equal 'B', @to.list_index.last + end + + def accept_list_item_start_bullet + assert_equal %W"\e[0m", @to.res + assert_equal '* ', @to.prefix + end + + def accept_list_item_start_label + assert_equal %W"\e[0m", @to.res + assert_equal "cat:\n ", @to.prefix + + assert_equal 2, @to.indent + end + + def accept_list_item_start_lalpha + assert_equal %W"\e[0m", @to.res + assert_equal 'a. ', @to.prefix + + assert_equal 'a', @to.list_index.last + assert_equal 3, @to.indent + end + + def accept_list_item_start_note + assert_equal %W"\e[0m", @to.res + assert_equal "cat:\n ", @to.prefix + + assert_equal 2, @to.indent + end + + def accept_list_item_start_number + assert_equal %W"\e[0m", @to.res + assert_equal '1. ', @to.prefix + + assert_equal 1, @to.list_index.last + assert_equal 3, @to.indent + end + + def accept_list_item_start_ualpha + assert_equal %W"\e[0m", @to.res + assert_equal 'A. ', @to.prefix + + assert_equal 'A', @to.list_index.last + assert_equal 3, @to.indent + end + + def accept_list_start_bullet + assert_equal "\e[0m", @to.res.join + assert_equal [nil], @to.list_index + assert_equal [:BULLET], @to.list_type + assert_equal [1], @to.list_width + end + + def accept_list_start_label + assert_equal "\e[0m", @to.res.join + assert_equal [nil], @to.list_index + assert_equal [:LABEL], @to.list_type + assert_equal [2], @to.list_width + end + + def accept_list_start_lalpha + assert_equal "\e[0m", @to.res.join + assert_equal ['a'], @to.list_index + assert_equal [:LALPHA], @to.list_type + assert_equal [1], @to.list_width + end + + def accept_list_start_note + assert_equal "\e[0m", @to.res.join + assert_equal [nil], @to.list_index + assert_equal [:NOTE], @to.list_type + assert_equal [2], @to.list_width + end + + def accept_list_start_number + assert_equal "\e[0m", @to.res.join + assert_equal [1], @to.list_index + assert_equal [:NUMBER], @to.list_type + assert_equal [1], @to.list_width + end + + def accept_list_start_ualpha + assert_equal "\e[0m", @to.res.join + assert_equal ['A'], @to.list_index + assert_equal [:UALPHA], @to.list_type + assert_equal [1], @to.list_width + end + + def accept_paragraph + assert_equal "\e[0mhi\n", @to.res.join + end + + def accept_rule + assert_equal "\e[0m#{'-' * 78}\n", @to.res.join + end + + def accept_verbatim # FormatterTestCase doesn't set indent for ToAnsi + assert_equal "\e[0m hi\n world\n\n", @to.res.join + end + + def end_accepting + assert_equal "\e[0mhi", @to.end_accepting + end + + def start_accepting + assert_equal 0, @to.indent + assert_equal %W"\e[0m", @to.res + assert_empty @to.list_index + assert_empty @to.list_type + assert_empty @to.list_width + end + + def test_accept_heading_1 + @to.start_accepting + @to.accept_heading @RM::Heading.new(1, 'Hello') + + assert_equal "\e[0m\e[1;32mHello\e[m\n", @to.end_accepting + end + + def test_accept_heading_2 + @to.start_accepting + @to.accept_heading @RM::Heading.new(2, 'Hello') + + assert_equal "\e[0m\e[4;32mHello\e[m\n", @to.end_accepting + end + + def test_accept_heading_3 + @to.start_accepting + @to.accept_heading @RM::Heading.new(3, 'Hello') + + assert_equal "\e[0m\e[32mHello\e[m\n", @to.end_accepting + end + + def test_accept_heading_4 + @to.start_accepting + @to.accept_heading @RM::Heading.new(4, 'Hello') + + assert_equal "\e[0mHello\n", @to.end_accepting + end + + def test_accept_heading_indent + @to.start_accepting + @to.indent = 3 + @to.accept_heading @RM::Heading.new(1, 'Hello') + + assert_equal "\e[0m \e[1;32mHello\e[m\n", @to.end_accepting + end + + def test_accept_heading_b + @to.start_accepting + @to.indent = 3 + @to.accept_heading @RM::Heading.new(1, '*Hello*') + + assert_equal "\e[0m \e[1;32m\e[1mHello\e[m\e[m\n", @to.end_accepting + end + + def test_accept_list_item_start_note_2 + list = @RM::List.new(:NOTE, + @RM::ListItem.new('teletype', + @RM::Paragraph.new('teletype description'))) + + @to.start_accepting + + list.accept @to + + expected = "\e[0m\e[7mteletype\e[m:\n teletype description\n\n" + + assert_equal expected, @to.end_accepting + end + + def test_accept_paragraph_b + @to.start_accepting + @to.accept_paragraph @RM::Paragraph.new('reg bold words reg') + + expected = "\e[0mreg \e[1mbold words\e[m reg\n" + + assert_equal expected, @to.end_accepting + end + + def test_accept_paragraph_i + @to.start_accepting + @to.accept_paragraph @RM::Paragraph.new('reg italic words reg') + + expected = "\e[0mreg \e[4mitalic words\e[m reg\n" + + assert_equal expected, @to.end_accepting + end + + def test_accept_paragraph_indent + @to.start_accepting + @to.indent = 3 + @to.accept_paragraph @RM::Paragraph.new('words ' * 30) + + expected = <<-EXPECTED +\e[0m words words words words words words words words words words words words + words words words words words words words words words words words words + words words words words words words + EXPECTED + + assert_equal expected, @to.end_accepting + end + + def test_accept_paragraph_plus + @to.start_accepting + @to.accept_paragraph @RM::Paragraph.new('regular +teletype+ regular') + + expected = "\e[0mregular \e[7mteletype\e[m regular\n" + + assert_equal expected, @to.end_accepting + end + + def test_accept_paragraph_star + @to.start_accepting + @to.accept_paragraph @RM::Paragraph.new('regular *bold* regular') + + expected = "\e[0mregular \e[1mbold\e[m regular\n" + + assert_equal expected, @to.end_accepting + end + + def test_accept_paragraph_underscore + @to.start_accepting + @to.accept_paragraph @RM::Paragraph.new('regular _italic_ regular') + + expected = "\e[0mregular \e[4mitalic\e[m regular\n" + + assert_equal expected, @to.end_accepting + end + + def test_accept_paragraph_wrap + @to.start_accepting + @to.accept_paragraph @RM::Paragraph.new('words ' * 30) + + expected = <<-EXPECTED +\e[0mwords words words words words words words words words words words words words +words words words words words words words words words words words words words +words words words words + EXPECTED + + assert_equal expected, @to.end_accepting + end + + def test_accept_rule_indent + @to.start_accepting + @to.indent = 3 + + @to.accept_rule @RM::Rule.new(1) + + assert_equal "\e[0m #{'-' * 75}\n", @to.end_accepting + end + + def test_accept_verbatim_indent + @to.start_accepting + + @to.indent = 2 + + @to.accept_verbatim @RM::Verbatim.new(' ', 'hi', "\n", + ' ', 'world', "\n") + + assert_equal "\e[0m hi\n world\n\n", @to.end_accepting + end + + def test_accept_verbatim_big_indent + @to.start_accepting + + @to.indent = 2 + + @to.accept_verbatim @RM::Verbatim.new(' ', 'hi', "\n", + ' ', 'world', "\n") + + assert_equal "\e[0m hi\n world\n\n", @to.end_accepting + end + + def test_attributes + assert_equal 'Dog', @to.attributes("\\Dog") + end + + 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')))) + + output = doc.accept @to + + expected = <<-EXPECTED +\e[0m* l1 + * l1.1 +* l2 + EXPECTED + + assert_equal expected, output + end + + def test_list_verbatim # HACK overblown + doc = @RM::Document.new( + @RM::List.new(:BULLET, + @RM::ListItem.new(nil, + @RM::Paragraph.new('list', 'stuff'), + @RM::BlankLine.new(), + @RM::Verbatim.new(' ', '*', ' ', 'list', "\n", + ' ', 'with', "\n", + "\n", + ' ', 'second', "\n", + "\n", + ' ', '1.', ' ', 'indented', "\n", + ' ', '2.', ' ', 'numbered', "\n", + "\n", + ' ', 'third', "\n", + "\n", + ' ', '*', ' ', 'second', "\n")))) + + output = doc.accept @to + + expected = <<-EXPECTED +\e[0m* list stuff + + * list + with + + second + + 1. indented + 2. numbered + + third + + * second + + EXPECTED + + assert_equal expected, output + end + +end + diff --git a/test/rdoc/test_rdoc_markup_to_bs.rb b/test/rdoc/test_rdoc_markup_to_bs.rb new file mode 100644 index 0000000000..a82d462ad8 --- /dev/null +++ b/test/rdoc/test_rdoc_markup_to_bs.rb @@ -0,0 +1,443 @@ +require 'rubygems' +require 'rdoc/markup/formatter_test_case' +require 'rdoc/markup/to_bs' +require 'minitest/autorun' + +class TestRDocMarkupToBs < RDoc::Markup::FormatterTestCase + + add_visitor_tests + + def setup + super + + @to = RDoc::Markup::ToBs.new + end + + def accept_blank_line + assert_equal "\n", @to.res.join + end + + def accept_heading + skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars + assert_equal "===== H\bHe\bel\bll\blo\bo\n", @to.res.join + end + + def accept_list_end_bullet + assert_empty @to.list_index + assert_empty @to.list_type + assert_empty @to.list_width + end + + def accept_list_end_label + assert_empty @to.list_index + assert_empty @to.list_type + assert_empty @to.list_width + end + + def accept_list_end_lalpha + assert_empty @to.list_index + assert_empty @to.list_type + assert_empty @to.list_width + end + + def accept_list_end_note + assert_empty @to.list_index + assert_empty @to.list_type + assert_empty @to.list_width + end + + def accept_list_end_number + assert_empty @to.list_index + assert_empty @to.list_type + assert_empty @to.list_width + end + + def accept_list_end_ualpha + assert_empty @to.list_index + assert_empty @to.list_type + assert_empty @to.list_width + end + + def accept_list_item_end_bullet + assert_equal 0, @to.indent, 'indent' + end + + def accept_list_item_end_label + assert_equal 0, @to.indent, 'indent' + end + + def accept_list_item_end_lalpha + assert_equal 0, @to.indent, 'indent' + assert_equal 'b', @to.list_index.last + end + + def accept_list_item_end_note + assert_equal 0, @to.indent, 'indent' + end + + def accept_list_item_end_number + assert_equal 0, @to.indent, 'indent' + assert_equal 2, @to.list_index.last + end + + def accept_list_item_end_ualpha + assert_equal 0, @to.indent, 'indent' + assert_equal 'B', @to.list_index.last + end + + def accept_list_item_start_bullet + assert_equal [''], @to.res + assert_equal '* ', @to.prefix + end + + def accept_list_item_start_label + assert_equal [''], @to.res + assert_equal "cat:\n ", @to.prefix + + assert_equal 2, @to.indent + end + + def accept_list_item_start_lalpha + assert_equal [''], @to.res + assert_equal 'a. ', @to.prefix + + assert_equal 'a', @to.list_index.last + assert_equal 3, @to.indent + end + + def accept_list_item_start_note + assert_equal [''], @to.res + assert_equal "cat:\n ", @to.prefix + + assert_equal 2, @to.indent + end + + def accept_list_item_start_number + assert_equal [''], @to.res + assert_equal '1. ', @to.prefix + + assert_equal 1, @to.list_index.last + assert_equal 3, @to.indent + end + + def accept_list_item_start_ualpha + assert_equal [''], @to.res + assert_equal 'A. ', @to.prefix + + assert_equal 'A', @to.list_index.last + assert_equal 3, @to.indent + end + + def accept_list_start_bullet + assert_equal "", @to.res.join + assert_equal [nil], @to.list_index + assert_equal [:BULLET], @to.list_type + assert_equal [1], @to.list_width + end + + def accept_list_start_label + assert_equal "", @to.res.join + assert_equal [nil], @to.list_index + assert_equal [:LABEL], @to.list_type + assert_equal [2], @to.list_width + end + + def accept_list_start_lalpha + assert_equal "", @to.res.join + assert_equal ['a'], @to.list_index + assert_equal [:LALPHA], @to.list_type + assert_equal [1], @to.list_width + end + + def accept_list_start_note + assert_equal "", @to.res.join + assert_equal [nil], @to.list_index + assert_equal [:NOTE], @to.list_type + assert_equal [2], @to.list_width + end + + def accept_list_start_number + assert_equal "", @to.res.join + assert_equal [1], @to.list_index + assert_equal [:NUMBER], @to.list_type + assert_equal [1], @to.list_width + end + + def accept_list_start_ualpha + assert_equal "", @to.res.join + assert_equal ['A'], @to.list_index + assert_equal [:UALPHA], @to.list_type + assert_equal [1], @to.list_width + end + + def accept_paragraph + assert_equal "hi\n", @to.res.join + end + + def accept_rule + assert_equal "#{'-' * 78}\n", @to.res.join + end + + def accept_verbatim # FormatterTestCase doesn't set indent for ToAnsi + assert_equal " hi\n world\n\n", @to.res.join + end + + def end_accepting + assert_equal "hi", @to.end_accepting + end + + def start_accepting + assert_equal 0, @to.indent + assert_equal [''], @to.res + assert_empty @to.list_index + assert_empty @to.list_type + assert_empty @to.list_width + end + + def test_accept_heading_1 + skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars + @to.start_accepting + @to.accept_heading @RM::Heading.new(1, 'Hello') + + assert_equal "= H\bHe\bel\bll\blo\bo\n", @to.end_accepting + end + + def test_accept_heading_2 + skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars + @to.start_accepting + @to.accept_heading @RM::Heading.new(2, 'Hello') + + assert_equal "== H\bHe\bel\bll\blo\bo\n", @to.end_accepting + end + + def test_accept_heading_3 + skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars + @to.start_accepting + @to.accept_heading @RM::Heading.new(3, 'Hello') + + assert_equal "=== H\bHe\bel\bll\blo\bo\n", @to.end_accepting + end + + def test_accept_heading_4 + skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars + @to.start_accepting + @to.accept_heading @RM::Heading.new(4, 'Hello') + + assert_equal "==== H\bHe\bel\bll\blo\bo\n", @to.end_accepting + end + + def test_accept_heading_indent + skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars + @to.start_accepting + @to.indent = 3 + @to.accept_heading @RM::Heading.new(1, 'Hello') + + assert_equal " = H\bHe\bel\bll\blo\bo\n", @to.end_accepting + end + + def test_accept_heading_b + skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars + @to.start_accepting + @to.indent = 3 + @to.accept_heading @RM::Heading.new(1, '*Hello*') + + assert_equal " = H\bHe\bel\bll\blo\bo\n", @to.end_accepting + end + + def test_accept_heading_suppressed_crossref + skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars + @to.start_accepting + @to.accept_heading @RM::Heading.new(1, '\\Hello') + + assert_equal "= H\bHe\bel\bll\blo\bo\n", @to.end_accepting + end + + def test_accept_list_item_start_note_2 + list = @RM::List.new(:NOTE, + @RM::ListItem.new('teletype', + @RM::Paragraph.new('teletype description'))) + + @to.start_accepting + + list.accept @to + + expected = "teletype:\n teletype description\n\n" + + assert_equal expected, @to.end_accepting + end + + def test_accept_paragraph_b + skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars + @to.start_accepting + @to.accept_paragraph @RM::Paragraph.new('reg bold words reg') + + expected = "reg b\bbo\bol\bld\bd \b w\bwo\bor\brd\bds\bs reg\n" + + assert_equal expected, @to.end_accepting + end + + def test_accept_paragraph_i + skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars + @to.start_accepting + @to.accept_paragraph @RM::Paragraph.new('reg italic words reg') + + expected = "reg _\bi_\bt_\ba_\bl_\bi_\bc_\b _\bw_\bo_\br_\bd_\bs reg\n" + + assert_equal expected, @to.end_accepting + end + + def test_accept_paragraph_indent + @to.start_accepting + @to.indent = 3 + @to.accept_paragraph @RM::Paragraph.new('words ' * 30) + + expected = <<-EXPECTED + words words words words words words words words words words words words + words words words words words words words words words words words words + words words words words words words + EXPECTED + + assert_equal expected, @to.end_accepting + end + + def test_accept_paragraph_plus + @to.start_accepting + @to.accept_paragraph @RM::Paragraph.new('regular +teletype+ regular') + + expected = "regular teletype regular\n" + + assert_equal expected, @to.end_accepting + end + + def test_accept_paragraph_star + skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars + @to.start_accepting + @to.accept_paragraph @RM::Paragraph.new('regular *bold* regular') + + expected = "regular b\bbo\bol\bld\bd regular\n" + + assert_equal expected, @to.end_accepting + end + + def test_accept_paragraph_underscore + skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars + @to.start_accepting + @to.accept_paragraph @RM::Paragraph.new('regular _italic_ regular') + + expected = "regular _\bi_\bt_\ba_\bl_\bi_\bc regular\n" + + assert_equal expected, @to.end_accepting + end + + def test_accept_paragraph_wrap + @to.start_accepting + @to.accept_paragraph @RM::Paragraph.new('words ' * 30) + + expected = <<-EXPECTED +words words words words words words words words words words words words words +words words words words words words words words words words words words words +words words words words + EXPECTED + + assert_equal expected, @to.end_accepting + end + + def test_accept_rule_indent + @to.start_accepting + @to.indent = 3 + + @to.accept_rule @RM::Rule.new(1) + + assert_equal " #{'-' * 75}\n", @to.end_accepting + end + + def test_accept_verbatim_indent + @to.start_accepting + + @to.indent = 2 + + @to.accept_verbatim @RM::Verbatim.new(' ', 'hi', "\n", + ' ', 'world', "\n") + + assert_equal " hi\n world\n\n", @to.end_accepting + end + + def test_accept_verbatim_big_indent + @to.start_accepting + + @to.indent = 2 + + @to.accept_verbatim @RM::Verbatim.new(' ', 'hi', "\n", + ' ', 'world', "\n") + + assert_equal " hi\n world\n\n", @to.end_accepting + end + + def test_attributes + assert_equal 'Dog', @to.attributes("\\Dog") + end + + 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')))) + + output = doc.accept @to + + expected = <<-EXPECTED +* l1 + * l1.1 +* l2 + EXPECTED + + assert_equal expected, output + end + + def test_list_verbatim # HACK overblown + doc = @RM::Document.new( + @RM::List.new(:BULLET, + @RM::ListItem.new(nil, + @RM::Paragraph.new('list', 'stuff'), + @RM::BlankLine.new(), + @RM::Verbatim.new(' ', '*', ' ', 'list', "\n", + ' ', 'with', "\n", + "\n", + ' ', 'second', "\n", + "\n", + ' ', '1.', ' ', 'indented', "\n", + ' ', '2.', ' ', 'numbered', "\n", + "\n", + ' ', 'third', "\n", + "\n", + ' ', '*', ' ', 'second', "\n")))) + + output = doc.accept @to + + expected = <<-EXPECTED +* list stuff + + * list + with + + second + + 1. indented + 2. numbered + + third + + * second + + EXPECTED + + assert_equal expected, output + end + +end + diff --git a/test/rdoc/test_rdoc_markup_to_html.rb b/test/rdoc/test_rdoc_markup_to_html.rb index b611b768a3..29cef00a0c 100644 --- a/test/rdoc/test_rdoc_markup_to_html.rb +++ b/test/rdoc/test_rdoc_markup_to_html.rb @@ -1,18 +1,220 @@ require 'rubygems' -require 'minitest/unit' -require 'rdoc/markup' +require 'rdoc/markup/formatter_test_case' require 'rdoc/markup/to_html' +require 'minitest/autorun' -class TestRDocMarkupToHtml < MiniTest::Unit::TestCase +class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase + + add_visitor_tests def setup - @am = RDoc::Markup::AttributeManager.new - @th = RDoc::Markup::ToHtml.new + super + + @to = RDoc::Markup::ToHtml.new + end + + def test_class_gen_relative_url + def gen(from, to) + RDoc::Markup::ToHtml.gen_relative_url from, to + end + + assert_equal 'a.html', gen('a.html', 'a.html') + assert_equal 'b.html', gen('a.html', 'b.html') + + assert_equal 'd.html', gen('a/c.html', 'a/d.html') + assert_equal '../a.html', gen('a/c.html', 'a.html') + assert_equal 'a/c.html', gen('a.html', 'a/c.html') + end + + def accept_blank_line + assert_empty @to.res.join + end + + def accept_heading + assert_equal "
Hello
\n", @to.res.join + end + + def accept_list_end_bullet + assert_equal [], @to.list + assert_equal [], @to.in_list_entry + + assert_equal "\n", @to.res.join + end + + def accept_list_end_label + assert_equal [], @to.list + assert_equal [], @to.in_list_entry + + assert_equal "
\n
\n", @to.res.join + end + + def accept_list_end_lalpha + assert_equal [], @to.list + assert_equal [], @to.in_list_entry + + assert_equal "
    \n
\n", @to.res.join + end + + def accept_list_end_number + assert_equal [], @to.list + assert_equal [], @to.in_list_entry + + assert_equal "
    \n
\n", @to.res.join + end + + def accept_list_end_note + assert_equal [], @to.list + assert_equal [], @to.in_list_entry + + assert_equal "\n
\n", @to.res.join + end + + def accept_list_end_ualpha + assert_equal [], @to.list + assert_equal [], @to.in_list_entry + + assert_equal "
    \n
\n", @to.res.join + end + + def accept_list_item_end_bullet + assert_equal %w[], @to.in_list_entry + end + + def accept_list_item_end_label + assert_equal %w[], @to.in_list_entry + end + + def accept_list_item_end_lalpha + assert_equal %w[], @to.in_list_entry + end + + def accept_list_item_end_note + assert_equal %w[], @to.in_list_entry + end + + def accept_list_item_end_number + assert_equal %w[], @to.in_list_entry + end + + def accept_list_item_end_ualpha + assert_equal %w[], @to.in_list_entry + end + + def accept_list_item_start_bullet + assert_equal "