2008-04-26 12:14:19 -04:00
|
|
|
require 'stringio'
|
2008-10-24 19:05:28 -04:00
|
|
|
require 'rubygems'
|
|
|
|
require 'minitest/unit'
|
2008-04-26 12:14:19 -04:00
|
|
|
require 'rdoc/ri/formatter'
|
|
|
|
require 'rdoc/ri/display'
|
|
|
|
require 'rdoc/ri/driver'
|
|
|
|
|
2008-10-24 19:05:28 -04:00
|
|
|
class TestRDocRiDefaultDisplay < MiniTest::Unit::TestCase
|
2008-04-26 12:14:19 -04:00
|
|
|
|
|
|
|
def setup
|
|
|
|
@output = StringIO.new
|
|
|
|
@width = 78
|
|
|
|
@indent = ' '
|
|
|
|
|
|
|
|
@dd = RDoc::RI::DefaultDisplay.new RDoc::RI::Formatter, @width, true,
|
|
|
|
@output
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
@some_method = h \
|
2008-04-26 12:14:19 -04:00
|
|
|
'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',
|
2008-07-17 20:46:16 -04:00
|
|
|
'visibility' => 'public'
|
2008-04-26 12:14:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_display_class_info
|
2008-07-17 20:46:16 -04:00
|
|
|
klass = h \
|
2008-04-26 12:14:19 -04:00
|
|
|
'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' => [
|
2008-09-24 22:43:03 -04:00
|
|
|
{ 'name' => 'CONSTANT', 'value' => '"value1"',
|
2008-04-26 12:14:19 -04:00
|
|
|
'comment' => [RDoc::Markup::Flow::P.new('CONSTANT value')] },
|
2008-09-24 22:43:03 -04:00
|
|
|
{ 'name' => 'CONSTANT_NOCOMMENT', 'value' => '"value2"',
|
2008-04-26 12:14:19 -04:00
|
|
|
'comment' => nil },
|
|
|
|
],
|
|
|
|
'display_name' => 'Class',
|
|
|
|
'full_name' => 'SomeClass',
|
|
|
|
'includes' => [],
|
|
|
|
'instance_methods' => [
|
|
|
|
{ 'name' => 'instance_method' },
|
2008-10-24 19:05:28 -04:00
|
|
|
{ 'name' => 'instance_method2' },
|
2008-04-26 12:14:19 -04:00
|
|
|
],
|
|
|
|
'instance_method_extensions' => [
|
|
|
|
{ 'name' => 'instance_method_extension' },
|
|
|
|
],
|
2008-10-24 19:05:28 -04:00
|
|
|
'superclass' => 'Object'
|
2008-04-26 12:14:19 -04:00
|
|
|
|
2008-09-24 22:43:03 -04:00
|
|
|
@dd.display_class_info klass
|
2008-04-26 12:14:19 -04:00
|
|
|
|
|
|
|
expected = <<-EOF
|
|
|
|
---------------------------------------------------- Class: SomeClass < Object
|
|
|
|
SomeClass comment
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
Constants:
|
|
|
|
----------
|
|
|
|
|
2008-09-24 22:43:03 -04:00
|
|
|
CONSTANT = "value1"
|
2008-04-26 12:14:19 -04:00
|
|
|
CONSTANT value
|
|
|
|
|
2008-09-24 22:43:03 -04:00
|
|
|
CONSTANT_NOCOMMENT = "value2"
|
|
|
|
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
-----------
|
|
|
|
|
|
|
|
attribute (RW):
|
|
|
|
attribute comment
|
|
|
|
|
|
|
|
attribute_no_comment (RW)
|
2008-04-26 12:14:19 -04:00
|
|
|
|
|
|
|
|
|
|
|
Class methods:
|
|
|
|
--------------
|
|
|
|
|
|
|
|
class_method
|
|
|
|
|
|
|
|
|
|
|
|
Class method extensions:
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
class_method_extension
|
|
|
|
|
|
|
|
|
|
|
|
Instance methods:
|
|
|
|
-----------------
|
|
|
|
|
2008-10-24 19:05:28 -04:00
|
|
|
instance_method, instance_method2
|
2008-04-26 12:14:19 -04:00
|
|
|
|
|
|
|
|
|
|
|
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| ...}
|
|
|
|
|
2008-09-24 22:43:03 -04:00
|
|
|
From /nonexistent
|
2008-04-26 12:14:19 -04:00
|
|
|
------------------------------------------------------------------------------
|
|
|
|
some comment
|
|
|
|
|
|
|
|
|
|
|
|
(also known as some_method_alias)
|
|
|
|
EOF
|
|
|
|
|
|
|
|
assert_equal expected, @output.string
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_display_method_info_singleton
|
2008-09-24 22:43:03 -04:00
|
|
|
method = RDoc::RI::Driver::OpenStructHash.new.update \
|
2008-04-26 12:14:19 -04:00
|
|
|
'aliases' => [],
|
|
|
|
'block_params' => nil,
|
|
|
|
'comment' => nil,
|
|
|
|
'full_name' => 'SomeClass::some_method',
|
|
|
|
'is_singleton' => true,
|
|
|
|
'name' => 'some_method',
|
|
|
|
'params' => '(arg1, arg2)',
|
2008-07-17 20:46:16 -04:00
|
|
|
'visibility' => 'public'
|
2008-04-26 12:14:19 -04:00
|
|
|
|
|
|
|
@dd.display_method_info method
|
|
|
|
|
|
|
|
expected = <<-EOF
|
|
|
|
------------------------------------------------------- SomeClass::some_method
|
|
|
|
SomeClass::some_method(arg1, arg2)
|
2008-09-24 22:43:03 -04:00
|
|
|
|
2009-03-06 22:31:32 -05:00
|
|
|
From
|
2008-04-26 12:14:19 -04:00
|
|
|
------------------------------------------------------------------------------
|
|
|
|
[no description]
|
|
|
|
EOF
|
|
|
|
|
|
|
|
assert_equal expected, @output.string
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_display_method_list
|
|
|
|
methods = [
|
2008-09-24 22:43:03 -04:00
|
|
|
RDoc::RI::Driver::OpenStructHash.new.update(
|
2008-04-26 12:14:19 -04:00
|
|
|
"aliases" => [],
|
|
|
|
"block_params" => nil,
|
|
|
|
"comment" => nil,
|
|
|
|
"full_name" => "SomeClass#some_method",
|
|
|
|
"is_singleton" => false,
|
|
|
|
"name" => "some_method",
|
|
|
|
"params" => "()",
|
2008-07-17 20:46:16 -04:00
|
|
|
"visibility" => "public"
|
|
|
|
),
|
2008-09-24 22:43:03 -04:00
|
|
|
RDoc::RI::Driver::OpenStructHash.new.update(
|
2008-04-26 12:14:19 -04:00
|
|
|
"aliases" => [],
|
|
|
|
"block_params" => nil,
|
|
|
|
"comment" => nil,
|
|
|
|
"full_name" => "SomeClass#some_other_method",
|
|
|
|
"is_singleton" => false,
|
|
|
|
"name" => "some_other_method",
|
|
|
|
"params" => "()",
|
2008-07-17 20:46:16 -04:00
|
|
|
"visibility" => "public"
|
|
|
|
),
|
2008-04-26 12:14:19 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
@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:
|
|
|
|
|
2008-09-24 22:43:03 -04:00
|
|
|
SomeClass#some_method []
|
|
|
|
SomeClass#some_other_method []
|
2008-04-26 12:14:19 -04:00
|
|
|
EOF
|
|
|
|
|
|
|
|
assert_equal expected, @output.string
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_display_params
|
|
|
|
@dd.display_params @some_method
|
|
|
|
|
|
|
|
expected = <<-EOF
|
|
|
|
some_method(arg1, arg2) {|block_param| ...}
|
|
|
|
|
2008-09-24 22:43:03 -04:00
|
|
|
From /nonexistent
|
2008-04-26 12:14:19 -04:00
|
|
|
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)
|
|
|
|
|
2008-09-24 22:43:03 -04:00
|
|
|
From /nonexistent
|
2008-04-26 12:14:19 -04:00
|
|
|
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| ...}
|
|
|
|
|
2008-09-24 22:43:03 -04:00
|
|
|
From /nonexistent
|
2008-04-26 12:14:19 -04:00
|
|
|
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
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
def h(hash)
|
2008-09-24 22:43:03 -04:00
|
|
|
RDoc::RI::Driver::OpenStructHash.convert hash
|
2008-07-17 20:46:16 -04:00
|
|
|
end
|
|
|
|
|
2008-04-26 12:14:19 -04:00
|
|
|
end
|
2008-10-24 19:05:28 -04:00
|
|
|
|
|
|
|
MiniTest::Unit.autorun
|