rdoc 3.6.1 → 3.7

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 (66) hide show
  1. data.tar.gz.sig +0 -0
  2. data/History.txt +45 -0
  3. data/Manifest.txt +4 -0
  4. data/lib/rdoc.rb +3 -2
  5. data/lib/rdoc/any_method.rb +12 -7
  6. data/lib/rdoc/attr.rb +16 -1
  7. data/lib/rdoc/class_module.rb +156 -42
  8. data/lib/rdoc/code_object.rb +8 -1
  9. data/lib/rdoc/context.rb +75 -29
  10. data/lib/rdoc/generator/markup.rb +3 -1
  11. data/lib/rdoc/generator/ri.rb +3 -2
  12. data/lib/rdoc/generator/template/darkfish/rdoc.css +4 -0
  13. data/lib/rdoc/known_classes.rb +2 -2
  14. data/lib/rdoc/markup.rb +63 -18
  15. data/lib/rdoc/markup/document.rb +43 -4
  16. data/lib/rdoc/markup/formatter.rb +13 -3
  17. data/lib/rdoc/markup/formatter_test_case.rb +13 -3
  18. data/lib/rdoc/markup/indented_paragraph.rb +33 -0
  19. data/lib/rdoc/markup/inline.rb +8 -1
  20. data/lib/rdoc/markup/parser.rb +1 -0
  21. data/lib/rdoc/markup/pre_process.rb +7 -0
  22. data/lib/rdoc/markup/to_ansi.rb +4 -4
  23. data/lib/rdoc/markup/to_bs.rb +1 -1
  24. data/lib/rdoc/markup/to_html.rb +2 -2
  25. data/lib/rdoc/markup/to_html_crossref.rb +3 -2
  26. data/lib/rdoc/markup/to_rdoc.rb +10 -1
  27. data/lib/rdoc/markup/to_test.rb +1 -1
  28. data/lib/rdoc/markup/to_tt_only.rb +1 -1
  29. data/lib/rdoc/parser.rb +1 -1
  30. data/lib/rdoc/parser/c.rb +69 -26
  31. data/lib/rdoc/parser/ruby.rb +19 -9
  32. data/lib/rdoc/rdoc.rb +14 -3
  33. data/lib/rdoc/ri/driver.rb +137 -103
  34. data/lib/rdoc/ri/store.rb +111 -26
  35. data/lib/rdoc/ruby_lex.rb +1 -1
  36. data/lib/rdoc/rubygems_hook.rb +220 -0
  37. data/lib/rdoc/text.rb +1 -1
  38. data/lib/rdoc/top_level.rb +31 -0
  39. data/test/test_rdoc_any_method.rb +68 -0
  40. data/test/test_rdoc_attr.rb +62 -0
  41. data/test/test_rdoc_class_module.rb +459 -29
  42. data/test/test_rdoc_code_object.rb +17 -0
  43. data/test/test_rdoc_context.rb +70 -0
  44. data/test/test_rdoc_context_section.rb +1 -1
  45. data/test/test_rdoc_generator_ri.rb +14 -3
  46. data/test/test_rdoc_markup.rb +55 -1
  47. data/test/test_rdoc_markup_document.rb +83 -0
  48. data/test/test_rdoc_markup_indented_paragraph.rb +40 -0
  49. data/test/test_rdoc_markup_paragraph.rb +12 -0
  50. data/test/test_rdoc_markup_pre_process.rb +13 -2
  51. data/test/test_rdoc_markup_to_ansi.rb +4 -0
  52. data/test/test_rdoc_markup_to_bs.rb +4 -0
  53. data/test/test_rdoc_markup_to_html.rb +7 -3
  54. data/test/test_rdoc_markup_to_rdoc.rb +14 -0
  55. data/test/test_rdoc_markup_to_tt_only.rb +4 -0
  56. data/test/test_rdoc_parser_c.rb +302 -2
  57. data/test/test_rdoc_parser_ruby.rb +48 -1
  58. data/test/test_rdoc_rdoc.rb +41 -10
  59. data/test/test_rdoc_ri_driver.rb +40 -7
  60. data/test/test_rdoc_ri_store.rb +111 -23
  61. data/test/test_rdoc_rubygems_hook.rb +201 -0
  62. data/test/test_rdoc_stats.rb +12 -12
  63. data/test/test_rdoc_text.rb +17 -0
  64. data/test/test_rdoc_top_level.rb +35 -0
  65. metadata +18 -14
  66. metadata.gz.sig +0 -0
@@ -18,6 +18,10 @@ class TestRDocMarkupToBs < RDoc::Markup::TextFormatterTestCase
18
18
  assert_equal "\n", @to.res.join
19
19
  end
20
20
 
21
+ def accept_document
22
+ assert_equal "hello\n", @to.res.join
23
+ end
24
+
21
25
  def accept_heading
22
26
  skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars
23
27
  assert_equal "===== H\bHe\bel\bll\blo\bo\n", @to.res.join
@@ -30,6 +30,10 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase
30
30
  assert_empty @to.res.join
31
31
  end
32
32
 
33
+ def accept_document
34
+ assert_equal "\n<p>hello</p>\n", @to.res.join
35
+ end
36
+
33
37
  def accept_heading
34
38
  assert_equal "\n<h5>Hello</h5>\n", @to.res.join
35
39
  end
@@ -69,7 +73,7 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase
69
73
  assert_equal [], @to.list
70
74
  assert_equal [], @to.in_list_entry
71
75
 
72
- assert_equal "<dl></dl>\n", @to.res.join
76
+ assert_equal "<dl class=\"rdoc-list\"></dl>\n", @to.res.join
73
77
  end
74
78
 
75
79
  def accept_list_end_lalpha
@@ -129,7 +133,7 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase
129
133
  end
130
134
 
131
135
  def accept_list_item_start_label
132
- assert_equal "<dl><dt>cat</dt>\n<dd>", @to.res.join
136
+ assert_equal "<dl class=\"rdoc-list\"><dt>cat</dt>\n<dd>", @to.res.join
133
137
  end
134
138
 
135
139
  def accept_list_item_start_lalpha
@@ -171,7 +175,7 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase
171
175
  assert_equal [:LABEL], @to.list
172
176
  assert_equal [false], @to.in_list_entry
173
177
 
174
- assert_equal "<dl>", @to.res.join
178
+ assert_equal '<dl class="rdoc-list">', @to.res.join
175
179
  end
176
180
 
177
181
  def accept_list_start_lalpha
@@ -18,6 +18,10 @@ class TestRDocMarkupToRDoc < RDoc::Markup::TextFormatterTestCase
18
18
  assert_equal "\n", @to.res.join
19
19
  end
20
20
 
21
+ def accept_document
22
+ assert_equal "hello\n", @to.res.join
23
+ end
24
+
21
25
  def accept_heading
22
26
  assert_equal "===== Hello\n", @to.res.join
23
27
  end
@@ -323,5 +327,15 @@ words words words words
323
327
  assert_equal expected, @to.end_accepting
324
328
  end
325
329
 
330
+ def test_accept_indented_paragraph
331
+ ip = RDoc::Markup::IndentedParagraph.new 2, 'cats are cool'
332
+
333
+ @to.start_accepting
334
+
335
+ @to.accept_indented_paragraph ip
336
+
337
+ assert_equal " cats are cool\n", @to.end_accepting
338
+ end
339
+
326
340
  end
327
341
 
@@ -17,6 +17,10 @@ class TestRDocMarkupToTtOnly < RDoc::Markup::FormatterTestCase
17
17
  assert_empty @to.end_accepting
18
18
  end
19
19
 
20
+ def accept_document
21
+ assert_equal [], @to.res
22
+ end
23
+
20
24
  def accept_heading
21
25
  assert_empty @to.end_accepting
22
26
  end
@@ -46,7 +46,7 @@ assert call-seq correct
46
46
  =end
47
47
 
48
48
  class RDoc::Parser::C
49
- attr_accessor :classes, :singleton_classes
49
+ attr_accessor :classes
50
50
 
51
51
  public :do_classes, :do_constants
52
52
  end
@@ -70,6 +70,22 @@ class TestRDocParserC < MiniTest::Unit::TestCase
70
70
  @tempfile.close
71
71
  end
72
72
 
73
+ def test_class_can_parse
74
+ c_parser = RDoc::Parser::C
75
+
76
+ assert_equal c_parser, c_parser.can_parse('file.C')
77
+ assert_equal c_parser, c_parser.can_parse('file.CC')
78
+ assert_equal c_parser, c_parser.can_parse('file.H')
79
+ assert_equal c_parser, c_parser.can_parse('file.HH')
80
+ assert_equal c_parser, c_parser.can_parse('file.c')
81
+ assert_equal c_parser, c_parser.can_parse('file.cc')
82
+ assert_equal c_parser, c_parser.can_parse('file.cpp')
83
+ assert_equal c_parser, c_parser.can_parse('file.cxx')
84
+ assert_equal c_parser, c_parser.can_parse('file.h')
85
+ assert_equal c_parser, c_parser.can_parse('file.hh')
86
+ assert_equal c_parser, c_parser.can_parse('file.y')
87
+ end
88
+
73
89
  def test_do_attr_rb_attr
74
90
  content = <<-EOF
75
91
  void Init_Blah(void) {
@@ -224,6 +240,21 @@ VALUE cFoo = boot_defclass("Foo", 0);
224
240
  assert_equal nil, klass.superclass
225
241
  end
226
242
 
243
+ def test_do_aliases_missing_class
244
+ content = <<-EOF
245
+ void Init_Blah(void) {
246
+ rb_define_alias(cDate, "b", "a");
247
+ }
248
+ EOF
249
+
250
+ _, err = capture_io do
251
+ refute util_get_class(content, 'cDate')
252
+ end
253
+
254
+ assert_equal "Enclosing class/module \"cDate\" for alias b a not known\n",
255
+ err
256
+ end
257
+
227
258
  def test_do_classes_class
228
259
  content = <<-EOF
229
260
  /* Document-class: Foo
@@ -398,6 +429,140 @@ Multiline comment goes here because this comment spans multiple lines.
398
429
  assert constants.empty?, constants.inspect
399
430
  end
400
431
 
432
+ def test_do_constants_curses
433
+ content = <<-EOF
434
+ void Init_curses(){
435
+ mCurses = rb_define_module("Curses");
436
+
437
+ /*
438
+ * Document-const: Curses::COLOR_BLACK
439
+ *
440
+ * Value of the color black
441
+ */
442
+ rb_curses_define_const(COLOR_BLACK);
443
+ }
444
+ EOF
445
+
446
+ @parser = util_parser content
447
+
448
+ @parser.do_classes
449
+ @parser.do_constants
450
+
451
+ klass = @parser.classes['mCurses']
452
+
453
+ constants = klass.constants
454
+ refute_empty klass.constants
455
+
456
+ assert_equal 'COLOR_BLACK', constants.first.name
457
+ assert_equal 'UINT2NUM(COLOR_BLACK)', constants.first.value
458
+ assert_equal 'Value of the color black', constants.first.comment
459
+ end
460
+
461
+ def test_do_includes
462
+ content = <<-EOF
463
+ Init_foo() {
464
+ VALUE cFoo = rb_define_class("Foo", rb_cObject);
465
+ VALUE mInc = rb_define_module("Inc");
466
+
467
+ rb_include_module(cFoo, mInc);
468
+ }
469
+ EOF
470
+
471
+ klass = util_get_class content, 'cFoo'
472
+
473
+ incl = klass.includes.first
474
+ assert_equal 'Inc', incl.name
475
+ assert_equal '', incl.comment
476
+ assert_equal @top_level, incl.file
477
+ end
478
+
479
+ # HACK parsing warning instead of setting up in file
480
+ def test_do_methods_in_c
481
+ content = <<-EOF
482
+ VALUE blah(VALUE klass, VALUE year) {
483
+ }
484
+
485
+ void Init_Blah(void) {
486
+ cDate = rb_define_class("Date", rb_cObject);
487
+
488
+ rb_define_method(cDate, "blah", blah, 1); /* in blah.c */
489
+ }
490
+ EOF
491
+
492
+ klass = nil
493
+
494
+ _, err = capture_io do
495
+ klass = util_get_class content, 'cDate'
496
+ end
497
+
498
+ assert_match ' blah.c ', err
499
+ end
500
+
501
+ # HACK parsing warning instead of setting up in file
502
+ def test_do_methods_in_cpp
503
+ content = <<-EOF
504
+ VALUE blah(VALUE klass, VALUE year) {
505
+ }
506
+
507
+ void Init_Blah(void) {
508
+ cDate = rb_define_class("Date", rb_cObject);
509
+
510
+ rb_define_method(cDate, "blah", blah, 1); /* in blah.cpp */
511
+ }
512
+ EOF
513
+
514
+ klass = nil
515
+
516
+ _, err = capture_io do
517
+ klass = util_get_class content, 'cDate'
518
+ end
519
+
520
+ assert_match ' blah.cpp ', err
521
+ end
522
+
523
+ # HACK parsing warning instead of setting up in file
524
+ def test_do_methods_in_y
525
+ content = <<-EOF
526
+ VALUE blah(VALUE klass, VALUE year) {
527
+ }
528
+
529
+ void Init_Blah(void) {
530
+ cDate = rb_define_class("Date", rb_cObject);
531
+
532
+ rb_define_method(cDate, "blah", blah, 1); /* in blah.y */
533
+ }
534
+ EOF
535
+
536
+ klass = nil
537
+
538
+ _, err = capture_io do
539
+ klass = util_get_class content, 'cDate'
540
+ end
541
+
542
+ assert_match ' blah.y ', err
543
+ end
544
+
545
+ def test_do_methods_singleton_class
546
+ content = <<-EOF
547
+ VALUE blah(VALUE klass, VALUE year) {
548
+ }
549
+
550
+ void Init_Blah(void) {
551
+ cDate = rb_define_class("Date", rb_cObject);
552
+ sDate = rb_singleton_class(cDate);
553
+
554
+ rb_define_method(sDate, "blah", blah, 1);
555
+ }
556
+ EOF
557
+
558
+ klass = util_get_class content, 'cDate'
559
+
560
+ methods = klass.method_list
561
+ assert_equal 1, methods.length
562
+ assert_equal 'blah', methods.first.name
563
+ assert methods.first.singleton
564
+ end
565
+
401
566
  def test_find_alias_comment
402
567
  parser = util_parser ''
403
568
 
@@ -525,6 +690,53 @@ Init_Foo(void) {
525
690
  assert_equal '', klass.comment
526
691
  end
527
692
 
693
+ def test_find_const_comment_rb_define
694
+ content = <<-EOF
695
+ /*
696
+ * A comment
697
+ */
698
+ rb_define_const(cFoo, "CONST", value);
699
+ EOF
700
+
701
+ parser = util_parser content
702
+
703
+ comment = parser.find_const_comment 'const', 'CONST'
704
+
705
+ assert_equal "/*\n * A comment\n */\n", comment
706
+ end
707
+
708
+ def test_find_const_comment_document_const
709
+ content = <<-EOF
710
+ /*
711
+ * Document-const: CONST
712
+ *
713
+ * A comment
714
+ */
715
+ EOF
716
+
717
+ parser = util_parser content
718
+
719
+ comment = parser.find_const_comment nil, 'CONST'
720
+
721
+ assert_equal " *\n * A comment\n */", comment
722
+ end
723
+
724
+ def test_find_const_comment_document_const_full_name
725
+ content = <<-EOF
726
+ /*
727
+ * Document-const: Foo::CONST
728
+ *
729
+ * A comment
730
+ */
731
+ EOF
732
+
733
+ parser = util_parser content
734
+
735
+ comment = parser.find_const_comment nil, 'CONST', 'Foo'
736
+
737
+ assert_equal " *\n * A comment\n */", comment
738
+ end
739
+
528
740
  def test_find_body
529
741
  content = <<-EOF
530
742
  /*
@@ -699,6 +911,81 @@ Init_Foo(void) {
699
911
  assert_equal "a comment for bar", baz.comment
700
912
  end
701
913
 
914
+ def test_find_body_document_method_equals
915
+ content = <<-EOF
916
+ /*
917
+ * Document-method: Zlib::GzipFile#mtime=
918
+ *
919
+ * A comment
920
+ */
921
+ static VALUE
922
+ rb_gzfile_set_mtime(VALUE obj, VALUE mtime)
923
+ {
924
+
925
+ void
926
+ Init_zlib() {
927
+ mZlib = rb_define_module("Zlib");
928
+ cGzipFile = rb_define_class_under(mZlib, "GzipFile", rb_cObject);
929
+ cGzipWriter = rb_define_class_under(mZlib, "GzipWriter", cGzipFile);
930
+ rb_define_method(cGzipWriter, "mtime=", rb_gzfile_set_mtime, 1);
931
+ }
932
+ EOF
933
+
934
+ klass = util_get_class content, 'cGzipWriter'
935
+ assert_equal 1, klass.method_list.length
936
+
937
+ methods = klass.method_list.sort
938
+
939
+ bar = methods.first
940
+ assert_equal 'Zlib::GzipWriter#mtime=', bar.full_name
941
+ assert_equal 'A comment', bar.comment
942
+ end
943
+
944
+ def test_find_body_document_method_same
945
+ content = <<-EOF
946
+ VALUE
947
+ s_bar() {
948
+ }
949
+
950
+ VALUE
951
+ bar() {
952
+ }
953
+
954
+ /*
955
+ * Document-method: Foo::bar
956
+ *
957
+ * a comment for Foo::bar
958
+ */
959
+
960
+ /*
961
+ * Document-method: Foo#bar
962
+ *
963
+ * a comment for Foo#bar
964
+ */
965
+
966
+ void
967
+ Init_Foo(void) {
968
+ VALUE foo = rb_define_class("Foo", rb_cObject);
969
+
970
+ rb_define_singleton_method(foo, "bar", s_bar, 0);
971
+ rb_define_method(foo, "bar", bar, 0);
972
+ }
973
+ EOF
974
+
975
+ klass = util_get_class content, 'foo'
976
+ assert_equal 2, klass.method_list.length
977
+
978
+ methods = klass.method_list.sort
979
+
980
+ s_bar = methods.first
981
+ assert_equal 'Foo::bar', s_bar.full_name
982
+ assert_equal "a comment for Foo::bar", s_bar.comment
983
+
984
+ bar = methods.last
985
+ assert_equal 'Foo#bar', bar.full_name
986
+ assert_equal "a comment for Foo#bar", bar.comment
987
+ end
988
+
702
989
  def test_find_modifiers_call_seq
703
990
  comment = <<-COMMENT
704
991
  /* call-seq:
@@ -830,7 +1117,6 @@ rb_m(int argc, VALUE *argv, VALUE obj) {
830
1117
  assert_equal '(p1)', m.params
831
1118
  end
832
1119
 
833
-
834
1120
  def test_handle_method_args_0
835
1121
  parser = util_parser "Document-method: BasicObject#==\n blah */"
836
1122
 
@@ -905,6 +1191,20 @@ rb_m(int argc, VALUE *argv, VALUE obj) {
905
1191
  assert_equal :public, new.visibility
906
1192
  end
907
1193
 
1194
+ def test_handle_singleton
1195
+ parser = util_parser <<-SINGLE
1196
+ void Init_Blah(void) {
1197
+ cDate = rb_define_class("Date", rb_cObject);
1198
+ sDate = rb_singleton_class(cDate);
1199
+ }
1200
+ SINGLE
1201
+
1202
+ parser.scan
1203
+
1204
+ assert_equal 'Date', parser.known_classes['sDate']
1205
+ assert_equal 'Date', parser.singleton_classes['sDate']
1206
+ end
1207
+
908
1208
  def test_look_for_directives_in
909
1209
  parser = util_parser ''
910
1210
 
@@ -1084,6 +1084,26 @@ EOF
1084
1084
  assert_equal top_bar, bar.find_module_named('A')
1085
1085
  end
1086
1086
 
1087
+ def test_parse_include
1088
+ klass = RDoc::NormalClass.new 'C'
1089
+ klass.parent = @top_level
1090
+
1091
+ comment = "# my include\n"
1092
+
1093
+ util_parser "include I"
1094
+
1095
+ @parser.get_tk # include
1096
+
1097
+ @parser.parse_include klass, comment
1098
+
1099
+ assert_equal 1, klass.includes.length
1100
+
1101
+ incl = klass.includes.first
1102
+ assert_equal 'I', incl.name
1103
+ assert_equal 'my include', incl.comment
1104
+ assert_equal @top_level, incl.file
1105
+ end
1106
+
1087
1107
  def test_parse_meta_method
1088
1108
  klass = RDoc::NormalClass.new 'Foo'
1089
1109
  klass.parent = @top_level
@@ -2028,6 +2048,33 @@ end
2028
2048
  assert_equal 'm comment', m.comment
2029
2049
  end
2030
2050
 
2051
+ def test_scan_block_comment_nested # Issue #41
2052
+ content = <<-CONTENT
2053
+ require 'something'
2054
+ =begin rdoc
2055
+ findmeindoc
2056
+ =end
2057
+ module Foo
2058
+ class Bar
2059
+ end
2060
+ end
2061
+ CONTENT
2062
+
2063
+ util_parser content
2064
+
2065
+ @parser.scan
2066
+
2067
+ foo = @top_level.modules.first
2068
+
2069
+ assert_equal 'Foo', foo.full_name
2070
+ assert_equal 'findmeindoc', foo.comment
2071
+
2072
+ bar = foo.classes.first
2073
+
2074
+ assert_equal 'Foo::Bar', bar.full_name
2075
+ assert_equal '', bar.comment
2076
+ end
2077
+
2031
2078
  def test_scan_block_comment_notflush
2032
2079
  ##
2033
2080
  #
@@ -2067,7 +2114,7 @@ end
2067
2114
 
2068
2115
  foo = @top_level.classes.first
2069
2116
 
2070
- assert_equal "= DESCRIPTION\n\nThis is a simple test class\n\n= RUMPUS\n\nIs a silly word",
2117
+ assert_equal "= DESCRIPTION\n\nThis is a simple test class\n\n= RUMPUS\n\nIs a silly word",
2071
2118
  foo.comment
2072
2119
 
2073
2120
  m = foo.method_list.first