8000 * lib/rdoc/cross_reference.rb: Fixed matching of C#=== or #===. RDoc · tenderlove/ruby@b2e68bc · GitHub
[go: up one dir, main page]

Skip to content

Commit b2e68bc

Browse files
committed
* lib/rdoc/cross_reference.rb: Fixed matching of C#=== or #===. RDoc
bug ruby#164 * test/rdoc/test_rdoc_cross_reference.rb: Test for above. * lib/rdoc/parser/changelog.rb: Fixed parsing of dates. RDoc bug ruby#165 * test/rdoc/test_rdoc_parser_changelog.rb: Test for above. * lib/rdoc/parser.rb: Fixed parsing multibyte files with incomplete characters at byte 1024. [ruby-trunk - Bug ruby#6393] Fixed handling of -E. [ruby-trunk - Bug ruby#6392] * test/rdoc/test_rdoc_options.rb: Test for above. * test/rdoc/test_rdoc_parser.rb: ditto. * test/rdoc/test_rdoc_parser_c.rb: ditto. * test/rdoc/test_rdoc_parser_changelog.rb: ditto. * test/rdoc/test_rdoc_parser_markdown.rb: ditto. * test/rdoc/test_rdoc_parser_rd.rb: ditto. * test/rdoc/test_rdoc_rdoc.rb: ditto. * lib/rdoc/tom_doc.rb: Fixed parsing of [] in TomDoc arguments list. RDoc bug ruby#167 * test/rdoc/test_rdoc_tom_doc.rb: Test for above. * lib/rdoc.rb: Update version. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38690 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 0b9f17a commit b2e68bc

16 files changed

+266
-52
lines changed

ChangeLog

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
Fri Jan 4 15:05:25 2013 Eric Hodel <drbrain@segment7.net>
2+
3+
* lib/rdoc/cross_reference.rb: Fixed matching of C#=== or #===. RDoc
4+
bug #164
5+
* test/rdoc/test_rdoc_cross_reference.rb: Test for above.
6+
7+
* lib/rdoc/parser/changelog.rb: Fixed parsing of dates. RDoc bug #165
8+
* test/rdoc/test_rdoc_parser_changelog.rb: Test for above.
9+
10+
* lib/rdoc/parser.rb: Fixed parsing multibyte files with incomplete
11+
characters at byte 1024. [ruby-trunk - Bug #6393]
12+
Fixed handling of -E. [ruby-trunk - Bug #6392]
13+
* test/rdoc/test_rdoc_options.rb: Test for above.
14+
* test/rdoc/test_rdoc_parser.rb: ditto.
15+
* test/rdoc/test_rdoc_parser_c.rb: ditto.
16+
* test/rdoc/test_rdoc_parser_changelog.rb: ditto.
17+
* test/rdoc/test_rdoc_parser_markdown.rb: ditto.
18+
* test/rdoc/test_rdoc_parser_rd.rb: ditto.
19+
* test/rdoc/test_rdoc_rdoc.rb: ditto.
20+
21+
* lib/rdoc/tom_doc.rb: Fixed parsing of [] in TomDoc arguments list.
22+
RDoc bug #167
23+
* test/rdoc/test_rdoc_tom_doc.rb: Test for above.
24+
25+
* lib/rdoc.rb: Update version.
26+
127
Fri Jan 4 11:51:00 2013 Zachary Scott <zachary@zacharyscott.net>
228

329
* lib/forwardable.rb: Fix rdoc parameters for ::def_single_delegator.

lib/rdoc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Error < RuntimeError; end
6464
##
6565
# RDoc version you are using
6666

67-
VERSION = '4.0.0.preview2.1'
67+
VERSION = '4.0.0.preview3.1'
6868

6969
##
7070
# Method visibilities

lib/rdoc/cross_reference.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class RDoc::CrossReference
1818
#
1919
# See CLASS_REGEXP_STR
2020

21-
METHOD_REGEXP_STR = '([a-z]\w*[!?=]?|%)(?:\([\w.+*/=<>-]*\))?'
21+
METHOD_REGEXP_STR = '([a-z]\w*[!?=]?|%|===)(?:\([\w.+*/=<>-]*\))?'
2222

2323
##
2424
# Regular expressions matching text that should potentially have

lib/rdoc/parser.rb

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def self.alias_extension(old_ext, new_ext)
5858
old_ext = old_ext.sub(/^\.(.*)/, '\1')
5959
new_ext = new_ext.sub(/^\.(.*)/, '\1')
6060

61-
parser = can_parse "xxx.#{old_ext}"
61+
parser = can_parse_by_name "xxx.#{old_ext}"
6262
return false unless parser
6363

6464
RDoc::Parser.parsers.unshift [/\.#{new_ext}$/, parser]
@@ -77,14 +77,14 @@ def self.binary?(file)
7777

7878
have_encoding = s.respond_to? :encoding
7979

80-
if have_encoding then
81-
return false if s.encoding != Encoding::ASCII_8BIT and s.valid_encoding?
82-
end
83-
8480
return true if s[0, 2] == Marshal.dump('')[0, 2] or s.index(&q F438 uot;\x00")
8581

8682
if have_encoding then
87-
s.force_encoding Encoding.default_external
83+
mode = "r"
84+
s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024.
85+
encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1]
86+
mode = "r:#{encoding}" if encoding
87+
s = File.open(file, mode) {|f| f.gets(nil, 1024)}
8888

8989
not s.valid_encoding?
9090
else
@@ -131,23 +131,36 @@ def self.zip? file
131131
zip_signature == "PK\x03\x04" or
132132
zip_signature == "PK\x05\x06" or
133133
zip_signature == "PK\x07\x08"
134+
rescue
135+
false
134136
end
135137

136138
##
137139
# Return a parser that can handle a particular extension
138140

139-
def self.can_parse(file_name)
140-
parser = RDoc::Parser.parsers.find { |regexp,| regexp =~ file_name }.last
141+
def self.can_parse file_name
142+
parser = can_parse_by_name file_name
141143

142144
# HACK Selenium hides a jar file using a .txt extension
143145
return if parser == RDoc::Parser::Simple and zip? file_name
144146

147+
parser
148+
end
149+
150+
##
151+
# Returns a parser that can handle the extension for +file_name+. This does
152+
# not depend upon the file being readable.
153+
154+
def self.can_parse_by_name file_name
155+
_, parser = RDoc::Parser.parsers.find { |regexp,| regexp =~ file_name }
156+
145157
# The default parser must not parse binary files
146158
ext_name = File.extname file_name
147159
return parser if ext_name.empty?
160+
148161
if parser == RDoc::Parser::Simple and ext_name !~ /txt|rdoc/ then
149162
case check_modeline file_name
150-
when 'rdoc' then # continue
163+
when nil, 'rdoc' then # continue
151164
else return nil
152165
end
153166
end
@@ -173,6 +186,8 @@ def self.check_modeline file_name
173186
type = $1
174187
end
175188

189+
return nil if /coding:/i =~ type
190+
176191
type.downcase
177192
rescue ArgumentError # invalid byte sequence, etc.
178193
end
@@ -204,6 +219,8 @@ def self.for top_level, file_name, content, options, stats
204219
return unless parser
205220

206221
parser.new top_level, file_name, content, options, stats
222+
rescue SystemCallError
223+
nil
207224
end
208225

209226
##

lib/rdoc/parser/changelog.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ def create_items items
102102

103103
def group_entries entries
104104
entries.group_by do |title, _|
105-
Time.parse(title).strftime "%Y-%m-%d"
105+
begin
106+
Time.parse(title).strftime '%Y-%m-%d'
107+
rescue NoMethodError, ArgumentError
108+
time, = title.split ' ', 2
109+
Time.parse(time).strftime '%Y-%m-%d'
110+
end
106111
end
107112
end
108113

@@ -139,6 +144,9 @@ def parse_entries
139144
time = Time.parse entry_name
140145
# HACK Ruby 1.8 does not raise ArgumentError for Time.parse "Other"
141146
entry_name = nil unless entry_name =~ /#{time.year}/
147+
rescue NoMethodError
148+
time, = entry_name.split ' ', 2
149+
time = Time.parse time
142150
rescue ArgumentError
143151
entry_name = nil
144152
end

lib/rdoc/tom_doc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def tokenize text
218218
@tokens << [:HEADER, 3, *token_pos(pos)]
219219

220220
[:TEXT, @s[1], *token_pos(pos)]
221-
when @s.scan(/([:\w]\w*)[ ]+- /) then
221+
when @s.scan(/([:\w][\w\[\]]*)[ ]+- /) then
222222
[:NOTE, @s[1], *token_pos(pos)]
223223
else
224224
@s.scan(/.*/)

test/rdoc/test.ja.largedoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# -*- coding: utf-8 -*-
2+
吾輩(わがはい)は猫である。名前はまだ無い。
3+
どこで生れたかとんと見当(けんとう)がつかぬ。何でも薄暗いじめじめした所でニャーニャー泣いていた事だけは記憶している。吾輩はここで始めて人間というものを見た。しかもあとで聞くとそれは書生という人間中で一番獰悪(どうあく)な種族であったそうだ。この書生というのは時々我々を捕(つかま)えて煮(に)て食うという話である。しかしその当時は何という考もなかったから別段恐しいとも思わなかった。ただ彼の掌(てのひら)に載せられてスーと持ち上げられた時何だかフワフワした感じがあったばかりである。掌の上で少し落ちついて書生の顔を見たのがいわゆる人間というものの見始(みはじめ)であろう。この時妙なものだと思った感じが今でも残っている。第一毛をもって装飾されべきはずの顔がつるつるしてまるで薬缶(やかん)だ。その後(ご)猫にもだいぶ逢(あ)ったがこんな片輪(かたわ)には一度も出会(でく)わした事がない。のみならず顔の真中があまりに突起している。そうしてその穴の中から時々ぷうぷうと煙(けむり)を吹く。どうも咽(む)せぽくて実に弱った。これが人間の飲む煙草(たばこ)というものである事はようやくこの頃知った。

test/rdoc/test_rdoc_cross_reference.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ def refute_ref name
1616
assert_equal name, @xref.resolve(name, name)
1717
end
1818

19+
def test_METHOD_REGEXP_STR
20+
re = /#{RDoc::CrossReference::METHOD_REGEXP_STR}/
21+
22+
re =~ '==='
23+
24+
assert_equal '===', $&
25+
end
26+
1927
def test_resolve_C2
2028
@xref = RDoc::CrossReference.new @c2
2129

@@ -129,6 +137,13 @@ def test_resolve_method
129137
assert_ref @c2_c3_m, '::C2::C3#m(*)'
130138
end
131139

140+
def test_resolve_method_equals3
141+
m = RDoc::AnyMethod.new '', '==='
142+
@c1.add_method m
143+
144+
assert_ref m, '==='
145+
end
146+
132147
def test_resolve_page
133148
page = @store.add_file 'README.txt'
134149
page.parser = RDoc::Parser::Simple

test/rdoc/test_rdoc_options.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,17 @@ def test_parse_write_options
549549
FileUtils.rm_rf tmpdir
550550
end
551551

552+
def test_parse_extension_alias
553+
out, err = capture_io do
554+
@options.parse %w[--extension foobar=rdoc]
555+
end
556+
557+
assert_includes RDoc::Parser.parsers, [/\.foobar$/, RDoc::Parser::Simple]
558+
559+
assert_empty out
560+
assert_empty err
561+
end
562+
552563
def test_setup_generator
553564
test_generator = Class.new do
554565
def self.setup_options op

test/rdoc/test_rdoc_parser.rb

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,18 @@ def test_class_binary_japanese_text
3333
end
3434

3535
def test_class_binary_large_japanese_rdoc
36-
file_name = File.expand_path '../test.ja.large.rdoc', __FILE__
37-
assert !@RP.binary?(file_name)
36+
skip "Encoding not implemented" unless Object.const_defined? :Encoding
37+
38+
capture_io do
39+
begin
40+
extenc, Encoding.default_external =
41+
Encoding.default_external, Encoding::US_ASCII
42+
file_name = File.expand_path '../test.ja.largedoc', __FILE__
43+
assert !@RP.binary?(file_name)
44+
ensure
45+
Encoding.default_external = extenc
46+
end
47+
end
3848
end
3949

4050
def test_class_binary_japanese_rdoc
@@ -51,7 +61,7 @@ def test_class_can_parse
5161

5262
assert_equal @RP::Simple, @RP.can_parse(readme_file_name)
5363

54-
assert_nil @RP.can_parse(@binary_dat)
64+
assert_equal @RP::Simple, @RP.can_parse(@binary_dat)
5565

5666
jtest_file_name = File.expand_path '../test.ja.txt', __FILE__
5767
assert_equal @RP::Simple, @RP.can_parse(jtest_file_name)
@@ -61,27 +71,20 @@ def test_class_can_parse
6171

6272
readme_file_name = File.expand_path '../README', __FILE__
6373
assert_equal @RP::Simple, @RP.can_parse(readme_file_name)
64-
end
6574

66-
def test_class_can_parse_forbidden
67-
skip 'chmod not supported' if Gem.win_platform?
68-
69-
Tempfile.open 'forbidden' do |io|
70-
begin
71-
File.chmod 0000, io.path
75+
jtest_largerdoc_file_name = File.expand_path '../test.ja.largedoc', __FILE__
76+
assert_equal @RP::Simple, @RP.can_parse(jtest_largerdoc_file_name)
7277

73-
assert_nil @RP.can_parse io.path
74-
ensure
75-
File.chmod 0400, io.path
76-
end
77-
end
78+
@RP.alias_extension 'rdoc', 'largedoc'
79+
assert_equal @RP::Simple, @RP.can_parse(jtest_largerdoc_file_name)
7880
end
7981

8082
def test_class_for_executable
8183
temp_dir do
8284
content = "#!/usr/bin/env ruby -w\n"
8385
open 'app', 'w' do |io| io.write content end
8486
app = @store.add_file 'app'
87+
8588
parser = @RP.for app, 'app', content, @options, :stats
8689

8790
assert_kind_of RDoc::Parser::Ruby, parser
@@ -90,6 +93,23 @@ def test_class_for_executable
9093
end
9194
end
9295

96+
def test_class_for_forbidden
97+
skip 'chmod not supported' if Gem.win_platform?
98+
99+
Tempfile.open 'forbidden' do |io|
100+
begin
101+
File.chmod 0000, io.path
102+
forbidden = @store.add_file io.path
103+
104+
parser = @RP.for forbidden, 'forbidden', '', @options, :stats
105+
106+
assert_nil parser
107+
ensure
108+
File.chmod 0400, io.path
109+
end
110+
end
111+
end
112+
93113
def test_can_parse_modeline
94114
readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}"
95115

@@ -126,6 +146,18 @@ def test_check_modeline
126146
File.unlink readme_ext
127147
end
128148

149+
def test_check_modeline_coding
150+
readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}"
151+
152+
open readme_ext, 'w' do |io|
153+
io.puts "# -*- coding: utf-8 -*-"
154+
end
155+
156+
assert_nil @RP.check_modeline readme_ext
157+
ensure
158+
File.unlink readme_ext
159+
end
160+
129161
def test_check_modeline_with_other
130162
readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}"
131163

0 commit comments

Comments
 (0)
0