summaryrefslogtreecommitdiff
path: root/test/rdoc
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-13 07:58:47 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-13 07:58:47 +0000
commitd8c7695fbb2944aba9a69dce75f41b6881d1fc12 (patch)
treebe6a5904c879c9fa9a7c2556031064233e70880b /test/rdoc
parenta0046fe94972ba4873244a1b985cb69f1685b5f3 (diff)
* lib/rdoc/class_module.rb: Fixed duplicate comments for classes and
modules from C. * test/rdoc/test_rdoc_class_module.rb: Test for the above. * lib/rdoc/parser/c.rb: Reload C variable names to allow proper updates of an ri store for C files. * lib/rdoc/rdoc.rb: ditto. * lib/rdoc/store.rb: ditto. * test/rdoc/test_rdoc_parser_c.rb: Test for the above. * test/rdoc/test_rdoc_store.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38362 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rdoc')
-rw-r--r--test/rdoc/test_rdoc_class_module.rb10
-rw-r--r--test/rdoc/test_rdoc_parser_c.rb135
-rw-r--r--test/rdoc/test_rdoc_store.rb183
3 files changed, 286 insertions, 42 deletions
diff --git a/test/rdoc/test_rdoc_class_module.rb b/test/rdoc/test_rdoc_class_module.rb
index e5d855b2cd..670f732290 100644
--- a/test/rdoc/test_rdoc_class_module.rb
+++ b/test/rdoc/test_rdoc_class_module.rb
@@ -41,6 +41,16 @@ class TestRDocClassModule < XrefTestCase
assert_equal 'comment', cm.comment.text
end
+ def test_add_comment_duplicate
+ tl1 = @store.add_file 'one.rb'
+
+ cm = RDoc::ClassModule.new 'Klass'
+ cm.add_comment '# comment 1', tl1
+ cm.add_comment '# comment 2', tl1
+
+ assert_equal [['comment 2', tl1]], cm.comment_location
+ end
+
def test_add_comment_stopdoc
tl = @store.add_file 'file.rb'
diff --git a/test/rdoc/test_rdoc_parser_c.rb b/test/rdoc/test_rdoc_parser_c.rb
index e739476b74..bc93be803b 100644
--- a/test/rdoc/test_rdoc_parser_c.rb
+++ b/test/rdoc/test_rdoc_parser_c.rb
@@ -40,12 +40,6 @@ assert call-seq correct
=end
-class RDoc::Parser::C
- attr_accessor :classes
-
- public :do_classes, :do_constants
-end
-
class TestRDocParserC < RDoc::TestCase
def setup
@@ -83,6 +77,37 @@ class TestRDocParserC < RDoc::TestCase
assert_equal c_parser, c_parser.can_parse('file.y')
end
+ def test_initialize
+ some_ext = @top_level.add_class RDoc::NormalClass, 'SomeExt'
+ @top_level.add_class RDoc::SingleClass, 'SomeExtSingle'
+
+ @store.cache[:c_class_variables] = {
+ @fn => { 'cSomeExt' => 'SomeExt' }
+ }
+
+ @store.cache[:c_singleton_class_variables] = {
+ @fn => { 'cSomeExtSingle' => 'SomeExtSingle' }
+ }
+
+ parser = RDoc::Parser::C.new @top_level, @fn, '', @options, @stats
+
+ expected = { 'cSomeExt' => some_ext }
+ assert_equal expected, parser.classes
+
+ expected = { 'cSomeExtSingle' => 'SomeExtSingle' }
+ assert_equal expected, parser.singleton_classes
+
+ expected = {
+ 'cSomeExt' => 'SomeExt',
+ 'cSomeExtSingle' => 'SomeExtSingle',
+ }
+ known_classes = parser.known_classes.delete_if do |key, _|
+ RDoc::KNOWN_CLASSES.keys.include? key
+ end
+
+ assert_equal expected, known_classes
+ end
+
def test_do_attr_rb_attr
content = <<-EOF
void Init_Blah(void) {
@@ -1317,6 +1342,81 @@ void Init_Blah(void) {
assert_equal 'not_handled', @top_level.metadata['other']
end
+ def test_load_variable_map
+ some_ext = @top_level.add_class RDoc::NormalClass, 'SomeExt'
+ @top_level.add_class RDoc::NormalClass, 'OtherExt'
+
+ @store.cache[:c_class_variables][@fn] = { 'cSomeExt' => 'SomeExt' }
+ @store.cache[:c_class_variables]['other.c'] = { 'cOtherExt' => 'OtherExt' }
+
+ parser = util_parser
+
+ map = parser.load_variable_map :c_class_variables
+
+ expected = { 'cSomeExt' => some_ext }
+
+ assert_equal expected, map
+
+ assert_equal 'SomeExt', parser.known_classes['cSomeExt']
+ assert_nil parser.known_classes['cOtherExt']
+ end
+
+ def test_load_variable_map_empty
+ parser = util_parser
+
+ map = parser.load_variable_map :c_class_variables
+
+ assert_empty map
+ end
+
+ def test_load_variable_map_legacy
+ @store.cache[:c_class_variables] = nil
+
+ parser = util_parser
+
+ map = parser.load_variable_map :c_class_variables
+
+ assert_empty map
+ end
+
+ def test_load_variable_map_singleton
+ @top_level.add_class RDoc::NormalClass, 'SomeExt'
+ @top_level.add_class RDoc::NormalClass, 'OtherExt'
+
+ @store.cache[:c_singleton_class_variables][@fn] =
+ { 'cSomeExt' => 'SomeExt' }
+ @store.cache[:c_singleton_class_variables]['other.c'] =
+ { 'cOtherExt' => 'OtherExt' }
+
+ parser = util_parser
+
+ map = parser.load_variable_map :c_singleton_class_variables
+
+ expected = { 'cSomeExt' => 'SomeExt' }
+
+ assert_equal expected, map
+
+ assert_equal 'SomeExt', parser.known_classes['cSomeExt']
+ assert_nil parser.known_classes['cOtherExt']
+ end
+
+ def test_load_variable_map_trim
+ a = @top_level.add_class RDoc::NormalClass, 'A'
+
+ @store.cache[:c_class_variables][@fn] = {
+ 'cA' => 'A',
+ 'cB' => 'B',
+ }
+
+ parser = util_parser
+
+ map = parser.load_variable_map :c_class_variables
+
+ expected = { 'cA' => a }
+
+ assert_equal expected, map
+ end
+
def test_define_method
content = <<-EOF
/*Method Comment! */
@@ -1523,6 +1623,29 @@ Init_IO(void) {
parser.rb_scan_args('rb_scan_args(a, b, "*:&",)')
end
+ def test_scan
+ parser = util_parser <<-C
+void Init(void) {
+ mM = rb_define_module("M");
+ cC = rb_define_class("C", rb_cObject);
+ sC = rb_singleton_class(cC);
+}
+ C
+
+ parser.scan
+
+ expected = {
+ @fn => {
+ 'mM' => 'M',
+ 'cC' => 'C', }}
+ assert_equal expected, @store.c_class_variables
+
+ expected = {
+ @fn => {
+ 'sC' => 'C' } }
+ assert_equal expected, @store.c_singleton_class_variables
+ end
+
def test_scan_order_dependent
parser = util_parser <<-C
void a(void) {
diff --git a/test/rdoc/test_rdoc_store.rb b/test/rdoc/test_rdoc_store.rb
index a5a5adec7b..3b4f7cf2ff 100644
--- a/test/rdoc/test_rdoc_store.rb
+++ b/test/rdoc/test_rdoc_store.rb
@@ -18,6 +18,7 @@ class TestRDocStore < XrefTestCase
@klass = @top_level.add_class RDoc::NormalClass, 'Object'
@klass.add_comment 'original', @top_level
+ @klass.record_location @top_level
@cmeth = RDoc::AnyMethod.new nil, 'cmethod'
@cmeth.singleton = true
@@ -87,15 +88,17 @@ class TestRDocStore < XrefTestCase
@s.clean_cache_collection ancestors
expected = {
- :ancestors => ancestors,
- :attributes => attrs,
- :class_methods => cmethods,
- :encoding => nil,
- :instance_methods => imethods,
- :modules => modules,
- :pages => pages,
- :main => main,
- :title => title,
+ :ancestors => ancestors,
+ :attributes => attrs,
+ :class_methods => cmethods,
+ :c_class_variables => {},
+ :c_singleton_class_variables => {},
+ :encoding => nil,
+ :instance_methods => imethods,
+ :modules => modules,
+ :pages => pages,
+ :main => main,
+ :title => title,
}
@s.save_cache
@@ -115,6 +118,38 @@ class TestRDocStore < XrefTestCase
refute File.exist?(path), "#{path} exists"
end
+ def test_add_c_enclosure
+ @s.add_c_enclosure 'cC1', @c1
+
+ expected = { 'cC1' => @c1 }
+
+ assert_equal expected, @s.c_enclosure_classes
+ end
+
+ def test_add_c_variables
+ options = RDoc::Options.new
+
+ c_file = @s.add_file 'ext.c'
+
+ some_ext = c_file.add_class RDoc::NormalClass, 'SomeExt'
+ c_file.add_class RDoc::SingleClass, 'SomeExtSingle'
+
+ c_parser = RDoc::Parser::C.new c_file, 'ext.c', '', options, nil
+
+ c_parser.classes['cSomeExt'] = some_ext
+ c_parser.singleton_classes['s_cSomeExt'] = 'SomeExtSingle'
+
+ @s.add_c_variables c_parser
+
+ expected = { 'ext.c' => { 'cSomeExt' => 'SomeExt' } }
+
+ assert_equal expected, @s.c_class_variables
+
+ expected = { 'ext.c' => { 's_cSomeExt' => 'SomeExtSingle' } }
+
+ assert_equal expected, @s.c_singleton_class_variables
+ end
+
def test_add_file
top_level = @store.add_file 'file.rb'
@@ -214,6 +249,31 @@ class TestRDocStore < XrefTestCase
refute_empty a1.aliases
end
+ def test_find_c_enclosure
+ assert_nil @s.find_c_enclosure 'cC1'
+
+ @s.add_c_enclosure 'cC1', @c1
+
+ assert_equal @c1, @s.find_c_enclosure('cC1')
+ end
+
+ def test_find_c_enclosure_from_cache
+ @s.save_class @klass
+ @s.classes_hash.clear
+
+ assert_nil @s.find_c_enclosure 'cObject'
+
+ @s.c_enclosure_names['cObject'] = 'Object'
+
+ klass = @s.find_c_enclosure('cObject')
+ assert_equal @klass, klass
+
+ assert_empty klass.comment_location
+ assert_equal @top_level, klass.parent
+
+ assert_includes @s.c_enclosure_classes, 'cObject'
+ end
+
def test_find_class_named
assert_equal @c1, @store.find_class_named('C1')
@@ -329,11 +389,15 @@ class TestRDocStore < XrefTestCase
def test_load_cache
cache = {
- :encoding => :encoding_value,
- :methods => { "Object" => %w[Object#method] },
- :main => @page.full_name,
- :modules => %w[Object],
- :pages => [],
+ :c_class_variables =>
+ { 'file.c' => { 'cKlass' => 'Klass' } },
+ :c_singleton_class_variables =>
+ { 'file.c' => { 'sKlass' => 'KlassSingle' } },
+ :encoding => :encoding_value,
+ :methods => { "Object" => %w[Object#method] },
+ :main => @page.full_name,
+ :modules => %w[Object],
+ :pages => [],
}
Dir.mkdir @tmpdir
@@ -348,17 +412,28 @@ class TestRDocStore < XrefTestCase
assert_equal :encoding_value, @s.encoding
assert_equal 'README.txt', @s.main
+
+ expected = { 'file.c' => { 'cKlass' => 'Klass' } }
+ assert_equal expected, @s.cache[:c_class_variables]
+
+ expected = { 'file.c' => { 'sKlass' => 'KlassSingle' } }
+ assert_equal expected, @s.cache[:c_singleton_class_variables]
+
+ expected = { 'cKlass' => 'Klass' }
+ assert_equal expected, @s.c_enclosure_names
end
def test_load_cache_encoding_differs
skip "Encoding not implemented" unless Object.const_defined? :Encoding
cache = {
- :encoding => Encoding::ISO_8859_1,
- :main => nil,
- :methods => { "Object" => %w[Object#method] },
- :modules => %w[Object],
- :pages => [],
+ :c_class_variables => {},
+ :c_singleton_class_variables => {},
+ :encoding => Encoding::ISO_8859_1,
+ :main => nil,
+ :methods => { "Object" => %w[Object#method] },
+ :modules => %w[Object],
+ :pages => [],
}
Dir.mkdir @tmpdir
@@ -378,15 +453,17 @@ class TestRDocStore < XrefTestCase
def test_load_cache_no_cache
cache = {
- :ancestors => {},
- :attributes => {},
- :class_methods => {},
- :encoding => nil,
- :instance_methods => {},
- :main => nil,
- :modules => [],
- :pages => [],
- :title => nil,
+ :ancestors => {},
+ :attributes => {},
+ :class_methods => {},
+ :c_class_variables => {},
+ :c_singleton_class_variables => {},
+ :encoding => nil,
+ :instance_methods => {},
+ :main => nil,
+ :modules => [],
+ :pages => [],
+ :title => nil,
}
@s.load_cache
@@ -404,6 +481,8 @@ class TestRDocStore < XrefTestCase
:modules => %w[Object],
# no :pages
# no :main
+ # no :c_class_variables
+ # no :c_singleton_class_variables
}
Dir.mkdir @tmpdir
@@ -415,14 +494,16 @@ class TestRDocStore < XrefTestCase
@s.load_cache
expected = {
- :ancestors => {},
- :attributes => {},
- :class_methods => {},
- :encoding => :encoding_value,
- :instance_methods => { "Object" => %w[Object#method] },
- :main => nil,
- :modules => %w[Object],
- :pages => [],
+ :ancestors => {},
+ :attributes => {},
+ :class_methods => {},
+ :c_class_variables => {},
+ :c_singleton_class_variables => {},
+ :encoding => :encoding_value,
+ :instance_methods => { "Object" => %w[Object#method] },
+ :main => nil,
+ :modules => %w[Object],
+ :pages => [],
}
assert_equal expected, @s.cache
@@ -534,6 +615,8 @@ class TestRDocStore < XrefTestCase
},
:attributes => { 'Object' => ['attr_accessor attr'] },
:class_methods => { 'Object' => %w[cmethod] },
+ :c_class_variables => {},
+ :c_singleton_class_variables => {},
:instance_methods => {
'Object' => %w[attr method method! method_bang],
'Object::SubClass' => %w[method],
@@ -564,16 +647,44 @@ class TestRDocStore < XrefTestCase
@s.main = @page.full_name
@s.title = 'title'
+ options = RDoc::Options.new
+
+ c_file = @s.add_file 'ext.c'
+
+ some_ext = c_file.add_class RDoc::NormalClass, 'SomeExt'
+ c_file.add_class RDoc::SingleClass, 'SomeExtSingle'
+
+ c_parser = RDoc::Parser::C.new c_file, 'ext.c', '', options, nil
+
+ c_parser.classes['cSomeExt'] = some_ext
+ c_parser.singleton_classes['s_cSomeExt'] = 'SomeExtSingle'
+
+ @s.add_c_variables c_parser
+
@s.save_cache
assert_file File.join(@tmpdir, 'cache.ri')
+ c_class_variables = {
+ 'ext.c' => {
+ 'cSomeExt' => 'SomeExt'
+ }
+ }
+
+ c_singleton_class_variables = {
+ 'ext.c' => {
+ 's_cSomeExt' => 'SomeExtSingle'
+ }
+ }
+
expected = {
:ancestors => {
'Object::SubClass' => %w[Incl Object],
},
:attributes => { 'Object' => ['attr_accessor attr'] },
:class_methods => { 'Object' => %w[cmethod] },
+ :c_class_variables => c_class_variables,
+ :c_singleton_class_variables => c_singleton_class_variables,
:instance_methods => {
'Object' => %w[method method! method_bang],
'Object::SubClass' => %w[method],