summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-04-26 16:14:19 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-04-26 16:14:19 +0000
commitc42a631063e79fab2369c1983a6f2a075b584f62 (patch)
tree2ea8c0381d5d491a5f46e210239e1494df57d240 /test
parent2142a5af51ce882641a060e69bc58c7322ff5188 (diff)
Import RDoc 2.0.0 r56.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16212 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/rdoc/test_rdoc_c_parser.rb2
-rw-r--r--test/rdoc/test_rdoc_markup_attribute_manager.rb47
-rw-r--r--test/rdoc/test_rdoc_ri_default_display.rb295
-rw-r--r--test/rdoc/test_rdoc_ri_formatter.rb37
4 files changed, 342 insertions, 39 deletions
diff --git a/test/rdoc/test_rdoc_c_parser.rb b/test/rdoc/test_rdoc_c_parser.rb
index ef686daed4..6cbb2c92dc 100644
--- a/test/rdoc/test_rdoc_c_parser.rb
+++ b/test/rdoc/test_rdoc_c_parser.rb
@@ -226,7 +226,7 @@ VALUE foo = rb_define_class("Foo", rb_cObject);
assert_equal " \n a comment for class Foo\n ", klass.comment
end
- def test_find_class_comment_define_class
+ def test_find_class_comment_define_class_Init_Foo
content = <<-EOF
/*
* a comment for class Foo on Init
diff --git a/test/rdoc/test_rdoc_markup_attribute_manager.rb b/test/rdoc/test_rdoc_markup_attribute_manager.rb
index 8e66b6b936..8ba9d7440a 100644
--- a/test/rdoc/test_rdoc_markup_attribute_manager.rb
+++ b/test/rdoc/test_rdoc_markup_attribute_manager.rb
@@ -43,6 +43,29 @@ class TestRDocMarkupAttributeManager < Test::Unit::TestCase
#assert_equal(["cat {and} dog" ], @am.flow("cat \\{and} dog"))
end
+ 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?('&')
+ end
+
+ def test_add_word_pair_angle
+ e = assert_raise ArgumentError do
+ @am.add_word_pair '<', '>', 'angles'
+ end
+
+ assert_equal "Word flags may not start with '<'", e.message
+ end
+
+ 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?('^')
+ end
+
def test_basic
assert_equal(["cat"], @am.flow("cat"))
@@ -79,7 +102,6 @@ class TestRDocMarkupAttributeManager < Test::Unit::TestCase
assert_equal(["cat ", @em_on, "_", @em_off, " dog"],
@am.flow("cat ___ dog"))
-
end
def test_bold
@@ -101,6 +123,29 @@ class TestRDocMarkupAttributeManager < Test::Unit::TestCase
@am.flow("cat _a__nd_ *dog*"))
end
+ def test_convert_attrs
+ str = '+foo+'
+ attrs = RDoc::Markup::AttrSpan.new str.length
+
+ @am.convert_attrs str, attrs
+
+ assert_equal "\000foo\000", str
+
+ str = '+:foo:+'
+ attrs = RDoc::Markup::AttrSpan.new str.length
+
+ @am.convert_attrs str, attrs
+
+ assert_equal "\000:foo:\000", str
+
+ str = '+x-y+'
+ attrs = RDoc::Markup::AttrSpan.new str.length
+
+ @am.convert_attrs str, attrs
+
+ assert_equal "\000x-y\000", str
+ end
+
def test_html_like_em_bold
assert_equal ["cat ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
@am.flow("cat <i>and </i><b>dog</b>")
diff --git a/test/rdoc/test_rdoc_ri_default_display.rb b/test/rdoc/test_rdoc_ri_default_display.rb
new file mode 100644
index 0000000000..d92516f3ab
--- /dev/null
+++ b/test/rdoc/test_rdoc_ri_default_display.rb
@@ -0,0 +1,295 @@
+require 'stringio'
+require 'test/unit'
+require 'rdoc/ri/formatter'
+require 'rdoc/ri/display'
+require 'rdoc/ri/driver'
+
+class TestRDocRIDefaultDisplay < Test::Unit::TestCase
+
+ def setup
+ @output = StringIO.new
+ @width = 78
+ @indent = ' '
+
+ @dd = RDoc::RI::DefaultDisplay.new RDoc::RI::Formatter, @width, true,
+ @output
+
+ @some_method = {
+ '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
+ ri_reader = nil
+ klass = {
+ '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' => '"value"',
+ 'comment' => [RDoc::Markup::Flow::P.new('CONSTANT value')] },
+ { 'name' => 'CONSTANT_NOCOMMENT', 'value' => '"value"',
+ 'comment' => nil },
+ ],
+ 'display_name' => 'Class',
+ 'full_name' => 'SomeClass',
+ 'includes' => [],
+ 'instance_methods' => [
+ { 'name' => 'instance_method' },
+ ],
+ 'instance_method_extensions' => [
+ { 'name' => 'instance_method_extension' },
+ ],
+ 'superclass_string' => 'Object',
+ }
+
+ @dd.display_class_info klass, ri_reader
+
+ expected = <<-EOF
+---------------------------------------------------- Class: SomeClass < Object
+ SomeClass comment
+
+------------------------------------------------------------------------------
+
+
+Constants:
+----------
+
+ CONSTANT:
+ CONSTANT value
+
+ CONSTANT_NOCOMMENT
+
+
+Class methods:
+--------------
+
+ class_method
+
+
+Class method extensions:
+------------------------
+
+ class_method_extension
+
+
+Instance methods:
+-----------------
+
+ instance_method
+
+
+Instance method extensions:
+---------------------------
+
+ instance_method_extension
+
+
+Attributes:
+-----------
+
+ attribute (RW):
+ attribute comment
+
+ attribute_no_comment (RW)
+ 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| ...}
+
+ Extension from /nonexistent
+------------------------------------------------------------------------------
+ some comment
+
+
+ (also known as some_method_alias)
+ EOF
+
+ assert_equal expected, @output.string
+ end
+
+ def test_display_method_info_singleton
+ method = {
+ '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)
+------------------------------------------------------------------------------
+ [no description]
+ EOF
+
+ assert_equal expected, @output.string
+ end
+
+ def test_display_method_list
+ methods = [
+ {
+ "aliases" => [],
+ "block_params" => nil,
+ "comment" => nil,
+ "full_name" => "SomeClass#some_method",
+ "is_singleton" => false,
+ "name" => "some_method",
+ "params" => "()",
+ "visibility" => "public",
+ },
+ {
+ "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| ...}
+
+ Extension 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)
+
+ Extension 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| ...}
+
+ Extension 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
+
+end
+
diff --git a/test/rdoc/test_rdoc_ri_formatter.rb b/test/rdoc/test_rdoc_ri_formatter.rb
index b5bc2d3245..ed2ccba22d 100644
--- a/test/rdoc/test_rdoc_ri_formatter.rb
+++ b/test/rdoc/test_rdoc_ri_formatter.rb
@@ -149,43 +149,6 @@ class TestRDocRIFormatter < Test::Unit::TestCase
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')