rdoc 3.9.5 → 3.10.pre.1

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 (183) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.autotest +6 -3
  3. data/History.txt +63 -13
  4. data/LICENSE.rdoc +57 -0
  5. data/Manifest.txt +60 -6
  6. data/Rakefile +24 -12
  7. data/TODO.rdoc +30 -0
  8. data/bin/rdoc +0 -2
  9. data/lib/rdoc.rb +55 -2
  10. data/lib/rdoc/alias.rb +0 -2
  11. data/lib/rdoc/anon_class.rb +0 -2
  12. data/lib/rdoc/any_method.rb +0 -3
  13. data/lib/rdoc/attr.rb +0 -2
  14. data/lib/rdoc/class_module.rb +40 -7
  15. data/lib/rdoc/code_object.rb +1 -3
  16. data/lib/rdoc/code_objects.rb +3 -21
  17. data/lib/rdoc/comment.rb +225 -0
  18. data/lib/rdoc/constant.rb +0 -2
  19. data/lib/rdoc/context.rb +37 -120
  20. data/lib/rdoc/context/section.rb +114 -0
  21. data/lib/rdoc/cross_reference.rb +16 -7
  22. data/lib/rdoc/encoding.rb +0 -2
  23. data/lib/rdoc/gauntlet.rb +1 -1
  24. data/lib/rdoc/generator.rb +7 -2
  25. data/lib/rdoc/generator/darkfish.rb +126 -20
  26. data/lib/rdoc/generator/json_index.rb +240 -0
  27. data/lib/rdoc/generator/markup.rb +17 -54
  28. data/lib/rdoc/generator/ri.rb +0 -3
  29. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
  30. data/lib/rdoc/generator/template/darkfish/_head.rhtml +16 -0
  31. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +18 -0
  32. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +9 -0
  33. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +8 -0
  34. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +16 -0
  35. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +12 -0
  36. data/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +7 -0
  37. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +12 -0
  38. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +10 -0
  39. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +10 -0
  40. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +10 -0
  41. data/lib/rdoc/generator/template/darkfish/class.rhtml +161 -0
  42. data/lib/rdoc/generator/template/darkfish/fileinfo.rhtml +32 -0
  43. data/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
  44. data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
  45. data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
  46. data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
  47. data/lib/rdoc/generator/template/darkfish/index.rhtml +16 -61
  48. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +99 -64
  49. data/lib/rdoc/generator/template/darkfish/js/jquery.js +15 -29
  50. data/lib/rdoc/generator/template/darkfish/js/search.js +94 -0
  51. data/lib/rdoc/generator/template/darkfish/page.rhtml +16 -0
  52. data/lib/rdoc/generator/template/darkfish/rdoc.css +126 -286
  53. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +50 -0
  54. data/lib/rdoc/generator/template/json_index/js/navigation.js +142 -0
  55. data/lib/rdoc/generator/template/json_index/js/searcher.js +228 -0
  56. data/lib/rdoc/ghost_method.rb +0 -2
  57. data/lib/rdoc/include.rb +0 -2
  58. data/lib/rdoc/markup.rb +204 -43
  59. data/lib/rdoc/markup/attr_changer.rb +25 -0
  60. data/lib/rdoc/markup/attr_span.rb +29 -0
  61. data/lib/rdoc/markup/attribute.rb +51 -0
  62. data/lib/rdoc/markup/document.rb +22 -1
  63. data/lib/rdoc/markup/formatter.rb +4 -11
  64. data/lib/rdoc/markup/formatter_test_case.rb +1 -2
  65. data/lib/rdoc/markup/heading.rb +44 -0
  66. data/lib/rdoc/markup/include.rb +42 -0
  67. data/lib/rdoc/markup/inline.rb +1 -144
  68. data/lib/rdoc/markup/list.rb +2 -1
  69. data/lib/rdoc/markup/parser.rb +6 -16
  70. data/lib/rdoc/markup/pre_process.rb +64 -10
  71. data/lib/rdoc/markup/raw.rb +1 -1
  72. data/lib/rdoc/markup/special.rb +40 -0
  73. data/lib/rdoc/markup/text_formatter_test_case.rb +0 -2
  74. data/lib/rdoc/markup/to_ansi.rb +0 -2
  75. data/lib/rdoc/markup/to_bs.rb +0 -2
  76. data/lib/rdoc/markup/to_html.rb +102 -34
  77. data/lib/rdoc/markup/to_html_crossref.rb +36 -5
  78. data/lib/rdoc/markup/to_html_snippet.rb +270 -0
  79. data/lib/rdoc/markup/to_label.rb +55 -0
  80. data/lib/rdoc/markup/to_rdoc.rb +0 -3
  81. data/lib/rdoc/markup/to_table_of_contents.rb +62 -0
  82. data/lib/rdoc/markup/to_test.rb +0 -3
  83. data/lib/rdoc/markup/to_tt_only.rb +0 -3
  84. data/lib/rdoc/markup/verbatim.rb +18 -0
  85. data/lib/rdoc/meta_method.rb +0 -2
  86. data/lib/rdoc/method_attr.rb +17 -1
  87. data/lib/rdoc/normal_class.rb +0 -2
  88. data/lib/rdoc/normal_module.rb +0 -2
  89. data/lib/rdoc/options.rb +18 -3
  90. data/lib/rdoc/parser.rb +74 -42
  91. data/lib/rdoc/parser/c.rb +79 -118
  92. data/lib/rdoc/parser/rd.rb +22 -0
  93. data/lib/rdoc/parser/ruby.rb +86 -54
  94. data/lib/rdoc/parser/simple.rb +21 -9
  95. data/lib/rdoc/parser/text.rb +11 -0
  96. data/lib/rdoc/rd.rb +95 -0
  97. data/lib/rdoc/rd/block_parser.ry +638 -0
  98. data/lib/rdoc/rd/inline.rb +71 -0
  99. data/lib/rdoc/rd/inline_parser.ry +575 -0
  100. data/lib/rdoc/rdoc.rb +8 -23
  101. data/lib/rdoc/require.rb +0 -2
  102. data/lib/rdoc/ri.rb +4 -2
  103. data/lib/rdoc/ri/driver.rb +2 -6
  104. data/lib/rdoc/ri/store.rb +0 -1
  105. data/lib/rdoc/ruby_lex.rb +43 -20
  106. data/lib/rdoc/ruby_token.rb +44 -2
  107. data/lib/rdoc/single_class.rb +0 -2
  108. data/lib/rdoc/stats.rb +0 -5
  109. data/lib/rdoc/task.rb +2 -6
  110. data/lib/rdoc/test_case.rb +59 -0
  111. data/lib/rdoc/text.rb +42 -30
  112. data/lib/rdoc/token_stream.rb +45 -0
  113. data/lib/rdoc/tom_doc.rb +232 -0
  114. data/lib/rdoc/top_level.rb +36 -4
  115. data/test/test_attribute_manager.rb +26 -29
  116. data/test/test_rdoc_any_method.rb +2 -26
  117. data/test/test_rdoc_attr.rb +4 -4
  118. data/test/test_rdoc_class_module.rb +95 -12
  119. data/test/test_rdoc_code_object.rb +10 -3
  120. data/test/test_rdoc_comment.rb +504 -0
  121. data/test/test_rdoc_context.rb +60 -11
  122. data/test/test_rdoc_context_section.rb +16 -17
  123. data/test/test_rdoc_cross_reference.rb +17 -2
  124. data/test/test_rdoc_encoding.rb +4 -7
  125. data/test/test_rdoc_generator_darkfish.rb +12 -11
  126. data/test/test_rdoc_generator_json_index.rb +255 -0
  127. data/test/test_rdoc_generator_markup.rb +56 -0
  128. data/test/test_rdoc_generator_ri.rb +8 -11
  129. data/test/test_rdoc_markup.rb +9 -5
  130. data/test/test_rdoc_markup_attribute_manager.rb +5 -8
  131. data/test/test_rdoc_markup_document.rb +34 -6
  132. data/test/test_rdoc_markup_formatter.rb +11 -13
  133. data/test/test_rdoc_markup_heading.rb +20 -0
  134. data/test/test_rdoc_markup_include.rb +19 -0
  135. data/test/test_rdoc_markup_indented_paragraph.rb +4 -5
  136. data/test/test_rdoc_markup_paragraph.rb +2 -5
  137. data/test/test_rdoc_markup_parser.rb +87 -7
  138. data/test/test_rdoc_markup_pre_process.rb +60 -9
  139. data/test/test_rdoc_markup_raw.rb +4 -6
  140. data/test/test_rdoc_markup_to_ansi.rb +1 -4
  141. data/test/test_rdoc_markup_to_bs.rb +1 -4
  142. data/test/test_rdoc_markup_to_html.rb +170 -31
  143. data/test/test_rdoc_markup_to_html_crossref.rb +89 -11
  144. data/test/test_rdoc_markup_to_html_snippet.rb +668 -0
  145. data/test/test_rdoc_markup_to_label.rb +50 -0
  146. data/test/test_rdoc_markup_to_rdoc.rb +1 -4
  147. data/test/test_rdoc_markup_to_table_of_contents.rb +90 -0
  148. data/test/test_rdoc_markup_to_tt_only.rb +1 -4
  149. data/test/test_rdoc_markup_verbatim.rb +16 -0
  150. data/test/test_rdoc_method_attr.rb +16 -1
  151. data/test/test_rdoc_options.rb +17 -7
  152. data/test/test_rdoc_parser.rb +75 -6
  153. data/test/test_rdoc_parser_c.rb +56 -104
  154. data/test/test_rdoc_parser_rd.rb +52 -0
  155. data/test/test_rdoc_parser_ruby.rb +264 -323
  156. data/test/test_rdoc_parser_simple.rb +33 -17
  157. data/test/test_rdoc_rd.rb +30 -0
  158. data/test/test_rdoc_rd_block_parser.rb +527 -0
  159. data/test/test_rdoc_rd_inline.rb +63 -0
  160. data/test/test_rdoc_rd_inline_parser.rb +173 -0
  161. data/test/test_rdoc_rdoc.rb +7 -9
  162. data/test/test_rdoc_ri_driver.rb +10 -15
  163. data/test/test_rdoc_ri_paths.rb +6 -6
  164. data/test/test_rdoc_ri_store.rb +6 -13
  165. data/test/test_rdoc_ruby_lex.rb +53 -5
  166. data/test/test_rdoc_rubygems_hook.rb +2 -1
  167. data/test/test_rdoc_stats.rb +83 -103
  168. data/test/test_rdoc_task.rb +5 -4
  169. data/test/test_rdoc_text.rb +156 -11
  170. data/test/test_rdoc_token_stream.rb +42 -0
  171. data/test/test_rdoc_tom_doc.rb +458 -0
  172. data/test/test_rdoc_top_level.rb +49 -2
  173. data/test/xref_test_case.rb +4 -8
  174. metadata +217 -111
  175. metadata.gz.sig +0 -0
  176. checksums.yaml +0 -7
  177. checksums.yaml.gz.sig +0 -0
  178. data/CVE-2013-0256.rdoc +0 -49
  179. data/LICENSE.txt +0 -57
  180. data/lib/rdoc/generator/template/darkfish/classpage.rhtml +0 -321
  181. data/lib/rdoc/generator/template/darkfish/filepage.rhtml +0 -124
  182. data/lib/rdoc/generator/template/darkfish/js/quicksearch.js +0 -114
  183. data/lib/rdoc/generator/template/darkfish/js/thickbox-compressed.js +0 -10
@@ -1,5 +1,3 @@
1
- require 'rubygems'
2
- require 'minitest/autorun'
3
1
  require File.expand_path '../xref_test_case', __FILE__
4
2
 
5
3
  class TestRDocContext < XrefTestCase
@@ -255,18 +253,18 @@ class TestRDocContext < XrefTestCase
255
253
  def test_add_section
256
254
  default_section = @context.sections.first
257
255
 
258
- @context.add_section nil, '# comment'
256
+ @context.add_section nil, RDoc::Comment.new('# comment', @top_level)
259
257
 
260
258
  assert_equal 1, @context.sections.length
261
- assert_equal '# comment', @context.sections.first.comment
259
+ assert_equal '# comment', @context.sections.first.comment.text
262
260
 
263
- @context.add_section nil, '# new comment'
261
+ @context.add_section nil, RDoc::Comment.new('# new comment', @top_level)
264
262
 
265
263
  assert_equal 1, @context.sections.length
266
264
  assert_equal "# comment\n# ---\n# new comment",
267
- @context.sections.first.comment
265
+ @context.sections.first.comment.text
268
266
 
269
- @context.add_section 'other', ''
267
+ @context.add_section 'other', RDoc::Comment.new('', @top_level)
270
268
 
271
269
  assert_equal 2, @context.sections.length
272
270
 
@@ -275,6 +273,23 @@ class TestRDocContext < XrefTestCase
275
273
  assert_equal default_section, @context.current_section
276
274
  end
277
275
 
276
+ def test_add_section_no_comment
277
+ default_section = @context.sections.first
278
+
279
+ @context.add_section nil
280
+
281
+ assert_equal 1, @context.sections.length
282
+
283
+ @context.add_section 'other'
284
+
285
+ assert_equal 2, @context.sections.length
286
+
287
+ new_section = @context.sections.find { |section| section.title == 'other' }
288
+
289
+ assert new_section
290
+ assert_equal default_section, @context.current_section
291
+ end
292
+
278
293
  def test_add_to
279
294
  incl = RDoc::Include.new 'Name', 'comment'
280
295
  arr = []
@@ -288,7 +303,8 @@ class TestRDocContext < XrefTestCase
288
303
  def test_add_to_temporary_section
289
304
  incl = RDoc::Include.new 'Name', 'comment'
290
305
  arr = []
291
- section = @context.add_section 'temporary', ''
306
+ section =
307
+ @context.add_section 'temporary', RDoc::Comment.new('', @top_level)
292
308
  @context.temporary_section = section
293
309
 
294
310
  @context.add_to arr, incl
@@ -328,7 +344,8 @@ class TestRDocContext < XrefTestCase
328
344
  def test_current_section
329
345
  default_section = @context.current_section
330
346
 
331
- new_section = @context.add_section 'other', ''
347
+ new_section =
348
+ @context.add_section 'other', RDoc::Comment.new('', @top_level)
332
349
  @context.temporary_section = new_section
333
350
 
334
351
  assert_equal new_section, @context.current_section
@@ -653,11 +670,11 @@ class TestRDocContext < XrefTestCase
653
670
  def test_set_current_section
654
671
  default_section = @context.sections.first
655
672
 
656
- @context.set_current_section nil, ''
673
+ @context.set_current_section nil, RDoc::Comment.new('', @top_level)
657
674
 
658
675
  assert_equal default_section, @context.current_section
659
676
 
660
- @context.set_current_section 'other', ''
677
+ @context.set_current_section 'other', RDoc::Comment.new('', @top_level)
661
678
 
662
679
  new_section = @context.sections.find { |section|
663
680
  section != default_section
@@ -666,6 +683,38 @@ class TestRDocContext < XrefTestCase
666
683
  assert_equal new_section, @context.current_section
667
684
  end
668
685
 
686
+ def test_sort_sections
687
+ c = RDoc::Context.new
688
+ c.add_section 'C'
689
+ c.add_section 'A'
690
+ c.add_section 'B'
691
+
692
+ titles = c.sort_sections.map { |section| section.title }
693
+
694
+ assert_equal [nil, 'A', 'B', 'C'], titles
695
+ end
696
+
697
+ def test_sort_sections_tomdoc
698
+ c = RDoc::Context.new
699
+ c.add_section 'Public'
700
+ c.add_section 'Internal'
701
+ c.add_section 'Deprecated'
702
+
703
+ titles = c.sort_sections.map { |section| section.title }
704
+
705
+ assert_equal [nil, 'Public', 'Internal', 'Deprecated'], titles
706
+ end
707
+
708
+ def test_sort_sections_tomdoc_missing
709
+ c = RDoc::Context.new
710
+ c.add_section 'Internal'
711
+ c.add_section 'Public'
712
+
713
+ titles = c.sort_sections.map { |section| section.title }
714
+
715
+ assert_equal [nil, 'Public', 'Internal'], titles
716
+ end
717
+
669
718
  def util_visibilities
670
719
  @pub = RDoc::AnyMethod.new nil, 'pub'
671
720
  @prot = RDoc::AnyMethod.new nil, 'prot'
@@ -1,14 +1,12 @@
1
- require 'rubygems'
2
- require 'cgi'
3
- require 'minitest/autorun'
4
- require 'rdoc'
5
- require 'rdoc/code_objects'
1
+ require 'rdoc/test_case'
6
2
 
7
- class TestRDocContextSection < MiniTest::Unit::TestCase
3
+ class TestRDocContextSection < RDoc::TestCase
8
4
 
9
5
  def setup
6
+ super
7
+
10
8
  @S = RDoc::Context::Section
11
- @s = @S.new nil, 'section', '# comment'
9
+ @s = @S.new nil, 'section', comment('# comment')
12
10
  end
13
11
 
14
12
  def test_aref
@@ -20,26 +18,27 @@ class TestRDocContextSection < MiniTest::Unit::TestCase
20
18
  end
21
19
 
22
20
  def test_comment_equals
23
- @s.comment = "# :section: section\n"
21
+ @s.comment = RDoc::Comment.new "# :section: section\n"
24
22
 
25
- assert_equal "# comment", @s.comment
23
+ assert_equal "# comment", @s.comment.text
26
24
 
27
- @s.comment = "# :section: section\n# other"
25
+ @s.comment = RDoc::Comment.new "# :section: section\n# other"
28
26
 
29
- assert_equal "# comment\n# ---\n# other", @s.comment
27
+ assert_equal "# comment\n# ---\n# other", @s.comment.text
30
28
 
31
29
  s = @S.new nil, nil, nil
32
30
 
33
- s.comment = "# :section:\n# other"
31
+ s.comment = RDoc::Comment.new "# :section:\n# other"
34
32
 
35
- assert_equal "# other", s.comment
33
+ assert_equal "# other", s.comment.text
36
34
  end
37
35
 
38
36
  def test_extract_comment
39
- assert_equal '', @s.extract_comment('')
40
- assert_equal '', @s.extract_comment("# :section: b\n")
41
- assert_equal '# c', @s.extract_comment("# :section: b\n# c")
42
- assert_equal '# c', @s.extract_comment("# a\n# :section: b\n# c")
37
+ assert_equal '', @s.extract_comment(comment('')).text
38
+ assert_equal '', @s.extract_comment(comment("# :section: b\n")).text
39
+ assert_equal '# c', @s.extract_comment(comment("# :section: b\n# c")).text
40
+ assert_equal '# c',
41
+ @s.extract_comment(comment("# a\n# :section: b\n# c")).text
43
42
  end
44
43
 
45
44
  def test_sequence
@@ -1,5 +1,3 @@
1
- require 'rubygems'
2
- require 'minitest/autorun'
3
1
  require File.expand_path '../xref_test_case', __FILE__
4
2
 
5
3
  class TestRDocCrossReference < XrefTestCase
@@ -131,6 +129,23 @@ class TestRDocCrossReference < XrefTestCase
131
129
  assert_ref @c2_c3_m, '::C2::C3#m(*)'
132
130
  end
133
131
 
132
+ def test_resolve_percent
133
+ i_percent = RDoc::AnyMethod.new nil, '%'
134
+ i_percent.singleton = false
135
+ @c1.add_method i_percent
136
+
137
+ c_percent = RDoc::AnyMethod.new nil, '%'
138
+ c_percent.singleton = true
139
+ @c1.add_method c_percent
140
+
141
+ assert_ref i_percent, '%'
142
+ assert_ref i_percent, '#%'
143
+ assert_ref c_percent, '::%'
144
+
145
+ assert_ref i_percent, 'C1#%'
146
+ assert_ref c_percent, 'C1::%'
147
+ end
148
+
134
149
  def test_resolve_no_ref
135
150
  assert_equal '', @xref.resolve('', '')
136
151
 
@@ -1,15 +1,12 @@
1
1
  # coding: US-ASCII
2
2
 
3
- require 'rubygems'
4
- require 'minitest/autorun'
5
- require 'rdoc'
6
- require 'rdoc/encoding'
3
+ require 'rdoc/test_case'
7
4
 
8
- require 'tempfile'
9
-
10
- class TestRDocEncoding < MiniTest::Unit::TestCase
5
+ class TestRDocEncoding < RDoc::TestCase
11
6
 
12
7
  def setup
8
+ super
9
+
13
10
  @tempfile = Tempfile.new 'test_rdoc_encoding'
14
11
  end
15
12
 
@@ -1,16 +1,12 @@
1
- require 'minitest/autorun'
2
- require 'rdoc/rdoc'
3
- require 'rdoc/generator/darkfish'
4
- require 'tmpdir'
5
- require 'fileutils'
1
+ require 'rdoc/test_case'
6
2
 
7
- class TestRDocGeneratorDarkfish < MiniTest::Unit::TestCase
3
+ class TestRDocGeneratorDarkfish < RDoc::TestCase
8
4
 
9
5
  def setup
10
- @pwd = Dir.pwd
6
+ super
7
+
11
8
  @lib_dir = "#{@pwd}/lib"
12
9
  $LOAD_PATH.unshift @lib_dir # ensure we load from this RDoc
13
- RDoc::TopLevel.reset
14
10
 
15
11
  @options = RDoc::Options.new
16
12
  @options.option_parser = OptionParser.new
@@ -22,7 +18,7 @@ class TestRDocGeneratorDarkfish < MiniTest::Unit::TestCase
22
18
  @options.generator = RDoc::Generator::Darkfish
23
19
 
24
20
  $LOAD_PATH.each do |path|
25
- darkfish_dir = File.join path, 'rdoc/generator/template/darkfish'
21
+ darkfish_dir = File.join path, 'rdoc/generator/template/darkfish/'
26
22
  next unless File.directory? darkfish_dir
27
23
  @options.template_dir = darkfish_dir
28
24
  break
@@ -37,6 +33,7 @@ class TestRDocGeneratorDarkfish < MiniTest::Unit::TestCase
37
33
  rd.generator = @g
38
34
 
39
35
  @top_level = RDoc::TopLevel.new 'file.rb'
36
+ @top_level.parser = RDoc::Parser::Ruby
40
37
  @klass = @top_level.add_class RDoc::NormalClass, 'Object'
41
38
 
42
39
  @meth = RDoc::AnyMethod.new nil, 'method'
@@ -52,6 +49,8 @@ class TestRDocGeneratorDarkfish < MiniTest::Unit::TestCase
52
49
  end
53
50
 
54
51
  def teardown
52
+ super
53
+
55
54
  $LOAD_PATH.shift
56
55
  Dir.chdir @pwd
57
56
  FileUtils.rm_rf @tmpdir
@@ -74,6 +73,8 @@ class TestRDocGeneratorDarkfish < MiniTest::Unit::TestCase
74
73
  assert_file 'index.html'
75
74
  assert_file 'Object.html'
76
75
  assert_file 'file_rb.html'
76
+ assert_file 'table_of_contents.html'
77
+ assert_file 'js/search_index.js'
77
78
 
78
79
  encoding = if Object.const_defined? :Encoding then
79
80
  Regexp.escape Encoding.default_external.name
@@ -104,7 +105,7 @@ class TestRDocGeneratorDarkfish < MiniTest::Unit::TestCase
104
105
  end
105
106
 
106
107
  def test_template_for
107
- classpage = Pathname.new @options.template_dir + '/classpage.rhtml'
108
+ classpage = Pathname.new @options.template_dir + 'class.rhtml'
108
109
 
109
110
  template = @g.send(:template_for, classpage)
110
111
  assert_kind_of RDoc::ERBIO, template
@@ -113,7 +114,7 @@ class TestRDocGeneratorDarkfish < MiniTest::Unit::TestCase
113
114
  end
114
115
 
115
116
  def test_template_for_dry_run
116
- classpage = Pathname.new @options.template_dir + '/classpage.rhtml'
117
+ classpage = Pathname.new @options.template_dir + 'class.rhtml'
117
118
 
118
119
  template = @g.send(:template_for, classpage)
119
120
  assert_kind_of ERB, template
@@ -0,0 +1,255 @@
1
+ # coding: US-ASCII
2
+
3
+ require 'rdoc/test_case'
4
+
5
+ class TestRDocGeneratorJsonIndex < RDoc::TestCase
6
+
7
+ def setup
8
+ super
9
+
10
+ @tmpdir = File.join Dir.tmpdir, "test_rdoc_generator_darkfish_#{$$}"
11
+ FileUtils.mkdir_p @tmpdir
12
+
13
+ @options = RDoc::Options.new
14
+ @options.files = []
15
+ # JsonIndex is used in conjunction with another generator
16
+ @options.setup_generator 'darkfish'
17
+ @options.template_dir = ''
18
+ @options.op_dir = @tmpdir
19
+ @options.option_parser = OptionParser.new
20
+ @options.finish
21
+
22
+ @darkfish = RDoc::Generator::Darkfish.new @options
23
+ @g = RDoc::Generator::JsonIndex.new @darkfish, @options
24
+
25
+ @rdoc = RDoc::RDoc.new
26
+ @rdoc.options = @options
27
+ @rdoc.generator = @g
28
+ RDoc::RDoc.current = @rdoc
29
+
30
+ @top_level = RDoc::TopLevel.new 'file.rb'
31
+ @top_level.parser = RDoc::Parser::Ruby
32
+
33
+ @klass = @top_level.add_class RDoc::NormalClass, 'C'
34
+
35
+ @meth = @klass.add_method RDoc::AnyMethod.new(nil, 'meth')
36
+ @meth.record_location @top_level
37
+
38
+ @nest_klass = @klass.add_class RDoc::NormalClass, 'D'
39
+ @nest_klass.record_location @top_level
40
+
41
+ @nest_meth = @nest_klass.add_method RDoc::AnyMethod.new(nil, 'meth')
42
+
43
+ @ignored = @top_level.add_class RDoc::NormalClass, 'Ignored'
44
+ @ignored.ignore
45
+
46
+ @page = RDoc::TopLevel.new 'page.rdoc'
47
+ @page.parser = RDoc::Parser::Simple
48
+
49
+ @top_levels = [@top_level, @page].sort
50
+ @klasses = [@klass, @nest_klass, @ignored]
51
+
52
+ Dir.chdir @tmpdir
53
+ end
54
+
55
+ def teardown
56
+ super
57
+
58
+ Dir.chdir @pwd
59
+ FileUtils.rm_rf @tmpdir
60
+ end
61
+
62
+ def assert_file path
63
+ assert File.file?(path), "#{path} is not a file"
64
+ end
65
+
66
+ def mu_pp obj
67
+ s = ''
68
+ s = PP.pp obj, s
69
+ s = s.force_encoding Encoding.default_external if defined? Encoding
70
+ s.chomp
71
+ end
72
+
73
+ def test_class_dir
74
+ assert_equal @darkfish.class_dir, @g.class_dir
75
+ end
76
+
77
+ def test_file_dir
78
+ assert_equal @darkfish.file_dir, @g.file_dir
79
+ end
80
+
81
+ def test_generate
82
+ @g.generate @top_levels
83
+
84
+ assert_file 'js/searcher.js'
85
+ assert_file 'js/navigation.js'
86
+ assert_file 'js/search_index.js'
87
+
88
+ json = File.read 'js/search_index.js'
89
+
90
+ json =~ /\Avar search_data = /
91
+
92
+ assignment = $&
93
+ index = $'
94
+
95
+ refute_empty assignment
96
+
97
+ index = JSON.parse index
98
+
99
+ info = [
100
+ @klass.search_record[2..-1],
101
+ @nest_klass.search_record[2..-1],
102
+ @meth.search_record[2..-1],
103
+ @nest_meth.search_record[2..-1],
104
+ @page.search_record[2..-1],
105
+ ]
106
+
107
+ expected = {
108
+ 'index' => {
109
+ 'searchIndex' => [
110
+ 'c',
111
+ 'd',
112
+ 'meth()',
113
+ 'meth()',
114
+ 'page',
115
+ ],
116
+ 'longSearchIndex' => [
117
+ 'c',
118
+ 'c::d',
119
+ 'c#meth()',
120
+ 'c::d#meth()',
121
+ '',
122
+ ],
123
+ 'info' => info,
124
+ },
125
+ }
126
+
127
+ assert_equal expected, index
128
+ end
129
+
130
+ def test_generate_utf_8
131
+ skip "Encoding not implemented" unless Object.const_defined? :Encoding
132
+
133
+ text = "5\xB0"
134
+ text.force_encoding Encoding::ISO_8859_1
135
+ @klass.add_comment comment(text), @top_level
136
+
137
+ @g.generate @top_levels
138
+
139
+ json = File.read 'js/search_index.js'
140
+ json.force_encoding Encoding::UTF_8
141
+
142
+ json =~ /\Avar search_data = /
143
+
144
+ index = $'
145
+
146
+ index = JSON.parse index
147
+
148
+ klass_record = @klass.search_record[2..-1]
149
+ klass_record[-1] = "<p>5\xc2\xb0\n"
150
+ klass_record.last.force_encoding Encoding::UTF_8
151
+
152
+ info = [
153
+ klass_record,
154
+ @nest_klass.search_record[2..-1],
155
+ @meth.search_record[2..-1],
156
+ @nest_meth.search_record[2..-1],
157
+ @page.search_record[2..-1],
158
+ ]
159
+
160
+ expected = {
161
+ 'index' => {
162
+ 'searchIndex' => [
163
+ 'c',
164
+ 'd',
165
+ 'meth()',
166
+ 'meth()',
167
+ 'page',
168
+ ],
169
+ 'longSearchIndex' => [
170
+ 'c',
171
+ 'c::d',
172
+ 'c#meth()',
173
+ 'c::d#meth()',
174
+ '',
175
+ ],
176
+ 'info' => info,
177
+ },
178
+ }
179
+
180
+ assert_equal expected, index
181
+ end
182
+
183
+ def test_index_classes
184
+ @g.reset @top_levels, @klasses
185
+
186
+ @g.index_classes
187
+
188
+ expected = {
189
+ :searchIndex => %w[c d],
190
+ :longSearchIndex => %w[c c::d],
191
+ :info => [
192
+ @klass.search_record[2..-1],
193
+ @nest_klass.search_record[2..-1],
194
+ ],
195
+ }
196
+
197
+ assert_equal expected, @g.index
198
+ end
199
+
200
+ def test_index_classes_nodoc
201
+ @klass.document_self = false
202
+ @nest_klass.document_self = false
203
+ @meth.document_self = false
204
+ @nest_meth.document_self = false
205
+
206
+ @g.reset @top_levels, @klasses
207
+
208
+ @g.index_classes
209
+
210
+ expected = {
211
+ :searchIndex => [],
212
+ :longSearchIndex => [],
213
+ :info => [],
214
+ }
215
+
216
+ assert_equal expected, @g.index
217
+ end
218
+
219
+ def test_index_methods
220
+ @g.reset @top_levels, @klasses
221
+
222
+ @g.index_methods
223
+
224
+ expected = {
225
+ :searchIndex => %w[meth() meth()],
226
+ :longSearchIndex => %w[c#meth() c::d#meth()],
227
+ :info => [
228
+ @meth.search_record[2..-1],
229
+ @nest_meth.search_record[2..-1],
230
+ ],
231
+ }
232
+
233
+ assert_equal expected, @g.index
234
+ end
235
+
236
+ def test_index_pages
237
+ @g.reset @top_levels, @klasses
238
+
239
+ @g.index_pages
240
+
241
+ expected = {
242
+ :searchIndex => %w[page],
243
+ :longSearchIndex => [''],
244
+ :info => [@page.search_record[2..-1]],
245
+ }
246
+
247
+ assert_equal expected, @g.index
248
+ end
249
+
250
+ def test_search_string
251
+ assert_equal 'cd', @g.search_string('C d')
252
+ end
253
+
254
+ end
255
+