Skip to content

Commit 725d921

Browse files
committed
Fix rdoc -C for ignored classes and modules.
Add missing documentation
1 parent ec4de39 commit 725d921

File tree

6 files changed

+95
-13
lines changed

6 files changed

+95
-13
lines changed

lib/rdoc/rd/block_parser.ry

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ end
526526
private :set_term_to_element
527527

528528
##
529-
# Raises a ParseError
529+
# Raises a ParseError when invalid formatting is found
530530

531531
def on_error(et, ev, _values)
532532
prv, cur, nxt = format_line_num(@i, @i+1, @i+2)

lib/rdoc/rd/inline_parser.ry

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -422,25 +422,28 @@ OTHER_RE = Regexp.new(
422422

423423
# :startdoc:
424424

425+
##
426+
# Creates a new parser for inline markup in the rd format. The +block_parser+
427+
# is used to for footnotes and labels in the inline text.
428+
425429
def initialize block_parser
426430
@block_parser = block_parser
427431
end
428432

433+
##
434+
# Parses the +inline+ text from RD format into RDoc format.
435+
429436
def parse inline
430437
@inline = inline
431438
@src = StringScanner.new inline
432439
@pre = ""
433440
@yydebug = true
434441
do_parse.to_s
435-
rescue
436-
puts $!
437-
puts
438-
puts @inline[0, @src.pos].inspect
439-
puts @src.rest[0..40]
440-
puts
441-
raise
442442
end
443443

444+
##
445+
# Returns the next token from the inline text
446+
444447
def next_token
445448
return [false, false] if @src.eos?
446449
# p @src.rest if @yydebug
@@ -518,6 +521,9 @@ def next_token
518521
end
519522
end
520523

524+
##
525+
# Raises a ParseError when invalid formatting is found
526+
521527
def on_error(et, ev, values)
522528
lines_of_rest = @src.rest.lines.to_a.length
523529
prev_words = prev_words_on_error(ev)
@@ -532,6 +538,9 @@ RD syntax error: line #{@block_parser.line_index - lines_of_rest}:
532538
raise ParseError, message
533539
end
534540

541+
##
542+
# Returns words before the error
543+
535544
def prev_words_on_error(ev)
536545
pre = @pre
537546
if ev and /#{Regexp.quote(ev)}$/ =~ pre
@@ -540,6 +549,9 @@ def prev_words_on_error(ev)
540549
last_line(pre)
541550
end
542551

552+
##
553+
# Returns the last line of +src+
554+
543555
def last_line(src)
544556
if n = src.rindex("\n")
545557
src[(n+1) .. -1]
@@ -549,6 +561,9 @@ def last_line(src)
549561
end
550562
private :last_line
551563

564+
##
565+
# Returns words following an error
566+
552567
def next_words_on_error
553568
if n = @src.rest.index("\n")
554569
@src.rest[0 .. (n-1)]
@@ -557,6 +572,9 @@ def next_words_on_error
557572
end
558573
end
559574

575+
##
576+
# Creates a new RDoc::RD::Inline for the +rdoc+ markup and the raw +reference+
577+
560578
def inline rdoc, reference = rdoc
561579
RDoc::RD::Inline.new rdoc, reference
562580
end

lib/rdoc/ruby_lex.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020

2121
class RDoc::RubyLex
2222

23-
# :stopdoc:
24-
2523
##
2624
# Raised upon invalid input
2725

2826
class Error < RDoc::Error
2927
end
3028

29+
# :stopdoc:
30+
3131
extend Exception2MessageMapper
3232

3333
def_exception(:AlreadyDefinedToken, "Already defined token(%s)")
@@ -55,11 +55,17 @@ def self.debug?
5555
end
5656

5757
self.debug_level = 0
58+
59+
# :startdoc:
5860

59-
def self.tokenize text, options
61+
##
62+
# Returns an Array of +ruby+ tokens. See ::new for a description of
63+
# +options+.
64+
65+
def self.tokenize ruby, options
6066
tokens = []
6167

62-
scanner = RDoc::RubyLex.new text, options
68+
scanner = RDoc::RubyLex.new ruby, options
6369
scanner.exception_on_syntax_error = true
6470

6571
while token = scanner.token do
@@ -69,6 +75,10 @@ def self.tokenize text, options
6975
tokens
7076
end
7177

78+
##
79+
# Creates a new lexer for +content+. +options+ is an RDoc::Options, only
80+
# +tab_width is used.
81+
7282
def initialize(content, options)
7383
lex_init
7484

@@ -112,6 +122,8 @@ def initialize(content, options)
112122
@ltype = nil
113123
end
114124

125+
# :stopdoc:
126+
115127
def inspect # :nodoc:
116128
"#<%s:0x%x pos %d lex_state %p space_seen %p>" % [
117129
self.class, object_id,

lib/rdoc/stats.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ def coverage_level= level
158158
# Returns the length and number of undocumented items in +collection+.
159159

160160
def doc_stats collection
161-
[collection.length, collection.count { |item| not item.documented? }]
161+
visible = collection.select { |item| item.display? }
162+
[visible.length, visible.count { |item| not item.documented? }]
162163
end
163164

164165
##
@@ -266,6 +267,7 @@ def report_attributes cm
266267

267268
def report_class_module cm
268269
return if cm.fully_documented? and @coverage_level.zero?
270+
return unless cm.display?
269271

270272
report = []
271273

test/test_rdoc_parser_ruby.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,6 +2356,25 @@ class C
23562356
assert_equal expected, m.comment.parse
23572357
end
23582358

2359+
def test_scan_stopdoc
2360+
util_parser <<-RUBY
2361+
class C
2362+
# :stopdoc:
2363+
class Hidden
2364+
end
2365+
end
2366+
RUBY
2367+
2368+
@parser.scan
2369+
2370+
c = @top_level.classes.first
2371+
2372+
hidden = c.classes.first
2373+
2374+
refute hidden.document_self
2375+
assert hidden.ignored?
2376+
end
2377+
23592378
def test_stopdoc_after_comment
23602379
util_parser <<-EOS
23612380
module Bar

test/test_rdoc_stats.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,26 @@ def setup
1111
@tl.parser = RDoc::Parser::Ruby
1212
end
1313

14+
def test_doc_stats
15+
c = RDoc::CodeObject.new
16+
17+
assert_equal [1, 1], @s.doc_stats([c])
18+
end
19+
20+
def test_doc_stats_documented
21+
c = RDoc::CodeObject.new
22+
c.comment = comment 'x'
23+
24+
assert_equal [1, 0], @s.doc_stats([c])
25+
end
26+
27+
def test_doc_stats_display_eh
28+
c = RDoc::CodeObject.new
29+
c.ignore
30+
31+
assert_equal [0, 0], @s.doc_stats([c])
32+
end
33+
1434
def test_report_attr
1535
c = @tl.add_class RDoc::NormalClass, 'C'
1636
c.record_location @tl
@@ -266,6 +286,17 @@ class C
266286
assert_equal expected, report
267287
end
268288

289+
def test_report_class_module_ignore
290+
c = @tl.add_class RDoc::NormalClass, 'C'
291+
c.ignore
292+
293+
RDoc::TopLevel.complete :public
294+
295+
report = @s.report_class_module c
296+
297+
assert_nil report
298+
end
299+
269300
def test_report_empty
270301
RDoc::TopLevel.complete :public
271302

0 commit comments

Comments
 (0)