Permalink
Browse files

Attach fully-qualified constants to their modules

Previously a comment assignment like A::B::C = 1 would place the comment
on Object.  Now the full name is parsed so the comment can be created
properly.

This has the downside of reducing coverage accidentally.  A follow-up
commit will be needed to fix the other bug.
  • Loading branch information...
1 parent 4879c4e commit f5951bb899d6f53844deb66c6a242f42f26c1e30 @drbrain drbrain committed Dec 6, 2012
Showing with 42 additions and 1 deletion.
  1. +7 −1 History.rdoc
  2. +14 −0 lib/rdoc/parser/ruby.rb
  3. +21 −0 test/test_rdoc_parser_ruby.rb
View
@@ -1,4 +1,4 @@
-=== 4.0.0.preview2
+=== 4.0.0.preview2.1 / ??
As a preview release, please file bugs for any problems you have with rdoc at
https://github.com/rdoc/rdoc/issues
@@ -10,6 +10,12 @@ Notable feature additions are markdown support and an WEBrick servlet that can
serve HTML from an ri store. (This means that RubyGems 2.0+ no longer needs
to build HTML documentation when installing gems.)
+* Bug fixes
+ * Fully qualified names for constants declared from the top level are now
+ attached to their class or module properly.
+
+=== 4.0.0.preview2 / 2012-12-01
+
* Breaking changes
* The default output encoding for RDoc is now UTF-8. Previously RDoc used
the default external encoding which was determined from your locale.
View
@@ -676,6 +676,20 @@ def parse_constant container, tk, comment
eq_tk = get_tk
+ case eq_tk
+ when TkASSIGN then
+ # continue
+ when TkCOLON2 then
+ unget_tk eq_tk
+ unget_tk tk
+
+ container, name_t, given_name = get_class_or_module container
+
+ name = name_t.name
+
+ eq_tk = get_tk
+ end
+
unless TkASSIGN === eq_tk then
unget_tk eq_tk
return false
@@ -1121,6 +1121,27 @@ def test_parse_constant_stopdoc
assert_empty klass.constants
end
+ def test_parse_comment_nested
+ content = <<-CONTENT
+A::B::C = 1
+ CONTENT
+
+ util_parser content
+
+ tk = @parser.get_tk
+
+ parsed = @parser.parse_constant @top_level, tk, 'comment'
+
+ assert parsed
+
+ a = @top_level.find_module_named 'A'
+ b = a.find_module_named 'B'
+ c = b.constants.first
+
+ assert_equal 'A::B::C', c.full_name
+ assert_equal 'comment', c.comment
+ end
+
def test_parse_include
klass = RDoc::NormalClass.new 'C'
klass.parent = @top_level

0 comments on commit f5951bb

Please sign in to comment.