rdoc 3.10.pre.3 → 3.10

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rdoc might be problematic. Click here for more details.

@@ -1801,12 +1801,10 @@ class RDoc::Parser::Ruby < RDoc::Parser
1801
1801
  end
1802
1802
 
1803
1803
  ##
1804
- # Prints +msg+ to +$stderr+ unless we're being quiet
1804
+ # Prints +message+ to +$stderr+ unless we're being quiet
1805
1805
 
1806
- def warn(msg)
1807
- return if @options.quiet
1808
- msg = make_message msg
1809
- $stderr.puts msg
1806
+ def warn message
1807
+ @options.warn make_message message
1810
1808
  end
1811
1809
 
1812
1810
  end
data/lib/rdoc/rdoc.rb CHANGED
@@ -37,6 +37,11 @@ require 'time'
37
37
 
38
38
  class RDoc::RDoc
39
39
 
40
+ ##
41
+ # This is the list of supported output generators
42
+
43
+ GENERATORS = {}
44
+
40
45
  ##
41
46
  # File pattern to exclude
42
47
 
@@ -62,11 +67,6 @@ class RDoc::RDoc
62
67
 
63
68
  attr_reader :stats
64
69
 
65
- ##
66
- # This is the list of supported output generators
67
-
68
- GENERATORS = {}
69
-
70
70
  ##
71
71
  # Add +klass+ that can generate output after parsing
72
72
 
@@ -155,6 +155,33 @@ class RDoc::RDoc
155
155
  end
156
156
  end
157
157
 
158
+ ##
159
+ # Loads options from .rdoc_options if the file exists, otherwise creates a
160
+ # new RDoc::Options instance.
161
+
162
+ def load_options
163
+ options_file = File.expand_path '.rdoc_options'
164
+ return RDoc::Options.new unless File.exist? options_file
165
+
166
+ RDoc.load_yaml
167
+
168
+ parse_error = if Object.const_defined? :Psych then
169
+ Psych::SyntaxError
170
+ else
171
+ ArgumentError
172
+ end
173
+
174
+ begin
175
+ options = YAML.load_file '.rdoc_options'
176
+ rescue *parse_error
177
+ end
178
+
179
+ raise RDoc::Error, "#{options_file} is not a valid rdoc options file" unless
180
+ RDoc::Options === options
181
+
182
+ options
183
+ end
184
+
158
185
  ##
159
186
  # Create an output dir if it doesn't exist. If it does exist, but doesn't
160
187
  # contain the flag file <tt>created.rid</tt> then we refuse to use it, as
@@ -405,7 +432,7 @@ The internal error was:
405
432
  @options = options
406
433
  @options.finish
407
434
  else
408
- @options = RDoc::Options.new
435
+ @options = load_options
409
436
  @options.parse options
410
437
  end
411
438
 
data/lib/rdoc/ruby_lex.rb CHANGED
@@ -55,7 +55,7 @@ class RDoc::RubyLex
55
55
  end
56
56
 
57
57
  self.debug_level = 0
58
-
58
+
59
59
  # :startdoc:
60
60
 
61
61
  ##
@@ -69,7 +69,7 @@ class RDoc::RubyLex
69
69
  scanner.exception_on_syntax_error = true
70
70
 
71
71
  while token = scanner.token do
72
- tokens << token
72
+ tokens << token
73
73
  end
74
74
 
75
75
  tokens
@@ -960,7 +960,8 @@ class RDoc::RubyLex
960
960
  if peek(0) == '='
961
961
  token.concat getc
962
962
  end
963
- elsif @lex_state == EXPR_BEG || @lex_state == EXPR_DOT
963
+ elsif @lex_state == EXPR_BEG || @lex_state == EXPR_DOT ||
964
+ @lex_state == EXPR_ARG
964
965
  @lex_state = EXPR_ARG
965
966
  else
966
967
  @lex_state = EXPR_END
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'minitest/autorun'
3
+ require 'minitest/benchmark' if ENV['BENCHMARK']
3
4
 
4
5
  require 'fileutils'
5
6
  require 'pp'
@@ -48,6 +49,22 @@ class RDoc::TestCase < MiniTest::Unit::TestCase
48
49
  RDoc::Comment.new text, top_level
49
50
  end
50
51
 
52
+ ##
53
+ # Creates a temporary directory changes the current directory to it for the
54
+ # duration of the block.
55
+ #
56
+ # Depends upon Dir.mktmpdir
57
+
58
+ def temp_dir
59
+ skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir
60
+
61
+ Dir.mktmpdir do |temp_dir|
62
+ Dir.chdir temp_dir do
63
+ yield temp_dir
64
+ end
65
+ end
66
+ end
67
+
51
68
  end
52
69
 
53
70
  # This hack allows autoload to work when Dir.pwd is changed for Ruby 1.8 since
@@ -378,6 +378,14 @@ class RDoc::TopLevel < RDoc::Context
378
378
 
379
379
  alias name base_name
380
380
 
381
+ ##
382
+ # Only a TopLevel that contains text file) will be displayed. See also
383
+ # RDoc::CodeObject#display?
384
+
385
+ def display?
386
+ text? and super
387
+ end
388
+
381
389
  ##
382
390
  # See RDoc::TopLevel::find_class_or_module
383
391
  #--
@@ -176,6 +176,15 @@ method(a, b) { |c, d| ... }
176
176
  assert_equal %w[a b c d], m.param_list
177
177
  end
178
178
 
179
+ def test_param_list_default
180
+ m = RDoc::AnyMethod.new nil, 'method'
181
+ m.parent = @c1
182
+
183
+ m.params = '(b = default)'
184
+
185
+ assert_equal %w[b], m.param_list
186
+ end
187
+
179
188
  def test_param_list_params
180
189
  m = RDoc::AnyMethod.new nil, 'method'
181
190
  m.parent = @c1
@@ -65,6 +65,16 @@ class TestRDocAttr < RDoc::TestCase
65
65
  assert_equal 'RW', loaded.rw
66
66
  assert_equal false, loaded.singleton
67
67
  assert_equal :public, loaded.visibility
68
+ end
69
+
70
+ def test_marshal_dump_singleton
71
+ tl = RDoc::TopLevel.new 'file.rb'
72
+
73
+ @a.comment = 'this is a comment'
74
+ @a.record_location tl
75
+
76
+ cm = RDoc::ClassModule.new 'Klass'
77
+ cm.add_attribute @a
68
78
 
69
79
  @a.rw = 'R'
70
80
  @a.singleton = true
@@ -74,6 +84,9 @@ class TestRDocAttr < RDoc::TestCase
74
84
 
75
85
  assert_equal @a, loaded
76
86
 
87
+ comment = RDoc::Markup::Document.new(
88
+ RDoc::Markup::Paragraph.new('this is a comment'))
89
+
77
90
  assert_equal comment, loaded.comment
78
91
  assert_equal 'Klass::attr', loaded.full_name
79
92
  assert_equal 'attr', loaded.name
@@ -774,6 +774,19 @@ class TestRDocClassModule < XrefTestCase
774
774
  assert_equal [a, c], @c1.includes
775
775
  end
776
776
 
777
+ def test_update_includes_trim
778
+ a = RDoc::Include.new 'D::M', nil
779
+ b = RDoc::Include.new 'D::M', nil
780
+
781
+ @c1.add_include a
782
+ @c1.add_include b
783
+ @c1.ancestors # cache included modules
784
+
785
+ @c1.update_includes
786
+
787
+ assert_equal [a], @c1.includes
788
+ end
789
+
777
790
  def test_update_includes_with_colons
778
791
  a = RDoc::Include.new 'M1', nil
779
792
  b = RDoc::Include.new 'M1::M2', nil
@@ -183,16 +183,6 @@ class TestRDocContext < XrefTestCase
183
183
  assert_equal [incl], @context.includes
184
184
  end
185
185
 
186
- def test_add_include_twice
187
- incl1 = RDoc::Include.new 'Name', 'comment'
188
- @context.add_include incl1
189
-
190
- incl2 = RDoc::Include.new 'Name', 'comment'
191
- @context.add_include incl2
192
-
193
- assert_equal [incl1], @context.includes
194
- end
195
-
196
186
  def test_add_method
197
187
  meth = RDoc::AnyMethod.new nil, 'old_name'
198
188
  meth.visibility = nil
@@ -334,6 +324,16 @@ class TestRDocContext < XrefTestCase
334
324
  refute_includes arr, incl
335
325
  end
336
326
 
327
+ def bench_add_include
328
+ cm = RDoc::ClassModule.new 'Klass'
329
+
330
+ assert_performance_linear 0.9 do |count|
331
+ count.times do |i|
332
+ cm.add_include RDoc::Include.new("N::M#{i}", nil)
333
+ end
334
+ end
335
+ end
336
+
337
337
  def test_child_name
338
338
  assert_equal 'C1::C1', @c1.child_name('C1')
339
339
  end
@@ -16,13 +16,6 @@ class TestRDocCrossReference < XrefTestCase
16
16
  assert_equal name, @xref.resolve(name, name)
17
17
  end
18
18
 
19
- def test_resolve_page
20
- page = RDoc::TopLevel.new 'README.txt'
21
- page.parser = RDoc::Parser::Simple
22
-
23
- assert_ref page, 'README'
24
- end
25
-
26
19
  def test_resolve_C2
27
20
  @xref = RDoc::CrossReference.new @c2
28
21
 
@@ -100,7 +93,7 @@ class TestRDocCrossReference < XrefTestCase
100
93
  end
101
94
 
102
95
  def test_resolve_file
103
- assert_ref @xref_data, 'xref_data.rb'
96
+ refute_ref 'xref_data.rb'
104
97
  end
105
98
 
106
99
  def test_resolve_method
@@ -136,6 +129,13 @@ class TestRDocCrossReference < XrefTestCase
136
129
  assert_ref @c2_c3_m, '::C2::C3#m(*)'
137
130
  end
138
131
 
132
+ def test_resolve_page
133
+ page = RDoc::TopLevel.new 'README.txt'
134
+ page.parser = RDoc::Parser::Simple
135
+
136
+ assert_ref page, 'README'
137
+ end
138
+
139
139
  def test_resolve_percent
140
140
  i_percent = RDoc::AnyMethod.new nil, '%'
141
141
  i_percent.singleton = false
@@ -441,6 +441,17 @@ a. 新しい機能
441
441
  assert_equal expected, @RMP.parse(str).parts
442
442
  end
443
443
 
444
+ def test_parse_line_break
445
+ str = "now is\nthe time \nfor all"
446
+
447
+ expected = [
448
+ @RM::Paragraph.new('now is', 'the time'),
449
+ @RM::BlankLine.new,
450
+ @RM::Paragraph.new('for all')]
451
+
452
+ assert_equal expected, @RMP.parse(str).parts
453
+ end
454
+
444
455
  def test_parse_list_list_1
445
456
  str = <<-STR
446
457
  10. para 1
@@ -1233,6 +1244,53 @@ b. l1.1
1233
1244
  assert_equal expected, @RMP.tokenize(str)
1234
1245
  end
1235
1246
 
1247
+ def test_tokenize_line_break
1248
+ str = "now is\nthe time \nfor all\n"
1249
+
1250
+ expected = [
1251
+ [:TEXT, 'now is', 0, 0],
1252
+ [:NEWLINE, "\n", 6, 0],
1253
+ [:TEXT, 'the time', 0, 1],
1254
+ [:BREAK, " ", 8, 1],
1255
+ [:NEWLINE, "\n", 10, 1],
1256
+ [:TEXT, 'for all', 0, 2],
1257
+ [:NEWLINE, "\n", 7, 2],
1258
+ ]
1259
+
1260
+ assert_equal expected, @RMP.tokenize(str)
1261
+ end
1262
+
1263
+ def test_tokenize_line_break_long
1264
+ str = "now is\nthe time \nfor all\n"
1265
+
1266
+ expected = [
1267
+ [:TEXT, 'now is', 0, 0],
1268
+ [:NEWLINE, "\n", 6, 0],
1269
+ [:TEXT, 'the time ', 0, 1],
1270
+ [:BREAK, ' ', 9, 1],
1271
+ [:NEWLINE, "\n", 11, 1],
1272
+ [:TEXT, 'for all', 0, 2],
1273
+ [:NEWLINE, "\n", 7, 2],
1274
+ ]
1275
+
1276
+ assert_equal expected, @RMP.tokenize(str)
1277
+ end
1278
+
1279
+ def test_tokenize_line_break_no_short
1280
+ str = "now is\nthe time \nfor all\n"
1281
+
1282
+ expected = [
1283
+ [:TEXT, 'now is', 0, 0],
1284
+ [:NEWLINE, "\n", 6, 0],
1285
+ [:TEXT, 'the time ', 0, 1],
1286
+ [:NEWLINE, "\n", 9, 1],
1287
+ [:TEXT, 'for all', 0, 2],
1288
+ [:NEWLINE, "\n", 7, 2],
1289
+ ]
1290
+
1291
+ assert_equal expected, @RMP.tokenize(str)
1292
+ end
1293
+
1236
1294
  def test_tokenize_note
1237
1295
  str = <<-STR
1238
1296
  cat:: l1
@@ -43,7 +43,7 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
43
43
  def test_convert_RDOCLINK_rdoc_ref_method
44
44
  result = @to.convert 'rdoc-ref:C1#m'
45
45
 
46
- assert_equal para("<a href=\"C1.html#method-i-m\">C1#m</a>"), result
46
+ assert_equal para("<a href=\"C1.html#method-i-m\">#m</a>"), result
47
47
  end
48
48
 
49
49
  def test_convert_RDOCLINK_rdoc_ref_method_label
@@ -59,14 +59,13 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
59
59
 
60
60
  result = @to.convert 'rdoc-ref:C1#%'
61
61
 
62
- assert_equal para("<a href=\"C1.html#method-i-25\">C1#%</a>"), result
62
+ assert_equal para("<a href=\"C1.html#method-i-25\">#%</a>"), result
63
63
 
64
64
  m.singleton = true
65
65
 
66
66
  result = @to.convert 'rdoc-ref:C1::%'
67
67
 
68
- assert_equal para("<a href=\"C1.html#method-c-25\">C1::%</a>"), result
69
-
68
+ assert_equal para("<a href=\"C1.html#method-c-25\">::%</a>"), result
70
69
  end
71
70
 
72
71
  def test_convert_RDOCLINK_rdoc_ref_method_percent_label
@@ -113,12 +112,14 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
113
112
  def test_handle_special_CROSSREF_show_hash_false
114
113
  @to.show_hash = false
115
114
 
116
- assert_equal "<a href=\"C1.html#method-i-m\">m</a>",
115
+ assert_equal "<a href=\"C1.html#method-i-m\">#m</a>",
117
116
  SPECIAL('#m')
118
117
  end
119
118
 
120
119
  def test_handle_special_HYPERLINK_rdoc
121
- RDoc::TopLevel.new 'README.txt'
120
+ readme = RDoc::TopLevel.new 'README.txt'
121
+ readme.parser = RDoc::Parser::Simple
122
+
122
123
  @to = RDoc::Markup::ToHtmlCrossref.new 'C2.html', @c2, true
123
124
 
124
125
  link = @to.handle_special_HYPERLINK hyper 'C2::C3'
@@ -135,7 +136,9 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
135
136
  end
136
137
 
137
138
  def test_handle_special_TIDYLINK_rdoc
138
- RDoc::TopLevel.new 'README.txt'
139
+ readme = RDoc::TopLevel.new 'README.txt'
140
+ readme.parser = RDoc::Parser::Simple
141
+
139
142
  @to = RDoc::Markup::ToHtmlCrossref.new 'C2.html', @c2, true
140
143
 
141
144
  link = @to.handle_special_TIDYLINK tidy 'C2::C3'
@@ -161,7 +164,12 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
161
164
  def test_link
162
165
  assert_equal 'n', @to.link('n', 'n')
163
166
 
164
- assert_equal '<a href="C1.html#method-c-m">m</a>', @to.link('m', 'm')
167
+ assert_equal '<a href="C1.html#method-c-m">::m</a>', @to.link('m', 'm')
168
+ end
169
+
170
+ def test_link_class_method_full
171
+ assert_equal '<a href="Parent.html#method-c-m">Parent.m</a>',
172
+ @to.link('Parent::m', 'Parent::m')
165
173
  end
166
174
 
167
175
  def para text
@@ -111,6 +111,19 @@ class TestRDocMethodAttr < XrefTestCase
111
111
  assert_nil @m1_m.find_method_or_attribute 'm'
112
112
  end
113
113
 
114
+ def test_full_name
115
+ assert_equal 'C1#m', @c1_m.full_name
116
+ assert_equal 'C1::m', @c1__m.full_name
117
+ end
118
+
119
+ def test_output_name
120
+ assert_equal '#m', @c1_m.output_name(@c1)
121
+ assert_equal '::m', @c1__m.output_name(@c1)
122
+
123
+ assert_equal 'C1#m', @c1_m.output_name(@c2)
124
+ assert_equal 'C1.m', @c1__m.output_name(@c2)
125
+ end
126
+
114
127
  def test_search_record
115
128
  @c1_m.comment = 'This is a comment.'
116
129