Skip to content

Commit 2632973

Browse files
authored
Remove RDoc::Comment#{remove_private,extract_call_seq} (#1706)
It was changed in b92986a and can now be removed entirely
1 parent 19d3400 commit 2632973

2 files changed

Lines changed: 0 additions & 366 deletions

File tree

lib/rdoc/comment.rb

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -76,49 +76,6 @@ def ==(other) # :nodoc:
7676
other.text == @text and other.location == @location
7777
end
7878

79-
##
80-
# Look for a 'call-seq' in the comment to override the normal parameter
81-
# handling. The :call-seq: is indented from the baseline. All lines of the
82-
# same indentation level and prefix are consumed.
83-
#
84-
# For example, all of the following will be used as the :call-seq:
85-
#
86-
# # :call-seq:
87-
# # ARGF.readlines(sep=$/) -> array
88-
# # ARGF.readlines(limit) -> array
89-
# # ARGF.readlines(sep, limit) -> array
90-
# #
91-
# # ARGF.to_a(sep=$/) -> array
92-
# # ARGF.to_a(limit) -> array
93-
# # ARGF.to_a(sep, limit) -> array
94-
95-
def extract_call_seq
96-
# we must handle situations like the above followed by an unindented first
97-
# comment. The difficulty is to make sure not to match lines starting
98-
# with ARGF at the same indent, but that are after the first description
99-
# paragraph.
100-
if /^(?<S> ((?!\n)\s)*+ (?# whitespaces except newline))
101-
:?call-seq:
102-
(?<B> \g<S>(?<N>\n|\z) (?# trailing spaces))?
103-
(?<seq>
104-
(\g<S>(?!\w)\S.*\g<N>)*
105-
(?>
106-
(?<H> \g<S>\w+ (?# ' # ARGF' in the example above))
107-
.*\g<N>)?
108-
(\g<S>\S.*\g<N> (?# other non-blank line))*+
109-
(\g<B>+(\k<H>.*\g<N> (?# ARGF.to_a lines))++)*+
110-
)
111-
(?m:^\s*$|\z)
112-
/x =~ @text
113-
seq = $~[:seq]
114-
115-
all_start, all_stop = $~.offset(0)
116-
@text.slice! all_start...all_stop
117-
118-
seq.gsub!(/^\s*/, '')
119-
end
120-
end
121-
12279
##
12380
# A comment is empty if its text String is empty.
12481

@@ -187,28 +144,6 @@ def parse
187144
@document
188145
end
189146

190-
##
191-
# Removes private sections from this comment. Private sections are flush to
192-
# the comment marker and start with <tt>--</tt> and end with <tt>++</tt>.
193-
# For C-style comments, a private marker may not start at the opening of the
194-
# comment.
195-
#
196-
# /*
197-
# *--
198-
# * private
199-
# *++
200-
# * public
201-
# */
202-
203-
def remove_private
204-
# Workaround for gsub encoding for Ruby 1.9.2 and earlier
205-
empty = ''
206-
empty = RDoc::Encoding.change_encoding empty, @text.encoding
207-
208-
@text = @text.gsub(%r%^\s*([#*]?)--.*?^\s*(\1)\+\+\n?%m, empty)
209-
@text = @text.sub(%r%^\s*[#*]?--.*%m, '')
210-
end
211-
212147
##
213148
# Replaces this comment's text with +text+ and resets the parsed document.
214149
#

test/rdoc/rdoc_comment_test.rb

Lines changed: 0 additions & 301 deletions
Original file line numberDiff line numberDiff line change
@@ -41,154 +41,6 @@ def test_equals2
4141
refute_equal @comment, c3
4242
end
4343

44-
def test_extract_call_seq
45-
comment = RDoc::Comment.new <<-COMMENT, @top_level
46-
call-seq:
47-
bla => true or false
48-
49-
moar comment
50-
COMMENT
51-
52-
assert_equal "bla => true or false\n", comment.extract_call_seq
53-
end
54-
55-
def test_extract_call_seq_blank
56-
comment = RDoc::Comment.new <<-COMMENT, @top_level
57-
call-seq:
58-
bla => true or false
59-
60-
COMMENT
61-
62-
assert_equal "bla => true or false\n", comment.extract_call_seq
63-
end
64-
65-
def test_extract_call_seq_commented
66-
comment = RDoc::Comment.new <<-COMMENT, @top_level
67-
# call-seq:
68-
# bla => true or false
69-
#
70-
# moar comment
71-
COMMENT
72-
73-
assert_nil comment.extract_call_seq
74-
end
75-
76-
def test_extract_call_seq_no_blank
77-
comment = RDoc::Comment.new <<-COMMENT, @top_level
78-
call-seq:
79-
bla => true or false
80-
COMMENT
81-
82-
assert_equal "bla => true or false\n", comment.extract_call_seq
83-
end
84-
85-
def test_extract_call_seq_undent
86-
comment = RDoc::Comment.new <<-COMMENT, @top_level
87-
call-seq:
88-
bla => true or false
89-
moar comment
90-
COMMENT
91-
92-
assert_equal "bla => true or false\nmoar comment\n", comment.extract_call_seq
93-
end
94-
95-
def test_extract_call_seq_c
96-
comment = RDoc::Comment.new <<-COMMENT
97-
call-seq:
98-
commercial() -> Date <br />
99-
commercial(cwyear, cweek=41, cwday=5, sg=nil) -> Date [ruby 1.8] <br />
100-
commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9]
101-
102-
If no arguments are given:
103-
* ruby 1.8: returns a +Date+ for 1582-10-15 (the Day of Calendar Reform in
104-
Italy)
105-
* ruby 1.9: returns a +Date+ for julian day 0
106-
107-
Otherwise, returns a +Date+ for the commercial week year, commercial week,
108-
and commercial week day given. Ignores the 4th argument.
109-
COMMENT
110-
111-
expected = <<-CALL_SEQ.chomp
112-
commercial() -> Date <br />
113-
commercial(cwyear, cweek=41, cwday=5, sg=nil) -> Date [ruby 1.8] <br />
114-
commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9]
115-
116-
CALL_SEQ
117-
118-
assert_equal expected, comment.extract_call_seq
119-
end
120-
121-
def test_extract_call_seq_c_no_blank
122-
comment = RDoc::Comment.new <<-COMMENT
123-
call-seq:
124-
commercial() -> Date <br />
125-
commercial(cwyear, cweek=41, cwday=5, sg=nil) -> Date [ruby 1.8] <br />
126-
commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9]
127-
COMMENT
128-
129-
expected = <<-CALL_SEQ.chomp
130-
commercial() -> Date <br />
131-
commercial(cwyear, cweek=41, cwday=5, sg=nil) -> Date [ruby 1.8] <br />
132-
commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9]
133-
134-
CALL_SEQ
135-
136-
assert_equal expected, comment.extract_call_seq
137-
end
138-
139-
def test_extract_call_seq_c_separator
140-
comment = RDoc::Comment.new <<-'COMMENT'
141-
call-seq:
142-
ARGF.readlines(sep=$/) -> array
143-
ARGF.readlines(limit) -> array
144-
ARGF.readlines(sep, limit) -> array
145-
146-
ARGF.to_a(sep=$/) -> array
147-
ARGF.to_a(limit) -> array
148-
ARGF.to_a(sep, limit) -> array
149-
150-
Reads +ARGF+'s current file in its entirety, returning an +Array+ of its
151-
lines, one line per element. Lines are assumed to be separated by _sep_.
152-
153-
lines = ARGF.readlines
154-
lines[0] #=> "This is line one\n"
155-
156-
COMMENT
157-
158-
expected = <<-CALL_SEQ
159-
ARGF.readlines(sep=$/) -> array
160-
ARGF.readlines(limit) -> array
161-
ARGF.readlines(sep, limit) -> array
162-
ARGF.to_a(sep=$/) -> array
163-
ARGF.to_a(limit) -> array
164-
ARGF.to_a(sep, limit) -> array
165-
CALL_SEQ
166-
167-
assert_equal expected, comment.extract_call_seq
168-
169-
expected = <<-'COMMENT'
170-
171-
Reads +ARGF+'s current file in its entirety, returning an +Array+ of its
172-
lines, one line per element. Lines are assumed to be separated by _sep_.
173-
174-
lines = ARGF.readlines
175-
lines[0] #=> "This is line one\n"
176-
177-
COMMENT
178-
179-
assert_equal expected, comment.text
180-
end
181-
182-
# This test relies on AnyMethod#call_seq's behaviour as well
183-
def test_extract_call_linear_performance
184-
pre = ->(n) {[n, RDoc::Comment.new("\n"*n + 'call-seq:' + 'a'*n)]}
185-
method_obj = RDoc::AnyMethod.new nil, 'blah'
186-
assert_linear_performance((2..5).map {|i| 10**i}, pre: pre) do |n, comment|
187-
method_obj.call_seq = comment.extract_call_seq
188-
assert_equal n, method_obj.call_seq.size
189-
end
190-
end
191-
19244
def test_force_encoding
19345
@comment = RDoc::Encoding.change_encoding @comment, Encoding::UTF_8
19446

@@ -324,159 +176,6 @@ def test_parse_rd
324176
assert_equal expected, c.parse
325177
end
326178

327-
def test_remove_private_encoding
328-
comment = RDoc::Comment.new <<-EOS, @top_level
329-
# This is text
330-
#--
331-
# this is private
332-
EOS
333-
334-
comment = RDoc::Encoding.change_encoding comment, Encoding::IBM437
335-
336-
comment.remove_private
337-
338-
assert_equal Encoding::IBM437, comment.text.encoding
339-
end
340-
341-
def test_remove_private_hash
342-
@comment.text = <<-TEXT
343-
#--
344-
# private
345-
#++
346-
# public
347-
TEXT
348-
349-
@comment.remove_private
350-
351-
assert_equal "# public\n", @comment.text
352-
end
353-
354-
def test_remove_private_hash_trail
355-
comment = RDoc::Comment.new <<-EOS, @top_level
356-
# This is text
357-
#--
358-
# this is private
359-
EOS
360-
361-
expected = RDoc::Comment.new <<-EOS, @top_level
362-
# This is text
363-
EOS
364-
365-
comment.remove_private
366-
367-
assert_equal expected, comment
368-
end
369-
370-
def test_remove_private_long
371-
comment = RDoc::Comment.new <<-EOS, @top_level
372-
#-----
373-
#++
374-
# this is text
375-
#-----
376-
EOS
377-
378-
expected = RDoc::Comment.new <<-EOS, @top_level
379-
# this is text
380-
EOS
381-
382-
comment.remove_private
383-
384-
assert_equal expected, comment
385-
end
386-
387-
def test_remove_private_rule
388-
comment = RDoc::Comment.new <<-EOS, @top_level
389-
# This is text with a rule:
390-
# ---
391-
# this is also text
392-
EOS
393-
394-
expected = comment.dup
395-
396-
comment.remove_private
397-
398-
assert_equal expected, comment
399-
end
400-
401-
def test_remove_private_star
402-
@comment.text = <<-TEXT
403-
/*
404-
*--
405-
* private
406-
*++
407-
* public
408-
*/
409-
TEXT
410-
411-
@comment.remove_private
412-
413-
assert_equal "/*\n * public\n */\n", @comment.text
414-
end
415-
416-
def test_remove_private_star2
417-
@comment.text = <<-TEXT
418-
/*--
419-
* private
420-
*++
421-
* public
422-
*/
423-
TEXT
424-
425-
@comment.remove_private
426-
427-
assert_equal "/*--\n * private\n *++\n * public\n */\n", @comment.text
428-
end
429-
430-
def test_remove_private_toggle
431-
comment = RDoc::Comment.new <<-EOS, @top_level
432-
# This is text
433-
#--
434-
# this is private
435-
#++
436-
# This is text again.
437-
EOS
438-
439-
expected = RDoc::Comment.new <<-EOS, @top_level
440-
# This is text
441-
# This is text again.
442-
EOS
443-
444-
comment.remove_private
445-
446-
assert_equal expected, comment
447-
end
448-
449-
def test_remove_private_toggle_encoding
450-
comment = RDoc::Comment.new <<-EOS, @top_level
451-
# This is text
452-
#--
453-
# this is private
454-
#++
455-
# This is text again.
456-
EOS
457-
458-
comment = RDoc::Encoding.change_encoding comment, Encoding::IBM437
459-
460-
comment.remove_private
461-
462-
assert_equal Encoding::IBM437, comment.text.encoding
463-
end
464-
465-
def test_remove_private_toggle_encoding_ruby_bug?
466-
comment = RDoc::Comment.new <<-EOS, @top_level
467-
#--
468-
# this is private
469-
#++
470-
# This is text again.
471-
EOS
472-
473-
comment = RDoc::Encoding.change_encoding comment, Encoding::IBM437
474-
475-
comment.remove_private
476-
477-
assert_equal Encoding::IBM437, comment.text.encoding
478-
end
479-
480179
def test_parse_directives
481180
comment = <<~COMMENT
482181
comment1

0 commit comments

Comments
 (0)