aboutsummaryrefslogtreecommitdiffstats
path: root/test/rdoc
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-29 21:17:31 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-29 21:17:31 +0000
commite75e7fcc9f90d41ae14019c0f3b5d5048badbb5a (patch)
tree3611123592f58ecbf7c0ff8d54b22b5fcdeb60f1 /test/rdoc
parent6f1ce28d624007f1d7688865a782c3ba4ad376a0 (diff)
downloadruby-e75e7fcc9f90d41ae14019c0f3b5d5048badbb5a.tar.gz
* lib/rdoc: Update to RDoc 3.8 which contains fixes for documentation
in trunk. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32305 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rdoc')
-rw-r--r--test/rdoc/test_rdoc_class_module.rb38
-rw-r--r--test/rdoc/test_rdoc_parser_ruby.rb292
-rw-r--r--test/rdoc/test_rdoc_ri_store.rb27
-rw-r--r--test/rdoc/test_rdoc_top_level.rb81
4 files changed, 435 insertions, 3 deletions
diff --git a/test/rdoc/test_rdoc_class_module.rb b/test/rdoc/test_rdoc_class_module.rb
index 1ac0eda298..7d32a91580 100644
--- a/test/rdoc/test_rdoc_class_module.rb
+++ b/test/rdoc/test_rdoc_class_module.rb
@@ -40,6 +40,17 @@ class TestRDocClassModule < XrefTestCase
assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment
end
+ def test_add_comment_stopdoc
+ tl = RDoc::TopLevel.new 'file.rb'
+
+ cm = RDoc::ClassModule.new 'Klass'
+ cm.stop_doc
+
+ cm.add_comment '# comment 1', tl
+
+ assert_empty cm.comment
+ end
+
def test_ancestors
assert_equal [@parent], @child.ancestors
end
@@ -258,6 +269,33 @@ class TestRDocClassModule < XrefTestCase
assert_equal expected, cm1.attributes.sort
end
+ def test_merge_collections_drop
+ tl = RDoc::TopLevel.new 'file'
+
+ cm1 = RDoc::ClassModule.new 'C'
+ cm1.record_location tl
+
+ const = cm1.add_constant RDoc::Constant.new('CONST', nil, nil)
+ const.record_location tl
+
+ cm2 = RDoc::ClassModule.new 'C'
+ cm2.record_location tl
+
+ added = []
+ removed = []
+
+ cm1.merge_collections cm1.constants, cm2.constants, cm2.in_files do |add, c|
+ if add then
+ added << c
+ else
+ removed << c
+ end
+ end
+
+ assert_empty added
+ assert_equal [const], removed
+ end
+
def test_merge_comment
tl1 = RDoc::TopLevel.new 'one.rb'
tl2 = RDoc::TopLevel.new 'two.rb'
diff --git a/test/rdoc/test_rdoc_parser_ruby.rb b/test/rdoc/test_rdoc_parser_ruby.rb
index e02ed56beb..4904d5dfca 100644
--- a/test/rdoc/test_rdoc_parser_ruby.rb
+++ b/test/rdoc/test_rdoc_parser_ruby.rb
@@ -437,6 +437,21 @@ class C; end
assert alas.singleton
end
+ def test_parse_alias_stopdoc
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+ klass.stop_doc
+
+ util_parser "alias :next= :bar"
+
+ tk = @parser.get_tk
+
+ @parser.parse_alias klass, RDoc::Parser::Ruby::NORMAL, tk, 'comment'
+
+ assert_empty klass.aliases
+ assert_empty klass.unmatched_alias_lists
+ end
+
def test_parse_alias_meta
klass = RDoc::NormalClass.new 'Foo'
klass.parent = @top_level
@@ -472,6 +487,22 @@ class C; end
assert_equal 1, foo.line
end
+ def test_parse_attr_stopdoc
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+ klass.stop_doc
+
+ 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_empty klass.attributes
+ end
+
def test_parse_attr_accessor
klass = RDoc::NormalClass.new 'Foo'
klass.parent = @top_level
@@ -515,6 +546,22 @@ class C; end
assert_equal 0, klass.attributes.length
end
+ def test_parse_attr_accessor_stopdoc
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+ klass.stop_doc
+
+ 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_empty klass.attributes
+ end
+
def test_parse_attr_accessor_writer
klass = RDoc::NormalClass.new 'Foo'
klass.parent = @top_level
@@ -620,6 +667,22 @@ class C; end
assert_equal @top_level, foo.file
end
+ def test_parse_meta_attr_stopdoc
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+ klass.stop_doc
+
+ 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_empty klass.attributes
+ end
+
def test_parse_meta_attr_writer
klass = RDoc::NormalClass.new 'Foo'
klass.parent = @top_level
@@ -640,7 +703,7 @@ class C; end
end
def test_parse_class
- comment = "##\n# my method\n"
+ comment = "##\n# my class\n"
util_parser "class Foo\nend"
@@ -650,7 +713,7 @@ class C; end
foo = @top_level.classes.first
assert_equal 'Foo', foo.full_name
- assert_equal 'my method', foo.comment
+ assert_equal 'my class', foo.comment
assert_equal [@top_level], foo.in_files
assert_equal 0, foo.offset
assert_equal 1, foo.line
@@ -706,6 +769,42 @@ end
assert_equal 2, foo.method_list.length
end
+ def test_parse_class_nodoc
+ comment = "##\n# my class\n"
+
+ util_parser "class Foo # :nodoc:\nend"
+
+ tk = @parser.get_tk
+
+ @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ foo = @top_level.classes.first
+ assert_equal 'Foo', foo.full_name
+ assert_empty foo.comment
+ assert_equal [@top_level], foo.in_files
+ assert_equal 0, foo.offset
+ assert_equal 1, foo.line
+ end
+
+ def test_parse_class_stopdoc
+ @top_level.stop_doc
+
+ comment = "##\n# my class\n"
+
+ util_parser "class Foo\nend"
+
+ tk = @parser.get_tk
+
+ @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ foo = @top_level.classes.first
+ assert_equal 'Foo', foo.full_name
+ assert_equal 'my class', foo.comment
+ assert_equal [@top_level], foo.in_files
+ assert_equal 0, foo.offset
+ assert_equal 1, foo.line
+ end
+
def test_parse_multi_ghost_methods
util_parser <<-'CLASS'
class Foo
@@ -785,6 +884,38 @@ end
assert_equal 'my module', foo.comment
end
+ def test_parse_module_nodoc
+ @top_level.stop_doc
+
+ comment = "##\n# my module\n"
+
+ util_parser "module Foo # :nodoc:\nend"
+
+ tk = @parser.get_tk
+
+ @parser.parse_module @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ foo = @top_level.modules.first
+ assert_equal 'Foo', foo.full_name
+ assert_empty foo.comment
+ end
+
+ def test_parse_module_stopdoc
+ @top_level.stop_doc
+
+ comment = "##\n# my module\n"
+
+ util_parser "module Foo\nend"
+
+ tk = @parser.get_tk
+
+ @parser.parse_module @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ foo = @top_level.modules.first
+ assert_equal 'Foo', foo.full_name
+ assert_equal 'my module', foo.comment
+ end
+
def test_parse_class_colon3
code = <<-CODE
class A
@@ -976,6 +1107,22 @@ EOF
assert_equal klass.current_section, foo.section
end
+ def test_parse_comment_attr_stopdoc
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+ klass.stop_doc
+
+ comment = "##\n# :attr: foo\n# my attr\n"
+
+ util_parser "\n"
+
+ tk = @parser.get_tk
+
+ @parser.parse_comment klass, tk, comment
+
+ assert_empty klass.attributes
+ end
+
def test_parse_comment_method
klass = RDoc::NormalClass.new 'Foo'
klass.parent = @top_level
@@ -1021,6 +1168,22 @@ EOF
assert_equal stream, foo.token_stream
end
+ def test_parse_comment_method_stopdoc
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+ klass.stop_doc
+
+ comment = "##\n# :method: foo\n# my method\n"
+
+ util_parser "\n"
+
+ tk = @parser.get_tk
+
+ @parser.parse_comment klass, tk, comment
+
+ assert_empty klass.method_list
+ end
+
def test_parse_constant
util_top_level
@@ -1084,6 +1247,21 @@ EOF
assert_equal top_bar, bar.find_module_named('A')
end
+ def test_parse_constant_stopdoc
+ util_top_level
+
+ klass = @top_level.add_class RDoc::NormalClass, 'Foo'
+ klass.stop_doc
+
+ util_parser "A = v"
+
+ tk = @parser.get_tk
+
+ @parser.parse_constant klass, tk, ''
+
+ assert_empty klass.constants
+ end
+
def test_parse_include
klass = RDoc::NormalClass.new 'C'
klass.parent = @top_level
@@ -1249,6 +1427,22 @@ end
assert_equal @top_level, foo.file
end
+ def test_parse_meta_method_stopdoc
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+ klass.stop_doc
+
+ comment = "##\n# my method\n"
+
+ util_parser "add_my_method :foo, :bar\nadd_my_method :baz"
+
+ tk = @parser.get_tk
+
+ @parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ assert_empty klass.method_list
+ end
+
def test_parse_meta_method_unknown
klass = RDoc::NormalClass.new 'Foo'
comment = "##\n# my method\n"
@@ -1464,6 +1658,22 @@ end
assert_equal '(arg1, arg2, arg3)', foo.params
end
+ def test_parse_method_stopdoc
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+ klass.stop_doc
+
+ comment = "##\n# my method\n"
+
+ util_parser "def foo() :bar end"
+
+ tk = @parser.get_tk
+
+ @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ assert_empty klass.method_list
+ end
+
def test_parse_method_toplevel
klass = @top_level
@@ -1879,6 +2089,69 @@ end
assert_equal 1, @top_level.requires.length
end
+ def test_parse_statements_stopdoc_TkALIAS
+ util_top_level
+
+ klass = @top_level.add_class RDoc::NormalClass, 'Foo'
+
+ util_parser "\n# :stopdoc:\nalias old new"
+
+ @parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil
+
+ assert_empty klass.aliases
+ assert_empty klass.unmatched_alias_lists
+ end
+
+ def test_parse_statements_stopdoc_TkIDENTIFIER_alias_method
+ util_top_level
+
+ klass = @top_level.add_class RDoc::NormalClass, 'Foo'
+
+ util_parser "\n# :stopdoc:\nalias_method :old :new"
+
+ @parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil
+
+ assert_empty klass.aliases
+ assert_empty klass.unmatched_alias_lists
+ end
+
+ def test_parse_statements_stopdoc_TkIDENTIFIER_metaprogrammed
+ util_top_level
+
+ klass = @top_level.add_class RDoc::NormalClass, 'Foo'
+
+ util_parser "\n# :stopdoc:\n# attr :meta"
+
+ @parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil
+
+ assert_empty klass.method_list
+ assert_empty klass.attributes
+ end
+
+ def test_parse_statements_stopdoc_TkCONSTANT
+ util_top_level
+
+ klass = @top_level.add_class RDoc::NormalClass, 'Foo'
+
+ util_parser "\n# :stopdoc:\nA = v"
+
+ @parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil
+
+ assert_empty klass.constants
+ end
+
+ def test_parse_statements_stopdoc_TkDEF
+ util_top_level
+
+ klass = @top_level.add_class RDoc::NormalClass, 'Foo'
+
+ util_parser "\n# :stopdoc:\ndef m\n end"
+
+ @parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil
+
+ assert_empty klass.method_list
+ end
+
def test_parse_statements_while_begin
util_parser <<-RUBY
class A
@@ -1924,7 +2197,7 @@ end
assert_equal nil, @parser.parse_symbol_in_arg
end
- def test_parse_top_level_statements_alias_method
+ def test_parse_statements_alias_method
content = <<-CONTENT
class A
alias_method :a, :[] unless c
@@ -1939,6 +2212,19 @@ end
util_parser content
@parser.parse_statements @top_level
+
+ # HACK where are the assertions?
+ end
+
+ def test_parse_top_level_statements_stopdoc
+ @top_level.stop_doc
+ content = "# this is the top-level comment"
+
+ util_parser content
+
+ @parser.parse_top_level_statements @top_level
+
+ assert_empty @top_level.comment
end
def test_parse_yield_in_braces_with_parens
diff --git a/test/rdoc/test_rdoc_ri_store.rb b/test/rdoc/test_rdoc_ri_store.rb
index 1077383d86..23e441b633 100644
--- a/test/rdoc/test_rdoc_ri_store.rb
+++ b/test/rdoc/test_rdoc_ri_store.rb
@@ -1,5 +1,6 @@
require 'rubygems'
require 'minitest/autorun'
+require 'rdoc/rdoc'
require 'rdoc/ri'
require 'rdoc/markup'
require 'tmpdir'
@@ -392,6 +393,32 @@ class TestRDocRIStore < MiniTest::Unit::TestCase
assert_equal document, s.load_class('Object').comment
end
+ # This is a functional test
+ def test_save_class_merge_constant
+ tl = RDoc::TopLevel.new 'file.rb'
+ klass = RDoc::NormalClass.new 'C'
+ klass.add_comment 'comment', tl
+
+ const = klass.add_constant RDoc::Constant.new('CONST', nil, nil)
+ const.record_location tl
+
+ @s.save_class klass
+
+ RDoc::RDoc.reset
+
+ klass2 = RDoc::NormalClass.new 'C'
+ klass2.record_location tl
+
+ s = RDoc::RI::Store.new @tmpdir
+ s.save_class klass2
+
+ s = RDoc::RI::Store.new @tmpdir
+
+ result = s.load_class 'C'
+
+ assert_empty result.constants
+ end
+
def test_save_class_methods
@s.save_class @klass
diff --git a/test/rdoc/test_rdoc_top_level.rb b/test/rdoc/test_rdoc_top_level.rb
index 6c1bc43e7a..9e68bc4bdd 100644
--- a/test/rdoc/test_rdoc_top_level.rb
+++ b/test/rdoc/test_rdoc_top_level.rb
@@ -98,6 +98,87 @@ class TestRDocTopLevel < XrefTestCase
assert_empty RDoc::TopLevel.files
end
+ def test_add_alias
+ a = RDoc::Alias.new nil, 'old', 'new', nil
+ @top_level.add_alias a
+
+ object = RDoc::TopLevel.find_class_named 'Object'
+ expected = { '#old' => [a] }
+ assert_equal expected, object.unmatched_alias_lists
+ assert_includes object.in_files, @top_level
+ end
+
+ def test_add_alias_nodoc
+ @top_level.document_self = false
+
+ a = RDoc::Alias.new nil, 'old', 'new', nil
+ @top_level.add_alias a
+
+ object = RDoc::TopLevel.find_class_named('Object')
+ assert_empty object.unmatched_alias_lists
+ assert_includes object.in_files, @top_level
+ end
+
+ def test_add_constant
+ const = RDoc::Constant.new 'C', nil, nil
+ @top_level.add_constant const
+
+ object = RDoc::TopLevel.find_class_named 'Object'
+ assert_equal [const], object.constants
+ assert_includes object.in_files, @top_level
+ end
+
+ def test_add_constant_nodoc
+ @top_level.document_self = false
+
+ const = RDoc::Constant.new 'C', nil, nil
+ @top_level.add_constant const
+
+ object = RDoc::TopLevel.find_class_named 'Object'
+ assert_empty object.constants
+ assert_includes object.in_files, @top_level
+ end
+
+ def test_add_include
+ include = RDoc::Include.new 'C', nil
+ @top_level.add_include include
+
+ object = RDoc::TopLevel.find_class_named 'Object'
+ assert_equal [include], object.includes
+ assert_includes object.in_files, @top_level
+ end
+
+ def test_add_include_nodoc
+ @top_level.document_self = false
+
+ include = RDoc::Include.new 'C', nil
+ @top_level.add_include include
+
+ object = RDoc::TopLevel.find_class_named('Object')
+ assert_empty object.includes
+ assert_includes object.in_files, @top_level
+ end
+
+ def test_add_method
+ method = RDoc::AnyMethod.new nil, 'm'
+ @top_level.add_method method
+
+ object = RDoc::TopLevel.find_class_named 'Object'
+ assert_equal [method], object.method_list
+ assert_includes object.in_files, @top_level
+ end
+
+ def test_add_method_stopdoc
+ @top_level.document_self = false
+
+ method = RDoc::AnyMethod.new nil, 'm'
+ @top_level.add_method method
+
+ object = RDoc::TopLevel.find_class_named('Object')
+ assert_empty object.method_list
+ assert_includes object.in_files, @top_level
+ end
+
def test_base_name
assert_equal 'top_level.rb', @top_level.base_name
end