rdoc 2.0.0

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.

Files changed (62) hide show
  1. data/History.txt +13 -0
  2. data/Manifest.txt +61 -0
  3. data/README.txt +34 -0
  4. data/Rakefile +10 -0
  5. data/bin/rdoc +22 -0
  6. data/bin/ri +6 -0
  7. data/lib/rdoc.rb +277 -0
  8. data/lib/rdoc/code_objects.rb +776 -0
  9. data/lib/rdoc/diagram.rb +338 -0
  10. data/lib/rdoc/dot.rb +249 -0
  11. data/lib/rdoc/generator.rb +1048 -0
  12. data/lib/rdoc/generator/chm.rb +113 -0
  13. data/lib/rdoc/generator/chm/chm.rb +98 -0
  14. data/lib/rdoc/generator/html.rb +370 -0
  15. data/lib/rdoc/generator/html/hefss.rb +414 -0
  16. data/lib/rdoc/generator/html/html.rb +704 -0
  17. data/lib/rdoc/generator/html/kilmer.rb +418 -0
  18. data/lib/rdoc/generator/html/one_page_html.rb +121 -0
  19. data/lib/rdoc/generator/ri.rb +229 -0
  20. data/lib/rdoc/generator/xml.rb +120 -0
  21. data/lib/rdoc/generator/xml/rdf.rb +113 -0
  22. data/lib/rdoc/generator/xml/xml.rb +111 -0
  23. data/lib/rdoc/markup.rb +473 -0
  24. data/lib/rdoc/markup/attribute_manager.rb +274 -0
  25. data/lib/rdoc/markup/formatter.rb +14 -0
  26. data/lib/rdoc/markup/fragments.rb +337 -0
  27. data/lib/rdoc/markup/inline.rb +101 -0
  28. data/lib/rdoc/markup/lines.rb +152 -0
  29. data/lib/rdoc/markup/preprocess.rb +71 -0
  30. data/lib/rdoc/markup/to_flow.rb +185 -0
  31. data/lib/rdoc/markup/to_html.rb +353 -0
  32. data/lib/rdoc/markup/to_html_crossref.rb +86 -0
  33. data/lib/rdoc/markup/to_latex.rb +328 -0
  34. data/lib/rdoc/markup/to_test.rb +50 -0
  35. data/lib/rdoc/options.rb +616 -0
  36. data/lib/rdoc/parsers/parse_c.rb +775 -0
  37. data/lib/rdoc/parsers/parse_f95.rb +1841 -0
  38. data/lib/rdoc/parsers/parse_rb.rb +2584 -0
  39. data/lib/rdoc/parsers/parse_simple.rb +40 -0
  40. data/lib/rdoc/parsers/parserfactory.rb +99 -0
  41. data/lib/rdoc/rdoc.rb +277 -0
  42. data/lib/rdoc/ri.rb +4 -0
  43. data/lib/rdoc/ri/cache.rb +188 -0
  44. data/lib/rdoc/ri/descriptions.rb +150 -0
  45. data/lib/rdoc/ri/display.rb +274 -0
  46. data/lib/rdoc/ri/driver.rb +452 -0
  47. data/lib/rdoc/ri/formatter.rb +616 -0
  48. data/lib/rdoc/ri/paths.rb +102 -0
  49. data/lib/rdoc/ri/reader.rb +106 -0
  50. data/lib/rdoc/ri/util.rb +81 -0
  51. data/lib/rdoc/ri/writer.rb +68 -0
  52. data/lib/rdoc/stats.rb +25 -0
  53. data/lib/rdoc/template.rb +64 -0
  54. data/lib/rdoc/tokenstream.rb +33 -0
  55. data/test/test_rdoc_c_parser.rb +261 -0
  56. data/test/test_rdoc_markup.rb +613 -0
  57. data/test/test_rdoc_markup_attribute_manager.rb +224 -0
  58. data/test/test_rdoc_ri_attribute_formatter.rb +42 -0
  59. data/test/test_rdoc_ri_default_display.rb +295 -0
  60. data/test/test_rdoc_ri_formatter.rb +318 -0
  61. data/test/test_rdoc_ri_overstrike_formatter.rb +69 -0
  62. metadata +134 -0
@@ -0,0 +1,224 @@
1
+ require "test/unit"
2
+ require "rdoc/markup/inline"
3
+
4
+ class TestRDocMarkupAttributeManager < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @am = RDoc::Markup::AttributeManager.new
8
+
9
+ @bold_on = @am.changed_attribute_by_name([], [:BOLD])
10
+ @bold_off = @am.changed_attribute_by_name([:BOLD], [])
11
+
12
+ @tt_on = @am.changed_attribute_by_name([], [:TT])
13
+ @tt_off = @am.changed_attribute_by_name([:TT], [])
14
+
15
+ @em_on = @am.changed_attribute_by_name([], [:EM])
16
+ @em_off = @am.changed_attribute_by_name([:EM], [])
17
+
18
+ @bold_em_on = @am.changed_attribute_by_name([], [:BOLD] | [:EM])
19
+ @bold_em_off = @am.changed_attribute_by_name([:BOLD] | [:EM], [])
20
+
21
+ @em_then_bold = @am.changed_attribute_by_name([:EM], [:EM] | [:BOLD])
22
+
23
+ @em_to_bold = @am.changed_attribute_by_name([:EM], [:BOLD])
24
+
25
+ @am.add_word_pair("{", "}", :WOMBAT)
26
+ @wombat_on = @am.changed_attribute_by_name([], [:WOMBAT])
27
+ @wombat_off = @am.changed_attribute_by_name([:WOMBAT], [])
28
+ end
29
+
30
+ def crossref(text)
31
+ crossref_bitmap = RDoc::Markup::Attribute.bitmap_for(:_SPECIAL_) |
32
+ RDoc::Markup::Attribute.bitmap_for(:CROSSREF)
33
+
34
+ [ @am.changed_attribute_by_name([], [:CROSSREF, :_SPECIAL_]),
35
+ RDoc::Markup::Special.new(crossref_bitmap, text),
36
+ @am.changed_attribute_by_name([:CROSSREF, :_SPECIAL_], [])
37
+ ]
38
+ end
39
+
40
+ def test_adding
41
+ assert_equal(["cat ", @wombat_on, "and", @wombat_off, " dog" ],
42
+ @am.flow("cat {and} dog"))
43
+ #assert_equal(["cat {and} dog" ], @am.flow("cat \\{and} dog"))
44
+ end
45
+
46
+ def test_add_word_pair
47
+ @am.add_word_pair '%', '&', 'percent and'
48
+
49
+ assert RDoc::Markup::AttributeManager::WORD_PAIR_MAP.include?(/(%)(\S+)(&)/)
50
+ assert RDoc::Markup::AttributeManager::PROTECTABLE.include?('%')
51
+ assert !RDoc::Markup::AttributeManager::PROTECTABLE.include?('&')
52
+ end
53
+
54
+ def test_add_word_pair_angle
55
+ e = assert_raise ArgumentError do
56
+ @am.add_word_pair '<', '>', 'angles'
57
+ end
58
+
59
+ assert_equal "Word flags may not start with '<'", e.message
60
+ end
61
+
62
+ def test_add_word_pair_matching
63
+ @am.add_word_pair '^', '^', 'caret'
64
+
65
+ assert RDoc::Markup::AttributeManager::MATCHING_WORD_PAIRS.include?('^')
66
+ assert RDoc::Markup::AttributeManager::PROTECTABLE.include?('^')
67
+ end
68
+
69
+ def test_basic
70
+ assert_equal(["cat"], @am.flow("cat"))
71
+
72
+ assert_equal(["cat ", @bold_on, "and", @bold_off, " dog"],
73
+ @am.flow("cat *and* dog"))
74
+
75
+ assert_equal(["cat ", @bold_on, "AND", @bold_off, " dog"],
76
+ @am.flow("cat *AND* dog"))
77
+
78
+ assert_equal(["cat ", @em_on, "And", @em_off, " dog"],
79
+ @am.flow("cat _And_ dog"))
80
+
81
+ assert_equal(["cat *and dog*"], @am.flow("cat *and dog*"))
82
+
83
+ assert_equal(["*cat and* dog"], @am.flow("*cat and* dog"))
84
+
85
+ assert_equal(["cat *and ", @bold_on, "dog", @bold_off],
86
+ @am.flow("cat *and *dog*"))
87
+
88
+ assert_equal(["cat ", @em_on, "and", @em_off, " dog"],
89
+ @am.flow("cat _and_ dog"))
90
+
91
+ assert_equal(["cat_and_dog"],
92
+ @am.flow("cat_and_dog"))
93
+
94
+ assert_equal(["cat ", @tt_on, "and", @tt_off, " dog"],
95
+ @am.flow("cat +and+ dog"))
96
+
97
+ assert_equal(["cat ", @bold_on, "a_b_c", @bold_off, " dog"],
98
+ @am.flow("cat *a_b_c* dog"))
99
+
100
+ assert_equal(["cat __ dog"],
101
+ @am.flow("cat __ dog"))
102
+
103
+ assert_equal(["cat ", @em_on, "_", @em_off, " dog"],
104
+ @am.flow("cat ___ dog"))
105
+ end
106
+
107
+ def test_bold
108
+ assert_equal [@bold_on, 'bold', @bold_off],
109
+ @am.flow("*bold*")
110
+
111
+ assert_equal [@bold_on, 'Bold:', @bold_off],
112
+ @am.flow("*Bold:*")
113
+
114
+ assert_equal [@bold_on, '\\bold', @bold_off],
115
+ @am.flow("*\\bold*")
116
+ end
117
+
118
+ def test_combined
119
+ assert_equal(["cat ", @em_on, "and", @em_off, " ", @bold_on, "dog", @bold_off],
120
+ @am.flow("cat _and_ *dog*"))
121
+
122
+ assert_equal(["cat ", @em_on, "a__nd", @em_off, " ", @bold_on, "dog", @bold_off],
123
+ @am.flow("cat _a__nd_ *dog*"))
124
+ end
125
+
126
+ def test_convert_attrs
127
+ str = '+foo+'
128
+ attrs = RDoc::Markup::AttrSpan.new str.length
129
+
130
+ @am.convert_attrs str, attrs
131
+
132
+ assert_equal "\000foo\000", str
133
+
134
+ str = '+:foo:+'
135
+ attrs = RDoc::Markup::AttrSpan.new str.length
136
+
137
+ @am.convert_attrs str, attrs
138
+
139
+ assert_equal "\000:foo:\000", str
140
+
141
+ str = '+x-y+'
142
+ attrs = RDoc::Markup::AttrSpan.new str.length
143
+
144
+ @am.convert_attrs str, attrs
145
+
146
+ assert_equal "\000x-y\000", str
147
+ end
148
+
149
+ def test_html_like_em_bold
150
+ assert_equal ["cat ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
151
+ @am.flow("cat <i>and </i><b>dog</b>")
152
+ end
153
+
154
+ def test_html_like_em_bold_SGML
155
+ assert_equal ["cat ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
156
+ @am.flow("cat <i>and <b></i>dog</b>")
157
+ end
158
+
159
+ def test_html_like_em_bold_nested_1
160
+ assert_equal(["cat ", @bold_em_on, "and", @bold_em_off, " dog"],
161
+ @am.flow("cat <i><b>and</b></i> dog"))
162
+ end
163
+
164
+ def test_html_like_em_bold_nested_2
165
+ assert_equal ["cat ", @em_on, "and ", @em_then_bold, "dog", @bold_em_off],
166
+ @am.flow("cat <i>and <b>dog</b></i>")
167
+ end
168
+
169
+ def test_html_like_em_bold_nested_mixed_case
170
+ assert_equal ["cat ", @em_on, "and ", @em_then_bold, "dog", @bold_em_off],
171
+ @am.flow("cat <i>and <B>dog</B></I>")
172
+ end
173
+
174
+ def test_html_like_em_bold_mixed_case
175
+ assert_equal ["cat ", @em_on, "and", @em_off, " ", @bold_on, "dog", @bold_off],
176
+ @am.flow("cat <i>and</i> <B>dog</b>")
177
+ end
178
+
179
+ def test_html_like_teletype
180
+ assert_equal ["cat ", @tt_on, "dog", @tt_off],
181
+ @am.flow("cat <tt>dog</Tt>")
182
+ end
183
+
184
+ def test_html_like_teletype_em_bold_SGML
185
+ assert_equal [@tt_on, "cat", @tt_off, " ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
186
+ @am.flow("<tt>cat</tt> <i>and <b></i>dog</b>")
187
+ end
188
+
189
+ def test_protect
190
+ assert_equal(['cat \\ dog'], @am.flow('cat \\ dog'))
191
+
192
+ assert_equal(["cat <tt>dog</Tt>"], @am.flow("cat \\<tt>dog</Tt>"))
193
+
194
+ assert_equal(["cat ", @em_on, "and", @em_off, " <B>dog</b>"],
195
+ @am.flow("cat <i>and</i> \\<B>dog</b>"))
196
+
197
+ assert_equal(["*word* or <b>text</b>"], @am.flow("\\*word* or \\<b>text</b>"))
198
+
199
+ assert_equal(["_cat_", @em_on, "dog", @em_off],
200
+ @am.flow("\\_cat_<i>dog</i>"))
201
+ end
202
+
203
+ def test_special
204
+ # class names, variable names, file names, or instance variables
205
+ @am.add_special(/(
206
+ \b([A-Z]\w+(::\w+)*)
207
+ | \#\w+[!?=]?
208
+ | \b\w+([_\/\.]+\w+)+[!?=]?
209
+ )/x,
210
+ :CROSSREF)
211
+
212
+ assert_equal(["cat"], @am.flow("cat"))
213
+
214
+ assert_equal(["cat ", crossref("#fred"), " dog"].flatten,
215
+ @am.flow("cat #fred dog"))
216
+
217
+ assert_equal([crossref("#fred"), " dog"].flatten,
218
+ @am.flow("#fred dog"))
219
+
220
+ assert_equal(["cat ", crossref("#fred")].flatten, @am.flow("cat #fred"))
221
+ end
222
+
223
+ end
224
+
@@ -0,0 +1,42 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require 'rdoc/ri/formatter'
4
+
5
+ class TestRDocRIAttributeFormatter < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @output = StringIO.new
9
+ @width = 78
10
+ @indent = ' '
11
+
12
+ @f = RDoc::RI::AttributeFormatter.new @output, @width, @indent
13
+ end
14
+
15
+ def test_wrap_empty
16
+ @f.wrap ''
17
+ assert_equal '', @output.string
18
+ end
19
+
20
+ def test_wrap_long
21
+ @f.wrap 'a ' * (@width / 2)
22
+ assert_equal " a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a \n a \n",
23
+ @output.string
24
+ end
25
+
26
+ def test_wrap_markup
27
+ @f.wrap 'a <tt>b</tt> c'
28
+ assert_equal " a b c\n", @output.string
29
+ end
30
+
31
+ def test_wrap_nil
32
+ @f.wrap nil
33
+ assert_equal '', @output.string
34
+ end
35
+
36
+ def test_wrap_short
37
+ @f.wrap 'a b c'
38
+ assert_equal " a b c\n", @output.string
39
+ end
40
+
41
+ end
42
+
@@ -0,0 +1,295 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require 'rdoc/ri/formatter'
4
+ require 'rdoc/ri/display'
5
+ require 'rdoc/ri/driver'
6
+
7
+ class TestRDocRIDefaultDisplay < Test::Unit::TestCase
8
+
9
+ def setup
10
+ @output = StringIO.new
11
+ @width = 78
12
+ @indent = ' '
13
+
14
+ @dd = RDoc::RI::DefaultDisplay.new RDoc::RI::Formatter, @width, true,
15
+ @output
16
+
17
+ @some_method = {
18
+ 'aliases' => [{'name' => 'some_method_alias'}],
19
+ 'block_params' => 'block_param',
20
+ 'comment' => [RDoc::Markup::Flow::P.new('some comment')],
21
+ 'full_name' => 'SomeClass#some_method',
22
+ 'is_singleton' => false,
23
+ 'name' => 'some_method',
24
+ 'params' => '(arg1, arg2) {|block_param| ...}',
25
+ 'source_path' => '/nonexistent',
26
+ 'visibility' => 'public',
27
+ }
28
+ end
29
+
30
+ def test_display_class_info
31
+ ri_reader = nil
32
+ klass = {
33
+ 'attributes' => [
34
+ { 'name' => 'attribute', 'rw' => 'RW',
35
+ 'comment' => [RDoc::Markup::Flow::P.new('attribute comment')] },
36
+ { 'name' => 'attribute_no_comment', 'rw' => 'RW',
37
+ 'comment' => nil },
38
+ ],
39
+ 'class_methods' => [
40
+ { 'name' => 'class_method' },
41
+ ],
42
+ 'class_method_extensions' => [
43
+ { 'name' => 'class_method_extension' },
44
+ ],
45
+ 'comment' => [RDoc::Markup::Flow::P.new('SomeClass comment')],
46
+ 'constants' => [
47
+ { 'name' => 'CONSTANT', 'value' => '"value"',
48
+ 'comment' => [RDoc::Markup::Flow::P.new('CONSTANT value')] },
49
+ { 'name' => 'CONSTANT_NOCOMMENT', 'value' => '"value"',
50
+ 'comment' => nil },
51
+ ],
52
+ 'display_name' => 'Class',
53
+ 'full_name' => 'SomeClass',
54
+ 'includes' => [],
55
+ 'instance_methods' => [
56
+ { 'name' => 'instance_method' },
57
+ ],
58
+ 'instance_method_extensions' => [
59
+ { 'name' => 'instance_method_extension' },
60
+ ],
61
+ 'superclass_string' => 'Object',
62
+ }
63
+
64
+ @dd.display_class_info klass, ri_reader
65
+
66
+ expected = <<-EOF
67
+ ---------------------------------------------------- Class: SomeClass < Object
68
+ SomeClass comment
69
+
70
+ ------------------------------------------------------------------------------
71
+
72
+
73
+ Constants:
74
+ ----------
75
+
76
+ CONSTANT:
77
+ CONSTANT value
78
+
79
+ CONSTANT_NOCOMMENT
80
+
81
+
82
+ Class methods:
83
+ --------------
84
+
85
+ class_method
86
+
87
+
88
+ Class method extensions:
89
+ ------------------------
90
+
91
+ class_method_extension
92
+
93
+
94
+ Instance methods:
95
+ -----------------
96
+
97
+ instance_method
98
+
99
+
100
+ Instance method extensions:
101
+ ---------------------------
102
+
103
+ instance_method_extension
104
+
105
+
106
+ Attributes:
107
+ -----------
108
+
109
+ attribute (RW):
110
+ attribute comment
111
+
112
+ attribute_no_comment (RW)
113
+ EOF
114
+
115
+ assert_equal expected, @output.string
116
+ end
117
+
118
+ def test_display_flow
119
+ flow = [RDoc::Markup::Flow::P.new('flow')]
120
+
121
+ @dd.display_flow flow
122
+
123
+ assert_equal " flow\n\n", @output.string
124
+ end
125
+
126
+ def test_display_flow_empty
127
+ @dd.display_flow []
128
+
129
+ assert_equal " [no description]\n", @output.string
130
+ end
131
+
132
+ def test_display_flow_nil
133
+ @dd.display_flow nil
134
+
135
+ assert_equal " [no description]\n", @output.string
136
+ end
137
+
138
+ def test_display_method_info
139
+ @dd.display_method_info @some_method
140
+
141
+ expected = <<-EOF
142
+ -------------------------------------------------------- SomeClass#some_method
143
+ some_method(arg1, arg2) {|block_param| ...}
144
+
145
+ Extension from /nonexistent
146
+ ------------------------------------------------------------------------------
147
+ some comment
148
+
149
+
150
+ (also known as some_method_alias)
151
+ EOF
152
+
153
+ assert_equal expected, @output.string
154
+ end
155
+
156
+ def test_display_method_info_singleton
157
+ method = {
158
+ 'aliases' => [],
159
+ 'block_params' => nil,
160
+ 'comment' => nil,
161
+ 'full_name' => 'SomeClass::some_method',
162
+ 'is_singleton' => true,
163
+ 'name' => 'some_method',
164
+ 'params' => '(arg1, arg2)',
165
+ 'visibility' => 'public',
166
+ }
167
+
168
+ @dd.display_method_info method
169
+
170
+ expected = <<-EOF
171
+ ------------------------------------------------------- SomeClass::some_method
172
+ SomeClass::some_method(arg1, arg2)
173
+ ------------------------------------------------------------------------------
174
+ [no description]
175
+ EOF
176
+
177
+ assert_equal expected, @output.string
178
+ end
179
+
180
+ def test_display_method_list
181
+ methods = [
182
+ {
183
+ "aliases" => [],
184
+ "block_params" => nil,
185
+ "comment" => nil,
186
+ "full_name" => "SomeClass#some_method",
187
+ "is_singleton" => false,
188
+ "name" => "some_method",
189
+ "params" => "()",
190
+ "visibility" => "public",
191
+ },
192
+ {
193
+ "aliases" => [],
194
+ "block_params" => nil,
195
+ "comment" => nil,
196
+ "full_name" => "SomeClass#some_other_method",
197
+ "is_singleton" => false,
198
+ "name" => "some_other_method",
199
+ "params" => "()",
200
+ "visibility" => "public",
201
+ },
202
+ ]
203
+
204
+ @dd.display_method_list methods
205
+
206
+ expected = <<-EOF
207
+ More than one method matched your request. You can refine your search by
208
+ asking for information on one of:
209
+
210
+ SomeClass#some_method, SomeClass#some_other_method
211
+ EOF
212
+
213
+ assert_equal expected, @output.string
214
+ end
215
+
216
+ def test_display_params
217
+ @dd.display_params @some_method
218
+
219
+ expected = <<-EOF
220
+ some_method(arg1, arg2) {|block_param| ...}
221
+
222
+ Extension from /nonexistent
223
+ EOF
224
+
225
+ assert_equal expected, @output.string
226
+ end
227
+
228
+ def test_display_params_multiple
229
+ @some_method['params'] = <<-EOF
230
+ some_method(index)
231
+ some_method(start, length)
232
+ EOF
233
+
234
+ @dd.display_params @some_method
235
+
236
+ expected = <<-EOF
237
+ some_method(index)
238
+ some_method(start, length)
239
+
240
+ Extension from /nonexistent
241
+ EOF
242
+
243
+ assert_equal expected, @output.string
244
+ end
245
+
246
+ def test_display_params_singleton
247
+ @some_method['is_singleton'] = true
248
+ @some_method['full_name'] = 'SomeClass::some_method'
249
+
250
+ @dd.display_params @some_method
251
+
252
+ expected = <<-EOF
253
+ SomeClass::some_method(arg1, arg2) {|block_param| ...}
254
+
255
+ Extension from /nonexistent
256
+ EOF
257
+
258
+ assert_equal expected, @output.string
259
+ end
260
+
261
+ def test_list_known_classes
262
+ klasses = %w[SomeClass SomeModule]
263
+
264
+ @dd.list_known_classes klasses
265
+
266
+ expected = <<-EOF
267
+ ---------------------------------------------------- Known classes and modules
268
+
269
+ SomeClass, SomeModule
270
+ EOF
271
+
272
+ assert_equal expected, @output.string
273
+ end
274
+
275
+ def test_list_known_classes_empty
276
+ @dd.list_known_classes []
277
+
278
+ expected = <<-EOF
279
+ No ri data found
280
+
281
+ If you've installed Ruby yourself, you need to generate documentation using:
282
+
283
+ make install-doc
284
+
285
+ from the same place you ran `make` to build ruby.
286
+
287
+ If you installed Ruby from a packaging system, then you may need to
288
+ install an additional package, or ask the packager to enable ri generation.
289
+ EOF
290
+
291
+ assert_equal expected, @output.string
292
+ end
293
+
294
+ end
295
+