summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/rdoc/empty.dat0
-rw-r--r--test/rdoc/hidden.zip.txt1
-rw-r--r--test/rdoc/rdoc_markup_to_html_crossref_reference.rb31
-rw-r--r--test/rdoc/test.ja.rdoc8
-rw-r--r--test/rdoc/test.ja.txt8
-rw-r--r--test/rdoc/test.txt1
-rw-r--r--test/rdoc/test_attribute_manager.rb25
-rw-r--r--test/rdoc/test_rdoc_any_method.rb33
-rw-r--r--test/rdoc/test_rdoc_attr.rb40
-rw-r--r--test/rdoc/test_rdoc_class_module.rb100
-rw-r--r--test/rdoc/test_rdoc_code_object.rb96
-rw-r--r--test/rdoc/test_rdoc_constant.rb15
-rw-r--r--test/rdoc/test_rdoc_context.rb291
-rw-r--r--test/rdoc/test_rdoc_generator_ri.rb56
-rw-r--r--test/rdoc/test_rdoc_include.rb17
-rw-r--r--test/rdoc/test_rdoc_info_formatting.rb179
-rw-r--r--test/rdoc/test_rdoc_info_sections.rb139
-rw-r--r--test/rdoc/test_rdoc_markup.rb620
-rw-r--r--test/rdoc/test_rdoc_markup_attribute_manager.rb40
-rw-r--r--test/rdoc/test_rdoc_markup_document.rb51
-rw-r--r--test/rdoc/test_rdoc_markup_paragraph.rb27
-rw-r--r--test/rdoc/test_rdoc_markup_parser.rb1327
-rw-r--r--test/rdoc/test_rdoc_markup_to_ansi.rb426
-rw-r--r--test/rdoc/test_rdoc_markup_to_bs.rb443
-rw-r--r--test/rdoc/test_rdoc_markup_to_html.rb225
-rw-r--r--test/rdoc/test_rdoc_markup_to_html_crossref.rb408
-rw-r--r--test/rdoc/test_rdoc_markup_to_rdoc.rb426
-rw-r--r--test/rdoc/test_rdoc_normal_class.rb17
-rw-r--r--test/rdoc/test_rdoc_normal_module.rb26
-rw-r--r--test/rdoc/test_rdoc_options.rb41
-rw-r--r--test/rdoc/test_rdoc_parser.rb79
-rw-r--r--test/rdoc/test_rdoc_parser_c.rb253
-rw-r--r--test/rdoc/test_rdoc_parser_perl.rb5
-rw-r--r--test/rdoc/test_rdoc_parser_ruby.rb672
-rw-r--r--test/rdoc/test_rdoc_parser_simple.rb48
-rw-r--r--test/rdoc/test_rdoc_rdoc.rb66
-rw-r--r--test/rdoc/test_rdoc_require.rb25
-rw-r--r--test/rdoc/test_rdoc_ri_attribute_formatter.rb44
-rw-r--r--test/rdoc/test_rdoc_ri_default_display.rb301
-rw-r--r--test/rdoc/test_rdoc_ri_driver.rb790
-rw-r--r--test/rdoc/test_rdoc_ri_formatter.rb320
-rw-r--r--test/rdoc/test_rdoc_ri_overstrike_formatter.rb71
-rw-r--r--test/rdoc/test_rdoc_ri_paths.rb43
-rw-r--r--test/rdoc/test_rdoc_ri_store.rb309
-rw-r--r--test/rdoc/test_rdoc_task.rb64
-rw-r--r--test/rdoc/test_rdoc_text.rb157
-rw-r--r--test/rdoc/test_rdoc_top_level.rb111
-rw-r--r--test/rdoc/xref_data.rb54
-rw-r--r--test/rdoc/xref_test_case.rb53
49 files changed, 6423 insertions, 2159 deletions
diff --git a/test/rdoc/empty.dat b/test/rdoc/empty.dat
deleted file mode 100644
index e69de29bb2..0000000000
--- a/test/rdoc/empty.dat
+++ /dev/null
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("\<b\>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 <b>bold me</b> 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 <em>italicize me</em> becomes @emph{italicized}
- def test_italics
- assert_match(/@emph\{italics\}/)
- assert_match(/@emph\{italicize me\}/)
- end
-
- # And that typewriter +text+ and <tt>typewriter me</tt> 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 <a href="ftp://ftp.gnu.org/gnu">GNU ftp site</a>
- # 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 <b>dog</b>'], @am.flow('cat \<b>dog</b>')
+ 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 <tt>dog</Tt>"], @am.flow("cat \\<tt>dog</Tt>"))
+ assert_equal(["cat <tt>dog</Tt>"],
+ @am.flow("cat \\<tt>dog</Tt>"))
assert_equal(["cat ", @em_on, "and", @em_off, " <B>dog</b>"],
@am.flow("cat <i>and</i> \\<B>dog</b>"))
- assert_equal(["*word* or <b>text</b>"], @am.flow("\\*word* or \\<b>text</b>"))
+ assert_equal(["*word* or <b>text</b>"],
+ @am.flow("\\*word* or \\<b>text</b>"))
assert_equal(["_cat_", @em_on, "dog", @em_off],
@am.flow("\\_cat_<i>dog</i>"))
@@ -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('<tt>"\n"</tt>')
+ 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('<tt>teletype</tt>',
+ @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 <b>bold words</b> 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 <em>italic words</em> 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('<tt>teletype</tt>',
+ @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 <b>bold words</b> 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 <em>italic words</em> 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 "<h5>Hello</h5>\n", @to.res.join
+ end
+
+ def accept_list_end_bullet
+ assert_equal [], @to.list
+ assert_equal [], @to.in_list_entry
+
+ assert_equal "<ul>\n</ul>\n", @to.res.join
+ end
+
+ def accept_list_end_label
+ assert_equal [], @to.list
+ assert_equal [], @to.in_list_entry
+
+ assert_equal "<dl>\n</dl>\n", @to.res.join
+ end
+
+ def accept_list_end_lalpha
+ assert_equal [], @to.list
+ assert_equal [], @to.in_list_entry
+
+ assert_equal "<ol style=\"display: lower-alpha\">\n</ol>\n", @to.res.join
+ end
+
+ def accept_list_end_number
+ assert_equal [], @to.list
+ assert_equal [], @to.in_list_entry
+
+ assert_equal "<ol>\n</ol>\n", @to.res.join
+ end
+
+ def accept_list_end_note
+ assert_equal [], @to.list
+ assert_equal [], @to.in_list_entry
+
+ assert_equal "<table>\n</table>\n", @to.res.join
+ end
+
+ def accept_list_end_ualpha
+ assert_equal [], @to.list
+ assert_equal [], @to.in_list_entry
+
+ assert_equal "<ol style=\"display: upper-alpha\">\n</ol>\n", @to.res.join
+ end
+
+ def accept_list_item_end_bullet
+ assert_equal %w[</li>], @to.in_list_entry
+ end
+
+ def accept_list_item_end_label
+ assert_equal %w[</dd>], @to.in_list_entry
+ end
+
+ def accept_list_item_end_lalpha
+ assert_equal %w[</li>], @to.in_list_entry
+ end
+
+ def accept_list_item_end_note
+ assert_equal %w[</td></tr>], @to.in_list_entry
+ end
+
+ def accept_list_item_end_number
+ assert_equal %w[</li>], @to.in_list_entry
+ end
+
+ def accept_list_item_end_ualpha
+ assert_equal %w[</li>], @to.in_list_entry
+ end
+
+ def accept_list_item_start_bullet
+ assert_equal "<ul>\n<li>", @to.res.join
+ end
+
+ def accept_list_item_start_label
+ assert_equal "<dl>\n<dt>cat</dt><dd>", @to.res.join
+ end
+
+ def accept_list_item_start_lalpha
+ assert_equal "<ol style=\"display: lower-alpha\">\n<li>", @to.res.join
+ end
+
+ def accept_list_item_start_note
+ assert_equal "<table>\n<tr><td valign=\"top\">cat</td><td>", @to.res.join
+ end
+
+ def accept_list_item_start_number
+ assert_equal "<ol>\n<li>", @to.res.join
+ end
+
+ def accept_list_item_start_ualpha
+ assert_equal "<ol style=\"display: upper-alpha\">\n<li>", @to.res.join
+ end
+
+ def accept_list_start_bullet
+ assert_equal [:BULLET], @to.list
+ assert_equal [false], @to.in_list_entry
+
+ assert_equal "<ul>\n", @to.res.join
+ end
+
+ def accept_list_start_label
+ assert_equal [:LABEL], @to.list
+ assert_equal [false], @to.in_list_entry
+
+ assert_equal "<dl>\n", @to.res.join
+ end
+
+ def accept_list_start_lalpha
+ assert_equal [:LALPHA], @to.list
+ assert_equal [false], @to.in_list_entry
+
+ assert_equal "<ol style=\"display: lower-alpha\">\n", @to.res.join
+ end
+
+ def accept_list_start_note
+ assert_equal [:NOTE], @to.list
+ assert_equal [false], @to.in_list_entry
+
+ assert_equal "<table>\n", @to.res.join
+ end
+
+ def accept_list_start_number
+ assert_equal [:NUMBER], @to.list
+ assert_equal [false], @to.in_list_entry
+
+ assert_equal "<ol>\n", @to.res.join
+ end
+
+ def accept_list_start_ualpha
+ assert_equal [:UALPHA], @to.list
+ assert_equal [false], @to.in_list_entry
+
+ assert_equal "<ol style=\"display: upper-alpha\">\n", @to.res.join
+ end
+
+ def accept_paragraph
+ assert_equal "<p>\nhi\n</p>\n", @to.res.join
+ end
+
+ def accept_rule
+ assert_equal '<hr style="height: 4px"></hr>', @to.res.join
+ end
+
+ def accept_verbatim
+ assert_equal "<pre>\n hi\n world\n</pre>\n", @to.res.join
+ end
+
+ def end_accepting
+ assert_equal 'hi', @to.end_accepting
+ end
+
+ def start_accepting
+ assert_equal [], @to.res
+ assert_equal [], @to.in_list_entry
+ assert_equal [], @to.list
+ end
+
+ def test_list_verbatim
+ str = "* one\n verb1\n verb2\n* two\n"
+
+ expected = <<-EXPECTED
+<ul>
+<li><p>
+one
+</p>
+<pre>
+ verb1
+ verb2
+</pre>
+</li>
+<li><p>
+two
+</p>
+</li>
+</ul>
+ EXPECTED
+
+ assert_equal expected, @m.convert(str, @to)
end
def test_tt_formatting
assert_equal "<p>\n<tt>--</tt> &#8212; <tt>cats'</tt> cats&#8217;\n</p>\n",
util_format("<tt>--</tt> -- <tt>cats'</tt> cats'")
+
assert_equal "<p>\n<b>&#8212;</b>\n</p>\n", util_format("<b>--</b>")
end
@@ -28,18 +230,17 @@ class TestRDocMarkupToHtml < MiniTest::Unit::TestCase
assert_equal "<p>\ncat&#8217;s-\n</p>\n", util_format("cat\'s-")
end
- def util_fragment(text)
- RDoc::Markup::Fragment.new 0, nil, nil, text
+ def util_paragraph(text)
+ RDoc::Markup::Paragraph.new text
end
def util_format(text)
- fragment = util_fragment text
+ paragraph = util_paragraph text
- @th.start_accepting
- @th.accept_paragraph @am, fragment
- @th.end_accepting
+ @to.start_accepting
+ @to.accept_paragraph paragraph
+ @to.end_accepting
end
end
-MiniTest::Unit.autorun
diff --git a/test/rdoc/test_rdoc_markup_to_html_crossref.rb b/test/rdoc/test_rdoc_markup_to_html_crossref.rb
index f3a64f203b..a0c84666db 100644
--- a/test/rdoc/test_rdoc_markup_to_html_crossref.rb
+++ b/test/rdoc/test_rdoc_markup_to_html_crossref.rb
@@ -1,299 +1,159 @@
require 'rubygems'
-require 'minitest/unit'
-require 'rdoc/generator'
-require 'rdoc/stats'
+require 'minitest/autorun'
+require 'rdoc/rdoc'
require 'rdoc/code_objects'
require 'rdoc/markup/to_html_crossref'
-require 'rdoc/parser/ruby'
-
-require 'pathname'
-
-class TestRDocMarkupToHtmlCrossref < MiniTest::Unit::TestCase
-
- #
- # This method parses a source file and returns a Hash mapping
- # class names (Strings) to RDoc::Generator::Class instances
- # (classes), which can be used to create RDoc::Markup::ToHtmlCrossref
- # instances. The unit tests only test against classes starting with
- # Ref_, so this method only includes such classes in the Hash.
- #
- def create_class_hash
- # The relative gem would help here...
- # @source_file_name must be cleaned because rdoc does not deal
- # well with paths containing "." or "..".
- curr_file = Pathname.new(__FILE__)
- @source_file_name = curr_file.dirname + "rdoc_markup_to_html_crossref_reference.rb"
- @source_file_name = @source_file_name.cleanpath.to_s
-
- RDoc::TopLevel.reset
-
- # Reset RDoc::Generator::Method so that the method sequence number starts
- # at 1, making the method sequence numbers for the methods in the Ref_
- # predicable.
- RDoc::Generator::Method.reset
- top_level = RDoc::TopLevel.new @source_file_name
-
- options = RDoc::Options.new
- options.quiet = true
-
- # If this is false, then RDoc::Generator::Method will attempt to create
- # an HTML file containing the method source code when being instantiated,
- # which does not work in the context of this unit test.
- #
- # RDoc::Generator::Method needs to be refactored so that this does *not*
- # happen as part of instantiation.
- options.inline_source = true
-
- stats = RDoc::Stats.new 0
-
- parser = RDoc::Parser::Ruby.new(top_level,
- @source_file_name,
- IO.read(@source_file_name),
- options,
- stats)
- top_levels = []
- top_levels.push(parser.scan())
-
- files, classes = RDoc::Generator::Context.build_indices(top_levels, options)
-
- class_hash = {}
- classes.each do |klass|
- if(klass.name.include?("Ref_"))
- class_hash[klass.name] = klass
- end
- end
-
- return class_hash
+require File.expand_path '../xref_test_case', __FILE__
+
+class TestRDocMarkupToHtmlCrossref < XrefTestCase
+
+ def setup
+ super
+
+ @xref = RDoc::Markup::ToHtmlCrossref.new 'index.html', @c1, true
+ end
+
+ def assert_ref(path, ref)
+ assert_equal "<p>\n<a href=\"#{path}\">#{ref}</a>\n</p>\n",
+ @xref.convert(ref)
end
- #
- # This method uses xref to cross-reference String reference and
- # asserts that xref.convert(reference) is equal
- # to String expected_result.
- #
- def verify_convert(xref, reference, expected_result)
- # Everything converted in the tests will be within paragraph markup, so
- # add paragraph markup to the expected result.
- actual_expected_result = "<p>\n#{expected_result}\n</p>\n"
-
- result = xref.convert(reference)
-
- # RDoc::Markup::ToHtml word-wraps lines. It is tricky to predict where
- # a line will be wrapped except that it will happen on a space, so replace
- # all newlines with spaces in order to not have to worry about this.
- actual_expected_result.gsub!(/\n/, " ")
- result.gsub!(/\n/, " ")
-
- begin
- assert_equal actual_expected_result, result
- rescue MiniTest::Assertion => e
- bt = caller(2)
- raise e, [e.message, *bt.grep(/\A#{Regexp.quote(__FILE__)}:/o)].join("\n"), bt
- end
+ def refute_ref(body, ref)
+ assert_equal "<p>\n#{body}\n</p>\n", @xref.convert(ref)
+ end
+
+ def test_handle_special_CROSSREF_C2
+ @xref = RDoc::Markup::ToHtmlCrossref.new 'classes/C2.html', @c2, true
+
+ refute_ref '#m', '#m'
+
+ assert_ref '../C2/C3.html', 'C2::C3'
+ assert_ref '../C2/C3.html#M000002', 'C2::C3#m'
+ assert_ref '../C2/C3/H1.html', 'C3::H1'
+ assert_ref '../C4.html', 'C4'
+
+ # TODO there is a C3::H2 in the top-level namespace and RDoc should follow
+ # constant scoping rules
+ refute_ref 'C3::H2', 'C3::H2'
+ refute_ref 'H1', 'H1'
end
- #
- # This method verifies that xref generates no cross-reference link for
- # String reference.
- #
- def verify_no_crossref(xref, reference)
- if(reference[0, 1] == "\\") # Remove the markup suppression character
- expected_result = reference[1, reference.length() - 1]
- else
- expected_result = reference
- end
-
- verify_convert(xref, reference, expected_result)
+ def test_handle_special_CROSSREF_C2_C3
+ @xref = RDoc::Markup::ToHtmlCrossref.new 'classes/C2/C3.html', @c2_c3, true
+
+ assert_ref '../../C2/C3.html#M000002', '#m'
+
+ assert_ref '../../C2/C3.html', 'C3'
+ assert_ref '../../C2/C3.html#M000002', 'C3#m'
+
+ assert_ref '../../C2/C3/H1.html', 'H1'
+ assert_ref '../../C2/C3/H1.html', 'C3::H1'
+
+ assert_ref '../../C4.html', 'C4'
+
+ refute_ref 'C3::H2', 'C3::H2'
+ end
+
+ def test_handle_special_CROSSREF_C3
+ @xref = RDoc::Markup::ToHtmlCrossref.new 'classes/C3.html', @c3, true
+
+ assert_ref '../C3.html', 'C3'
+
+ refute_ref '#m', '#m'
+ refute_ref 'C3#m', 'C3#m'
+
+ assert_ref '../C3/H1.html', 'H1'
+
+ assert_ref '../C3/H1.html', 'C3::H1'
+ assert_ref '../C3/H2.html', 'C3::H2'
+
+ assert_ref '../C4.html', 'C4'
end
- #
- # This method verifies that xref generates a cross-reference link to
- # class_name (String) for String reference.
- #
- def verify_class_crossref(xref, reference, class_name)
- class_file_name = class_name.gsub(/::/, "/")
+ def test_handle_special_CROSSREF_C4
+ @xref = RDoc::Markup::ToHtmlCrossref.new 'classes/C4.html', @c4, true
+
+ # C4 ref inside a C4 containing a C4 should resolve to the contained class
+ assert_ref '../C4/C4.html', 'C4'
+ end
- result = "<a href=\"../classes/#{class_file_name}.html\">#{reference}</a>"
+ def test_handle_special_CROSSREF_C4_C4
+ @xref = RDoc::Markup::ToHtmlCrossref.new 'classes/C4/C4.html', @c4_c4, true
- verify_convert xref, reference, result
+ # A C4 reference inside a C4 class contained within a C4 class should
+ # resolve to the inner C4 class.
+ assert_ref '../../C4/C4.html', 'C4'
end
- #
- # This method verifies that xref generates a cross-reference link to method
- # method_seq (String, e.g, "M000001") in class_name (String) for
- # String reference.
- #
- def verify_method_crossref(xref, reference, class_name, method_seq)
- class_file_name = class_name.gsub(/::/, "/")
+ def test_handle_special_CROSSREF_class
+ assert_ref 'C1.html', 'C1'
+ refute_ref 'H1', 'H1'
- result = "<a href=\"../classes/#{class_file_name}.html##{method_seq}\">#{reference}</a>"
+ assert_ref 'C2.html', 'C2'
+ assert_ref 'C2/C3.html', 'C2::C3'
+ assert_ref 'C2/C3/H1.html', 'C2::C3::H1'
- verify_convert xref, reference, result
+ assert_ref 'C3.html', '::C3'
+ assert_ref 'C3/H1.html', '::C3::H1'
+
+ assert_ref 'C4/C4.html', 'C4::C4'
+ end
+
+ def test_handle_special_CROSSREF_file
+ assert_ref 'xref_data_rb.html', 'xref_data.rb'
end
- #
- # This method verifies that xref generates a cross-reference link to
- # file_name (String) for String reference.
- #
- def verify_file_crossref(xref, reference, file_name)
- generated_document_path = Pathname.new("../files/#{file_name.gsub(/\./, '_')}.html").cleanpath.to_s
- result = "<a href=\"#{generated_document_path}\">#{reference}</a>"
+ def test_handle_special_CROSSREF_method
+ refute_ref 'm', 'm'
+ assert_ref 'C1.html#M000000', '#m'
+
+ assert_ref 'C1.html#M000000', 'C1#m'
+ assert_ref 'C1.html#M000000', 'C1#m()'
+ assert_ref 'C1.html#M000000', 'C1#m(*)'
+
+ assert_ref 'C1.html#M000000', 'C1.m'
+ assert_ref 'C1.html#M000000', 'C1.m()'
+ assert_ref 'C1.html#M000000', 'C1.m(*)'
- verify_convert xref, reference, result
+ # HACK should this work
+ #assert_ref 'classes/C1.html#M000001', 'C1::m'
+ #assert_ref 'classes/C1.html#M000001', 'C1::m()'
+ #assert_ref 'classes/C1.html#M000001', 'C1::m(*)'
+
+ assert_ref 'C2/C3.html#M000002', 'C2::C3#m'
+
+ assert_ref 'C2/C3.html#M000002', 'C2::C3.m'
+
+ assert_ref 'C2/C3/H1.html#M000003', 'C2::C3::H1#m?'
+
+ assert_ref 'C2/C3.html#M000002', '::C2::C3#m'
+ assert_ref 'C2/C3.html#M000002', '::C2::C3#m()'
+ assert_ref 'C2/C3.html#M000002', '::C2::C3#m(*)'
end
- #
- # This method verifies that several invariant cross-references are
- # (or are not) generated.
- #
- def verify_invariant_crossrefs(xref)
- # bogus does not exist and so no cross-reference should be generated.
- verify_no_crossref xref, "bogus"
- verify_no_crossref xref, "\\bogus"
-
- # Ref_Class1 is in the top-level namespace, and so a cross-reference always
- # should be generated, unless markup is suppressed.
- verify_class_crossref xref, "Ref_Class1", "Ref_Class1"
- verify_no_crossref xref, "\\Ref_Class1"
-
- # Ref_Class2 is in the top-level namespace, and so a cross-reference always
- # should be generated for it and for its nested classes.
- verify_class_crossref xref, "Ref_Class2", "Ref_Class2"
- verify_class_crossref xref, "Ref_Class2::Ref_Class3", "Ref_Class2::Ref_Class3"
- verify_method_crossref xref, "Ref_Class2::Ref_Class3#method", "Ref_Class2::Ref_Class3", "M000001"
- verify_method_crossref xref, "Ref_Class2::Ref_Class3#method()", "Ref_Class2::Ref_Class3", "M000001"
- verify_method_crossref xref, "Ref_Class2::Ref_Class3.method()", "Ref_Class2::Ref_Class3", "M000001"
- verify_method_crossref xref, "Ref_Class2::Ref_Class3.method(*)", "Ref_Class2::Ref_Class3", "M000001"
- verify_class_crossref xref, "Ref_Class2::Ref_Class3::Helper1", "Ref_Class2::Ref_Class3::Helper1"
- verify_method_crossref xref, "Ref_Class2::Ref_Class3::Helper1#method?", "Ref_Class2::Ref_Class3::Helper1", "M000002"
-
- # The hyphen character is not a valid class/method separator character, so
- # rdoc just generates a class cross-reference (perhaps it should not
- # generate anything?).
- result = "<a href=\"../classes/Ref_Class2/Ref_Class3.html\">Ref_Class2::Ref_Class3</a>;method(*)"
- verify_convert xref, "Ref_Class2::Ref_Class3;method(*)", result
-
- # There is one Ref_Class3 nested in Ref_Class2 and one defined in the
- # top-level namespace; regardless, ::Ref_Class3 (Ref_Class3 relative
- # to the top-level namespace) always should generate a link to the
- # top-level Ref_Class3 (unless of course cross-references are suppressed).
- verify_class_crossref xref, "::Ref_Class3", "Ref_Class3"
- verify_no_crossref xref, "\\::Ref_Class3"
- verify_class_crossref xref, "::Ref_Class3::Helper1", "Ref_Class3::Helper1"
- verify_class_crossref xref, "::Ref_Class3::Helper2", "Ref_Class3::Helper2"
-
- #
- # Ref_Class3::Helper1 does not have method method.
- #
- verify_no_crossref xref, "::Ref_Class3::Helper1#method"
- verify_no_crossref xref, "\\::Ref_Class3::Helper1#method"
-
- # References to Ref_Class2 relative to the top-level namespace always should
- # generate links to Ref_Class2.
- verify_method_crossref xref, "::Ref_Class2::Ref_Class3#method", "Ref_Class2::Ref_Class3", "M000001"
- verify_method_crossref xref, "::Ref_Class2::Ref_Class3#method()", "Ref_Class2::Ref_Class3", "M000001"
- verify_method_crossref xref, "::Ref_Class2::Ref_Class3#method(*)", "Ref_Class2::Ref_Class3", "M000001"
- verify_class_crossref xref, "::Ref_Class2::Ref_Class3::Helper1", "Ref_Class2::Ref_Class3::Helper1"
- verify_no_crossref xref, "\\::Ref_Class2::Ref_Class3#method(*)"
-
- # Suppressing cross-references always should suppress the generation of
- # links.
- verify_no_crossref xref, "\\#method"
- verify_no_crossref xref, "\\#method()"
- verify_no_crossref xref, "\\#method(*)"
-
- # Links never should be generated for words solely consisting of lowercase
- # letters, because too many links would get generated by mistake (i.e., the
- # word "new" always would be a link).
- verify_no_crossref xref, "method"
-
- # A link always should be generated for a file name.
- verify_file_crossref xref, @source_file_name, @source_file_name
-
- # References should be generated correctly for a class scoped within
- # a class of the same name.
- verify_class_crossref xref, "Ref_Class4::Ref_Class4", "Ref_Class4::Ref_Class4"
+ def test_handle_special_CROSSREF_no_ref
+ assert_equal '', @xref.convert('')
+
+ refute_ref 'bogus', 'bogus'
+ refute_ref 'bogus', '\bogus'
+ refute_ref '\bogus', '\\\bogus'
+
+ refute_ref '#n', '\#n'
+ refute_ref '#n()', '\#n()'
+ refute_ref '#n(*)', '\#n(*)'
+
+ refute_ref 'C1', '\C1'
+ refute_ref '::C3', '\::C3'
+
+ refute_ref '::C3::H1#n', '::C3::H1#n'
+ refute_ref '::C3::H1#n(*)', '::C3::H1#n(*)'
+ refute_ref '::C3::H1#n', '\::C3::H1#n'
end
- def test_handle_special_CROSSREF_no_underscore
- class_hash = create_class_hash
-
- # Note that we instruct the ToHtmlCrossref instance to show hashes so that
- # an exception won't have to be made for words starting with a '#'.
- # I'm also not convinced that the current behavior of the rdoc code
- # is correct since, without this, it strips the leading # from all
- # words, whether or not they end up as cross-references.
- #
- # After the behavior has been sorted out, this can be changed.
- #
- # Create a variety of RDoc::Markup::ToHtmlCrossref instances, for
- # different classes, and test the cross-references generated by
- # each.
- klass = class_hash["Ref_Class1"]
- xref = RDoc::Markup::ToHtmlCrossref.new 'from_path', klass, true
- verify_invariant_crossrefs xref
- verify_class_crossref xref, "Ref_Class3", "Ref_Class3"
- verify_no_crossref xref, "Ref_Class3#method"
- verify_no_crossref xref, "#method"
- verify_class_crossref xref, "Ref_Class3::Helper1", "Ref_Class3::Helper1"
- verify_class_crossref xref, "Ref_Class3::Helper2", "Ref_Class3::Helper2"
- verify_no_crossref xref, "Helper1"
- verify_class_crossref xref, "Ref_Class4", "Ref_Class4"
-
- klass = class_hash["Ref_Class2"]
- xref = RDoc::Markup::ToHtmlCrossref.new 'from_path', klass, true
- verify_invariant_crossrefs xref
- verify_class_crossref xref, "Ref_Class3", "Ref_Class2::Ref_Class3"
- verify_method_crossref xref, "Ref_Class3#method", "Ref_Class2::Ref_Class3", "M000001"
- verify_no_crossref xref, "#method"
- verify_class_crossref xref, "Ref_Class3::Helper1", "Ref_Class2::Ref_Class3::Helper1"
- verify_class_crossref xref, "Ref_Class4", "Ref_Class4"
-
- # This one possibly is an rdoc bug...
- # Ref_Class2 has a nested Ref_Class3, but
- # Ref_Class2::Ref_Class3::Helper2 does not exist.
- # On the other hand, there is a Ref_Class3::Helper2
- # in the top-level namespace... Should rdoc stop
- # looking if it finds one class match?
- verify_no_crossref xref, "Ref_Class3::Helper2"
- verify_no_crossref xref, "Helper1"
-
- klass = class_hash["Ref_Class2::Ref_Class3"]
- xref = RDoc::Markup::ToHtmlCrossref.new 'from_path', klass, true
- verify_invariant_crossrefs xref
- verify_class_crossref xref, "Ref_Class3", "Ref_Class2::Ref_Class3"
- verify_method_crossref xref, "Ref_Class3#method", "Ref_Class2::Ref_Class3", "M000001"
- verify_method_crossref xref, "#method", "Ref_Class2::Ref_Class3", "M000001"
- verify_class_crossref xref, "Ref_Class3::Helper1", "Ref_Class2::Ref_Class3::Helper1"
- verify_no_crossref xref, "Ref_Class3::Helper2"
- verify_class_crossref xref, "Helper1", "Ref_Class2::Ref_Class3::Helper1"
- verify_class_crossref xref, "Ref_Class4", "Ref_Class4"
-
- klass = class_hash["Ref_Class3"]
- xref = RDoc::Markup::ToHtmlCrossref.new 'from_path', klass, true
- verify_invariant_crossrefs xref
- verify_class_crossref xref, "Ref_Class3", "Ref_Class3"
- verify_no_crossref xref, "Ref_Class3#method"
- verify_no_crossref xref, "#method"
- verify_class_crossref xref, "Ref_Class3::Helper1", "Ref_Class3::Helper1"
- verify_class_crossref xref, "Ref_Class3::Helper2", "Ref_Class3::Helper2"
- verify_class_crossref xref, "Helper1", "Ref_Class3::Helper1"
- verify_class_crossref xref, "Ref_Class4", "Ref_Class4"
-
- klass = class_hash["Ref_Class4"]
- xref = RDoc::Markup::ToHtmlCrossref.new 'from_path', klass, true
- verify_invariant_crossrefs xref
- # A Ref_Class4 reference inside a Ref_Class4 class containing a
- # Ref_Class4 class should resolve to the contained class.
- verify_class_crossref xref, "Ref_Class4", "Ref_Class4::Ref_Class4"
-
- klass = class_hash["Ref_Class4::Ref_Class4"]
- xref = RDoc::Markup::ToHtmlCrossref.new 'from_path', klass, true
- verify_invariant_crossrefs xref
- # A Ref_Class4 reference inside a Ref_Class4 class contained within
- # a Ref_Class4 class should resolve to the inner Ref_Class4 class.
- verify_class_crossref xref, "Ref_Class4", "Ref_Class4::Ref_Class4"
+ def test_handle_special_CROSSREF_special
+ assert_equal "<p>\n<a href=\"C2/C3.html\">C2::C3</a>;method(*)\n</p>\n",
+ @xref.convert('C2::C3;method(*)')
end
+
end
-MiniTest::Unit.autorun
diff --git a/test/rdoc/test_rdoc_markup_to_rdoc.rb b/test/rdoc/test_rdoc_markup_to_rdoc.rb
new file mode 100644
index 0000000000..62137c674d
--- /dev/null
+++ b/test/rdoc/test_rdoc_markup_to_rdoc.rb
@@ -0,0 +1,426 @@
+require 'rubygems'
+require 'rdoc/markup/formatter_test_case'
+require 'rdoc/markup/to_rdoc'
+require 'minitest/autorun'
+
+class TestRDocMarkupToRdoc < RDoc::Markup::FormatterTestCase
+
+ add_visitor_tests
+
+ def setup
+ super
+
+ @to = RDoc::Markup::ToRdoc.new
+ end
+
+ def accept_blank_line
+ assert_equal "\n", @to.res.join
+ end
+
+ def accept_heading
+ assert_equal "===== Hello\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 "\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 "\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 [""], @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
+ @to.start_accepting
+ @to.accept_heading @RM::Heading.new(1, 'Hello')
+
+ assert_equal "= Hello\n", @to.end_accepting
+ end
+
+ def test_accept_heading_2
+ @to.start_accepting
+ @to.accept_heading @RM::Heading.new(2, 'Hello')
+
+ assert_equal "== Hello\n", @to.end_accepting
+ end
+
+ def test_accept_heading_3
+ @to.start_accepting
+ @to.accept_heading @RM::Heading.new(3, 'Hello')
+
+ assert_equal "=== Hello\n", @to.end_accepting
+ end
+
+ def test_accept_heading_4
+ @to.start_accepting
+ @to.accept_heading @RM::Heading.new(4, 'Hello')
+
+ assert_equal "==== Hello\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 " = Hello\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 " = <b>Hello</b>\n", @to.end_accepting
+ end
+
+ def test_accept_list_item_start_note_2
+ list = @RM::List.new(:NOTE,
+ @RM::ListItem.new('<tt>teletype</tt>',
+ @RM::Paragraph.new('teletype description')))
+
+ @to.start_accepting
+
+ list.accept @to
+
+ expected = "<tt>teletype</tt>:\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 <b>bold words</b> reg')
+
+ expected = "reg <b>bold words</b> reg\n"
+
+ assert_equal expected, @to.end_accepting
+ end
+
+ def test_accept_paragraph_i
+ @to.start_accepting
+ @to.accept_paragraph @RM::Paragraph.new('reg <em>italic words</em> reg')
+
+ expected = "reg <em>italic words</em> 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 <tt>teletype</tt> 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 = "regular <b>bold</b> 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 = "regular <em>italic</em> 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_normal_class.rb b/test/rdoc/test_rdoc_normal_class.rb
new file mode 100644
index 0000000000..b7471f654f
--- /dev/null
+++ b/test/rdoc/test_rdoc_normal_class.rb
@@ -0,0 +1,17 @@
+require File.expand_path '../xref_test_case', __FILE__
+
+class TestRDocNormalClass < XrefTestCase
+
+ def test_ancestors_class
+ top_level = RDoc::TopLevel.new 'file.rb'
+ klass = top_level.add_class RDoc::NormalClass, 'Klass'
+ incl = RDoc::Include.new 'Incl', ''
+
+ sub_klass = klass.add_class RDoc::NormalClass, 'SubClass', 'Klass'
+ sub_klass.add_include incl
+
+ assert_equal [incl, klass], sub_klass.ancestors
+ end
+
+end
+
diff --git a/test/rdoc/test_rdoc_normal_module.rb b/test/rdoc/test_rdoc_normal_module.rb
new file mode 100644
index 0000000000..da48d33f55
--- /dev/null
+++ b/test/rdoc/test_rdoc_normal_module.rb
@@ -0,0 +1,26 @@
+require File.expand_path '../xref_test_case', __FILE__
+
+class TestRDocNormalModule < XrefTestCase
+
+ def setup
+ super
+
+ @mod = RDoc::NormalModule.new 'Mod'
+ end
+
+ def test_ancestors_module
+ top_level = RDoc::TopLevel.new 'file.rb'
+ mod = top_level.add_module RDoc::NormalModule, 'Mod'
+ incl = RDoc::Include.new 'Incl', ''
+
+ mod.add_include incl
+
+ assert_equal [incl], mod.ancestors
+ end
+
+ def test_module_eh
+ assert @mod.module?
+ end
+
+end
+
diff --git a/test/rdoc/test_rdoc_options.rb b/test/rdoc/test_rdoc_options.rb
new file mode 100644
index 0000000000..00d2b87b8d
--- /dev/null
+++ b/test/rdoc/test_rdoc_options.rb
@@ -0,0 +1,41 @@
+require 'rubygems'
+require 'minitest/autorun'
+require 'rdoc/options'
+
+class TestRDocOptions < MiniTest::Unit::TestCase
+
+ def setup
+ @options = RDoc::Options.new
+ end
+
+ def test_parse_ignore_invalid
+ out, err = capture_io do
+ @options.parse %w[--ignore-invalid --bogus]
+ end
+
+ refute_match %r%^Usage: %, err
+ assert_match %r%^invalid option: --bogus%, err
+ end
+
+ def test_parse_ignore_invalid_default
+ out, err = capture_io do
+ @options.parse %w[--bogus]
+ end
+
+ refute_match %r%^Usage: %, err
+ assert_match %r%^invalid option: --bogus%, err
+ end
+
+ def test_parse_ignore_invalid_no
+ out, err = capture_io do
+ assert_raises SystemExit do
+ @options.parse %w[--no-ignore-invalid --bogus]
+ end
+ end
+
+ assert_match %r%^Usage: %, err
+ assert_match %r%^invalid option: --bogus%, err
+ end
+
+end
+
diff --git a/test/rdoc/test_rdoc_parser.rb b/test/rdoc/test_rdoc_parser.rb
index 19e859e528..9eab360b24 100644
--- a/test/rdoc/test_rdoc_parser.rb
+++ b/test/rdoc/test_rdoc_parser.rb
@@ -1,25 +1,78 @@
require 'rubygems'
-require 'test/unit'
+require 'minitest/autorun'
require 'rdoc/parser'
require 'rdoc/parser/ruby'
+require 'tmpdir'
-class TestRDocParser < Test::Unit::TestCase
- def test_can_parse
- assert_equal(RDoc::Parser.can_parse(__FILE__), RDoc::Parser::Ruby)
+class TestRDocParser < MiniTest::Unit::TestCase
- readme_file_name = File.join(File.dirname(__FILE__), "..", "README.txt")
+ def setup
+ @RP = RDoc::Parser
+ @binary_dat = File.expand_path '../binary.dat', __FILE__
+ end
+
+ def test_class_binary_eh_erb
+ erb = File.join Dir.tmpdir, "test_rdoc_parser_#{$$}.erb"
+ open erb, 'wb' do |io|
+ io.write 'blah blah <%= stuff %> <% more stuff %>'
+ end
- unless File.exist? readme_file_name then # HACK for tests in trunk :/
- readme_file_name = File.join File.dirname(__FILE__), '..', '..', 'README'
+ assert @RP.binary?(erb)
+
+ erb_rb = File.join Dir.tmpdir, "test_rdoc_parser_#{$$}.erb.rb"
+ open erb_rb, 'wb' do |io|
+ io.write 'blah blah <%= stuff %>'
end
- assert_equal(RDoc::Parser.can_parse(readme_file_name), RDoc::Parser::Simple)
+ refute @RP.binary?(erb_rb)
+ ensure
+ File.unlink erb
+ File.unlink erb_rb if erb_rb
+ end
+
+ def test_class_binary_eh_marshal
+ marshal = File.join Dir.tmpdir, "test_rdoc_parser_#{$$}.marshal"
+ open marshal, 'wb' do |io|
+ io.write Marshal.dump('')
+ io.write 'lots of text ' * 500
+ end
+
+ assert @RP.binary?(marshal)
+ ensure
+ File.unlink marshal
+ end
+
+ def test_class_can_parse
+ assert_equal @RP.can_parse(__FILE__), @RP::Ruby
+
+ readme_file_name = File.expand_path '../test.txt', __FILE__
- binary_file_name = File.join(File.dirname(__FILE__), "binary.dat")
- assert_nil(RDoc::Parser.can_parse(binary_file_name))
- empty_file_name = File.join(File.dirname(__FILE__), "empty.dat")
- assert_not_nil(RDoc::Parser.can_parse(empty_file_name))
+ assert_equal @RP::Simple, @RP.can_parse(readme_file_name)
+
+ assert_nil @RP.can_parse(@binary_dat)
+
+ jtest_file_name = File.expand_path '../test.ja.txt', __FILE__
+ assert_equal @RP::Simple, @RP.can_parse(jtest_file_name)
+
+ jtest_rdoc_file_name = File.expand_path '../test.ja.rdoc', __FILE__
+ assert_equal @RP::Simple, @RP.can_parse(jtest_rdoc_file_name)
+ end
+
+ ##
+ # Selenium hides a .jar file using a .txt extension.
+
+ def test_class_can_parse_zip
+ hidden_zip = File.expand_path '../hidden.zip.txt', __FILE__
+ assert_nil @RP.can_parse(hidden_zip)
end
+
+ def test_class_for_binary
+ rp = @RP.dup
+
+ def rp.can_parse(*args) nil end
+
+ assert_nil @RP.for(nil, @binary_dat, nil, nil, nil)
+ end
+
end
-MiniTest::Unit.autorun
diff --git a/test/rdoc/test_rdoc_parser_c.rb b/test/rdoc/test_rdoc_parser_c.rb
index ebf96594c8..301e042bcc 100644
--- a/test/rdoc/test_rdoc_parser_c.rb
+++ b/test/rdoc/test_rdoc_parser_c.rb
@@ -21,6 +21,9 @@ class TestRDocParserC < MiniTest::Unit::TestCase
@fn = filename
@options = RDoc::Options.new
@stats = RDoc::Stats.new 0
+
+ RDoc::Parser::C.reset
+ RDoc::TopLevel.reset
end
def teardown
@@ -32,11 +35,25 @@ class TestRDocParserC < MiniTest::Unit::TestCase
/* Document-class: Foo
* this is the Foo boot class
*/
+VALUE cFoo = boot_defclass("Foo", rb_cObject);
+ EOF
+
+ klass = util_get_class content, 'cFoo'
+ assert_equal "this is the Foo boot class", klass.comment
+ assert_equal 'Object', klass.superclass
+ end
+
+ def test_do_classes_boot_class_nil
+ content = <<-EOF
+/* Document-class: Foo
+ * this is the Foo boot class
+ */
VALUE cFoo = boot_defclass("Foo", 0);
EOF
klass = util_get_class content, 'cFoo'
- assert_equal " this is the Foo boot class\n ", klass.comment
+ assert_equal "this is the Foo boot class", klass.comment
+ assert_equal nil, klass.superclass
end
def test_do_classes_class
@@ -48,7 +65,7 @@ VALUE cFoo = rb_define_class("Foo", rb_cObject);
EOF
klass = util_get_class content, 'cFoo'
- assert_equal " this is the Foo class\n ", klass.comment
+ assert_equal "this is the Foo class", klass.comment
end
def test_do_classes_class_under
@@ -60,7 +77,7 @@ VALUE cFoo = rb_define_class_under(rb_mKernel, "Foo", rb_cObject);
EOF
klass = util_get_class content, 'cFoo'
- assert_equal " this is the Foo class under Kernel\n ", klass.comment
+ assert_equal "this is the Foo class under Kernel", klass.comment
end
def test_do_classes_module
@@ -72,7 +89,7 @@ VALUE mFoo = rb_define_module("Foo");
EOF
klass = util_get_class content, 'mFoo'
- assert_equal " this is the Foo module\n ", klass.comment
+ assert_equal "this is the Foo module", klass.comment
end
def test_do_classes_module_under
@@ -84,7 +101,7 @@ VALUE mFoo = rb_define_module_under(rb_mKernel, "Foo");
EOF
klass = util_get_class content, 'mFoo'
- assert_equal " this is the Foo module under Kernel\n ", klass.comment
+ assert_equal "this is the Foo module under Kernel", klass.comment
end
def test_do_constants
@@ -100,7 +117,7 @@ void Init_foo(){
/* Huzzah!: What you cheer when you roll a perfect game */
rb_define_const(cFoo, "CHEER", rb_str_new2("Huzzah!"));
- /* TEST\:TEST: Checking to see if escaped semicolon works */
+ /* TEST\:TEST: Checking to see if escaped colon works */
rb_define_const(cFoo, "TEST", rb_str_new2("TEST:TEST"));
/* \\: The file separator on MS Windows */
@@ -137,12 +154,12 @@ void Init_foo(){
}
EOF
- parser = util_parser content
+ @parser = util_parser content
- parser.do_classes
- parser.do_constants
+ @parser.do_classes
+ @parser.do_constants
- klass = parser.classes['cFoo']
+ klass = @parser.classes['cFoo']
assert klass
constants = klass.constants
@@ -150,48 +167,35 @@ void Init_foo(){
constants = constants.map { |c| [c.name, c.value, c.comment] }
- assert_equal ['PERFECT', '300',
- "\n The highest possible score in bowling \n "],
+ assert_equal ['PERFECT', '300', 'The highest possible score in bowling '],
constants.shift
assert_equal ['CHEER', 'Huzzah!',
- "\n What you cheer when you roll a perfect game \n "],
+ 'What you cheer when you roll a perfect game '],
constants.shift
assert_equal ['TEST', 'TEST:TEST',
- "\n Checking to see if escaped semicolon works \n "],
+ 'Checking to see if escaped colon works '],
constants.shift
assert_equal ['MSEPARATOR', '\\',
- "\n The file separator on MS Windows \n "],
+ 'The file separator on MS Windows '],
constants.shift
assert_equal ['SEPARATOR', '/',
- "\n The file separator on Unix \n "],
+ 'The file separator on Unix '],
constants.shift
assert_equal ['STUFF', 'C:\\Program Files\\Stuff',
- "\n A directory on MS Windows \n "],
+ 'A directory on MS Windows '],
constants.shift
assert_equal ['NOSEMI', 'INT2FIX(99)',
- "\n Default definition \n "],
+ 'Default definition '],
constants.shift
- assert_equal ['NOCOMMENT', 'rb_str_new2("No comment")', nil],
+ assert_equal ['NOCOMMENT', 'rb_str_new2("No comment")', ''],
constants.shift
comment = <<-EOF.chomp
-
-
- Multiline comment goes here because this comment spans multiple lines.
- Multiline comment goes here because this comment spans multiple lines.
-
-
- EOF
- assert_equal ['MULTILINE', 'INT2FIX(1)', comment], constants.shift
- assert_equal ['MULTILINE_VALUE', '1', comment], constants.shift
-
- comment = <<-EOF.chomp
-
- Multiline comment goes here because this comment spans multiple lines.
- Multiline comment goes here because this comment spans multiple lines.
-
-
+Multiline comment goes here because this comment spans multiple lines.
+Multiline comment goes here because this comment spans multiple lines.
EOF
+ assert_equal ['MULTILINE', 'INT2FIX(1)', comment], constants.shift
+ assert_equal ['MULTILINE_VALUE', '1', comment], constants.shift
assert_equal ['MULTILINE_NOT_EMPTY', 'INT2FIX(1)', comment], constants.shift
assert constants.empty?, constants.inspect
@@ -210,7 +214,7 @@ Init_Foo(void) {
klass = util_get_class content, 'foo'
- assert_equal " \n a comment for class Foo\n \n", klass.comment
+ assert_equal "a comment for class Foo", klass.comment
end
def test_find_class_comment_define_class
@@ -223,7 +227,7 @@ VALUE foo = rb_define_class("Foo", rb_cObject);
klass = util_get_class content, 'foo'
- assert_equal " \n a comment for class Foo\n ", klass.comment
+ assert_equal "a comment for class Foo", klass.comment
end
def test_find_class_comment_define_class_Init_Foo
@@ -242,7 +246,144 @@ Init_Foo(void) {
klass = util_get_class content, 'foo'
- assert_equal " \n a comment for class Foo on Init\n \n", klass.comment
+ assert_equal "a comment for class Foo on Init", klass.comment
+ end
+
+ def test_find_class_comment_define_class_Init_Foo_no_void
+ content = <<-EOF
+/*
+ * a comment for class Foo on Init
+ */
+void
+Init_Foo() {
+ /*
+ * a comment for class Foo on rb_define_class
+ */
+ VALUE foo = rb_define_class("Foo", rb_cObject);
+}
+ EOF
+
+ klass = util_get_class content, 'foo'
+
+ assert_equal "a comment for class Foo on Init", klass.comment
+ end
+
+ def test_find_class_comment_define_class_bogus_comment
+ content = <<-EOF
+/*
+ * a comment for other_function
+ */
+void
+other_function() {
+}
+
+void
+Init_Foo(void) {
+ VALUE foo = rb_define_class("Foo", rb_cObject);
+}
+ EOF
+
+ klass = util_get_class content, 'foo'
+
+ assert_equal '', klass.comment
+ end
+
+ def test_find_body
+ content = <<-EOF
+/*
+ * a comment for other_function
+ */
+VALUE
+other_function() {
+}
+
+void
+Init_Foo(void) {
+ VALUE foo = rb_define_class("Foo", rb_cObject);
+
+ rb_define_method(foo, "my_method", other_function, 0);
+}
+ EOF
+
+ klass = util_get_class content, 'foo'
+ other_function = klass.method_list.first
+
+ assert_equal 'my_method', other_function.name
+ assert_equal "a comment for other_function",
+ other_function.comment
+ assert_equal '()', other_function.params
+
+ code = other_function.token_stream.first.text
+
+ assert_equal "VALUE\nother_function() ", code
+ end
+
+ def test_find_body_define
+ content = <<-EOF
+/*
+ * a comment for other_function
+ */
+#define other_function rb_other_function
+
+/* */
+VALUE
+rb_other_function() {
+}
+
+void
+Init_Foo(void) {
+ VALUE foo = rb_define_class("Foo", rb_cObject);
+
+ rb_define_method(foo, "my_method", other_function, 0);
+}
+ EOF
+
+ klass = util_get_class content, 'foo'
+ other_function = klass.method_list.first
+
+ assert_equal 'my_method', other_function.name
+ assert_equal "a comment for other_function",
+ other_function.comment
+ assert_equal '()', other_function.params
+
+ code = other_function.token_stream.first.text
+
+ assert_equal "#define other_function rb_other_function", code
+ end
+
+ def test_find_body_document_method
+ content = <<-EOF
+/*
+ * Document-method: bar
+ * Document-method: baz
+ *
+ * a comment for bar
+ */
+VALUE
+bar() {
+}
+
+void
+Init_Foo(void) {
+ VALUE foo = rb_define_class("Foo", rb_cObject);
+
+ rb_define_method(foo, "bar", bar, 0);
+ rb_define_method(foo, "baz", bar, 0);
+}
+ EOF
+
+ klass = util_get_class content, 'foo'
+ assert_equal 2, klass.method_list.length
+
+ methods = klass.method_list.sort
+
+ bar = methods.first
+ assert_equal 'Foo#bar', bar.full_name
+ assert_equal "a comment for bar", bar.comment
+
+ baz = methods.last
+ assert_equal 'Foo#baz', baz.full_name
+ assert_equal "a comment for bar", bar.comment
end
def test_define_method
@@ -269,13 +410,41 @@ Init_IO(void) {
klass = util_get_class content, 'rb_cIO'
read_method = klass.method_list.first
assert_equal "read", read_method.name
- assert_equal " Method Comment! \n", read_method.comment
+ assert_equal "Method Comment! ", read_method.comment
+ end
+
+ def test_define_method_private
+ content = <<-EOF
+/*Method Comment! */
+static VALUE
+rb_io_s_read(argc, argv, io)
+ int argc;
+ VALUE *argv;
+ VALUE io;
+{
+}
+
+void
+Init_IO(void) {
+ /*
+ * a comment for class Foo on rb_define_class
+ */
+ VALUE rb_cIO = rb_define_class("IO", rb_cObject);
+ rb_define_private_method(rb_cIO, "read", rb_io_s_read, -1);
+}
+ EOF
+
+ klass = util_get_class content, 'rb_cIO'
+ read_method = klass.method_list.first
+ assert_equal 'IO#read', read_method.full_name
+ assert_equal :private, read_method.visibility
+ assert_equal "Method Comment! ", read_method.comment
end
def util_get_class(content, name)
- parser = util_parser content
- parser.scan
- parser.classes[name]
+ @parser = util_parser content
+ @parser.scan
+ @parser.classes[name]
end
def util_parser(content)
diff --git a/test/rdoc/test_rdoc_parser_perl.rb b/test/rdoc/test_rdoc_parser_perl.rb
index 165cadaa5d..ce4e7d2b65 100644
--- a/test/rdoc/test_rdoc_parser_perl.rb
+++ b/test/rdoc/test_rdoc_parser_perl.rb
@@ -1,7 +1,7 @@
require 'stringio'
require 'tempfile'
require 'rubygems'
-require 'minitest/unit'
+require 'minitest/autorun'
require 'rdoc/options'
require 'rdoc/parser/perl'
@@ -55,7 +55,7 @@ This just contains plain old documentation
=end
EOF
comment = util_get_comment content
- assert_equal "\nThis just contains plain old documentation\n\n", comment
+ assert_equal 'This just contains plain old documentation', comment
end
# Get the comment of the @top_level when it has processed the input.
@@ -71,4 +71,3 @@ This just contains plain old documentation
end
-MiniTest::Unit.autorun
diff --git a/test/rdoc/test_rdoc_parser_ruby.rb b/test/rdoc/test_rdoc_parser_ruby.rb
index 7fe626c302..118af657e8 100644
--- a/test/rdoc/test_rdoc_parser_ruby.rb
+++ b/test/rdoc/test_rdoc_parser_ruby.rb
@@ -1,7 +1,9 @@
+# coding: utf-8
+
require 'stringio'
require 'tempfile'
require 'rubygems'
-require 'minitest/unit'
+require 'minitest/autorun'
require 'rdoc/options'
require 'rdoc/parser/ruby'
@@ -17,7 +19,7 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
@tempfile2 = Tempfile.new self.class.name
@filename2 = @tempfile2.path
- util_toplevel
+ util_top_level
@options = RDoc::Options.new
@options.quiet = true
@stats = RDoc::Stats.new 0
@@ -28,6 +30,28 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
@tempfile2.close
end
+ def test_look_for_directives_in_attr
+ util_parser ""
+
+ comment = "# :attr: my_attr\n"
+
+ @parser.look_for_directives_in @top_level, comment
+
+ assert_equal "# :attr: my_attr\n", comment
+
+ comment = "# :attr_reader: my_method\n"
+
+ @parser.look_for_directives_in @top_level, comment
+
+ assert_equal "# :attr_reader: my_method\n", comment
+
+ comment = "# :attr_writer: my_method\n"
+
+ @parser.look_for_directives_in @top_level, comment
+
+ assert_equal "# :attr_writer: my_method\n", comment
+ end
+
def test_look_for_directives_in_commented
util_parser ""
@@ -136,6 +160,197 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
assert_equal 'hi', @options.title
end
+ def test_parse_alias
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ util_parser "alias :next= :bar"
+
+ tk = @parser.get_tk
+
+ alas = @parser.parse_alias klass, RDoc::Parser::Ruby::NORMAL, tk, 'comment'
+
+ assert_equal 'bar', alas.old_name
+ assert_equal 'next=', alas.new_name
+ assert_equal klass, alas.parent
+ assert_equal 'comment', alas.comment
+ end
+
+ def test_parse_alias_meta
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ util_parser "alias m.chop m"
+
+ tk = @parser.get_tk
+
+ alas = @parser.parse_alias klass, RDoc::Parser::Ruby::NORMAL, tk, 'comment'
+
+ assert_nil alas
+ end
+
+ def test_parse_attr
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ comment = "##\n# my attr\n"
+
+ util_parser "attr :foo, :bar"
+
+ tk = @parser.get_tk
+
+ @parser.parse_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ assert_equal 1, klass.attributes.length
+
+ foo = klass.attributes.first
+ assert_equal 'foo', foo.name
+ assert_equal 'my attr', foo.comment
+ end
+
+ def test_parse_attr_accessor
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ comment = "##\n# my attr\n"
+
+ util_parser "attr_accessor :foo, :bar"
+
+ tk = @parser.get_tk
+
+ @parser.parse_attr_accessor klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ assert_equal 2, klass.attributes.length
+
+ foo = klass.attributes.first
+ assert_equal 'foo', foo.name
+ assert_equal 'RW', foo.rw
+ assert_equal 'my attr', foo.comment
+
+ bar = klass.attributes.last
+ assert_equal 'bar', bar.name
+ assert_equal 'RW', bar.rw
+ assert_equal 'my attr', bar.comment
+ end
+
+ def test_parse_attr_accessor_writer
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ comment = "##\n# my attr\n"
+
+ util_parser "attr_writer :foo, :bar"
+
+ tk = @parser.get_tk
+
+ @parser.parse_attr_accessor klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ assert_equal 2, klass.attributes.length
+
+ foo = klass.attributes.first
+ assert_equal 'foo', foo.name
+ assert_equal 'W', foo.rw
+ assert_equal "my attr", foo.comment
+
+ bar = klass.attributes.last
+ assert_equal 'bar', bar.name
+ assert_equal 'W', bar.rw
+ assert_equal "my attr", bar.comment
+ end
+
+ def test_parse_meta_attr
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ comment = "##\n# :attr: \n# my method\n"
+
+ util_parser "add_my_method :foo, :bar"
+
+ tk = @parser.get_tk
+
+ @parser.parse_meta_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ assert_equal 2, klass.attributes.length
+ foo = klass.attributes.first
+ assert_equal 'foo', foo.name
+ assert_equal 'RW', foo.rw
+ assert_equal "my method", foo.comment
+ end
+
+ def test_parse_meta_attr_accessor
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ comment = "##\n# :attr_accessor: \n# my method\n"
+
+ util_parser "add_my_method :foo, :bar"
+
+ tk = @parser.get_tk
+
+ @parser.parse_meta_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ assert_equal 2, klass.attributes.length
+ foo = klass.attributes.first
+ assert_equal 'foo', foo.name
+ assert_equal 'RW', foo.rw
+ assert_equal 'my method', foo.comment
+ end
+
+ def test_parse_meta_attr_named
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ comment = "##\n# :attr: foo\n# my method\n"
+
+ util_parser "add_my_method :foo, :bar"
+
+ tk = @parser.get_tk
+
+ @parser.parse_meta_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ assert_equal 1, klass.attributes.length
+ foo = klass.attributes.first
+ assert_equal 'foo', foo.name
+ assert_equal 'RW', foo.rw
+ assert_equal 'my method', foo.comment
+ end
+
+ def test_parse_meta_attr_reader
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ comment = "##\n# :attr_reader: \n# my method\n"
+
+ util_parser "add_my_method :foo, :bar"
+
+ tk = @parser.get_tk
+
+ @parser.parse_meta_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ foo = klass.attributes.first
+ assert_equal 'foo', foo.name
+ assert_equal 'R', foo.rw
+ assert_equal 'my method', foo.comment
+ end
+
+ def test_parse_meta_attr_writer
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ comment = "##\n# :attr_writer: \n# my method\n"
+
+ util_parser "add_my_method :foo, :bar"
+
+ tk = @parser.get_tk
+
+ @parser.parse_meta_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ foo = klass.attributes.first
+ assert_equal 'foo', foo.name
+ assert_equal 'W', foo.rw
+ assert_equal "my method", foo.comment
+ end
+
def test_parse_class
comment = "##\n# my method\n"
@@ -147,7 +362,27 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
foo = @top_level.classes.first
assert_equal 'Foo', foo.full_name
- assert_equal comment, foo.comment
+ assert_equal 'my method', foo.comment
+ end
+
+ def test_parse_class_ghost_method
+ util_parser <<-CLASS
+class Foo
+ ##
+ # :method: blah
+ # my method
+end
+ CLASS
+
+ tk = @parser.get_tk
+
+ @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, ''
+
+ foo = @top_level.classes.first
+ assert_equal 'Foo', foo.full_name
+
+ blah = foo.method_list.first
+ assert_equal 'Foo#blah', blah.full_name
end
def test_parse_class_nested_superclass
@@ -175,15 +410,45 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
foo = @top_level.modules.first
assert_equal 'Foo', foo.full_name
- assert_equal comment, foo.comment
+ assert_equal 'my module', foo.comment
+ end
+
+ def test_parse_class_colon3
+ code = <<-CODE
+class A
+ class ::B
+ end
+end
+ CODE
+
+ util_parser code
+
+ @parser.parse_class @top_level, false, @parser.get_tk, ''
+
+ assert_equal %w[A B], RDoc::TopLevel.classes.map { |c| c.full_name }
+ end
+
+ def test_parse_class_single
+ code = <<-CODE
+class A
+ class << B
+ end
+end
+ CODE
+
+ util_parser code
+
+ @parser.parse_class @top_level, false, @parser.get_tk, ''
+
+ assert_equal %w[A], RDoc::TopLevel.classes.map { |c| c.full_name }
+ assert_equal %w[A::B], RDoc::TopLevel.modules.map { |c| c.full_name }
end
def test_parse_class_mistaken_for_module
-#
-# The code below is not strictly legal Ruby (Foo must have been defined
-# before Foo::Bar is encountered), but RDoc might encounter Foo::Bar before
-# Foo if they live in different files.
-#
+ # The code below is not strictly legal Ruby (Foo must have been defined
+ # before Foo::Bar is encountered), but RDoc might encounter Foo::Bar
+ # before Foo if they live in different files.
+
code = <<-EOF
class Foo::Bar
end
@@ -193,13 +458,15 @@ end
class Foo
end
-EOF
+ EOF
util_parser code
- @parser.scan()
+ @parser.scan
+
+ assert_equal %w[Foo::Baz], RDoc::TopLevel.modules_hash.keys
+ assert_empty @top_level.modules
- assert(@top_level.modules.empty?)
foo = @top_level.classes.first
assert_equal 'Foo', foo.full_name
@@ -211,24 +478,25 @@ EOF
end
def test_parse_class_definition_encountered_after_class_reference
-#
-# The code below is not strictly legal Ruby (Foo must have been defined
-# before Foo.bar is encountered), but RDoc might encounter Foo.bar before
-# Foo if they live in different files.
-#
+ # The code below is not strictly legal Ruby (Foo must have been defined
+ # before Foo.bar is encountered), but RDoc might encounter Foo.bar before
+ # Foo if they live in different files.
+
code = <<-EOF
def Foo.bar
end
class Foo < IO
end
-EOF
+ EOF
util_parser code
- @parser.scan()
+ @parser.scan
- assert(@top_level.modules.empty?)
+ assert_empty RDoc::TopLevel.modules_hash
+ # HACK why does it fail?
+ #assert_empty @top_level.modules
foo = @top_level.classes.first
assert_equal 'Foo', foo.full_name
@@ -257,21 +525,41 @@ EOF
foo = @top_level.modules.first
assert_equal 'Foo', foo.full_name
- assert_equal comment, foo.comment
+ assert_equal 'Weirdly named module', foo.comment
helper = foo.classes.first
assert_equal 'Foo::Helper', helper.full_name
end
- def test_parse_comment
- content = <<-EOF
-class Foo
- ##
- # :method: my_method
- # my method comment
+ def test_parse_comment_attr
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
-end
- EOF
+ comment = "##\n# :attr: foo\n# my attr\n"
+
+ util_parser "\n"
+
+ tk = @parser.get_tk
+
+ @parser.parse_comment klass, tk, comment
+
+ foo = klass.attributes.first
+ assert_equal 'foo', foo.name
+ assert_equal 'RW', foo.rw
+ assert_equal 'my attr', foo.comment
+
+ assert_equal nil, foo.viewer
+ assert_equal true, foo.document_children
+ assert_equal true, foo.document_self
+ assert_equal false, foo.done_documenting
+ assert_equal false, foo.force_documentation
+ assert_equal klass, foo.parent
+ assert_equal :public, foo.visibility
+ assert_equal "\n", foo.text
+ assert_equal klass.current_section, foo.section
+ end
+
+ def test_parse_comment_method
klass = RDoc::NormalClass.new 'Foo'
klass.parent = @top_level
@@ -285,7 +573,7 @@ end
foo = klass.method_list.first
assert_equal 'foo', foo.name
- assert_equal comment, foo.comment
+ assert_equal 'my method', foo.comment
assert_equal [], foo.aliases
assert_equal nil, foo.block_params
@@ -305,14 +593,44 @@ end
assert_equal klass.current_section, foo.section
stream = [
- tk(:COMMENT, 1, 1, nil, "# File #{@top_level.file_absolute_name}, line 1"),
+ tk(:COMMENT, 1, 1, nil, "# File #{@top_level.absolute_name}, line 1"),
RDoc::Parser::Ruby::NEWLINE_TOKEN,
- tk(:SPACE, 1, 1, nil, ''),
+ tk(:SPACE, 1, 1, nil, ''),
]
assert_equal stream, foo.token_stream
end
+ def test_parse_constant_alias
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+ cB = klass.add_class RDoc::NormalClass, 'B'
+
+ util_parser "A = B"
+
+ tk = @parser.get_tk
+
+ @parser.parse_constant klass, tk, ''
+
+ assert_equal cB, klass.find_module_named('A')
+ end
+
+ def test_parse_constant_alias_same_name
+ foo = @top_level.add_class RDoc::NormalClass, 'Foo'
+ top_bar = @top_level.add_class RDoc::NormalClass, 'Bar'
+ bar = foo.add_class RDoc::NormalClass, 'Bar'
+
+ assert RDoc::TopLevel.find_class_or_module('::Bar')
+
+ util_parser "A = ::Bar"
+
+ tk = @parser.get_tk
+
+ @parser.parse_constant foo, tk, ''
+
+ assert_equal top_bar, bar.find_module_named('A')
+ end
+
def test_parse_meta_method
klass = RDoc::NormalClass.new 'Foo'
klass.parent = @top_level
@@ -327,7 +645,7 @@ end
foo = klass.method_list.first
assert_equal 'foo', foo.name
- assert_equal comment, foo.comment
+ assert_equal 'my method', foo.comment
assert_equal [], foo.aliases
assert_equal nil, foo.block_params
@@ -347,7 +665,7 @@ end
assert_equal klass.current_section, foo.section
stream = [
- tk(:COMMENT, 1, 1, nil, "# File #{@top_level.file_absolute_name}, line 1"),
+ tk(:COMMENT, 1, 1, nil, "# File #{@top_level.absolute_name}, line 1"),
RDoc::Parser::Ruby::NEWLINE_TOKEN,
tk(:SPACE, 1, 1, nil, ''),
tk(:IDENTIFIER, 1, 0, 'add_my_method', 'add_my_method'),
@@ -376,7 +694,7 @@ end
foo = klass.method_list.first
assert_equal 'woo_hoo!', foo.name
- assert_equal "##\n# my method\n", foo.comment
+ assert_equal 'my method', foo.comment
end
def test_parse_meta_method_singleton
@@ -394,7 +712,7 @@ end
foo = klass.method_list.first
assert_equal 'foo', foo.name
assert_equal true, foo.singleton, 'singleton method'
- assert_equal "##\n# my method\n", foo.comment
+ assert_equal 'my method', foo.comment
end
def test_parse_meta_method_singleton_name
@@ -412,7 +730,7 @@ end
foo = klass.method_list.first
assert_equal 'woo_hoo!', foo.name
assert_equal true, foo.singleton, 'singleton method'
- assert_equal "##\n# my method\n", foo.comment
+ assert_equal 'my method', foo.comment
end
def test_parse_meta_method_string_name
@@ -427,7 +745,22 @@ end
foo = klass.method_list.first
assert_equal 'foo', foo.name
- assert_equal comment, foo.comment
+ assert_equal 'my method', foo.comment
+ end
+
+ def test_parse_meta_method_unknown
+ klass = RDoc::NormalClass.new 'Foo'
+ comment = "##\n# my method\n"
+
+ util_parser "add_my_method ('foo')"
+
+ tk = @parser.get_tk
+
+ @parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ foo = klass.method_list.first
+ assert_equal 'unknown', foo.name
+ assert_equal 'my method', foo.comment
end
def test_parse_method
@@ -444,7 +777,7 @@ end
foo = klass.method_list.first
assert_equal 'foo', foo.name
- assert_equal comment, foo.comment
+ assert_equal 'my method', foo.comment
assert_equal [], foo.aliases
assert_equal nil, foo.block_params
@@ -464,7 +797,7 @@ end
assert_equal klass.current_section, foo.section
stream = [
- tk(:COMMENT, 1, 1, nil, "# File #{@top_level.file_absolute_name}, line 1"),
+ tk(:COMMENT, 1, 1, nil, "# File #{@top_level.absolute_name}, line 1"),
RDoc::Parser::Ruby::NEWLINE_TOKEN,
tk(:SPACE, 1, 1, nil, ''),
tk(:DEF, 1, 0, 'def', 'def'),
@@ -482,6 +815,184 @@ end
assert_equal stream, foo.token_stream
end
+ def test_parse_method_alias
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ util_parser "def m() alias a b; end"
+
+ tk = @parser.get_tk
+
+ @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
+
+ assert klass.aliases.empty?
+ end
+
+ def test_parse_method_utf8
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ comment = "##\n# my method\n"
+
+ method = "def ω() end"
+
+ assert_equal Encoding::UTF_8, method.encoding if defined? ::Encoding
+
+ util_parser method
+
+ tk = @parser.get_tk
+
+ @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ omega = klass.method_list.first
+ assert_equal "def \317\211", omega.text
+ end
+
+ def test_parse_method_funky
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ comment = "##\n# my method\n"
+
+ util_parser "def (blah).foo() :bar end"
+
+ tk = @parser.get_tk
+
+ @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ assert klass.method_list.empty?
+ end
+
+ def test_parse_method_internal_ivar
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ util_parser "def foo() def @blah.bar() end end"
+
+ tk = @parser.get_tk
+
+ @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
+
+ assert_equal 1, klass.method_list.length
+ end
+
+ def test_parse_method_internal_lvar
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ util_parser "def foo() def blah.bar() end end"
+
+ tk = @parser.get_tk
+
+ @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
+
+ assert_equal 1, klass.method_list.length
+ end
+
+ def test_parse_method_no_parens
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ comment = "##\n# my method\n"
+
+ util_parser "def foo arg1, arg2\nend"
+
+ tk = @parser.get_tk
+
+ @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ foo = klass.method_list.first
+ assert_equal '(arg1, arg2)', foo.params
+ end
+
+ def test_parse_method_parameters_comment
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ comment = "##\n# my method\n"
+
+ util_parser "def foo arg1, arg2 # some useful comment\nend"
+
+ tk = @parser.get_tk
+
+ @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ foo = klass.method_list.first
+ assert_equal '(arg1, arg2)', foo.params
+ end
+
+ def test_parse_method_parameters_comment_continue
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ comment = "##\n# my method\n"
+
+ util_parser "def foo arg1, arg2, # some useful comment\narg3\nend"
+
+ tk = @parser.get_tk
+
+ @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ foo = klass.method_list.first
+ assert_equal '(arg1, arg2, arg3)', foo.params
+ end
+
+ def test_parse_method_toplevel
+ klass = @top_level
+
+ comment = "##\n# my method\n"
+
+ util_parser "def foo arg1, arg2\nend"
+
+ tk = @parser.get_tk
+
+ @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ object = RDoc::TopLevel.find_class_named 'Object'
+
+ foo = object.method_list.first
+ assert_equal 'Object#foo', foo.full_name
+ end
+
+ def test_parse_method_toplevel_class
+ klass = @top_level
+
+ util_parser "def Object.foo arg1, arg2\nend"
+
+ tk = @parser.get_tk
+
+ @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
+
+ object = RDoc::TopLevel.find_class_named 'Object'
+
+ foo = object.method_list.first
+ assert_equal 'Object::foo', foo.full_name
+ end
+
+ def test_parse_statements_class_if
+ comment = "##\n# my method\n"
+
+ util_parser <<-CODE
+module Foo
+ X = if TRUE then
+ ''
+ end
+
+ def blah
+ end
+end
+ CODE
+
+ @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
+
+ foo = @top_level.modules.first
+ assert_equal 'Foo', foo.full_name, 'module Foo'
+
+ methods = foo.method_list
+ assert_equal 1, methods.length
+ assert_equal 'Foo#blah', methods.first.full_name
+ end
+
def test_parse_statements_class_nested
comment = "##\n# my method\n"
@@ -494,7 +1005,7 @@ end
bar = foo.classes.first
assert_equal 'Foo::Bar', bar.full_name, 'class Foo::Bar'
- assert_equal comment, bar.comment
+ assert_equal 'my method', bar.comment
end
def test_parse_statements_identifier_meta_method
@@ -648,20 +1159,6 @@ EOF
assert_equal 'RW', foo.rw
end
- def test_parse_statements_identifier_extra_accessors
- @options.extra_accessors = /^my_accessor$/
-
- content = "class Foo; my_accessor :foo; end"
-
- util_parser content
-
- @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
-
- foo = @top_level.classes.first.attributes.first
- assert_equal 'foo', foo.name
- assert_equal '?', foo.rw
- end
-
def test_parse_statements_identifier_include
content = "class Foo; include Bar; end"
@@ -713,14 +1210,70 @@ EOF
assert_equal 1, @top_level.requires.length
end
+ def test_parse_top_level_statements_alias_method
+ content = <<-CONTENT
+class A
+ alias_method :a, :[] unless c
+end
+
+B = A
+
+class C
+end
+ CONTENT
+
+ util_parser content
+
+ @parser.parse_statements @top_level
+ end
+
+ def test_sanity_integer
+ util_parser '1'
+ assert_equal '1', @parser.get_tk.text
+
+ util_parser '1.0'
+ assert_equal '1.0', @parser.get_tk.text
+ end
+
+ def test_sanity_interpolation
+ last_tk = nil
+ util_parser 'class A; B = "#{c}"; end'
+
+ while tk = @parser.get_tk do last_tk = tk end
+
+ assert_equal "\n", last_tk.text
+ end
+
+ # If you're writing code like this you're doing it wrong
+
+ def x_test_sanity_interpolation_crazy
+ last_tk = nil
+ util_parser '"#{"#{"a")}" if b}"'
+
+ assert_equal RDoc::RubyToken::TkDSTRING, tk.class
+ assert_equal RDoc::RubyToken::TkNL, @parser.get_tk.class
+ end
+
+ def test_sanity_interpolation_format
+ util_parser '"#{stftime("%m-%d")}"'
+
+ while tk = @parser.get_tk do end
+ end
+
+ def test_sanity_symbol_interpolation
+ util_parser ':"#{bar}="'
+
+ while tk = @parser.get_tk do end
+ end
+
def tk(klass, line, char, name, text)
klass = RDoc::RubyToken.const_get "Tk#{klass.to_s.upcase}"
- token = if klass.instance_method(:initialize).arity == 2 then
+ token = if klass.instance_method(:initialize).arity == 3 then
raise ArgumentError, "name not used for #{klass}" unless name.nil?
- klass.new line, char
+ klass.new nil, line, char
else
- klass.new line, char, name
+ klass.new nil, line, char, name
end
token.set_text text
@@ -740,7 +1293,7 @@ EOF
second_file_content, @options, @stats
end
- def util_toplevel
+ def util_top_level
RDoc::TopLevel.reset
@top_level = RDoc::TopLevel.new @filename
@top_level2 = RDoc::TopLevel.new @filename2
@@ -748,4 +1301,3 @@ EOF
end
-MiniTest::Unit.autorun
diff --git a/test/rdoc/test_rdoc_parser_simple.rb b/test/rdoc/test_rdoc_parser_simple.rb
new file mode 100644
index 0000000000..0b35a66c5e
--- /dev/null
+++ b/test/rdoc/test_rdoc_parser_simple.rb
@@ -0,0 +1,48 @@
+require 'tempfile'
+require 'rubygems'
+require 'minitest/autorun'
+require 'rdoc/options'
+require 'rdoc/parser'
+
+class TestRDocParserSimple < MiniTest::Unit::TestCase
+
+ def setup
+ @tempfile = Tempfile.new self.class.name
+ filename = @tempfile.path
+
+ @top_level = RDoc::TopLevel.new filename
+ @fn = filename
+ @options = RDoc::Options.new
+ @stats = RDoc::Stats.new 0
+
+ RDoc::TopLevel.reset
+ end
+
+ def teardown
+ @tempfile.close
+ end
+
+ def test_remove_private_comments
+ parser = util_parser ''
+ text = "foo\n\n--\nbar\n++\n\nbaz\n"
+
+ expected = "foo\n\n\n\nbaz\n"
+
+ assert_equal expected, parser.remove_private_comments(text)
+ end
+
+ def test_remove_private_comments_star
+ parser = util_parser ''
+
+ text = "* foo\n* bar\n"
+ expected = text.dup
+
+ assert_equal expected, parser.remove_private_comments(text)
+ end
+
+ def util_parser(content)
+ RDoc::Parser::Simple.new @top_level, @fn, content, @options, @stats
+ end
+
+end
+
diff --git a/test/rdoc/test_rdoc_rdoc.rb b/test/rdoc/test_rdoc_rdoc.rb
new file mode 100644
index 0000000000..91fbe35f85
--- /dev/null
+++ b/test/rdoc/test_rdoc_rdoc.rb
@@ -0,0 +1,66 @@
+require 'tempfile'
+require 'rubygems'
+require 'minitest/autorun'
+require 'rdoc/rdoc'
+
+class TestRDocRDoc < MiniTest::Unit::TestCase
+
+ def setup
+ @rdoc = RDoc::RDoc.new
+ @tempfile = Tempfile.new 'test_rdoc_rdoc'
+ end
+
+ def teardown
+ @tempfile.close
+ end
+
+ def test_gather_files
+ assert_equal(%w[lib/rdoc.rb],
+ @rdoc.gather_files(%w[lib/rdoc.rb lib/rdoc.rb]))
+ end
+
+ def test_read_file_contents
+ @tempfile.write "hi everybody"
+ @tempfile.flush
+
+ assert_equal "hi everybody", @rdoc.read_file_contents(@tempfile.path)
+ end
+
+ def test_read_file_contents_encoding
+ skip "Encoding not implemented" unless defined? ::Encoding
+
+ @tempfile.write "# coding: utf-8\nhi everybody"
+ @tempfile.flush
+
+ contents = @rdoc.read_file_contents @tempfile.path
+ assert_equal "# coding: utf-8\nhi everybody", contents
+ assert_equal Encoding::UTF_8, contents.encoding
+ end
+
+ def test_read_file_contents_encoding_fancy
+ skip "Encoding not implemented" unless defined? ::Encoding
+
+ @tempfile.write "# -*- coding: utf-8; fill-column: 74 -*-\nhi everybody"
+ @tempfile.flush
+
+ contents = @rdoc.read_file_contents @tempfile.path
+ assert_equal("# -*- coding: utf-8; fill-column: 74 -*-\nhi everybody",
+ contents)
+ assert_equal Encoding::UTF_8, contents.encoding
+ end
+
+ def test_remove_unparsable
+ file_list = %w[
+ blah.class
+ blah.eps
+ blah.erb
+ blah.scpt.txt
+ blah.ttf
+ blah.yml
+ ]
+
+ assert_empty @rdoc.remove_unparseable file_list
+ end
+
+end
+
diff --git a/test/rdoc/test_rdoc_require.rb b/test/rdoc/test_rdoc_require.rb
new file mode 100644
index 0000000000..b7995aff7b
--- /dev/null
+++ b/test/rdoc/test_rdoc_require.rb
@@ -0,0 +1,25 @@
+require File.expand_path '../xref_test_case', __FILE__
+
+class TestRDocRequire < XrefTestCase
+
+ def setup
+ super
+
+ @req = RDoc::Require.new 'foo', 'comment'
+ end
+
+ def test_initialize
+ assert_equal 'foo', @req.name
+
+ req = RDoc::Require.new '"foo"', ''
+ assert_equal 'foo', @req.name
+
+ req = RDoc::Require.new '\'foo\'', ''
+ assert_equal 'foo', @req.name
+
+ req = RDoc::Require.new '|foo|', ''
+ assert_equal 'foo', @req.name, 'for fortran?'
+ end
+
+end
+
diff --git a/test/rdoc/test_rdoc_ri_attribute_formatter.rb b/test/rdoc/test_rdoc_ri_attribute_formatter.rb
deleted file mode 100644
index a86312618b..0000000000
--- a/test/rdoc/test_rdoc_ri_attribute_formatter.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-require 'stringio'
-require 'rubygems'
-require 'minitest/unit'
-require 'rdoc/ri/formatter'
-
-class TestRDocRIAttributeFormatter < MiniTest::Unit::TestCase
-
- def setup
- @output = StringIO.new
- @width = 78
- @indent = ' '
-
- @f = RDoc::RI::AttributeFormatter.new @output, @width, @indent
- end
-
- def test_wrap_empty
- @f.wrap ''
- assert_equal '', @output.string
- end
-
- def test_wrap_long
- @f.wrap 'a ' * (@width / 2)
- assert_equal " a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a \n a \n",
- @output.string
- end
-
- def test_wrap_markup
- @f.wrap 'a <tt>b</tt> c'
- assert_equal " a b c\n", @output.string
- end
-
- def test_wrap_nil
- @f.wrap nil
- assert_equal '', @output.string
- end
-
- def test_wrap_short
- @f.wrap 'a b c'
- assert_equal " a b c\n", @output.string
- end
-
-end
-
-MiniTest::Unit.autorun
diff --git a/test/rdoc/test_rdoc_ri_default_display.rb b/test/rdoc/test_rdoc_ri_default_display.rb
deleted file mode 100644
index 1182b046c3..0000000000
--- a/test/rdoc/test_rdoc_ri_default_display.rb
+++ /dev/null
@@ -1,301 +0,0 @@
-require 'stringio'
-require 'rubygems'
-require 'minitest/unit'
-require 'rdoc/ri/formatter'
-require 'rdoc/ri/display'
-require 'rdoc/ri/driver'
-
-class TestRDocRiDefaultDisplay < MiniTest::Unit::TestCase
-
- def setup
- @output = StringIO.new
- @width = 78
- @indent = ' '
-
- @dd = RDoc::RI::DefaultDisplay.new RDoc::RI::Formatter, @width, true,
- @output
-
- @some_method = h \
- 'aliases' => [{'name' => 'some_method_alias'}],
- 'block_params' => 'block_param',
- 'comment' => [RDoc::Markup::Flow::P.new('some comment')],
- 'full_name' => 'SomeClass#some_method',
- 'is_singleton' => false,
- 'name' => 'some_method',
- 'params' => '(arg1, arg2) {|block_param| ...}',
- 'source_path' => '/nonexistent',
- 'visibility' => 'public'
- end
-
- def test_display_class_info
- klass = h \
- 'attributes' => [
- { 'name' => 'attribute', 'rw' => 'RW',
- 'comment' => [RDoc::Markup::Flow::P.new('attribute comment')] },
- { 'name' => 'attribute_no_comment', 'rw' => 'RW',
- 'comment' => nil },
- ],
- 'class_methods' => [
- { 'name' => 'class_method' },
- ],
- 'class_method_extensions' => [
- { 'name' => 'class_method_extension' },
- ],
- 'comment' => [RDoc::Markup::Flow::P.new('SomeClass comment')],
- 'constants' => [
- { 'name' => 'CONSTANT', 'value' => '"value1"',
- 'comment' => [RDoc::Markup::Flow::P.new('CONSTANT value')] },
- { 'name' => 'CONSTANT_NOCOMMENT', 'value' => '"value2"',
- 'comment' => nil },
- ],
- 'display_name' => 'Class',
- 'full_name' => 'SomeClass',
- 'includes' => [],
- 'instance_methods' => [
- { 'name' => 'instance_method' },
- { 'name' => 'instance_method2' },
- ],
- 'instance_method_extensions' => [
- { 'name' => 'instance_method_extension' },
- ],
- 'superclass' => 'Object'
-
- @dd.display_class_info klass
-
- expected = <<-EOF
----------------------------------------------------- Class: SomeClass < Object
- SomeClass comment
-
-------------------------------------------------------------------------------
-
-
-Constants:
-----------
-
- CONSTANT = "value1"
- CONSTANT value
-
- CONSTANT_NOCOMMENT = "value2"
-
-
-Attributes:
------------
-
- attribute (RW):
- attribute comment
-
- attribute_no_comment (RW)
-
-
-Class methods:
---------------
-
- class_method
-
-
-Class method extensions:
-------------------------
-
- class_method_extension
-
-
-Instance methods:
------------------
-
- instance_method, instance_method2
-
-
-Instance method extensions:
----------------------------
-
- instance_method_extension
- EOF
-
- assert_equal expected, @output.string
- end
-
- def test_display_flow
- flow = [RDoc::Markup::Flow::P.new('flow')]
-
- @dd.display_flow flow
-
- assert_equal " flow\n\n", @output.string
- end
-
- def test_display_flow_empty
- @dd.display_flow []
-
- assert_equal " [no description]\n", @output.string
- end
-
- def test_display_flow_nil
- @dd.display_flow nil
-
- assert_equal " [no description]\n", @output.string
- end
-
- def test_display_method_info
- @dd.display_method_info @some_method
-
- expected = <<-EOF
--------------------------------------------------------- SomeClass#some_method
- some_method(arg1, arg2) {|block_param| ...}
-
- From /nonexistent
-------------------------------------------------------------------------------
- some comment
-
-
- (also known as some_method_alias)
- EOF
-
- assert_equal expected, @output.string
- end
-
- def test_display_method_info_singleton
- method = RDoc::RI::Driver::OpenStructHash.new.update \
- 'aliases' => [],
- 'block_params' => nil,
- 'comment' => nil,
- 'full_name' => 'SomeClass::some_method',
- 'is_singleton' => true,
- 'name' => 'some_method',
- 'params' => '(arg1, arg2)',
- 'visibility' => 'public'
-
- @dd.display_method_info method
-
- expected = <<-EOF
-------------------------------------------------------- SomeClass::some_method
- SomeClass::some_method(arg1, arg2)
-
- From
-------------------------------------------------------------------------------
- [no description]
- EOF
-
- assert_equal expected, @output.string
- end
-
- def test_display_method_list
- methods = [
- RDoc::RI::Driver::OpenStructHash.new.update(
- "aliases" => [],
- "block_params" => nil,
- "comment" => nil,
- "full_name" => "SomeClass#some_method",
- "is_singleton" => false,
- "name" => "some_method",
- "params" => "()",
- "visibility" => "public"
- ),
- RDoc::RI::Driver::OpenStructHash.new.update(
- "aliases" => [],
- "block_params" => nil,
- "comment" => nil,
- "full_name" => "SomeClass#some_other_method",
- "is_singleton" => false,
- "name" => "some_other_method",
- "params" => "()",
- "visibility" => "public"
- ),
- ]
-
- @dd.display_method_list methods
-
- expected = <<-EOF
- More than one method matched your request. You can refine your search by
- asking for information on one of:
-
-SomeClass#some_method []
-SomeClass#some_other_method []
- EOF
-
- assert_equal expected, @output.string
- end
-
- def test_display_params
- @dd.display_params @some_method
-
- expected = <<-EOF
- some_method(arg1, arg2) {|block_param| ...}
-
- From /nonexistent
- EOF
-
- assert_equal expected, @output.string
- end
-
- def test_display_params_multiple
- @some_method['params'] = <<-EOF
-some_method(index)
-some_method(start, length)
- EOF
-
- @dd.display_params @some_method
-
- expected = <<-EOF
- some_method(index)
- some_method(start, length)
-
- From /nonexistent
- EOF
-
- assert_equal expected, @output.string
- end
-
- def test_display_params_singleton
- @some_method['is_singleton'] = true
- @some_method['full_name'] = 'SomeClass::some_method'
-
- @dd.display_params @some_method
-
- expected = <<-EOF
- SomeClass::some_method(arg1, arg2) {|block_param| ...}
-
- From /nonexistent
- EOF
-
- assert_equal expected, @output.string
- end
-
- def test_list_known_classes
- klasses = %w[SomeClass SomeModule]
-
- @dd.list_known_classes klasses
-
- expected = <<-EOF
----------------------------------------------------- Known classes and modules
-
- SomeClass, SomeModule
- EOF
-
- assert_equal expected, @output.string
- end
-
- def test_list_known_classes_empty
- @dd.list_known_classes []
-
- expected = <<-EOF
-No ri data found
-
-If you've installed Ruby yourself, you need to generate documentation using:
-
- make install-doc
-
-from the same place you ran `make` to build ruby.
-
-If you installed Ruby from a packaging system, then you may need to
-install an additional package, or ask the packager to enable ri generation.
- EOF
-
- assert_equal expected, @output.string
- end
-
- def h(hash)
- RDoc::RI::Driver::OpenStructHash.convert hash
- end
-
-end
-
-MiniTest::Unit.autorun
diff --git a/test/rdoc/test_rdoc_ri_driver.rb b/test/rdoc/test_rdoc_ri_driver.rb
index f160492057..0bb0e55b5c 100644
--- a/test/rdoc/test_rdoc_ri_driver.rb
+++ b/test/rdoc/test_rdoc_ri_driver.rb
@@ -1,94 +1,808 @@
+require 'pp'
require 'rubygems'
-require 'minitest/unit'
+require 'minitest/autorun'
require 'tmpdir'
+require 'fileutils'
require 'rdoc/ri/driver'
class TestRDocRIDriver < MiniTest::Unit::TestCase
def setup
+ @RM = RDoc::Markup
+
@tmpdir = File.join Dir.tmpdir, "test_rdoc_ri_driver_#{$$}"
@home_ri = File.join @tmpdir, 'dot_ri'
- @cache_dir = File.join @home_ri, 'cache'
- @class_cache = File.join @cache_dir, 'classes'
FileUtils.mkdir_p @tmpdir
FileUtils.mkdir_p @home_ri
- FileUtils.mkdir_p @cache_dir
- @driver = RDoc::RI::Driver.new(RDoc::RI::Driver.process_args([]))
- @driver.homepath = @home_ri
+ @orig_ri = ENV['RI']
+ @orig_home = ENV['HOME']
+ ENV['HOME'] = @tmpdir
+ ENV.delete 'RI'
+
+ options = RDoc::RI::Driver.process_args []
+ options[:home] = @tmpdir
+ options[:use_stdout] = true
+ options[:formatter] = @RM::ToRdoc
+ @driver = RDoc::RI::Driver.new options
end
def teardown
+ ENV['HOME'] = @orig_home
+ ENV['RI'] = @orig_ri
FileUtils.rm_rf @tmpdir
end
- def test_lookup_method
- def @driver.load_cache_for(klassname)
- { 'Foo#bar' => :found }
+ 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_self_dump
+ util_store
+
+ out, err = capture_io do
+ RDoc::RI::Driver.dump @store.cache_path
end
- assert @driver.lookup_method('Foo#bar', 'Foo')
+ assert_match %r%:class_methods%, out
+ assert_match %r%:modules%, out
+ assert_match %r%:instance_methods%, out
+ assert_match %r%:ancestors%, out
+ end
+
+ def test_add_also_in_empty
+ out = @RM::Document.new
+
+ @driver.add_also_in out, []
+
+ assert_empty out
+ end
+
+ def test_add_also_in
+ util_multi_store
+ @store1.type = :system
+ @store2.type = :home
+
+ out = @RM::Document.new
+
+ @driver.add_also_in out, [@store1, @store2]
+
+ expected = @RM::Document.new(
+ @RM::Rule.new(1),
+ @RM::Paragraph.new('Also found in:'),
+ @RM::Verbatim.new(' ', 'ruby core', "\n",
+ ' ', '~/.ri', "\n"))
+
+ assert_equal expected, out
+ end
+
+ def test_add_class
+ util_multi_store
+
+ out = @RM::Document.new
+
+ @driver.add_class out, 'Bar', [@cBar]
+
+ expected = @RM::Document.new(
+ @RM::Heading.new(1, 'Bar < Foo'),
+ @RM::BlankLine.new)
+
+ assert_equal expected, out
+ end
+
+ def test_add_from
+ util_store
+ @store.type = :system
+
+ out = @RM::Document.new
+
+ @driver.add_from out, @store
+
+ expected = @RM::Document.new @RM::Paragraph.new("(from ruby core)")
+
+ assert_equal expected, out
+ end
+
+ def test_add_includes_empty
+ out = @RM::Document.new
+
+ @driver.add_includes out, []
+
+ assert_empty out
+ end
+
+ def test_add_includes_many
+ util_store
+
+ out = @RM::Document.new
+
+ enum = RDoc::Include.new 'Enumerable', nil
+ @cFoo.add_include enum
+
+ @driver.add_includes out, [[[@cFooInc, enum], @store]]
+
+ expected = @RM::Document.new(
+ @RM::Rule.new(1),
+ @RM::Heading.new(1, "Includes:"),
+ @RM::Paragraph.new("(from #{@store.friendly_path})"),
+ @RM::BlankLine.new,
+ @RM::Paragraph.new("Inc"),
+ @RM::BlankLine.new,
+ @RM::Paragraph.new("Include thingy"),
+ @RM::BlankLine.new,
+ @RM::Verbatim.new(' ', 'Enumerable', "\n"))
+
+ assert_equal expected, out
end
- def test_lookup_method_class_method
- def @driver.load_cache_for(klassname)
- { 'Foo::Bar' => :found }
+ def test_add_includes_many_no_doc
+ util_store
+
+ out = @RM::Document.new
+
+ enum = RDoc::Include.new 'Enumerable', nil
+ @cFoo.add_include enum
+ @cFooInc.instance_variable_set :@comment, ''
+
+ @driver.add_includes out, [[[@cFooInc, enum], @store]]
+
+ expected = @RM::Document.new(
+ @RM::Rule.new(1),
+ @RM::Heading.new(1, "Includes:"),
+ @RM::Paragraph.new("(from #{@store.friendly_path})"),
+ @RM::Verbatim.new(' ', 'Inc', "\n",
+ ' ', 'Enumerable', "\n"))
+
+ assert_equal expected, out
+ end
+
+ def test_add_includes_one
+ util_store
+
+ out = @RM::Document.new
+
+ @driver.add_includes out, [[[@cFooInc], @store]]
+
+ expected = @RM::Document.new(
+ @RM::Rule.new(1),
+ @RM::Heading.new(1, "Includes:"),
+ @RM::Paragraph.new("Inc (from #{@store.friendly_path})"),
+ @RM::BlankLine.new,
+ @RM::Paragraph.new("Include thingy"),
+ @RM::BlankLine.new)
+
+ assert_equal expected, out
+ end
+
+ def test_add_method_list
+ out = @RM::Document.new
+
+ @driver.add_method_list out, %w[new], 'Class methods'
+
+ expected = @RM::Document.new(
+ @RM::Heading.new(1, 'Class methods:'),
+ @RM::BlankLine.new,
+ @RM::Verbatim.new(' ', 'new'),
+ @RM::BlankLine.new)
+
+ assert_equal expected, out
+ end
+
+ def test_add_method_list_none
+ out = @RM::Document.new
+
+ @driver.add_method_list out, nil, 'Class'
+
+ assert_equal @RM::Document.new, out
+ end
+
+ def test_ancestors_of
+ util_ancestors_store
+
+ assert_equal %w[X Mixin Object Foo], @driver.ancestors_of('Foo::Bar')
+ end
+
+ def test_classes
+ util_multi_store
+
+ expected = {
+ 'Ambiguous' => [@store1, @store2],
+ 'Bar' => [@store2],
+ 'Foo' => [@store1],
+ 'Foo::Bar' => [@store1],
+ 'Foo::Baz' => [@store1, @store2],
+ 'Inc' => [@store1],
+ }
+
+ assert_equal expected, @driver.classes
+ end
+
+ def test_complete
+ store = RDoc::RI::Store.new @home_ri
+ store.cache[:ancestors] = {
+ 'Foo' => %w[Object],
+ 'Foo::Bar' => %w[Object],
+ }
+ store.cache[:class_methods] = {
+ 'Foo' => %w[bar]
+ }
+ store.cache[:instance_methods] = {
+ 'Foo' => %w[Bar]
+ }
+ store.cache[:modules] = %w[
+ Foo
+ Foo::Bar
+ ]
+
+ @driver.stores = [store]
+
+ assert_equal %w[Foo Foo::Bar], @driver.complete('F')
+ assert_equal %w[ Foo::Bar], @driver.complete('Foo::B')
+
+ assert_equal %w[Foo#Bar], @driver.complete('Foo#'), 'Foo#'
+ assert_equal %w[Foo#Bar Foo::bar], @driver.complete('Foo.'), 'Foo.'
+ assert_equal %w[Foo::Bar Foo::bar], @driver.complete('Foo::'), 'Foo::'
+ end
+
+ def test_complete_ancestor
+ util_ancestors_store
+
+ assert_equal %w[Foo::Bar#i_method], @driver.complete('Foo::Bar#')
+
+ assert_equal %w[Foo::Bar#i_method Foo::Bar::c_method Foo::Bar::new],
+ @driver.complete('Foo::Bar.')
+ end
+
+ def test_complete_classes
+ util_store
+
+ assert_equal %w[Foo Foo::Bar Foo::Baz], @driver.complete('F')
+ assert_equal %w[Foo:: Foo::Bar Foo::Baz], @driver.complete('Foo::')
+ assert_equal %w[ Foo::Bar Foo::Baz], @driver.complete('Foo::B')
+ end
+
+ def test_complete_multistore
+ util_multi_store
+
+ assert_equal %w[Bar], @driver.complete('B')
+ assert_equal %w[Foo Foo::Bar Foo::Baz], @driver.complete('F')
+ end
+
+ def test_display
+ doc = @RM::Document.new(
+ @RM::Paragraph.new('hi'))
+
+ out, err = capture_io do
+ @driver.display doc
end
- assert @driver.lookup_method('Foo::Bar', 'Foo::Bar')
+ assert_equal "hi\n", out
end
- def test_lookup_method_class_missing
- def @driver.load_cache_for(klassname) end
+ def test_display_class
+ util_store
- assert_nil @driver.lookup_method('Foo#bar', 'Foo')
+ out, err = capture_io do
+ @driver.display_class 'Foo::Bar'
+ end
+
+ assert_match %r%^= Foo::Bar%, out
+ assert_match %r%^\(from%, out # )
+
+ assert_match %r%^= Class methods:%, out
+ assert_match %r%^ new%, out
+ assert_match %r%^= Instance methods:%, out
+ assert_match %r%^ blah%, out
+ assert_match %r%^= Attributes:%, out
+ assert_match %r%^ attr_accessor attr%, out
+
+ assert_equal 1, out.scan(/-\n/).length
end
- def test_lookup_method_dot_instance
- def @driver.load_cache_for(klassname)
- { 'Foo#bar' => :instance, 'Foo::bar' => :klass }
+ def test_display_class_ambiguous
+ util_multi_store
+
+ out, err = capture_io do
+ @driver.display_class 'Ambiguous'
end
- assert_equal :instance, @driver.lookup_method('Foo.bar', 'Foo')
+ assert_match %r%^= Ambiguous < Object$%, out
end
- def test_lookup_method_dot_class
- def @driver.load_cache_for(klassname)
- { 'Foo::bar' => :found }
+ def test_display_class_multi_no_doc
+ util_multi_store
+
+ out, err = capture_io do
+ @driver.display_class 'Foo::Baz'
end
- assert @driver.lookup_method('Foo.bar', 'Foo')
+ assert_match %r%^= Foo::Baz%, out
+ assert_match %r%-\n%, out
+ assert_match %r%Also found in:%, out
+ assert_match %r%#{Regexp.escape @home_ri}%, out
+ assert_match %r%#{Regexp.escape @home_ri2}%, out
end
- def test_lookup_method_method_missing
- def @driver.load_cache_for(klassname) {} end
+ def test_display_class_superclass
+ util_multi_store
+
+ out, err = capture_io do
+ @driver.display_class 'Bar'
+ end
- assert_nil @driver.lookup_method('Foo#bar', 'Foo')
+ assert_match %r%^= Bar < Foo%, out
end
- def test_parse_name
- klass, meth = @driver.parse_name 'Foo::Bar'
+ def test_display_class_module
+ util_store
- assert_equal 'Foo::Bar', klass, 'Foo::Bar class'
- assert_equal nil, meth, 'Foo::Bar method'
+ out, err = capture_io do
+ @driver.display_class 'Inc'
+ end
+
+ assert_match %r%^= Inc$%, out
+ end
- klass, meth = @driver.parse_name 'Foo#Bar'
+ def test_display_method
+ util_store
- assert_equal 'Foo', klass, 'Foo#Bar class'
- assert_equal 'Bar', meth, 'Foo#Bar method'
+ out, err = capture_io do
+ @driver.display_method 'Foo::Bar#blah'
+ end
+
+ assert_match %r%Foo::Bar#blah%, out
+ assert_match %r%blah.5%, out
+ assert_match %r%blah.6%, out
+ assert_match %r%yields: stuff%, out
+ end
+
+ def test_display_method_attribute
+ util_store
+
+ out, err = capture_io do
+ @driver.display_method 'Foo::Bar#attr'
+ end
+
+ assert_match %r%Foo::Bar#attr%, out
+ refute_match %r%Implementation from%, out
+ end
+
+ def test_display_method_inherited
+ util_multi_store
+
+ out, err = capture_io do
+ @driver.display_method 'Bar#inherit'
+ end
+
+ assert_match %r%^= Bar#inherit%, out
+ assert_match %r%^=== Implementation from Foo%, out
+ end
+
+ def test_display_name_not_found_class
+ util_store
+
+ out, err = capture_io do
+ assert_equal false, @driver.display_name('Foo::B')
+ end
+
+ expected = <<-EXPECTED
+Foo::B not found, maybe you meant:
+
+Foo::Bar
+Foo::Baz
+ EXPECTED
+
+ assert_equal expected, out
+ end
+
+ def test_display_name_not_found_method
+ util_store
+
+ out, err = capture_io do
+ assert_equal false, @driver.display_name('Foo::Bar#b')
+ end
+
+ expected = <<-EXPECTED
+Foo::Bar#b not found, maybe you meant:
+
+Foo::Bar#blah
+Foo::Bar#bother
+ EXPECTED
+
+ assert_equal expected, out
+ end
+
+ def test_expand_class
+ util_store
+
+ assert_equal 'Foo', @driver.expand_class('F')
+ assert_equal 'Foo::Bar', @driver.expand_class('F::Bar')
+
+ assert_raises RDoc::RI::Driver::NotFoundError do
+ @driver.expand_class 'F::B'
+ end
+ end
+
+ def test_expand_name
+ util_store
- klass, meth = @driver.parse_name 'Foo.Bar'
+ assert_equal '.b', @driver.expand_name('b')
+ assert_equal 'Foo', @driver.expand_name('F')
+ assert_equal 'Foo::Bar#', @driver.expand_name('F::Bar#')
+
+ e = assert_raises RDoc::RI::Driver::NotFoundError do
+ @driver.expand_name 'Z'
+ end
+
+ assert_equal 'Z', e.name
+ end
+
+ def test_find_methods
+ util_store
+
+ items = []
+
+ @driver.find_methods 'Foo::Bar.' do |store, klass, ancestor, types, method|
+ items << [store, klass, ancestor, types, method]
+ end
+
+ expected = [
+ [@store, 'Foo::Bar', 'Foo::Bar', :both, nil],
+ ]
+
+ assert_equal expected, items
+ end
+
+ def test_find_methods_method
+ util_store
+
+ items = []
+
+ @driver.find_methods '.blah' do |store, klass, ancestor, types, method|
+ items << [store, klass, ancestor, types, method]
+ end
+
+ expected = [
+ [@store, 'Ambiguous', 'Ambiguous', :both, 'blah'],
+ [@store, 'Foo', 'Foo', :both, 'blah'],
+ [@store, 'Foo::Bar', 'Foo::Bar', :both, 'blah'],
+ [@store, 'Foo::Baz', 'Foo::Baz', :both, 'blah'],
+ [@store, 'Inc', 'Inc', :both, 'blah'],
+ ]
+
+ assert_equal expected, items
+ end
+
+ def test_formatter
+ driver = RDoc::RI::Driver.new
+
+ assert_instance_of @RM::ToAnsi, driver.formatter
+
+ driver.instance_variable_set :@paging, true
+
+ assert_instance_of @RM::ToBs, driver.formatter
+
+ driver.instance_variable_set :@formatter_klass, @RM::ToHtml
+
+ assert_instance_of @RM::ToHtml, driver.formatter
+ end
+
+ def test_method_type
+ assert_equal :both, @driver.method_type(nil)
+ assert_equal :both, @driver.method_type('.')
+ assert_equal :instance, @driver.method_type('#')
+ assert_equal :class, @driver.method_type('::')
+ end
+
+ def test_list_known_classes
+ util_store
+
+ out, err = capture_io do
+ @driver.list_known_classes
+ end
+
+ assert_equal "Ambiguous\nFoo\nFoo::Bar\nFoo::Baz\nInc\n", out
+ end
+
+ def test_list_methods_matching
+ util_store
+
+ assert_equal %w[Foo::Bar#attr Foo::Bar#blah Foo::Bar#bother Foo::Bar::new],
+ @driver.list_methods_matching('Foo::Bar.')
+ end
+
+ def test_load_method
+ util_store
+
+ method = @driver.load_method(@store, :instance_methods, 'Foo', '#',
+ 'inherit')
+
+ assert_equal @inherit, method
+ end
+
+ def test_load_method_inherited
+ util_multi_store
+
+ method = @driver.load_method(@store2, :instance_methods, 'Bar', '#',
+ 'inherit')
+
+ assert_equal nil, method
+ end
+
+ def test_load_methods_matching
+ util_store
+
+ expected = [[@store, [@inherit]]]
+
+ assert_equal expected, @driver.load_methods_matching('Foo#inherit')
+
+ expected = [[@store, [@blah]]]
+
+ assert_equal expected, @driver.load_methods_matching('.blah')
+
+ assert_empty @driver.load_methods_matching('.b')
+ end
+
+ def test_load_methods_matching_inherited
+ util_multi_store
+
+ expected = [[@store1, [@inherit]]]
+
+ assert_equal expected, @driver.load_methods_matching('Bar#inherit')
+ end
+
+ def test_page
+ @driver.use_stdout = false
+
+ @driver.page do |io|
+ skip "couldn't find a standard pager" if io == $stdout
+
+ assert @driver.paging?
+ end
+
+ refute @driver.paging?
+ end
+
+ def test_page_stdout
+ @driver.use_stdout = true
+
+ @driver.page do |io|
+ assert_equal $stdout, io
+ end
+
+ refute @driver.paging?
+ end
+
+ def test_parse_name_method
+ klass, type, meth = @driver.parse_name 'foo'
+
+ assert_equal '', klass, 'foo class'
+ assert_equal '.', type, 'foo type'
+ assert_equal 'foo', meth, 'foo method'
+
+ klass, type, meth = @driver.parse_name '#foo'
+
+ assert_equal '', klass, '#foo class'
+ assert_equal '#', type, '#foo type'
+ assert_equal 'foo', meth, '#foo method'
+
+ klass, type, meth = @driver.parse_name '::foo'
+
+ assert_equal '', klass, '::foo class'
+ assert_equal '::', type, '::foo type'
+ assert_equal 'foo', meth, '::foo method'
+ end
+
+ def test_parse_name_single_class
+ klass, type, meth = @driver.parse_name 'Foo'
+
+ assert_equal 'Foo', klass, 'Foo class'
+ assert_equal nil, type, 'Foo type'
+ assert_equal nil, meth, 'Foo method'
+
+ klass, type, meth = @driver.parse_name 'Foo#'
+
+ assert_equal 'Foo', klass, 'Foo# class'
+ assert_equal '#', type, 'Foo# type'
+ assert_equal nil, meth, 'Foo# method'
+
+ klass, type, meth = @driver.parse_name 'Foo::'
+
+ assert_equal 'Foo', klass, 'Foo:: class'
+ assert_equal '::', type, 'Foo:: type'
+ assert_equal nil, meth, 'Foo:: method'
+
+ klass, type, meth = @driver.parse_name 'Foo.'
+
+ assert_equal 'Foo', klass, 'Foo. class'
+ assert_equal '.', type, 'Foo. type'
+ assert_equal nil, meth, 'Foo. method'
+
+ klass, type, meth = @driver.parse_name 'Foo#Bar'
assert_equal 'Foo', klass, 'Foo#Bar class'
+ assert_equal '#', type, 'Foo#Bar type'
assert_equal 'Bar', meth, 'Foo#Bar method'
- klass, meth = @driver.parse_name 'Foo::bar'
+ klass, type, meth = @driver.parse_name 'Foo.Bar'
+
+ assert_equal 'Foo', klass, 'Foo.Bar class'
+ assert_equal '.', type, 'Foo.Bar type'
+ assert_equal 'Bar', meth, 'Foo.Bar method'
+
+ klass, type, meth = @driver.parse_name 'Foo::bar'
assert_equal 'Foo', klass, 'Foo::bar class'
+ assert_equal '::', type, 'Foo::bar type'
assert_equal 'bar', meth, 'Foo::bar method'
end
+ def test_parse_name_namespace
+ klass, type, meth = @driver.parse_name 'Foo::Bar'
+
+ assert_equal 'Foo::Bar', klass, 'Foo::Bar class'
+ assert_equal nil, type, 'Foo::Bar type'
+ assert_equal nil, meth, 'Foo::Bar method'
+
+ klass, type, meth = @driver.parse_name 'Foo::Bar#'
+
+ assert_equal 'Foo::Bar', klass, 'Foo::Bar# class'
+ assert_equal '#', type, 'Foo::Bar# type'
+ assert_equal nil, meth, 'Foo::Bar# method'
+
+ klass, type, meth = @driver.parse_name 'Foo::Bar#baz'
+
+ assert_equal 'Foo::Bar', klass, 'Foo::Bar#baz class'
+ assert_equal '#', type, 'Foo::Bar#baz type'
+ assert_equal 'baz', meth, 'Foo::Bar#baz method'
+ end
+
+ def test_setup_pager
+ @driver.use_stdout = false
+
+ pager = @driver.setup_pager
+
+ skip "couldn't find a standard pager" unless pager
+
+ assert @driver.paging?
+ ensure
+ pager.close if pager
+ end
+
+ def util_ancestors_store
+ store1 = RDoc::RI::Store.new @home_ri
+ store1.cache[:ancestors] = {
+ 'Foo' => %w[Object],
+ 'Foo::Bar' => %w[Foo],
+ }
+ store1.cache[:class_methods] = {
+ 'Foo' => %w[c_method new],
+ 'Foo::Bar' => %w[new],
+ }
+ store1.cache[:instance_methods] = {
+ 'Foo' => %w[i_method],
+ }
+ store1.cache[:modules] = %w[
+ Foo
+ Foo::Bar
+ ]
+
+ store2 = RDoc::RI::Store.new @home_ri
+ store2.cache[:ancestors] = {
+ 'Foo' => %w[Mixin Object],
+ 'Mixin' => %w[],
+ 'Object' => %w[X Object],
+ 'X' => %w[Object],
+ }
+ store2.cache[:class_methods] = {
+ 'Foo' => %w[c_method new],
+ 'Mixin' => %w[],
+ 'X' => %w[],
+ 'Object' => %w[],
+ }
+ store2.cache[:instance_methods] = {
+ 'Foo' => %w[i_method],
+ 'Mixin' => %w[],
+ }
+ store2.cache[:modules] = %w[
+ Foo
+ Mixin
+ Object
+ X
+ ]
+
+ @driver.stores = store1, store2
+ end
+
+ def util_multi_store
+ util_store
+ @store1 = @store
+
+ @home_ri2 = "#{@home_ri}2"
+ @store2 = RDoc::RI::Store.new @home_ri2
+
+ # as if seen in a namespace like class Ambiguous::Other
+ @mAmbiguous = RDoc::NormalModule.new 'Ambiguous'
+
+ @cFoo = RDoc::NormalClass.new 'Foo'
+ @cBar = RDoc::NormalClass.new 'Bar'
+ @cBar.superclass = 'Foo'
+ @cFoo_Baz = RDoc::NormalClass.new 'Baz'
+ @cFoo_Baz.parent = @cFoo
+
+ @baz = RDoc::AnyMethod.new nil, 'baz'
+ @cBar.add_method @baz
+
+ @store2.save_class @mAmbiguous
+ @store2.save_class @cBar
+ @store2.save_class @cFoo_Baz
+
+ @store2.save_method @cBar, @baz
+
+ @store2.save_cache
+
+ @driver.stores = [@store1, @store2]
+ end
+
+ def util_store
+ @store = RDoc::RI::Store.new @home_ri
+
+ @cFoo = RDoc::NormalClass.new 'Foo'
+ @mInc = RDoc::NormalModule.new 'Inc'
+ @cAmbiguous = RDoc::NormalClass.new 'Ambiguous'
+
+ doc = @RM::Document.new @RM::Paragraph.new('Include thingy')
+
+ @cFooInc = RDoc::Include.new 'Inc', doc
+ @cFoo.add_include @cFooInc
+
+ @cFoo_Bar = RDoc::NormalClass.new 'Bar'
+ @cFoo_Bar.parent = @cFoo
+
+ @blah = RDoc::AnyMethod.new nil, 'blah'
+ @blah.call_seq = "blah(5) => 5\nblah(6) => 6\n"
+ @blah.block_params = "stuff"
+
+ @bother = RDoc::AnyMethod.new nil, 'bother'
+
+ @new = RDoc::AnyMethod.new nil, 'new'
+ @new.singleton = true
+
+ @cFoo_Bar.add_method @blah
+ @cFoo_Bar.add_method @bother
+ @cFoo_Bar.add_method @new
+
+ @attr = RDoc::Attr.new nil, 'attr', 'RW', ''
+
+ @cFoo_Bar.add_attribute @attr
+
+ @cFoo_Baz = RDoc::NormalClass.new 'Baz'
+ @cFoo_Baz.parent = @cFoo
+
+ @inherit = RDoc::AnyMethod.new nil, 'inherit'
+ @cFoo.add_method @inherit
+
+ @store.save_class @cFoo
+ @store.save_class @cFoo_Bar
+ @store.save_class @cFoo_Baz
+ @store.save_class @mInc
+ @store.save_class @cAmbiguous
+
+ @store.save_method @cFoo_Bar, @blah
+ @store.save_method @cFoo_Bar, @bother
+ @store.save_method @cFoo_Bar, @new
+ @store.save_method @cFoo_Bar, @attr
+
+ @store.save_method @cFoo, @inherit
+
+ @store.save_cache
+
+ @driver.stores = [@store]
+ end
+
end
-MiniTest::Unit.autorun
diff --git a/test/rdoc/test_rdoc_ri_formatter.rb b/test/rdoc/test_rdoc_ri_formatter.rb
deleted file mode 100644
index a70f9dcba7..0000000000
--- a/test/rdoc/test_rdoc_ri_formatter.rb
+++ /dev/null
@@ -1,320 +0,0 @@
-require 'stringio'
-require 'rubygems'
-require 'minitest/unit'
-require 'rdoc/ri/formatter'
-require 'rdoc/markup/to_flow'
-
-class TestRDocRIFormatter < MiniTest::Unit::TestCase
-
- def setup
- @output = StringIO.new
- @width = 78
- @indent = ' '
-
- @f = RDoc::RI::Formatter.new @output, @width, @indent
- @markup = RDoc::Markup.new
- @flow = RDoc::Markup::ToFlow.new
- end
-
- def test_blankline
- @f.blankline
-
- assert_equal "\n", @output.string
- end
-
- def test_bold_print
- @f.bold_print 'a b c'
-
- assert_equal 'a b c', @output.string
- end
-
- def test_break_to_newline
- @f.break_to_newline
-
- assert_equal '', @output.string
- end
-
- def test_conv_html
- assert_equal '> < " &', @f.conv_html('&gt; &lt; &quot; &amp;')
- end
-
- def test_conv_markup
- text = '<tt>a</tt> <code>b</code> <b>c</b> <em>d</em>'
-
- expected = '+a+ +b+ *c* _d_'
-
- assert_equal expected, @f.conv_markup(text)
- end
-
- def test_display_flow
- flow = [
- RDoc::Markup::Flow::H.new(1, 'heading'),
- RDoc::Markup::Flow::P.new('paragraph'),
- ]
-
- @f.display_flow flow
-
- assert_equal "\nHEADING\n=======\n\n paragraph\n\n", @output.string
- end
-
- def test_display_flow_item_h
- item = RDoc::Markup::Flow::H.new 1, 'heading'
-
- @f.display_flow_item item
-
- assert_equal "\nHEADING\n=======\n\n", @output.string
- end
-
- def test_display_flow_item_li
- item = RDoc::Markup::Flow::LI.new nil, 'paragraph'
-
- @f.display_flow_item item
-
- assert_equal " paragraph\n\n", @output.string
- end
-
- def test_display_flow_item_list
- item = RDoc::Markup::Flow::LIST.new :NUMBER
-
- @f.display_flow_item item
-
- assert_equal "", @output.string
- end
-
- def test_display_flow_item_p
- item = RDoc::Markup::Flow::P.new 'paragraph'
-
- @f.display_flow_item item
-
- assert_equal " paragraph\n\n", @output.string
- end
-
- def test_display_flow_item_rule
- item = RDoc::Markup::Flow::RULE.new 1
-
- @f.display_flow_item item
-
- assert_equal "#{'-' * 78}\n", @output.string
- end
-
- def test_display_flow_item_unknown
- e = assert_raises RDoc::Error do
- @f.display_flow_item Object.new
- end
-
- assert_equal "Unknown flow element: Object", e.message
- end
-
- def test_display_flow_item_verb
- item = RDoc::Markup::Flow::VERB.new 'a b c'
-
- @f.display_flow_item item
-
- assert_equal " a b c\n\n", @output.string
- end
-
- def test_display_heading_1
- @f.display_heading 'heading', 1, ' '
-
- assert_equal "\nHEADING\n=======\n\n", @output.string
- end
-
- def test_display_heading_2
- @f.display_heading 'heading', 2, ' '
-
- assert_equal "\nheading\n-------\n\n", @output.string
- end
-
- def test_display_heading_3
- @f.display_heading 'heading', 3, ' '
-
- assert_equal " heading\n\n", @output.string
- end
-
- def test_display_list
- list = RDoc::Markup::Flow::LIST.new :NUMBER
- list << RDoc::Markup::Flow::LI.new(nil, 'a b c')
- list << RDoc::Markup::Flow::LI.new(nil, 'd e f')
-
- @f.display_list list
-
- assert_equal " 1. a b c\n\n 2. d e f\n\n", @output.string
- end
-
- def test_display_list_bullet
- list = RDoc::Markup::Flow::LIST.new :BULLET
- list << RDoc::Markup::Flow::LI.new(nil, 'a b c')
-
- @f.display_list list
-
- assert_equal " * a b c\n\n", @output.string
- end
-
- def test_display_list_labeled
- list = RDoc::Markup::Flow::LIST.new :LABELED
- list << RDoc::Markup::Flow::LI.new('label', 'a b c')
-
- @f.display_list list
-
- assert_equal " label a b c\n\n", @output.string
- end
-
- def test_display_list_lower_alpha
- list = RDoc::Markup::Flow::LIST.new :LOWERALPHA
- list << RDoc::Markup::Flow::LI.new(nil, 'a b c')
-
- @f.display_list list
-
- assert_equal " a. a b c\n\n", @output.string
- end
-
- def test_display_list_note
- list = RDoc::Markup::Flow::LIST.new :NOTE
- list << RDoc::Markup::Flow::LI.new('note:', 'a b c')
-
- @f.display_list list
-
- assert_equal " note: a b c\n\n", @output.string
- end
-
- def test_display_list_number
- list = RDoc::Markup::Flow::LIST.new :NUMBER
- list << RDoc::Markup::Flow::LI.new(nil, 'a b c')
-
- @f.display_list list
-
- assert_equal " 1. a b c\n\n", @output.string
- end
-
- def test_display_list_unknown
- list = RDoc::Markup::Flow::LIST.new :UNKNOWN
- list << RDoc::Markup::Flow::LI.new(nil, 'a b c')
-
- e = assert_raises ArgumentError do
- @f.display_list list
- end
-
- assert_equal 'unknown list type UNKNOWN', e.message
- end
-
- def test_display_list_upper_alpha
- list = RDoc::Markup::Flow::LIST.new :UPPERALPHA
- list << RDoc::Markup::Flow::LI.new(nil, 'a b c')
-
- @f.display_list list
-
- assert_equal " A. a b c\n\n", @output.string
- end
-
- def test_display_verbatim_flow_item
- verbatim = RDoc::Markup::Flow::VERB.new "a b c\nd e f"
-
- @f.display_verbatim_flow_item verbatim
-
- assert_equal " a b c\n d e f\n\n", @output.string
- end
-
- def test_display_verbatim_flow_item_bold
- verbatim = RDoc::Markup::Flow::VERB.new "*a* b c"
-
- @f.display_verbatim_flow_item verbatim
-
- assert_equal " *a* b c\n\n", @output.string
- end
-
- def test_draw_line
- @f.draw_line
-
- expected = '-' * @width + "\n"
- assert_equal expected, @output.string
- end
-
- def test_draw_line_label
- @f.draw_line 'label'
-
- expected = '-' * (@width - 6) + " label\n"
- assert_equal expected, @output.string
- end
-
- def test_draw_line_label_long
- @f.draw_line 'a' * @width
-
- expected = '-' * @width + "\n" + ('a' * @width) + "\n"
- assert_equal expected, @output.string
- end
-
- def test_raw_print_line
- @f.raw_print_line 'a b c'
-
- assert_equal "a b c", @output.string
- end
-
- def test_strip_attributes_b
- text = @f.strip_attributes 'hello <b>world</b>'
-
- expected = 'hello world'
-
- assert_equal expected, text
- end
-
- def test_strip_attributes_code
- text = @f.strip_attributes 'hello <code>world</code>'
-
- expected = 'hello world'
-
- assert_equal expected, text
- end
-
- def test_strip_attributes_em
- text = @f.strip_attributes 'hello <em>world</em>'
-
- expected = 'hello world'
-
- assert_equal expected, text
- end
-
- def test_strip_attributes_i
- text = @f.strip_attributes 'hello <i>world</i>'
-
- expected = 'hello world'
-
- assert_equal expected, text
- end
-
- def test_strip_attributes_tt
- text = @f.strip_attributes 'hello <tt>world</tt>'
-
- expected = 'hello world'
-
- assert_equal expected, text
- end
-
- def test_wrap_empty
- @f.wrap ''
- assert_equal '', @output.string
- end
-
- def test_wrap_long
- @f.wrap 'a ' * (@width / 2)
- assert_equal " a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a\n a \n",
- @output.string
- end
-
- def test_wrap_markup
- @f.wrap 'a <tt>b</tt> c'
- assert_equal " a +b+ c\n", @output.string
- end
-
- def test_wrap_nil
- @f.wrap nil
- assert_equal '', @output.string
- end
-
- def test_wrap_short
- @f.wrap 'a b c'
- assert_equal " a b c\n", @output.string
- end
-
-end
-
-MiniTest::Unit.autorun
diff --git a/test/rdoc/test_rdoc_ri_overstrike_formatter.rb b/test/rdoc/test_rdoc_ri_overstrike_formatter.rb
deleted file mode 100644
index 38b95414dd..0000000000
--- a/test/rdoc/test_rdoc_ri_overstrike_formatter.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-require 'stringio'
-require 'rubygems'
-require 'minitest/unit'
-require 'rdoc/ri/formatter'
-require 'rdoc/markup/fragments'
-require 'rdoc/markup/to_flow'
-
-class TestRDocRIOverstrikeFormatter < MiniTest::Unit::TestCase
-
- def setup
- @output = StringIO.new
- @width = 78
- @indent = ' '
-
- @f = RDoc::RI::OverstrikeFormatter.new @output, @width, @indent
- @markup = RDoc::Markup.new
- @flow = RDoc::Markup::ToFlow.new
-
- @af = RDoc::RI::AttributeFormatter
- end
-
- def test_display_verbatim_flow_item_bold
- verbatim = RDoc::Markup::Flow::VERB.new "*a* b c"
-
- @f.display_verbatim_flow_item verbatim
-
- assert_equal " *a* b c\n\n", @output.string
- end
-
- def test_write_attribute_text_bold
- line = [RDoc::RI::AttributeFormatter::AttrChar.new('b', @af::BOLD)]
-
- @f.write_attribute_text ' ', line
-
- assert_equal " b\bb\n", @output.string
- end
-
- def test_write_attribute_text_bold_italic
- attr = @af::BOLD | @af::ITALIC
- line = [RDoc::RI::AttributeFormatter::AttrChar.new('d', attr)]
-
- @f.write_attribute_text ' ', line
-
- assert_equal " _\bd\bd\n", @output.string
- end
-
- def test_write_attribute_text_code
- line = [RDoc::RI::AttributeFormatter::AttrChar.new('c', @af::CODE)]
-
- @f.write_attribute_text ' ', line
-
- assert_equal " _\bc\n", @output.string
- end
-
- def test_write_attribute_text_italic
- line = [RDoc::RI::AttributeFormatter::AttrChar.new('a', @af::ITALIC)]
-
- @f.write_attribute_text ' ', line
-
- assert_equal " _\ba\n", @output.string
- end
-
- def test_bold_print
- @f.bold_print 'a b c'
-
- assert_equal "a\ba \b b\bb \b c\bc", @output.string
- end
-
-end
-
-MiniTest::Unit.autorun
diff --git a/test/rdoc/test_rdoc_ri_paths.rb b/test/rdoc/test_rdoc_ri_paths.rb
new file mode 100644
index 0000000000..e6f33d7d5e
--- /dev/null
+++ b/test/rdoc/test_rdoc_ri_paths.rb
@@ -0,0 +1,43 @@
+require 'rubygems'
+require 'minitest/autorun'
+require 'tmpdir'
+require 'fileutils'
+require 'rdoc/ri/paths'
+
+class TestRDocRIPaths < MiniTest::Unit::TestCase
+
+ def setup
+ RDoc::RI::Paths.instance_variable_set :@gemdirs, %w[/nonexistent/gemdir]
+ end
+
+ def teardown
+ RDoc::RI::Paths.instance_variable_set :@gemdirs, nil
+ end
+
+ def test_class_path_nonexistent
+ path = RDoc::RI::Paths.path true, true, true, true, '/nonexistent'
+
+ refute_includes path, '/nonexistent'
+ end
+
+ def test_class_raw_path
+ path = RDoc::RI::Paths.raw_path true, true, true, true
+
+ assert_equal RDoc::RI::Paths::SYSDIR, path.shift
+ assert_equal RDoc::RI::Paths::SITEDIR, path.shift
+ assert_equal RDoc::RI::Paths::HOMEDIR, path.shift
+ assert_equal '/nonexistent/gemdir', path.shift
+ end
+
+ def test_class_raw_path_extra_dirs
+ path = RDoc::RI::Paths.raw_path true, true, true, true, '/nonexistent'
+
+ assert_equal '/nonexistent', path.shift
+ assert_equal RDoc::RI::Paths::SYSDIR, path.shift
+ assert_equal RDoc::RI::Paths::SITEDIR, path.shift
+ assert_equal RDoc::RI::Paths::HOMEDIR, path.shift
+ assert_equal '/nonexistent/gemdir', path.shift
+ end
+
+end
+
diff --git a/test/rdoc/test_rdoc_ri_store.rb b/test/rdoc/test_rdoc_ri_store.rb
new file mode 100644
index 0000000000..4a52ded989
--- /dev/null
+++ b/test/rdoc/test_rdoc_ri_store.rb
@@ -0,0 +1,309 @@
+require 'rubygems'
+require 'minitest/autorun'
+require 'rdoc/ri'
+require 'rdoc/markup'
+require 'tmpdir'
+require 'fileutils'
+
+class TestRDocRIStore < MiniTest::Unit::TestCase
+
+ def setup
+ RDoc::TopLevel.reset
+
+ @tmpdir = File.join Dir.tmpdir, "test_rdoc_ri_store_#{$$}"
+ @s = RDoc::RI::Store.new @tmpdir
+
+ @top_level = RDoc::TopLevel.new 'file.rb'
+
+ @klass = @top_level.add_class RDoc::NormalClass, 'Object'
+ @klass.comment = 'original'
+
+ @cmeth = RDoc::AnyMethod.new nil, 'cmethod'
+ @cmeth.singleton = true
+
+ @meth = RDoc::AnyMethod.new nil, 'method'
+ @meth_bang = RDoc::AnyMethod.new nil, 'method!'
+
+ @attr = RDoc::Attr.new nil, 'attr', 'RW', ''
+
+ @klass.add_method @cmeth
+ @klass.add_method @meth
+ @klass.add_method @meth_bang
+ @klass.add_attribute @attr
+
+ @nest_klass = @klass.add_class RDoc::NormalClass, 'SubClass'
+ @nest_meth = RDoc::AnyMethod.new nil, 'method'
+ @nest_incl = RDoc::Include.new 'Incl', ''
+
+ @nest_klass.add_method @nest_meth
+ @nest_klass.add_include @nest_incl
+
+ @RM = RDoc::Markup
+ end
+
+ def teardown
+ FileUtils.rm_rf @tmpdir
+ end
+
+ def assert_cache imethods, cmethods, attrs, modules, ancestors = {}
+ expected = {
+ :class_methods => cmethods,
+ :instance_methods => imethods,
+ :attributes => attrs,
+ :modules => modules,
+ :ancestors => ancestors
+ }
+
+ assert_equal expected, @s.cache
+ end
+
+ def assert_directory path
+ assert File.directory?(path), "#{path} is not a directory"
+ end
+
+ def assert_file path
+ assert File.file?(path), "#{path} is not a file"
+ end
+
+ def test_attributes
+ @s.cache[:attributes]['Object'] = %w[attr]
+
+ expected = { 'Object' => %w[attr] }
+
+ assert_equal expected, @s.attributes
+ end
+
+ def test_class_file
+ assert_equal File.join(@tmpdir, 'Object', 'cdesc-Object.ri'),
+ @s.class_file('Object')
+ assert_equal File.join(@tmpdir, 'Object', 'SubClass', 'cdesc-SubClass.ri'),
+ @s.class_file('Object::SubClass')
+ end
+
+ def test_class_methods
+ @s.cache[:class_methods]['Object'] = %w[method]
+
+ expected = { 'Object' => %w[method] }
+
+ assert_equal expected, @s.class_methods
+ end
+
+ def test_class_path
+ assert_equal File.join(@tmpdir, 'Object'), @s.class_path('Object')
+ assert_equal File.join(@tmpdir, 'Object', 'SubClass'),
+ @s.class_path('Object::SubClass')
+ end
+
+ def test_friendly_path
+ @s.path = @tmpdir
+ @s.type = nil
+ assert_equal @s.path, @s.friendly_path
+
+ @s.type = :extra
+ assert_equal @s.path, @s.friendly_path
+
+ @s.type = :system
+ assert_equal "ruby core", @s.friendly_path
+
+ @s.type = :site
+ assert_equal "ruby site", @s.friendly_path
+
+ @s.type = :home
+ assert_equal "~/.ri", @s.friendly_path
+
+ @s.type = :gem
+ @s.path = "#{@tmpdir}/gem_repository/doc/gem_name-1.0/ri"
+ assert_equal "gem gem_name-1.0", @s.friendly_path
+ end
+
+ def test_instance_methods
+ @s.cache[:instance_methods]['Object'] = %w[method]
+
+ expected = { 'Object' => %w[method] }
+
+ assert_equal expected, @s.instance_methods
+ end
+
+ def test_load_cache
+ cache = {
+ :methods => %w[Object#method],
+ :modules => %w[Object],
+ }
+
+ Dir.mkdir @tmpdir
+
+ open File.join(@tmpdir, 'cache.ri'), 'wb' do |io|
+ Marshal.dump cache, io
+ end
+
+ @s.load_cache
+
+ assert_equal cache, @s.cache
+ end
+
+ def test_load_cache_no_cache
+ cache = {
+ :ancestors => {},
+ :attributes => {},
+ :class_methods => {},
+ :instance_methods => {},
+ :modules => [],
+ }
+
+ @s.load_cache
+
+ assert_equal cache, @s.cache
+ end
+
+ def test_load_class
+ @s.save_class @klass
+
+ assert_equal @klass, @s.load_class('Object')
+ end
+
+ def test_load_method_bang
+ @s.save_method @klass, @meth_bang
+
+ meth = @s.load_method('Object', '#method!')
+ assert_equal @meth_bang, meth
+ end
+
+ def test_method_file
+ assert_equal File.join(@tmpdir, 'Object', 'method-i.ri'),
+ @s.method_file('Object', 'Object#method')
+
+ assert_equal File.join(@tmpdir, 'Object', 'method%21-i.ri'),
+ @s.method_file('Object', 'Object#method!')
+
+ assert_equal File.join(@tmpdir, 'Object', 'SubClass', 'method%21-i.ri'),
+ @s.method_file('Object::SubClass', 'Object::SubClass#method!')
+
+ assert_equal File.join(@tmpdir, 'Object', 'method-c.ri'),
+ @s.method_file('Object', 'Object::method')
+ end
+
+ def test_save_cache
+ @s.save_class @klass
+ @s.save_method @klass, @meth
+ @s.save_method @klass, @cmeth
+ @s.save_class @nest_klass
+
+ @s.save_cache
+
+ assert_file File.join(@tmpdir, 'cache.ri')
+
+ expected = {
+ :attributes => { 'Object' => ['attr_accessor attr'] },
+ :class_methods => { 'Object' => %w[cmethod] },
+ :instance_methods => { 'Object' => %w[method] },
+ :modules => %w[Object Object::SubClass],
+ :ancestors => {
+ 'Object' => %w[Object],
+ 'Object::SubClass' => %w[Incl Object],
+ },
+ }
+
+ open File.join(@tmpdir, 'cache.ri'), 'rb' do |io|
+ cache = Marshal.load io.read
+
+ assert_equal expected, cache
+ end
+ end
+
+ def test_save_cache_duplicate_methods
+ @s.save_method @klass, @meth
+ @s.save_method @klass, @meth
+
+ @s.save_cache
+
+ assert_cache({ 'Object' => %w[method] }, {}, {}, [])
+ end
+
+ def test_save_class
+ @s.save_class @klass
+
+ assert_directory File.join(@tmpdir, 'Object')
+ assert_file File.join(@tmpdir, 'Object', 'cdesc-Object.ri')
+
+ assert_cache({}, {}, { 'Object' => ['attr_accessor attr'] }, %w[Object],
+ 'Object' => %w[Object])
+
+ assert_equal @klass, @s.load_class('Object')
+ end
+
+ def test_save_class_basic_object
+ @klass.instance_variable_set :@superclass, nil
+
+ @s.save_class @klass
+
+ assert_directory File.join(@tmpdir, 'Object')
+ assert_file File.join(@tmpdir, 'Object', 'cdesc-Object.ri')
+
+ assert_cache({}, {}, { 'Object' => ['attr_accessor attr'] }, %w[Object],
+ 'Object' => %w[])
+
+ assert_equal @klass, @s.load_class('Object')
+ end
+
+ def test_save_class_merge
+ @s.save_class @klass
+
+ klass = RDoc::NormalClass.new 'Object'
+ klass.comment = 'new class'
+
+ s = RDoc::RI::Store.new @tmpdir
+ s.save_class klass
+
+ s = RDoc::RI::Store.new @tmpdir
+
+ document = @RM::Document.new(
+ @RM::Paragraph.new('original'),
+ @RM::Paragraph.new('new class'))
+
+ assert_equal document, s.load_class('Object').comment
+ end
+
+ def test_save_class_methods
+ @s.save_class @klass
+
+ assert_directory File.join(@tmpdir, 'Object')
+ assert_file File.join(@tmpdir, 'Object', 'cdesc-Object.ri')
+
+ assert_cache({}, {}, { 'Object' => ['attr_accessor attr'] }, %w[Object],
+ 'Object' => %w[Object])
+
+ assert_equal @klass, @s.load_class('Object')
+ end
+
+ def test_save_class_nested
+ @s.save_class @nest_klass
+
+ assert_directory File.join(@tmpdir, 'Object', 'SubClass')
+ assert_file File.join(@tmpdir, 'Object', 'SubClass', 'cdesc-SubClass.ri')
+
+ assert_cache({}, {}, {}, %w[Object::SubClass],
+ 'Object::SubClass' => %w[Incl Object])
+ end
+
+ def test_save_method
+ @s.save_method @klass, @meth
+
+ assert_directory File.join(@tmpdir, 'Object')
+ assert_file File.join(@tmpdir, 'Object', 'method-i.ri')
+
+ assert_cache({ 'Object' => %w[method] }, {}, {}, [])
+
+ assert_equal @meth, @s.load_method('Object', '#method')
+ end
+
+ def test_save_method_nested
+ @s.save_method @nest_klass, @nest_meth
+
+ assert_directory File.join(@tmpdir, 'Object', 'SubClass')
+ assert_file File.join(@tmpdir, 'Object', 'SubClass', 'method-i.ri')
+
+ assert_cache({ 'Object::SubClass' => %w[method] }, {}, {}, [])
+ end
+
+end
+
diff --git a/test/rdoc/test_rdoc_task.rb b/test/rdoc/test_rdoc_task.rb
new file mode 100644
index 0000000000..dd3114fb57
--- /dev/null
+++ b/test/rdoc/test_rdoc_task.rb
@@ -0,0 +1,64 @@
+require 'rubygems'
+require 'minitest/autorun'
+require 'rdoc/task'
+
+class TestRDocTask < MiniTest::Unit::TestCase
+
+ def setup
+ Rake::Task.clear
+ end
+
+ def test_tasks_creation
+ RDoc::Task.new
+ assert Rake::Task[:rdoc]
+ assert Rake::Task[:clobber_rdoc]
+ assert Rake::Task[:rerdoc]
+ end
+
+ def test_tasks_creation_with_custom_name_symbol
+ rd = RDoc::Task.new(:rdoc_dev)
+ assert Rake::Task[:rdoc_dev]
+ assert Rake::Task[:clobber_rdoc_dev]
+ assert Rake::Task[:rerdoc_dev]
+ assert_equal :rdoc_dev, rd.name
+ end
+
+ def test_tasks_creation_with_custom_name_string
+ rd = RDoc::Task.new("rdoc_dev")
+ assert Rake::Task[:rdoc_dev]
+ assert Rake::Task[:clobber_rdoc_dev]
+ assert Rake::Task[:rerdoc_dev]
+ assert_equal "rdoc_dev", rd.name
+ end
+
+ def test_tasks_creation_with_custom_name_hash
+ options = { :rdoc => "rdoc", :clobber_rdoc => "rdoc:clean", :rerdoc => "rdoc:force" }
+ rd = RDoc::Task.new(options)
+ assert Rake::Task[:"rdoc"]
+ assert Rake::Task[:"rdoc:clean"]
+ assert Rake::Task[:"rdoc:force"]
+ assert_raises(RuntimeError) { Rake::Task[:clobber_rdoc] }
+ assert_equal options, rd.name
+ end
+
+ def test_tasks_creation_with_custom_name_hash_will_use_default_if_an_option_isnt_given
+ rd = RDoc::Task.new(:clobber_rdoc => "rdoc:clean")
+ assert Rake::Task[:rdoc]
+ assert Rake::Task[:"rdoc:clean"]
+ assert Rake::Task[:rerdoc]
+ end
+
+ def test_tasks_creation_with_custom_name_hash_raises_exception_if_invalid_option_given
+ assert_raises(ArgumentError) do
+ RDoc::Task.new(:foo => "bar")
+ end
+
+ begin
+ RDoc::Task.new(:foo => "bar")
+ rescue ArgumentError => e
+ assert_match(/foo/, e.message)
+ end
+ end
+
+end
+
diff --git a/test/rdoc/test_rdoc_text.rb b/test/rdoc/test_rdoc_text.rb
new file mode 100644
index 0000000000..7e0f2cf0ba
--- /dev/null
+++ b/test/rdoc/test_rdoc_text.rb
@@ -0,0 +1,157 @@
+require 'rubygems'
+require 'minitest/autorun'
+require 'rdoc'
+require 'rdoc/text'
+require 'rdoc/markup'
+require 'rdoc/markup/formatter'
+
+class TestRDocText < MiniTest::Unit::TestCase
+
+ include RDoc::Text
+
+ def test_expand_tabs
+ assert_equal("hello\n dave",
+ expand_tabs("hello\n dave"), 'spaces')
+
+ assert_equal("hello\n dave",
+ expand_tabs("hello\n\tdave"), 'tab')
+
+ assert_equal("hello\n dave",
+ expand_tabs("hello\n \tdave"), '1 space tab')
+
+ assert_equal("hello\n dave",
+ expand_tabs("hello\n \tdave"), '2 space tab')
+
+ assert_equal("hello\n dave",
+ expand_tabs("hello\n \tdave"), '3 space tab')
+
+ assert_equal("hello\n dave",
+ expand_tabs("hello\n \tdave"), '4 space tab')
+
+ assert_equal("hello\n dave",
+ expand_tabs("hello\n \tdave"), '5 space tab')
+
+ assert_equal("hello\n dave",
+ expand_tabs("hello\n \tdave"), '6 space tab')
+
+ assert_equal("hello\n dave",
+ expand_tabs("hello\n \tdave"), '7 space tab')
+
+ assert_equal("hello\n dave",
+ expand_tabs("hello\n \tdave"), '8 space tab')
+
+ assert_equal('. .',
+ expand_tabs(".\t\t."), 'dot tab tab dot')
+ end
+
+ def test_flush_left
+ text = <<-TEXT
+
+ we don't worry too much.
+
+ The comments associated with
+ TEXT
+
+ expected = <<-EXPECTED
+
+we don't worry too much.
+
+The comments associated with
+ EXPECTED
+
+ assert_equal expected, flush_left(text)
+ end
+
+ def test_markup
+ def formatter() RDoc::Markup::ToHtml.new end
+
+ assert_equal "<p>\nhi\n</p>\n", markup('hi')
+ end
+
+ def test_normalize_comment
+ text = <<-TEXT
+##
+# we don't worry too much.
+#
+# The comments associated with
+ TEXT
+
+ expected = <<-EXPECTED.rstrip
+we don't worry too much.
+
+The comments associated with
+ EXPECTED
+
+ assert_equal expected, normalize_comment(text)
+ end
+
+ def test_parse
+ assert_kind_of RDoc::Markup::Document, parse('hi')
+ end
+
+ def test_parse_document
+ assert_equal RDoc::Markup::Document.new, parse(RDoc::Markup::Document.new)
+ end
+
+ def test_parse_empty
+ assert_equal RDoc::Markup::Document.new, parse('')
+ end
+
+ def test_parse_empty_newline
+ assert_equal RDoc::Markup::Document.new, parse("#\n")
+ end
+
+ def test_parse_newline
+ assert_equal RDoc::Markup::Document.new, parse("\n")
+ end
+
+ def test_strip_hashes
+ text = <<-TEXT
+##
+# we don't worry too much.
+#
+# The comments associated with
+ TEXT
+
+ expected = <<-EXPECTED
+
+ we don't worry too much.
+
+ The comments associated with
+ EXPECTED
+
+ assert_equal expected, strip_hashes(text)
+ end
+
+ def test_strip_newlines
+ assert_equal ' ', strip_newlines("\n \n")
+
+ assert_equal 'hi', strip_newlines("\n\nhi")
+
+ assert_equal 'hi', strip_newlines( "hi\n\n")
+
+ assert_equal 'hi', strip_newlines("\n\nhi\n\n")
+ end
+
+ def test_strip_stars
+ text = <<-TEXT
+/*
+ * * we don't worry too much.
+ *
+ * The comments associated with
+ */
+ TEXT
+
+ expected = <<-EXPECTED
+
+ * we don't worry too much.
+
+ The comments associated with
+
+ EXPECTED
+
+ assert_equal expected, strip_stars(text)
+ end
+
+end
+
diff --git a/test/rdoc/test_rdoc_top_level.rb b/test/rdoc/test_rdoc_top_level.rb
new file mode 100644
index 0000000000..b96b74c182
--- /dev/null
+++ b/test/rdoc/test_rdoc_top_level.rb
@@ -0,0 +1,111 @@
+require 'rubygems'
+require 'minitest/autorun'
+require File.expand_path '../xref_test_case', __FILE__
+
+class TestRDocTopLevel < XrefTestCase
+
+ def setup
+ super
+
+ @top_level = RDoc::TopLevel.new 'path/top_level.rb'
+ end
+
+ def test_class_all_classes_and_modules
+ expected = %w[
+ C1 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1 M1 M1::M2
+ ]
+
+ assert_equal expected,
+ RDoc::TopLevel.all_classes_and_modules.map { |m| m.full_name }.sort
+ end
+
+ def test_class_classes
+ expected = %w[
+ C1 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1
+ ]
+
+ assert_equal expected, RDoc::TopLevel.classes.map { |m| m.full_name }.sort
+ end
+
+ def test_class_files
+ assert_equal %w[path/top_level.rb xref_data.rb],
+ RDoc::TopLevel.files.map { |m| m.full_name }.sort
+ end
+
+ def test_class_find_class_named
+ assert_equal @c1, RDoc::TopLevel.find_class_named('C1')
+
+ assert_equal @c2_c3, RDoc::TopLevel.find_class_named('C2::C3')
+ end
+
+ def test_class_find_class_named_from
+ assert_equal @c5_c1, RDoc::TopLevel.find_class_named_from('C1', 'C5')
+
+ assert_equal @c1, RDoc::TopLevel.find_class_named_from('C1', 'C4')
+ end
+
+ def test_class_find_class_or_module
+ assert_equal @m1, RDoc::TopLevel.find_class_or_module('M1')
+ assert_equal @c1, RDoc::TopLevel.find_class_or_module('C1')
+
+ assert_equal @m1, RDoc::TopLevel.find_class_or_module('::M1')
+ assert_equal @c1, RDoc::TopLevel.find_class_or_module('::C1')
+ end
+
+ def test_class_find_file_named
+ assert_equal @xref_data, RDoc::TopLevel.find_file_named(@file_name)
+ end
+
+ def test_class_find_module_named
+ assert_equal @m1, RDoc::TopLevel.find_module_named('M1')
+ assert_equal @m1_m2, RDoc::TopLevel.find_module_named('M1::M2')
+ end
+
+ def test_class_modules
+ assert_equal %w[M1 M1::M2],
+ RDoc::TopLevel.modules.map { |m| m.full_name }.sort
+ end
+
+ def test_class_reset
+ RDoc::TopLevel.reset
+
+ assert_empty RDoc::TopLevel.classes
+ assert_empty RDoc::TopLevel.modules
+ assert_empty RDoc::TopLevel.files
+ end
+
+ def test_base_name
+ assert_equal 'top_level.rb', @top_level.base_name
+ end
+
+ def test_find_class_or_module
+ assert_equal @c1, @xref_data.find_class_or_module('C1')
+ assert_equal @c2_c3, @xref_data.find_class_or_module('C2::C3')
+ assert_equal @c4, @xref_data.find_class_or_module('C4')
+ assert_equal @m1_m2, @xref_data.find_class_or_module('M1::M2')
+ end
+
+ def test_full_name
+ assert_equal 'path/top_level.rb', @top_level.full_name
+ end
+
+ def test_http_url
+ assert_equal 'prefix/path/top_level_rb.html', @top_level.http_url('prefix')
+ end
+
+ def test_last_modified
+ assert_equal 'Unknown', @top_level.last_modified
+
+ stat = Object.new
+ def stat.mtime() 0 end
+ @top_level.file_stat = stat
+
+ assert_equal '0', @top_level.last_modified
+ end
+
+ def test_name
+ assert_equal 'top_level.rb', @top_level.name
+ end
+
+end
+
diff --git a/test/rdoc/xref_data.rb b/test/rdoc/xref_data.rb
new file mode 100644
index 0000000000..38b2a0b2e2
--- /dev/null
+++ b/test/rdoc/xref_data.rb
@@ -0,0 +1,54 @@
+XREF_DATA = <<-XREF_DATA
+class C1
+
+ attr :attr
+ attr_reader :attr_reader
+ attr_writer :attr_writer
+ attr_accessor :attr_accessor
+
+ CONST = :const
+
+ def self.m
+ end
+
+ def m
+ end
+end
+
+class C2
+ class C3
+ def m
+ end
+
+ class H1
+ def m?
+ end
+ end
+ end
+end
+
+class C3
+ class H1
+ end
+
+ class H2 < H1
+ end
+end
+
+class C4
+ class C4
+ end
+end
+
+class C5
+ class C1
+ end
+end
+
+module M1
+end
+
+module M1::M2
+end
+XREF_DATA
+
diff --git a/test/rdoc/xref_test_case.rb b/test/rdoc/xref_test_case.rb
new file mode 100644
index 0000000000..285b5ea6a5
--- /dev/null
+++ b/test/rdoc/xref_test_case.rb
@@ -0,0 +1,53 @@
+ENV['RDOC_TEST'] = 'yes'
+
+require 'rubygems'
+require 'minitest/autorun'
+require 'rdoc'
+require 'rdoc/stats'
+require 'rdoc/options'
+require 'rdoc/code_objects'
+require 'rdoc/parser/ruby'
+require File.expand_path '../xref_data', __FILE__
+
+class XrefTestCase < MiniTest::Unit::TestCase
+
+ def setup
+ RDoc::TopLevel.reset
+ RDoc::AnyMethod.reset
+
+ @file_name = 'xref_data.rb'
+ @xref_data = RDoc::TopLevel.new @file_name
+
+ @options = RDoc::Options.new
+ @options.quiet = true
+
+ stats = RDoc::Stats.new 0
+
+ parser = RDoc::Parser::Ruby.new @xref_data, @file_name, XREF_DATA, @options,
+ stats
+ @top_levels = []
+ @top_levels.push parser.scan
+
+ generator = Object.new
+ def generator.class_dir() nil end
+ def generator.file_dir() nil end
+ rdoc = RDoc::RDoc.new
+ RDoc::RDoc.current = rdoc
+ rdoc.generator = generator
+
+ @c1 = @xref_data.find_module_named 'C1'
+ @c2 = @xref_data.find_module_named 'C2'
+ @c2_c3 = @xref_data.find_module_named 'C2::C3'
+ @c3 = @xref_data.find_module_named 'C3'
+ @c4 = @xref_data.find_module_named 'C4'
+ @c4_c4 = @xref_data.find_module_named 'C4::C4'
+ @c5_c1 = @xref_data.find_module_named 'C5::C1'
+ @c3_h1 = @xref_data.find_module_named 'C3::H1'
+ @c3_h2 = @xref_data.find_module_named 'C3::H2'
+
+ @m1 = @xref_data.find_module_named 'M1'
+ @m1_m2 = @xref_data.find_module_named 'M1::M2'
+ end
+
+end
+