aboutsummaryrefslogtreecommitdiffstats
path: root/test/rdoc
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-18 23:33:36 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-18 23:33:36 +0000
commitdf7dac9174a31e71b58be6184e23bfe6b742a494 (patch)
tree885edf624f0e8f37014b0d937340ac1c372a0066 /test/rdoc
parentfed428007c015ac3b7f4586f2491517fafffa030 (diff)
downloadruby-df7dac9174a31e71b58be6184e23bfe6b742a494.tar.gz
* lib/rdoc: Update to RDoc 4.1.0.preview.1
RDoc 4.1.0 contains a number of enhancements including a new default style and accessibility support. You can see the changelog here: https://github.com/rdoc/rdoc/blob/v4.1.0.preview.1/History.rdoc * test/rdoc: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rdoc')
-rw-r--r--test/rdoc/test_rdoc_any_method.rb105
-rw-r--r--test/rdoc/test_rdoc_class_module.rb77
-rw-r--r--test/rdoc/test_rdoc_code_object.rb149
-rw-r--r--test/rdoc/test_rdoc_context.rb17
-rw-r--r--test/rdoc/test_rdoc_context_section.rb7
-rw-r--r--test/rdoc/test_rdoc_cross_reference.rb7
-rw-r--r--test/rdoc/test_rdoc_generator_darkfish.rb78
-rw-r--r--test/rdoc/test_rdoc_generator_json_index.rb11
-rw-r--r--test/rdoc/test_rdoc_generator_ri.rb8
-rw-r--r--test/rdoc/test_rdoc_markdown.rb27
-rw-r--r--test/rdoc/test_rdoc_markdown_test.rb7
-rw-r--r--test/rdoc/test_rdoc_markup_attribute_manager.rb121
-rw-r--r--test/rdoc/test_rdoc_markup_document.rb7
-rw-r--r--test/rdoc/test_rdoc_markup_formatter.rb32
-rw-r--r--test/rdoc/test_rdoc_markup_heading.rb9
-rw-r--r--test/rdoc/test_rdoc_markup_parser.rb7
-rw-r--r--test/rdoc/test_rdoc_markup_pre_process.rb4
-rw-r--r--test/rdoc/test_rdoc_markup_raw.rb7
-rw-r--r--test/rdoc/test_rdoc_markup_to_html.rb86
-rw-r--r--test/rdoc/test_rdoc_markup_to_html_crossref.rb7
-rw-r--r--test/rdoc/test_rdoc_markup_to_html_snippet.rb8
-rw-r--r--test/rdoc/test_rdoc_markup_to_markdown.rb6
-rw-r--r--test/rdoc/test_rdoc_method_attr.rb8
-rw-r--r--test/rdoc/test_rdoc_normal_class.rb5
-rw-r--r--test/rdoc/test_rdoc_normal_module.rb5
-rw-r--r--test/rdoc/test_rdoc_options.rb149
-rw-r--r--test/rdoc/test_rdoc_parser.rb15
-rw-r--r--test/rdoc/test_rdoc_parser_c.rb124
-rw-r--r--test/rdoc/test_rdoc_parser_changelog.rb7
-rw-r--r--test/rdoc/test_rdoc_parser_rd.rb7
-rw-r--r--test/rdoc/test_rdoc_parser_ruby.rb357
-rw-r--r--test/rdoc/test_rdoc_rd_block_parser.rb8
-rw-r--r--test/rdoc/test_rdoc_rd_inline_parser.rb1
-rw-r--r--test/rdoc/test_rdoc_rdoc.rb25
-rw-r--r--test/rdoc/test_rdoc_ri_driver.rb31
-rw-r--r--test/rdoc/test_rdoc_ruby_lex.rb117
-rw-r--r--test/rdoc/test_rdoc_servlet.rb82
-rw-r--r--test/rdoc/test_rdoc_stats.rb302
-rw-r--r--test/rdoc/test_rdoc_store.rb30
-rw-r--r--test/rdoc/test_rdoc_text.rb74
-rw-r--r--test/rdoc/test_rdoc_tom_doc.rb60
-rw-r--r--test/rdoc/xref_test_case.rb2
42 files changed, 1743 insertions, 453 deletions
diff --git a/test/rdoc/test_rdoc_any_method.rb b/test/rdoc/test_rdoc_any_method.rb
index cb4a979392..77acfbee17 100644
--- a/test/rdoc/test_rdoc_any_method.rb
+++ b/test/rdoc/test_rdoc_any_method.rb
@@ -38,10 +38,39 @@ method(a, b) { |c, d| ... }
assert_equal 'my_c1_m', @c1_m.c_function
end
+ def test_call_seq_equals
+ m = RDoc::AnyMethod.new nil, nil
+
+ m.call_seq = ''
+
+ assert_nil m.call_seq
+
+ m.call_seq = 'foo'
+
+ assert_equal 'foo', m.call_seq
+ end
+
def test_full_name
assert_equal 'C1::m', @c1.method_list.first.full_name
end
+ def test_is_alias_for
+ assert_equal @c2_b, @c2_a.is_alias_for
+
+ # set string on instance variable
+ loaded = Marshal.load Marshal.dump @c2_a
+
+ loaded.store = @store
+
+ assert_equal @c2_b, loaded.is_alias_for, 'Marshal.load'
+
+ m1 = RDoc::AnyMethod.new nil, 'm1'
+ m1.store = @store
+ m1.instance_variable_set :@is_alias_for, ['Missing', false, 'method']
+
+ assert_nil m1.is_alias_for, 'missing alias'
+ end
+
def test_markup_code
tokens = [
RDoc::RubyToken::TkCONSTANT. new(0, 0, 0, 'CONSTANT'),
@@ -101,11 +130,14 @@ method(a, b) { |c, d| ... }
end
def test_marshal_load_aliased_method
- aliased_method = Marshal.load Marshal.dump(@c2.method_list.last)
+ aliased_method = Marshal.load Marshal.dump(@c2_a)
+
+ aliased_method.store = @store
assert_equal 'C2#a', aliased_method.full_name
assert_equal 'C2', aliased_method.parent_name
assert_equal '()', aliased_method.params
+ assert_equal @c2_b, aliased_method.is_alias_for, 'is_alias_for'
assert aliased_method.display?
end
@@ -170,16 +202,87 @@ method(a, b) { |c, d| ... }
assert_equal nil, loaded.file
assert_equal cm, loaded.parent
assert_equal section, loaded.section
+ assert_nil loaded.is_alias_for
assert loaded.display?
end
+ def test_marshal_dump_version_2
+ @store.path = Dir.tmpdir
+ top_level = @store.add_file 'file.rb'
+
+ m = RDoc::AnyMethod.new nil, 'method'
+ m.block_params = 'some_block'
+ m.call_seq = 'call_seq'
+ m.comment = 'this is a comment'
+ m.params = 'param'
+ m.record_location top_level
+
+ cm = top_level.add_class RDoc::ClassModule, 'Klass'
+ cm.add_method m
+
+ section = cm.sections.first
+
+ al = RDoc::Alias.new nil, 'method', 'aliased', 'alias comment'
+ al_m = m.add_alias al, cm
+
+ loaded = Marshal.load "\x04\bU:\x14RDoc::AnyMethod[\x14i\bI" +
+ "\"\vmethod\x06:\x06ETI" +
+ "\"\x11Klass#method\x06;\x06T0:\vpublic" +
+ "o:\eRDoc::Markup::Document\b:\v@parts[\x06" +
+ "o:\x1CRDoc::Markup::Paragraph\x06;\t[\x06I" +
+ "\"\x16this is a comment\x06;\x06T:\n@file0" +
+ ":0@omit_headings_from_table_of_contents_below0" +
+ "I\"\rcall_seq\x06;\x06TI\"\x0Fsome_block\x06" +
+ ";\x06T[\x06[\aI\"\faliased\x06;\x06To;\b\b;\t" +
+ "[\x06o;\n\x06;\t[\x06I\"\x12alias comment\x06" +
+ ";\x06T;\v0;\f0I\"\nparam\x06;\x06TI" +
+ "\"\ffile.rb\x06;\x06TFI\"\nKlass\x06;\x06T" +
+ "c\x16RDoc::ClassModule0"
+
+ loaded.store = @store
+
+ comment = doc(para('this is a comment'))
+
+ assert_equal m, loaded
+
+ assert_equal [al_m.name], loaded.aliases.map { |alas| alas.name }
+ assert_equal 'some_block', loaded.block_params
+ assert_equal 'call_seq', loaded.call_seq
+ assert_equal comment, loaded.comment
+ assert_equal top_level, loaded.file
+ assert_equal 'Klass#method', loaded.full_name
+ assert_equal 'method', loaded.name
+ assert_equal 'param', loaded.params
+ assert_equal nil, loaded.singleton # defaults to nil
+ assert_equal :public, loaded.visibility
+ assert_equal cm, loaded.parent
+ assert_equal section, loaded.section
+ assert_nil loaded.is_alias_for
+ end
+
def test_name
m = RDoc::AnyMethod.new nil, nil
assert_nil m.name
end
+ def test_name_call_seq
+ m = RDoc::AnyMethod.new nil, nil
+
+ m.call_seq = "yields(name)\nyields(name, description)"
+
+ assert_equal 'yields', m.name
+ end
+
+ def test_name_call_seq_dot
+ m = RDoc::AnyMethod.new nil, nil
+
+ m.call_seq = "obj.yields(name)\nobj.yields(name, description)"
+
+ assert_equal 'yields', m.name
+ end
+
def test_param_list_block_params
m = RDoc::AnyMethod.new nil, 'method'
m.parent = @c1
diff --git a/test/rdoc/test_rdoc_class_module.rb b/test/rdoc/test_rdoc_class_module.rb
index ec81282c35..0e06587dc6 100644
--- a/test/rdoc/test_rdoc_class_module.rb
+++ b/test/rdoc/test_rdoc_class_module.rb
@@ -2,13 +2,6 @@ require File.expand_path '../xref_test_case', __FILE__
class TestRDocClassModule < XrefTestCase
- def mu_pp obj
- s = ''
- s = PP.pp obj, s
- s.force_encoding Encoding.default_external if defined? Encoding
- s.chomp
- end
-
def test_add_comment
tl1 = @store.add_file 'one.rb'
tl2 = @store.add_file 'two.rb'
@@ -108,23 +101,23 @@ class TestRDocClassModule < XrefTestCase
def test_documented_eh
cm = RDoc::ClassModule.new 'C'
- refute cm.documented?
+ refute cm.documented?, 'no comments, no markers'
- cm.add_comment 'hi', @top_level
+ cm.add_comment '', @top_level
- assert cm.documented?
+ refute cm.documented?, 'empty comment'
- cm.comment.replace ''
+ cm.add_comment 'hi', @top_level
- assert cm.documented?
+ assert cm.documented?, 'commented'
cm.comment_location.clear
- refute cm.documented?
+ refute cm.documented?, 'no comment'
cm.document_self = nil # notify :nodoc:
- assert cm.documented?
+ assert cm.documented?, ':nodoc:'
end
def test_each_ancestor
@@ -165,6 +158,7 @@ class TestRDocClassModule < XrefTestCase
ns = tl.add_module RDoc::NormalModule, 'Namespace'
cm = ns.add_class RDoc::NormalClass, 'Klass', 'Super'
+ cm.document_self = true
cm.record_location tl
a1 = RDoc::Attr.new nil, 'a1', 'RW', ''
@@ -236,6 +230,59 @@ class TestRDocClassModule < XrefTestCase
assert_equal tl, loaded.method_list.first.file
end
+ def test_marshal_dump_visibilty
+ @store.path = Dir.tmpdir
+ tl = @store.add_file 'file.rb'
+
+ ns = tl.add_module RDoc::NormalModule, 'Namespace'
+
+ cm = ns.add_class RDoc::NormalClass, 'Klass', 'Super'
+ cm.record_location tl
+
+ a1 = RDoc::Attr.new nil, 'a1', 'RW', ''
+ a1.record_location tl
+ a1.document_self = false
+
+ m1 = RDoc::AnyMethod.new nil, 'm1'
+ m1.record_location tl
+ m1.document_self = false
+
+ c1 = RDoc::Constant.new 'C1', nil, ''
+ c1.record_location tl
+ c1.document_self = false
+
+ i1 = RDoc::Include.new 'I1', ''
+ i1.record_location tl
+ i1.document_self = false
+
+ e1 = RDoc::Extend.new 'E1', ''
+ e1.record_location tl
+ e1.document_self = false
+
+ section_comment = RDoc::Comment.new('section comment')
+ section_comment.location = tl
+
+ assert_equal 1, cm.sections.length, 'sanity, default section only'
+
+ cm.add_attribute a1
+ cm.add_method m1
+ cm.add_constant c1
+ cm.add_include i1
+ cm.add_extend e1
+ cm.add_comment 'this is a comment', tl
+
+ loaded = Marshal.load Marshal.dump cm
+ loaded.store = @store
+
+ assert_equal cm, loaded
+
+ assert_empty loaded.attributes
+ assert_empty loaded.constants
+ assert_empty loaded.includes
+ assert_empty loaded.extends
+ assert_empty loaded.method_list
+ end
+
def test_marshal_load_version_0
tl = @store.add_file 'file.rb'
ns = tl.add_module RDoc::NormalModule, 'Namespace'
@@ -1401,7 +1448,7 @@ class TestRDocClassModule < XrefTestCase
@c1.update_extends
- assert_equal [a, c], @c1.extends
+ assert_equal [a, b, c], @c1.extends
end
def test_update_extends_trim
diff --git a/test/rdoc/test_rdoc_code_object.rb b/test/rdoc/test_rdoc_code_object.rb
index ef8a5df713..1fda456930 100644
--- a/test/rdoc/test_rdoc_code_object.rb
+++ b/test/rdoc/test_rdoc_code_object.rb
@@ -100,24 +100,56 @@ class TestRDocCodeObject < XrefTestCase
refute @co.display?
end
+ def test_display_eh_suppress
+ assert @co.display?
+
+ @co.suppress
+
+ refute @co.display?
+
+ @co.comment = comment('hi')
+
+ refute @co.display?
+
+ @co.done_documenting = false
+
+ assert @co.display?
+
+ @co.ignore
+ @co.done_documenting = false
+
+ refute @co.display?
+ end
+
def test_document_children_equals
@co.document_children = false
+
refute @co.document_children
- # TODO this is not true anymore:
- # test all the nodoc stuff etc...
- #@c2.document_children = false
- #assert_empty @c2.classes
+ @store.rdoc.options.visibility = :nodoc
+
+ @co.store = @store
+
+ assert @co.document_children
+
+ @co.document_children = false
+
+ assert @co.document_children
end
def test_document_self_equals
@co.document_self = false
refute @co.document_self
- # TODO this is not true anymore:
- # test all the nodoc stuff etc...
- #@c1.document_self = false
- #assert_empty @c1.method_list
+ @store.rdoc.options.visibility = :nodoc
+
+ @co.store = @store
+
+ assert @co.document_self
+
+ @co.document_self = false
+
+ assert @co.document_self
end
def test_documented_eh
@@ -159,6 +191,18 @@ class TestRDocCodeObject < XrefTestCase
@co.done_documenting = false
assert @co.document_self
assert @co.document_children
+
+ @co.done_documenting = true
+
+ @store.rdoc.options.visibility = :nodoc
+
+ @co.store = @store
+
+ refute @co.done_documenting
+
+ @co.done_documenting = true
+
+ refute @co.done_documenting
end
def test_each_parent
@@ -195,6 +239,18 @@ class TestRDocCodeObject < XrefTestCase
refute @co.document_self
refute @co.document_children
assert @co.ignored?
+
+ @store.rdoc.options.visibility = :nodoc
+
+ @co.store = @store
+
+ assert @co.document_self
+ assert @co.document_children
+ refute @co.ignored?
+
+ @co.ignore
+
+ refute @co.ignored?
end
def test_ignore_eh
@@ -229,6 +285,14 @@ class TestRDocCodeObject < XrefTestCase
assert_equal 5, @c1_m.offset
end
+ def test_options
+ assert_kind_of RDoc::Options, @co.options
+
+ @co.store = @store
+
+ assert_same @options, @co.options
+ end
+
def test_parent_file_name
assert_equal '(unknown)', @co.parent_file_name
assert_equal 'xref_data.rb', @c1.parent_file_name
@@ -263,6 +327,13 @@ class TestRDocCodeObject < XrefTestCase
refute @co.ignored?
end
+ def test_record_location_suppressed
+ @co.suppress
+ @co.record_location @xref_data
+
+ refute @co.suppressed?
+ end
+
def test_section
parent = RDoc::Context.new
section = parent.sections.first
@@ -303,6 +374,30 @@ class TestRDocCodeObject < XrefTestCase
refute @co.ignored?
end
+ def test_start_doc_suppressed
+ @co.suppress
+
+ @co.start_doc
+
+ assert @co.document_self
+ assert @co.document_children
+ refute @co.suppressed?
+ end
+
+ def test_store_equals
+ @co.document_self = false
+
+ @co.store = @store
+
+ refute @co.document_self
+
+ @store.rdoc.options.visibility = :nodoc
+
+ @co.store = @store
+
+ assert @co.document_self
+ end
+
def test_stop_doc
@co.document_self = true
@co.document_children = true
@@ -311,6 +406,44 @@ class TestRDocCodeObject < XrefTestCase
refute @co.document_self
refute @co.document_children
+
+ @store.rdoc.options.visibility = :nodoc
+
+ @co.store = @store
+
+ assert @co.document_self
+ assert @co.document_children
+
+ @co.stop_doc
+
+ assert @co.document_self
+ assert @co.document_children
+ end
+
+ def test_suppress
+ @co.suppress
+
+ refute @co.document_self
+ refute @co.document_children
+ assert @co.suppressed?
+
+ @store.rdoc.options.visibility = :nodoc
+
+ @co.store = @store
+
+ refute @co.suppressed?
+
+ @co.suppress
+
+ refute @co.suppressed?
+ end
+
+ def test_suppress_eh
+ refute @co.suppressed?
+
+ @co.suppress
+
+ assert @co.suppressed?
end
end
diff --git a/test/rdoc/test_rdoc_context.rb b/test/rdoc/test_rdoc_context.rb
index 28b98dfe55..c6c5e2f109 100644
--- a/test/rdoc/test_rdoc_context.rb
+++ b/test/rdoc/test_rdoc_context.rb
@@ -41,6 +41,14 @@ class TestRDocContext < XrefTestCase
assert_equal [as], @context.unmatched_alias_lists['#old_name']
end
+ def test_add
+ @context.add RDoc::Extend, 'Ext', 'comment'
+ @context.add RDoc::Include, 'Incl', 'comment'
+
+ refute_empty @context.extends
+ refute_empty @context.includes
+ end
+
def test_add_alias_method_attr
top_level = @store.add_file 'file.rb'
@@ -691,6 +699,15 @@ class TestRDocContext < XrefTestCase
assert_equal [@apub, @aprot, @apriv], @vis.attributes
end
+ def test_remove_invisible_nodoc
+ util_visibilities
+
+ @vis.remove_invisible :nodoc
+
+ assert_equal [@pub, @prot, @priv], @vis.method_list
+ assert_equal [@apub, @aprot, @apriv], @vis.attributes
+ end
+
def test_remove_invisible_protected
util_visibilities
diff --git a/test/rdoc/test_rdoc_context_section.rb b/test/rdoc/test_rdoc_context_section.rb
index d492c17048..b8f8c7f756 100644
--- a/test/rdoc/test_rdoc_context_section.rb
+++ b/test/rdoc/test_rdoc_context_section.rb
@@ -13,13 +13,6 @@ class TestRDocContextSection < RDoc::TestCase
@s = @S.new @klass, 'section', comment('# comment', @top_level)
end
- def mu_pp obj
- s = ''
- s = PP.pp obj, s
- s.force_encoding Encoding.default_external if defined? Encoding
- s.chomp
- end
-
def test_add_comment
file1 = @store.add_file 'file1.rb'
diff --git a/test/rdoc/test_rdoc_cross_reference.rb b/test/rdoc/test_rdoc_cross_reference.rb
index ecb5f9aa41..99fc224d88 100644
--- a/test/rdoc/test_rdoc_cross_reference.rb
+++ b/test/rdoc/test_rdoc_cross_reference.rb
@@ -19,9 +19,10 @@ class TestRDocCrossReference < XrefTestCase
def test_METHOD_REGEXP_STR
re = /#{RDoc::CrossReference::METHOD_REGEXP_STR}/
- re =~ '==='
-
- assert_equal '===', $&
+ %w'=== [] []= << >>'.each do |x|
+ re =~ x
+ assert_equal x, $&
+ end
end
def test_resolve_C2
diff --git a/test/rdoc/test_rdoc_generator_darkfish.rb b/test/rdoc/test_rdoc_generator_darkfish.rb
index 613a1151e7..ff21515dfd 100644
--- a/test/rdoc/test_rdoc_generator_darkfish.rb
+++ b/test/rdoc/test_rdoc_generator_darkfish.rb
@@ -65,21 +65,6 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase
FileUtils.rm_rf @tmpdir
end
- def assert_file path
- assert File.file?(path), "#{path} is not a file"
- end
-
- def refute_file path
- refute File.exist?(path), "#{path} exists"
- end
-
- def mu_pp obj
- s = ''
- s = PP.pp obj, s
- s = s.force_encoding Encoding.default_external if defined? Encoding
- s.chomp
- end
-
def test_generate
top_level = @store.add_file 'file.rb'
top_level.add_class @klass.class, @klass.name
@@ -91,16 +76,20 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase
assert_file 'table_of_contents.html'
assert_file 'js/search_index.js'
+ assert_hard_link 'rdoc.css'
+ assert_hard_link 'fonts.css'
+
+ assert_hard_link 'fonts/SourceCodePro-Bold.ttf'
+ assert_hard_link 'fonts/SourceCodePro-Regular.ttf'
+
encoding = if Object.const_defined? :Encoding then
Regexp.escape Encoding::UTF_8.name
else
Regexp.escape 'UTF-8'
end
- assert_match(/<meta content="text\/html; charset=#{encoding}"/,
- File.read('index.html'))
- assert_match(/<meta content="text\/html; charset=#{encoding}"/,
- File.read('Object.html'))
+ assert_match %r%<meta charset="#{encoding}">%, File.read('index.html')
+ assert_match %r%<meta charset="#{encoding}">%, File.read('Object.html')
refute_match(/Ignored/, File.read('index.html'))
end
@@ -145,6 +134,36 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase
refute_file 'image.png'
end
+ def test_install_rdoc_static_file
+ src = Pathname(__FILE__)
+ dst = File.join @tmpdir, File.basename(src)
+ options = {}
+
+ @g.install_rdoc_static_file src, dst, options
+
+ assert_file dst
+
+ begin
+ assert_hard_link dst
+ rescue MiniTest::Assertion
+ return # hard links are not supported, no further tests needed
+ end
+
+ @g.install_rdoc_static_file src, dst, options
+
+ assert_hard_link dst
+ end
+
+ def test_install_rdoc_static_file_missing
+ src = Pathname(__FILE__) + 'nonexistent'
+ dst = File.join @tmpdir, File.basename(src)
+ options = {}
+
+ @g.install_rdoc_static_file src, dst, options
+
+ refute_file dst
+ end
+
def test_setup
@g.setup
@@ -183,5 +202,26 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase
assert_same template, @g.send(:template_for, partial)
end
+ ##
+ # Asserts that +filename+ has a link count greater than 1 if hard links to
+ # @tmpdir are supported.
+
+ def assert_hard_link filename
+ assert_file filename
+
+ src = @g.template_dir + '_head.rhtml'
+ dst = File.join @tmpdir, 'hardlinktest'
+
+ begin
+ FileUtils.ln src, dst
+ FileUtils.rm dst
+ rescue SystemCallError
+ return
+ end
+
+ assert_operator File.stat(filename).nlink, :>, 1,
+ "#{filename} is not hard-linked"
+ end
+
end
diff --git a/test/rdoc/test_rdoc_generator_json_index.rb b/test/rdoc/test_rdoc_generator_json_index.rb
index 717159eeda..214e4a0d91 100644
--- a/test/rdoc/test_rdoc_generator_json_index.rb
+++ b/test/rdoc/test_rdoc_generator_json_index.rb
@@ -57,17 +57,6 @@ class TestRDocGeneratorJsonIndex < RDoc::TestCase
FileUtils.rm_rf @tmpdir
end
- def assert_file path
- assert File.file?(path), "#{path} is not a file"
- end
-
- def mu_pp obj
- s = ''
- s = PP.pp obj, s
- s = s.force_encoding Encoding.default_external if defined? Encoding
- s.chomp
- end
-
def test_build_index
index = @g.build_index
diff --git a/test/rdoc/test_rdoc_generator_ri.rb b/test/rdoc/test_rdoc_generator_ri.rb
index a2bcec534d..f8ac97337d 100644
--- a/test/rdoc/test_rdoc_generator_ri.rb
+++ b/test/rdoc/test_rdoc_generator_ri.rb
@@ -42,14 +42,6 @@ class TestRDocGeneratorRI < RDoc::TestCase
FileUtils.rm_rf @tmpdir
end
- def assert_file path
- assert File.file?(path), "#{path} is not a file"
- end
-
- def refute_file path
- refute File.exist?(path), "#{path} exists"
- end
-
def test_generate
@g.generate
diff --git a/test/rdoc/test_rdoc_markdown.rb b/test/rdoc/test_rdoc_markdown.rb
index f3eb22227c..ea5dc73387 100644
--- a/test/rdoc/test_rdoc_markdown.rb
+++ b/test/rdoc/test_rdoc_markdown.rb
@@ -1,10 +1,6 @@
# coding: UTF-8
-require 'rubygems'
-require 'minitest/autorun'
-require 'pp'
-
-require 'rdoc'
+require 'rdoc/test_case'
require 'rdoc/markup/block_quote'
require 'rdoc/markdown'
@@ -14,13 +10,8 @@ class TestRDocMarkdown < RDoc::TestCase
@RM = RDoc::Markup
@parser = RDoc::Markdown.new
- end
- def mu_pp obj
- s = ''
- s = PP.pp obj, s
- s.force_encoding Encoding.default_external if defined? Encoding
- s.chomp
+ @to_html = RDoc::Markup::ToHtml.new(RDoc::Options.new, nil)
end
def test_class_parse
@@ -439,7 +430,19 @@ heading
def test_parse_image
doc = parse "image ![alt text](path/to/image.jpg)"
- expected = doc(para("image {alt text}[path/to/image.jpg]"))
+ expected = doc(para("image rdoc-image:path/to/image.jpg"))
+
+ assert_equal expected, doc
+ end
+
+ def test_parse_image_link
+ @parser.html = true
+
+ doc = parse "[![alt text](path/to/image.jpg)](http://example.com)"
+
+ expected =
+ doc(
+ para('{rdoc-image:path/to/image.jpg}[http://example.com]'))
assert_equal expected, doc
end
diff --git a/test/rdoc/test_rdoc_markdown_test.rb b/test/rdoc/test_rdoc_markdown_test.rb
index 7dfe727ef5..d464cba263 100644
--- a/test/rdoc/test_rdoc_markdown_test.rb
+++ b/test/rdoc/test_rdoc_markdown_test.rb
@@ -15,13 +15,6 @@ class TestRDocMarkdownTest < RDoc::TestCase
@parser = RDoc::Markdown.new
end
- def mu_pp obj
- s = ''
- s = PP.pp obj, s
- s.force_encoding Encoding.default_external if defined? Encoding
- s.chomp
- end
-
def test_amps_and_angle_encoding
input = File.read "#{MARKDOWN_TEST_PATH}/Amps and angle encoding.text"
diff --git a/test/rdoc/test_rdoc_markup_attribute_manager.rb b/test/rdoc/test_rdoc_markup_attribute_manager.rb
index 36edea3f73..9fe4476229 100644
--- a/test/rdoc/test_rdoc_markup_attribute_manager.rb
+++ b/test/rdoc/test_rdoc_markup_attribute_manager.rb
@@ -26,6 +26,12 @@ class TestRDocMarkupAttributeManager < RDoc::TestCase
@am.add_word_pair("{", "}", :WOMBAT)
@wombat_on = @am.changed_attribute_by_name([], [:WOMBAT])
@wombat_off = @am.changed_attribute_by_name([:WOMBAT], [])
+
+ @klass = RDoc::Markup::AttributeManager
+ @formatter = RDoc::Markup::Formatter.new @rdoc.options
+ @formatter.add_tag :BOLD, '<B>', '</B>'
+ @formatter.add_tag :EM, '<EM>', '</EM>'
+ @formatter.add_tag :TT, '<CODE>', '</CODE>'
end
def crossref(text)
@@ -44,6 +50,21 @@ class TestRDocMarkupAttributeManager < RDoc::TestCase
#assert_equal(["cat {and} dog" ], @am.flow("cat \\{and} dog"))
end
+ def test_add_html_tag
+ @am.add_html("Test", :TEST)
+ tags = @am.html_tags
+ assert_equal(6, tags.size)
+ assert(tags.has_key?("test"))
+ end
+
+ def test_add_special
+ @am.add_special "WikiWord", :WIKIWORD
+ specials = @am.special
+
+ assert_equal 1, specials.size
+ assert specials.assoc "WikiWord"
+ end
+
def test_add_word_pair
@am.add_word_pair '%', '&', 'percent and'
@@ -60,6 +81,20 @@ class TestRDocMarkupAttributeManager < RDoc::TestCase
assert_equal "Word flags may not start with '<'", e.message
end
+ def test_add_word_pair_invalid
+ assert_raises ArgumentError do
+ @am.add_word_pair("<", "<", :TEST)
+ end
+ end
+
+ def test_add_word_pair_map
+ @am.add_word_pair("x", "y", :TEST)
+
+ word_pair_map = @am.word_pair_map
+
+ assert_includes word_pair_map.keys.map { |r| r.source }, "(x)(\\S+)(y)"
+ end
+
def test_add_word_pair_matching
@am.add_word_pair '^', '^', 'caret'
@@ -151,6 +186,56 @@ class TestRDocMarkupAttributeManager < RDoc::TestCase
assert_equal "\000x-y\000", str
end
+ def test_convert_attrs_ignores_code
+ assert_equal 'foo <CODE>__send__</CODE> bar', output('foo <code>__send__</code> bar')
+ end
+
+ def test_convert_attrs_ignores_tt
+ assert_equal 'foo <CODE>__send__</CODE> bar', output('foo <tt>__send__</tt> bar')
+ end
+
+ def test_convert_attrs_preserves_double
+ assert_equal 'foo.__send__ :bar', output('foo.__send__ :bar')
+ assert_equal 'use __FILE__ to', output('use __FILE__ to')
+ end
+
+ def test_convert_attrs_does_not_ignore_after_tt
+ assert_equal 'the <CODE>IF:</CODE><EM>key</EM> directive', output('the <tt>IF:</tt>_key_ directive')
+ end
+
+ def test_escapes
+ assert_equal '<CODE>text</CODE>', output('<tt>text</tt>')
+ assert_equal '<tt>text</tt>', output('\\<tt>text</tt>')
+ assert_equal '<tt>', output('\\<tt>')
+ assert_equal '<CODE><tt></CODE>', output('<tt>\\<tt></tt>')
+ assert_equal '<CODE>\\<tt></CODE>', output('<tt>\\\\<tt></tt>')
+ assert_equal '<B>text</B>', output('*text*')
+ assert_equal '*text*', output('\\*text*')
+ assert_equal '\\', output('\\')
+ assert_equal '\\text', output('\\text')
+ assert_equal '\\\\text', output('\\\\text')
+ assert_equal 'text \\ text', output('text \\ text')
+
+ assert_equal 'and <CODE>\\s</CODE> matches space',
+ output('and <tt>\\s</tt> matches space')
+ assert_equal 'use <CODE><tt>text</CODE></tt> for code',
+ output('use <tt>\\<tt>text</tt></tt> for code')
+ assert_equal 'use <CODE><tt>text</tt></CODE> for code',
+ output('use <tt>\\<tt>text\\</tt></tt> for code')
+ assert_equal 'use <tt><tt>text</tt></tt> for code',
+ output('use \\<tt>\\<tt>text</tt></tt> for code')
+ assert_equal 'use <tt><CODE>text</CODE></tt> for code',
+ output('use \\<tt><tt>text</tt></tt> for code')
+ assert_equal 'use <CODE>+text+</CODE> for code',
+ output('use <tt>\\+text+</tt> for code')
+ assert_equal 'use <tt><CODE>text</CODE></tt> for code',
+ output('use \\<tt>+text+</tt> for code')
+ assert_equal 'illegal <tag>not</tag> changed',
+ output('illegal <tag>not</tag> changed')
+ assert_equal 'unhandled <p>tag</p> unchanged',
+ output('unhandled <p>tag</p> unchanged')
+ end
+
def test_html_like_em_bold
assert_equal ["cat ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
@am.flow("cat <i>and </i><b>dog</b>")
@@ -191,6 +276,38 @@ class TestRDocMarkupAttributeManager < RDoc::TestCase
@am.flow("<tt>cat</tt> <i>and <b></i>dog</b>")
end
+ def test_initial_html
+ html_tags = @am.html_tags
+ assert html_tags.is_a?(Hash)
+ assert_equal(5, html_tags.size)
+ end
+
+ def test_initial_word_pairs
+ word_pairs = @am.matching_word_pairs
+ assert word_pairs.is_a?(Hash)
+ assert_equal(3, word_pairs.size)
+ end
+
+ def test_mask_protected_sequence
+ def @am.str() @str end
+ def @am.str=(str) @str = str end
+
+ @am.str = '<code>foo</code>'
+ @am.mask_protected_sequences
+
+ assert_equal "<code>foo</code>", @am.str
+
+ @am.str = '<code>foo\\</code>'
+ @am.mask_protected_sequences
+
+ assert_equal "<code>foo<\x04/code>", @am.str, 'escaped close'
+
+ @am.str = '<code>foo\\\\</code>'
+ @am.mask_protected_sequences
+
+ assert_equal "<code>foo\\</code>", @am.str, 'escaped backslash'
+ end
+
def test_protect
assert_equal(['cat \\ dog'],
@am.flow('cat \\ dog'))
@@ -233,5 +350,9 @@ class TestRDocMarkupAttributeManager < RDoc::TestCase
@am.flow('<tt>"\n"</tt>')
end
+ def output str
+ @formatter.convert_flow @am.flow str
+ end
+
end
diff --git a/test/rdoc/test_rdoc_markup_document.rb b/test/rdoc/test_rdoc_markup_document.rb
index 0ab87280eb..718ae6d4c4 100644
--- a/test/rdoc/test_rdoc_markup_document.rb
+++ b/test/rdoc/test_rdoc_markup_document.rb
@@ -8,13 +8,6 @@ class TestRDocMarkupDocument < RDoc::TestCase
@d = @RM::Document.new
end
- def mu_pp obj
- s = ''
- s = PP.pp obj, s
- s.force_encoding Encoding.default_external if defined? Encoding
- s.chomp
- end
-
def test_append
@d << @RM::Paragraph.new('hi')
diff --git a/test/rdoc/test_rdoc_markup_formatter.rb b/test/rdoc/test_rdoc_markup_formatter.rb
index c0dde757cb..d01a42fca6 100644
--- a/test/rdoc/test_rdoc_markup_formatter.rb
+++ b/test/rdoc/test_rdoc_markup_formatter.rb
@@ -71,20 +71,46 @@ class TestRDocMarkupFormatter < RDoc::TestCase
@to.add_special_RDOCLINK
assert_includes special_names, 'RDOCLINK'
+
+ def @to.handle_special_RDOCLINK special
+ "<#{special.text}>"
+ end
+
+ document = doc(para('{foo}[rdoc-label:bar].'))
+
+ formatted = document.accept @to
+
+ assert_equal '{foo}[<rdoc-label:bar>].', formatted
end
def test_add_special_TIDYLINK
@to.add_special_TIDYLINK
assert_includes special_names, 'TIDYLINK'
+
+ def @to.handle_special_TIDYLINK special
+ "<#{special.text}>"
+ end
+
+ document = doc(para('foo[rdoc-label:bar].'))
+
+ formatted = document.accept @to
+
+ assert_equal '<foo[rdoc-label:bar]>.', formatted
+
+ document = doc(para('{foo}[rdoc-label:bar].'))
+
+ formatted = document.accept @to
+
+ assert_equal '<{foo}[rdoc-label:bar]>.', formatted
end
def test_parse_url
scheme, url, id = @to.parse_url 'example/foo'
- assert_equal 'http', scheme
- assert_equal 'http://example/foo', url
- assert_equal nil, id
+ assert_equal 'http', scheme
+ assert_equal 'example/foo', url
+ assert_equal nil, id
end
def test_parse_url_anchor
diff --git a/test/rdoc/test_rdoc_markup_heading.rb b/test/rdoc/test_rdoc_markup_heading.rb
index eef051a64e..ff53ff5ac3 100644
--- a/test/rdoc/test_rdoc_markup_heading.rb
+++ b/test/rdoc/test_rdoc_markup_heading.rb
@@ -12,6 +12,15 @@ class TestRDocMarkupHeading < RDoc::TestCase
assert_equal 'label-Hello+Friend%21', @h.aref
end
+ def test_label
+ assert_equal 'label-Hello+Friend%21', @h.label
+ assert_equal 'label-Hello+Friend%21', @h.label(nil)
+
+ context = RDoc::NormalClass.new 'Foo'
+
+ assert_equal 'class-Foo-label-Hello+Friend%21', @h.label(context)
+ end
+
def test_plain_html
assert_equal 'Hello <strong>Friend</strong>!', @h.plain_html
end
diff --git a/test/rdoc/test_rdoc_markup_parser.rb b/test/rdoc/test_rdoc_markup_parser.rb
index b367b23bcc..d27fb42f9a 100644
--- a/test/rdoc/test_rdoc_markup_parser.rb
+++ b/test/rdoc/test_rdoc_markup_parser.rb
@@ -12,13 +12,6 @@ class TestRDocMarkupParser < RDoc::TestCase
@RMP = @RM::Parser
end
- def mu_pp(obj)
- s = ''
- s = PP.pp obj, s
- s = s.force_encoding(Encoding.default_external) if @have_encoding
- s.chomp
- end
-
def test_build_heading
parser = @RMP.new
diff --git a/test/rdoc/test_rdoc_markup_pre_process.rb b/test/rdoc/test_rdoc_markup_pre_process.rb
index 82ab71ee14..a241d0dec3 100644
--- a/test/rdoc/test_rdoc_markup_pre_process.rb
+++ b/test/rdoc/test_rdoc_markup_pre_process.rb
@@ -147,7 +147,7 @@ contents of a string.
def test_handle_directive_blankline
result = @pp.handle_directive '#', 'arg', 'a, b'
- assert_equal "#\n", result
+ assert_equal "#:arg: a, b\n", result
end
def test_handle_directive_downcase
@@ -169,7 +169,7 @@ contents of a string.
def test_handle_directive_arg_no_context
result = @pp.handle_directive '', 'arg', 'a, b', nil
- assert_equal "\n", result
+ assert_equal ":arg: a, b\n", result
end
def test_handle_directive_args
diff --git a/test/rdoc/test_rdoc_markup_raw.rb b/test/rdoc/test_rdoc_markup_raw.rb
index 16cc60e3a8..43bfe0c3b1 100644
--- a/test/rdoc/test_rdoc_markup_raw.rb
+++ b/test/rdoc/test_rdoc_markup_raw.rb
@@ -8,13 +8,6 @@ class TestRDocMarkupRaw < RDoc::TestCase
@p = @RM::Raw.new
end
- def mu_pp obj
- s = ''
- s = PP.pp obj, s
- s.force_encoding Encoding.default_external if defined? Encoding
- s.chomp
- end
-
def test_push
@p.push 'hi', 'there'
diff --git a/test/rdoc/test_rdoc_markup_to_html.rb b/test/rdoc/test_rdoc_markup_to_html.rb
index ebd2fe7dd2..b1addc5dcb 100644
--- a/test/rdoc/test_rdoc_markup_to_html.rb
+++ b/test/rdoc/test_rdoc_markup_to_html.rb
@@ -256,7 +256,7 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase
end
def accept_paragraph_break
- assert_equal "\n<p>hello<br>\nworld</p>\n", @to.res.join
+ assert_equal "\n<p>hello<br> world</p>\n", @to.res.join
end
def accept_paragraph_i
@@ -288,7 +288,7 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase
end
def accept_rule
- assert_equal "<hr style=\"height: 4px\">\n", @to.res.join
+ assert_equal "<hr>\n", @to.res.join
end
def accept_verbatim
@@ -357,12 +357,12 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase
@to.code_object = RDoc::NormalClass.new 'Foo'
@to.start_accepting
- @to.accept_heading @RM::Heading.new(1, 'Hello')
+ @to.accept_heading head(1, 'Hello')
- links = '<span><a href="#label-Hello">&para;</a> ' +
+ links = '<span><a href="#class-Foo-label-Hello">&para;</a> ' +
'<a href="#documentation">&uarr;</a></span>'
- assert_equal "\n<h1 id=\"label-Hello\">Hello#{links}</h1>\n",
+ assert_equal "\n<h1 id=\"class-Foo-label-Hello\">Hello#{links}</h1>\n",
@to.res.join
end
@@ -389,6 +389,35 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase
assert_equal "\n<h1 id=\"label-Hello\">Hello</h1>\n", @to.res.join
end
+ def test_accept_paragraph_newline
+ @to.start_accepting
+
+ @to.accept_paragraph para("hello\n", "world\n")
+
+ assert_equal "\n<p>hello world</p>\n", @to.res.join
+ end
+
+ def test_accept_heading_output_decoration
+ @options.output_decoration = false
+
+ @to.start_accepting
+
+ @to.accept_heading @RM::Heading.new(1, 'Hello')
+
+ assert_equal "\n<h1>Hello<span><a href=\"#label-Hello\">&para;</a> <a href=\"#documentation\">&uarr;</a></span></h1>\n", @to.res.join
+ end
+
+ def test_accept_heading_output_decoration_with_pipe
+ @options.pipe = true
+ @options.output_decoration = false
+
+ @to.start_accepting
+
+ @to.accept_heading @RM::Heading.new(1, 'Hello')
+
+ assert_equal "\n<h1>Hello</h1>\n", @to.res.join
+ end
+
def test_accept_verbatim_parseable
verb = @RM::Verbatim.new("class C\n", "end\n")
@@ -422,6 +451,24 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase
assert_equal expected, @to.res.join
end
+ def test_accept_verbatim_pipe
+ @options.pipe = true
+
+ verb = @RM::Verbatim.new("1 + 1\n")
+ verb.format = :ruby
+
+ @to.start_accepting
+ @to.accept_verbatim verb
+
+ expected = <<-EXPECTED
+
+<pre><code>1 + 1
+</code></pre>
+ EXPECTED
+
+ assert_equal expected, @to.res.join
+ end
+
def test_accept_verbatim_ruby
verb = @RM::Verbatim.new("1 + 1\n")
verb.format = :ruby
@@ -457,13 +504,13 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase
def test_convert_RDOCLINK_label_foottext
result = @to.convert 'rdoc-label:foottext-1'
- assert_equal "\n<p><a href=\"#foottext-1\">*1</a></p>\n", result
+ assert_equal "\n<p><a href=\"#foottext-1\">1</a></p>\n", result
end
def test_convert_RDOCLINK_label_footmark
result = @to.convert 'rdoc-label:footmark-1'
- assert_equal "\n<p><a href=\"#footmark-1\">^1</a></p>\n", result
+ assert_equal "\n<p><a href=\"#footmark-1\">1</a></p>\n", result
end
def test_convert_RDOCLINK_ref
@@ -475,7 +522,28 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase
def test_convert_TIDYLINK_footnote
result = @to.convert 'text{*1}[rdoc-label:foottext-1:footmark-1]'
- assert_equal "\n<p>text<a id=\"footmark-1\" href=\"#foottext-1\">*1</a></p>\n", result
+ assert_equal "\n<p>text<sup><a id=\"footmark-1\" href=\"#foottext-1\">1</a></sup></p>\n", result
+ end
+
+ def test_convert_TIDYLINK_multiple
+ result = @to.convert '{a}[http://example] {b}[http://example]'
+
+ expected = <<-EXPECTED
+
+<p><a href=\"http://example\">a</a> <a href=\"http://example\">b</a></p>
+ EXPECTED
+
+ assert_equal expected, result
+ end
+
+ def test_convert_TIDYLINK_image
+ result =
+ @to.convert '{rdoc-image:path/to/image.jpg}[http://example.com]'
+
+ expected =
+ "\n<p><a href=\"http://example.com\"><img src=\"path/to/image.jpg\"></a></p>\n"
+
+ assert_equal expected, result
end
def test_convert_TIDYLINK_rdoc_label
@@ -501,7 +569,7 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase
end
def test_gen_url_rdoc_label_id
- assert_equal '<a id="footmark-1" href="#foottext-1">example</a>',
+ assert_equal '<sup><a id="footmark-1" href="#foottext-1">example</a></sup>',
@to.gen_url('rdoc-label:foottext-1:footmark-1', 'example')
end
diff --git a/test/rdoc/test_rdoc_markup_to_html_crossref.rb b/test/rdoc/test_rdoc_markup_to_html_crossref.rb
index 27a60120f4..872daea1dc 100644
--- a/test/rdoc/test_rdoc_markup_to_html_crossref.rb
+++ b/test/rdoc/test_rdoc_markup_to_html_crossref.rb
@@ -36,6 +36,13 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
result
end
+ def test_convert_CROSSREF_section
+ @c1.add_section 'Section'
+
+ result = @to.convert 'C1@Section'
+ assert_equal para("<a href=\"C1.html#Section\">Section at C1</a>"), result
+ end
+
def test_convert_RDOCLINK_rdoc_ref
result = @to.convert 'rdoc-ref:C1'
diff --git a/test/rdoc/test_rdoc_markup_to_html_snippet.rb b/test/rdoc/test_rdoc_markup_to_html_snippet.rb
index 065b2edbc8..4bb8ed1b47 100644
--- a/test/rdoc/test_rdoc_markup_to_html_snippet.rb
+++ b/test/rdoc/test_rdoc_markup_to_html_snippet.rb
@@ -626,15 +626,15 @@ This routine modifies its +comment+ parameter.
def test_convert_RDOCLINK_label_foottext
result = @to.convert 'rdoc-label:foottext-1'
- assert_equal "<p>*1\n", result
- assert_equal 2, @to.characters
+ assert_equal "<p>1\n", result
+ assert_equal 1, @to.characters
end
def test_convert_RDOCLINK_label_footmark
result = @to.convert 'rdoc-label:footmark-1'
- assert_equal "<p>^1\n", result
- assert_equal 2, @to.characters
+ assert_equal "<p>1\n", result
+ assert_equal 1, @to.characters
end
def test_convert_RDOCLINK_ref
diff --git a/test/rdoc/test_rdoc_markup_to_markdown.rb b/test/rdoc/test_rdoc_markup_to_markdown.rb
index 6d09ca62ea..442bb19e9c 100644
--- a/test/rdoc/test_rdoc_markup_to_markdown.rb
+++ b/test/rdoc/test_rdoc_markup_to_markdown.rb
@@ -354,6 +354,12 @@ words words words words
assert_equal "C\n", result
end
+ def test_convert_RDOCLINK_image
+ result = @to.convert 'rdoc-image:/path/to/image.jpg'
+
+ assert_equal "![](/path/to/image.jpg)\n", result
+ end
+
def test_convert_TIDYLINK
result = @to.convert \
'{DSL}[http://en.wikipedia.org/wiki/Domain-specific_language]'
diff --git a/test/rdoc/test_rdoc_method_attr.rb b/test/rdoc/test_rdoc_method_attr.rb
index 8fff038289..a91ebc23d7 100644
--- a/test/rdoc/test_rdoc_method_attr.rb
+++ b/test/rdoc/test_rdoc_method_attr.rb
@@ -2,6 +2,10 @@ require File.expand_path '../xref_test_case', __FILE__
class TestRDocMethodAttr < XrefTestCase
+ def test_initialize_copy
+ refute_same @c1_m.full_name, @c1_m.dup.full_name
+ end
+
def test_block_params_equal
m = RDoc::MethodAttr.new(nil, 'foo')
@@ -116,6 +120,10 @@ class TestRDocMethodAttr < XrefTestCase
assert_equal 'C1::m', @c1__m.full_name
end
+ def test_is_alias_for
+ assert_equal @c2_b, @c2_a.is_alias_for
+ end
+
def test_output_name
assert_equal '#m', @c1_m.output_name(@c1)
assert_equal '::m', @c1__m.output_name(@c1)
diff --git a/test/rdoc/test_rdoc_normal_class.rb b/test/rdoc/test_rdoc_normal_class.rb
index f3c7890d59..9f8896831b 100644
--- a/test/rdoc/test_rdoc_normal_class.rb
+++ b/test/rdoc/test_rdoc_normal_class.rb
@@ -21,6 +21,11 @@ class TestRDocNormalClass < XrefTestCase
assert_equal [c2, c1, 'Object'], c3.ancestors
end
+ def test_aref
+ assert_equal 'class-C1', @c1.aref
+ assert_equal 'class-C2::C3', @c2_c3.aref
+ end
+
def test_direct_ancestors
incl = RDoc::Include.new 'Incl', ''
diff --git a/test/rdoc/test_rdoc_normal_module.rb b/test/rdoc/test_rdoc_normal_module.rb
index 120f56a284..1944564596 100644
--- a/test/rdoc/test_rdoc_normal_module.rb
+++ b/test/rdoc/test_rdoc_normal_module.rb
@@ -23,6 +23,11 @@ class TestRDocNormalModule < XrefTestCase
assert_equal [mod2, incl.name], mod.ancestors
end
+ def test_aref
+ assert_equal 'module-M1', @m1.aref
+ assert_equal 'module-M1::M2', @m1_m2.aref
+ end
+
def test_definition
m = RDoc::NormalModule.new 'M'
diff --git a/test/rdoc/test_rdoc_options.rb b/test/rdoc/test_rdoc_options.rb
index e72489d307..f4929604f7 100644
--- a/test/rdoc/test_rdoc_options.rb
+++ b/test/rdoc/test_rdoc_options.rb
@@ -15,13 +15,6 @@ class TestRDocOptions < RDoc::TestCase
RDoc::RDoc::GENERATORS.replace @generators
end
- def mu_pp obj
- s = ''
- s = PP.pp obj, s
- s = s.force_encoding Encoding.default_external if defined? Encoding
- s.chomp
- end
-
def test_check_files
skip "assumes UNIX permission model" if /mswin|mingw/ =~ RUBY_PLATFORM
@@ -69,21 +62,23 @@ class TestRDocOptions < RDoc::TestCase
encoding = Object.const_defined?(:Encoding) ? 'UTF-8' : nil
expected = {
- 'charset' => 'UTF-8',
- 'encoding' => encoding,
- 'exclude' => [],
- 'hyperlink_all' => false,
- 'line_numbers' => false,
- 'main_page' => nil,
- 'markup' => 'rdoc',
- 'page_dir' => nil,
- 'rdoc_include' => [],
- 'show_hash' => false,
- 'static_path' => [],
- 'tab_width' => 8,
- 'title' => nil,
- 'visibility' => :protected,
- 'webcvs' => nil,
+ 'charset' => 'UTF-8',
+ 'encoding' => encoding,
+ 'exclude' => [],
+ 'hyperlink_all' => false,
+ 'line_numbers' => false,
+ 'main_page' => nil,
+ 'markup' => 'rdoc',
+ 'output_decoration' => true,
+ 'page_dir' => nil,
+ 'rdoc_include' => [],
+ 'show_hash' => false,
+ 'static_path' => [],
+ 'tab_width' => 8,
+ 'template_stylesheets' => [],
+ 'title' => nil,
+ 'visibility' => :protected,
+ 'webcvs' => nil,
}
assert_equal expected, coder
@@ -372,6 +367,20 @@ rdoc_include:
assert_equal 1, out.scan(/test generator options:/).length
end
+ def test_parse_format_for_extra_generator
+ RDoc::RDoc::GENERATORS['test'] = Class.new do
+ def self.setup_options options
+ op = options.option_parser
+
+ op.separator 'test generator options:'
+ end
+ end
+
+ @options.setup_generator 'test'
+
+ assert_equal @options.generator_name, 'test'
+ end
+
def test_parse_ignore_invalid
out, err = capture_io do
@options.parse %w[--ignore-invalid --bogus]
@@ -409,6 +418,39 @@ rdoc_include:
assert_empty out
end
+ def test_parse_ignore_invalid_no_quiet
+ out, err = capture_io do
+ assert_raises SystemExit do
+ @options.parse %w[--quiet --no-ignore-invalid --bogus=arg --bobogus --visibility=extended]
+ end
+ end
+
+ refute_match %r%^Usage: %, err
+ assert_match %r%^invalid options: --bogus=arg, --bobogus, --visibility=extended%, err
+
+ assert_empty out
+ end
+
+ def test_ignore_needless_arg
+ out, err = capture_io do
+ @options.parse %w[--ri=foo]
+ end
+
+ assert_match %r%^invalid options: --ri=foo%, err
+
+ assert_empty out
+ end
+
+ def test_ignore_missing_arg
+ out, err = capture_io do
+ @options.parse %w[--copy-files]
+ end
+
+ assert_match %r%^invalid options: --copy-files%, err
+
+ assert_empty out
+ end
+
def test_parse_main
out, err = capture_io do
@options.parse %w[--main MAIN]
@@ -468,6 +510,13 @@ rdoc_include:
end
end
+ def test_parse_ri_site
+ @options.parse %w[--ri-site]
+
+ assert_equal RDoc::Generator::RI, @options.generator
+ assert_equal RDoc::RI::Paths.site_dir, @options.op_dir
+ end
+
def test_parse_root
assert_equal Pathname(Dir.pwd), @options.root
@@ -479,7 +528,27 @@ rdoc_include:
assert_empty err
assert_equal Pathname(Dir.tmpdir), @options.root
- assert_includes @options.rdoc_include, @options.root.to_path
+ assert_includes @options.rdoc_include, @options.root.to_s
+ end
+
+ def test_parse_tab_width
+ @options.parse %w[--tab-width=1]
+ assert_equal 1, @options.tab_width
+
+ @options.parse %w[-w2]
+ assert_equal 2, @options.tab_width
+
+ _, err = capture_io do
+ @options.parse %w[-w=2]
+ end
+
+ assert_match 'invalid options', err
+
+ _, err = capture_io do
+ @options.parse %w[-w0]
+ end
+
+ assert_match 'invalid options', err
end
def test_parse_template
@@ -533,6 +602,20 @@ rdoc_include:
$LOAD_PATH.replace orig_LOAD_PATH
end
+ def test_parse_visibility
+ @options.parse %w[--visibility=public]
+ assert_equal :public, @options.visibility
+
+ @options.parse %w[--visibility=protected]
+ assert_equal :protected, @options.visibility
+
+ @options.parse %w[--visibility=private]
+ assert_equal :private, @options.visibility
+
+ @options.parse %w[--visibility=nodoc]
+ assert_equal :nodoc, @options.visibility
+ end
+
def test_parse_write_options
tmpdir = File.join Dir.tmpdir, "test_rdoc_options_#{$$}"
FileUtils.mkdir_p tmpdir
@@ -640,5 +723,25 @@ rdoc_include:
end
end
+ def test_version
+ out, _ = capture_io do
+ begin
+ @options.parse %w[--version]
+ rescue SystemExit
+ end
+ end
+
+ assert out.include?(RDoc::VERSION)
+
+ out, _ = capture_io do
+ begin
+ @options.parse %w[-v]
+ rescue SystemExit
+ end
+ end
+
+ assert out.include?(RDoc::VERSION)
+ end
+
end
diff --git a/test/rdoc/test_rdoc_parser.rb b/test/rdoc/test_rdoc_parser.rb
index 338693f97a..b9bff9c327 100644
--- a/test/rdoc/test_rdoc_parser.rb
+++ b/test/rdoc/test_rdoc_parser.rb
@@ -110,6 +110,21 @@ class TestRDocParser < RDoc::TestCase
end
end
+ def test_class_for_modeline
+ temp_dir do
+ content = "# -*- rdoc -*-\n= NEWS\n"
+
+ open 'NEWS', 'w' do |io| io.write content end
+ app = @store.add_file 'NEWS'
+
+ parser = @RP.for app, 'NEWS', content, @options, :stats
+
+ assert_kind_of RDoc::Parser::Simple, parser
+
+ assert_equal "= NEWS\n", parser.content
+ end
+ end
+
def test_can_parse_modeline
readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}"
diff --git a/test/rdoc/test_rdoc_parser_c.rb b/test/rdoc/test_rdoc_parser_c.rb
index 8fe1bf46ec..99f2159203 100644
--- a/test/rdoc/test_rdoc_parser_c.rb
+++ b/test/rdoc/test_rdoc_parser_c.rb
@@ -534,10 +534,6 @@ void Init_curses(){
def test_do_constants_file
content = <<-EOF
void Init_File(void) {
- rb_cFile = rb_define_class("File", rb_cIO);
- rb_mFConst = rb_define_module_under(rb_cFile, "Constants");
- rb_include_module(rb_cIO, rb_mFConst);
-
/* Document-const: LOCK_SH
*
* Shared lock
@@ -1000,6 +996,36 @@ init_gi_repository (void)
assert_equal 2, klass.method_list.length
end
+ def test_find_body_cast
+ content = <<-EOF
+/*
+ * a comment for other_function
+ */
+VALUE
+other_function() {
+}
+
+void
+Init_Foo(void) {
+ VALUE foo = rb_define_class("Foo", rb_cObject);
+
+ rb_define_method(foo, "my_method", (METHOD)other_function, 0);
+}
+ EOF
+
+ klass = util_get_class content, 'foo'
+ other_function = klass.method_list.first
+
+ assert_equal 'my_method', other_function.name
+ assert_equal "a comment for other_function",
+ other_function.comment.text
+ assert_equal '()', other_function.params
+
+ code = other_function.token_stream.first.text
+
+ assert_equal "VALUE\nother_function() {\n}", code
+ end
+
def test_find_body_define
content = <<-EOF
#define something something_else
@@ -1669,6 +1695,96 @@ void Init(void) {
assert_equal expected, @store.c_singleton_class_variables
end
+ def test_scan_method_copy
+ parser = util_parser <<-C
+/*
+ * call-seq:
+ * pathname.to_s -> string
+ * pathname.to_path -> string
+ *
+ * Return the path as a String.
+ *
+ * to_path is implemented so Pathname objects are usable with File.open, etc.
+ */
+static VALUE
+path_to_s(VALUE self) { }
+
+/*
+ * call-seq:
+ * str[index] -> new_str or nil
+ * str[start, length] -> new_str or nil
+ * str.slice(index) -> new_str or nil
+ * str.slice(start, length) -> new_str or nil
+ */
+static VALUE
+path_aref_m(int argc, VALUE *argv, VALUE str) { }
+
+/*
+ * call-seq:
+ * string <=> other_string -> -1, 0, +1 or nil
+ */
+static VALUE
+path_cmp_m(VALUE str1, VALUE str2) { }
+
+/*
+ * call-seq:
+ * str == obj -> true or false
+ * str === obj -> true or false
+ */
+VALUE
+rb_str_equal(VALUE str1, VALUE str2) { }
+
+Init_pathname()
+{
+ rb_cPathname = rb_define_class("Pathname", rb_cObject);
+
+ rb_define_method(rb_cPathname, "to_s", path_to_s, 0);
+ rb_define_method(rb_cPathname, "to_path", path_to_s, 0);
+ rb_define_method(rb_cPathname, "[]", path_aref_m, -1);
+ rb_define_method(rb_cPathname, "slice", path_aref_m, -1);
+ rb_define_method(rb_cPathname, "<=>", path_cmp_m, 1);
+ rb_define_method(rb_cPathname, "==", rb_str_equal), 2);
+ rb_define_method(rb_cPathname, "===", rb_str_equal), 2);
+}
+ C
+
+ parser.scan
+
+ pathname = @store.classes_hash['Pathname']
+
+ to_path = pathname.method_list.find { |m| m.name == 'to_path' }
+ assert_equal "pathname.to_path -> string", to_path.call_seq
+
+ to_s = pathname.method_list.find { |m| m.name == 'to_s' }
+ assert_equal "pathname.to_s -> string", to_s.call_seq
+
+ index_expected = <<-EXPECTED.chomp
+str[index] -> new_str or nil
+str[start, length] -> new_str or nil
+ EXPECTED
+
+ index = pathname.method_list.find { |m| m.name == '[]' }
+ assert_equal index_expected, index.call_seq, '[]'
+
+ slice_expected = <<-EXPECTED.chomp
+str.slice(index) -> new_str or nil
+str.slice(start, length) -> new_str or nil
+ EXPECTED
+
+ slice = pathname.method_list.find { |m| m.name == 'slice' }
+ assert_equal slice_expected, slice.call_seq
+
+ spaceship = pathname.method_list.find { |m| m.name == '<=>' }
+ assert_equal "string <=> other_string -> -1, 0, +1 or nil",
+ spaceship.call_seq
+
+ equals2 = pathname.method_list.find { |m| m.name == '==' }
+ assert_match 'str == obj', equals2.call_seq
+
+ equals3 = pathname.method_list.find { |m| m.name == '===' }
+ assert_match 'str === obj', equals3.call_seq
+ end
+
def test_scan_order_dependent
parser = util_parser <<-C
void a(void) {
diff --git a/test/rdoc/test_rdoc_parser_changelog.rb b/test/rdoc/test_rdoc_parser_changelog.rb
index ccd66f2b84..e6fa7a06c6 100644
--- a/test/rdoc/test_rdoc_parser_changelog.rb
+++ b/test/rdoc/test_rdoc_parser_changelog.rb
@@ -15,13 +15,6 @@ class TestRDocParserChangeLog < RDoc::TestCase
@tempfile.close
end
- def mu_pp obj
- s = ''
- s = PP.pp obj, s
- s = s.force_encoding Encoding.default_external if defined? Encoding
- s.chomp
- end
-
def test_class_can_parse
parser = RDoc::Parser::ChangeLog
diff --git a/test/rdoc/test_rdoc_parser_rd.rb b/test/rdoc/test_rdoc_parser_rd.rb
index 79959d2aae..bed47950fb 100644
--- a/test/rdoc/test_rdoc_parser_rd.rb
+++ b/test/rdoc/test_rdoc_parser_rd.rb
@@ -22,13 +22,6 @@ class TestRDocParserRd < RDoc::TestCase
@tempfile.close
end
- def mu_pp obj
- s = ''
- s = PP.pp obj, s
- s = s.force_encoding Encoding.default_external if defined? Encoding
- s.chomp
- end
-
def test_file
assert_kind_of RDoc::Parser::Text, util_parser('')
end
diff --git a/test/rdoc/test_rdoc_parser_ruby.rb b/test/rdoc/test_rdoc_parser_ruby.rb
index 2c61728571..397885806c 100644
--- a/test/rdoc/test_rdoc_parser_ruby.rb
+++ b/test/rdoc/test_rdoc_parser_ruby.rb
@@ -33,13 +33,6 @@ class TestRDocParserRuby < RDoc::TestCase
@tempfile2.close
end
- def mu_pp obj
- s = ''
- s = PP.pp obj, s
- s = s.force_encoding(Encoding.default_external) if defined? Encoding
- s.chomp
- end
-
def test_collect_first_comment
p = util_parser <<-CONTENT
# first
@@ -163,6 +156,35 @@ class C; end
assert_equal '/', @parser.get_symbol_or_name
end
+ def test_suppress_parents
+ a = @top_level.add_class RDoc::NormalClass, 'A'
+ b = a.add_class RDoc::NormalClass, 'B'
+ c = b.add_class RDoc::NormalClass, 'C'
+
+ util_parser ''
+
+ @parser.suppress_parents c, a
+
+ assert c.suppressed?
+ assert b.suppressed?
+ refute a.suppressed?
+ end
+
+ def test_suppress_parents_documented
+ a = @top_level.add_class RDoc::NormalClass, 'A'
+ b = a.add_class RDoc::NormalClass, 'B'
+ b.add_comment RDoc::Comment.new("hello"), @top_level
+ c = b.add_class RDoc::NormalClass, 'C'
+
+ util_parser ''
+
+ @parser.suppress_parents c, a
+
+ assert c.suppressed?
+ refute b.suppressed?
+ refute a.suppressed?
+ end
+
def test_look_for_directives_in_attr
util_parser ""
@@ -392,6 +414,23 @@ class C; end
assert_equal 0, klass.attributes.length
end
+ def test_parse_attr_accessor_nodoc_track
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ comment = RDoc::Comment.new "##\n# my attr\n", @top_level
+
+ @options.visibility = :nodoc
+
+ util_parser "attr_accessor :foo, :bar # :nodoc:"
+
+ tk = @parser.get_tk
+
+ @parser.parse_attr_accessor klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ refute_empty klass.attributes
+ end
+
def test_parse_attr_accessor_stopdoc
klass = RDoc::NormalClass.new 'Foo'
klass.parent = @top_level
@@ -568,6 +607,26 @@ class C; end
assert_equal 1, foo.line
end
+ def test_parse_class_singleton
+ comment = RDoc::Comment.new "##\n# my class\n", @top_level
+
+ util_parser <<-RUBY
+class C
+ class << self
+ end
+end
+ RUBY
+
+ tk = @parser.get_tk
+
+ @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ c = @top_level.classes.first
+ assert_equal 'C', c.full_name
+ assert_equal 0, c.offset
+ assert_equal 1, c.line
+ end
+
def test_parse_class_ghost_method
util_parser <<-CLASS
class Foo
@@ -589,6 +648,29 @@ end
assert_equal @top_level, blah.file
end
+ def test_parse_class_ghost_method_yields
+ util_parser <<-CLASS
+class Foo
+ ##
+ # :method:
+ # :call-seq:
+ # yields(name)
+end
+ CLASS
+
+ tk = @parser.get_tk
+
+ @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, @comment
+
+ foo = @top_level.classes.first
+ assert_equal 'Foo', foo.full_name
+
+ blah = foo.method_list.first
+ assert_equal 'Foo#yields', blah.full_name
+ assert_equal 'yields(name)', blah.call_seq
+ assert_equal @top_level, blah.file
+ end
+
def test_parse_class_multi_ghost_methods
util_parser <<-'CLASS'
class Foo
@@ -691,7 +773,7 @@ end
assert_equal 2, foo.method_list.length
end
- def test_parse_const_fail_w_meta
+ def test_parse_const_fail_w_meta_method
util_parser <<-CLASS
class ConstFailMeta
##
@@ -713,6 +795,27 @@ end
assert_equal 1, const_fail_meta.attributes.length
end
+ def test_parse_const_third_party
+ util_parser <<-CLASS
+class A
+ true if B::C
+ true if D::E::F
+end
+ CLASS
+
+ tk = @parser.get_tk
+
+ @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, @comment
+
+ a = @top_level.classes.first
+ assert_equal 'A', a.full_name
+
+ visible = @store.all_modules.reject { |mod| mod.suppressed? }
+ visible = visible.map { |mod| mod.full_name }
+
+ assert_empty visible
+ end
+
def test_parse_class_nested_superclass
foo = @top_level.add_module RDoc::NormalModule, 'Foo'
@@ -1002,6 +1105,23 @@ EOF
assert_equal klass.current_section, foo.section
end
+ def test_parse_comment_attr_attr_reader
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ comment = RDoc::Comment.new "##\n# :attr_reader: foo\n", @top_level
+
+ util_parser "\n"
+
+ tk = @parser.get_tk
+
+ @parser.parse_comment klass, tk, comment
+
+ foo = klass.attributes.first
+ assert_equal 'foo', foo.name
+ assert_equal 'R', foo.rw
+ end
+
def test_parse_comment_attr_stopdoc
klass = RDoc::NormalClass.new 'Foo'
klass.parent = @top_level
@@ -1064,6 +1184,23 @@ EOF
assert_equal stream, foo.token_stream
end
+ def test_parse_comment_method_args
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+
+ util_parser "\n"
+
+ tk = @parser.get_tk
+
+ @parser.parse_comment klass, tk,
+ comment("##\n# :method: foo\n# :args: a, b\n")
+
+ foo = klass.method_list.first
+ assert_equal 'foo', foo.name
+ assert_equal 'a, b', foo.params
+ end
+
def test_parse_comment_method_stopdoc
klass = RDoc::NormalClass.new 'Foo'
klass.parent = @top_level
@@ -1203,44 +1340,44 @@ A::B::C = 1
assert_equal 'comment', c.comment
end
- def test_parse_include
+ def test_parse_extend_or_include_extend
klass = RDoc::NormalClass.new 'C'
klass.parent = @top_level
- comment = RDoc::Comment.new "# my include\n", @top_level
+ comment = RDoc::Comment.new "# my extend\n", @top_level
- util_parser "include I"
+ util_parser "extend I"
- @parser.get_tk # include
+ @parser.get_tk # extend
- @parser.parse_include klass, comment
+ @parser.parse_extend_or_include RDoc::Extend, klass, comment
- assert_equal 1, klass.includes.length
+ assert_equal 1, klass.extends.length
- incl = klass.includes.first
- assert_equal 'I', incl.name
- assert_equal 'my include', incl.comment.text
- assert_equal @top_level, incl.file
+ ext = klass.extends.first
+ assert_equal 'I', ext.name
+ assert_equal 'my extend', ext.comment.text
+ assert_equal @top_level, ext.file
end
- def test_parse_extend
+ def test_parse_extend_or_include_include
klass = RDoc::NormalClass.new 'C'
klass.parent = @top_level
- comment = RDoc::Comment.new "# my extend\n", @top_level
+ comment = RDoc::Comment.new "# my include\n", @top_level
- util_parser "extend I"
+ util_parser "include I"
- @parser.get_tk # extend
+ @parser.get_tk # include
- @parser.parse_extend klass, comment
+ @parser.parse_extend_or_include RDoc::Include, klass, comment
- assert_equal 1, klass.extends.length
+ assert_equal 1, klass.includes.length
- ext = klass.extends.first
- assert_equal 'I', ext.name
- assert_equal 'my extend', ext.comment.text
- assert_equal @top_level, ext.file
+ incl = klass.includes.first
+ assert_equal 'I', incl.name
+ assert_equal 'my include', incl.comment.text
+ assert_equal @top_level, incl.file
end
def test_parse_meta_method
@@ -1644,6 +1781,34 @@ end
assert_equal 'foo', foo.name
end
+ def test_parse_method_nodoc
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ util_parser "def foo # :nodoc:\nend"
+
+ tk = @parser.get_tk
+
+ @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment('')
+
+ assert_empty klass.method_list
+ end
+
+ def test_parse_method_nodoc_track
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ @options.visibility = :nodoc
+
+ util_parser "def foo # :nodoc:\nend"
+
+ tk = @parser.get_tk
+
+ @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment('')
+
+ refute_empty klass.method_list
+ end
+
def test_parse_method_no_parens
klass = RDoc::NormalClass.new 'Foo'
klass.parent = @top_level
@@ -1884,6 +2049,24 @@ end
assert_equal Encoding::CP852, foo.comment.text.encoding
end
+ def test_parse_statements_enddoc
+ klass = @top_level.add_class RDoc::NormalClass, 'Foo'
+
+ util_parser "\n# :enddoc:"
+
+ @parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil
+
+ assert klass.done_documenting
+ end
+
+ def test_parse_statements_enddoc_top_level
+ util_parser "\n# :enddoc:"
+
+ assert_throws :eof do
+ @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil
+ end
+ end
+
def test_parse_statements_identifier_meta_method
content = <<-EOF
class Foo
@@ -2367,6 +2550,16 @@ end
# HACK where are the assertions?
end
+ def test_parse_top_level_statements_enddoc
+ util_parser <<-CONTENT
+# :enddoc:
+ CONTENT
+
+ assert_throws :eof do
+ @parser.parse_top_level_statements @top_level
+ end
+ end
+
def test_parse_top_level_statements_stopdoc
@top_level.stop_doc
content = "# this is the top-level comment"
@@ -2690,6 +2883,21 @@ end
assert_equal 'A nice girl', m.comment.text
end
+ def test_scan_class_nested_nodoc
+ content = <<-CONTENT
+class A::B # :nodoc:
+end
+ CONTENT
+
+ util_parser content
+
+ @parser.scan
+
+ visible = @store.all_classes_and_modules.select { |mod| mod.display? }
+
+ assert_empty visible.map { |mod| mod.full_name }
+ end
+
def test_scan_constant_in_method
content = <<-CONTENT # newline is after M is important
module M
@@ -2780,6 +2988,30 @@ end
assert c.documented?
end
+ def test_scan_duplicate_module
+ content = <<-CONTENT
+# comment a
+module Foo
+end
+
+# comment b
+module Foo
+end
+ CONTENT
+
+ util_parser content
+
+ @parser.scan
+
+ foo = @top_level.modules.first
+
+ expected = [
+ RDoc::Comment.new('comment b', @top_level)
+ ]
+
+ assert_equal expected, foo.comment_location.map { |c, l| c }
+ end
+
def test_scan_meta_method_block
content = <<-CONTENT
class C
@@ -2802,6 +3034,32 @@ class C
assert_equal 2, @top_level.classes.first.method_list.length
end
+ def test_scan_method_semi_method
+ content = <<-CONTENT
+class A
+ def self.m() end; def self.m=() end
+end
+
+class B
+ def self.m() end
+end
+ CONTENT
+
+ util_parser content
+
+ @parser.scan
+
+ a = @store.find_class_named 'A'
+ assert a, 'missing A'
+
+ assert_equal 2, a.method_list.length
+
+ b = @store.find_class_named 'B'
+ assert b, 'missing B'
+
+ assert_equal 1, b.method_list.length
+ end
+
def test_scan_markup_override
content = <<-CONTENT
# *awesome*
@@ -2847,6 +3105,20 @@ end
assert_equal 'rd', c.method_list.first.comment.format
end
+ def test_scan_rails_routes
+ util_parser <<-ROUTES_RB
+namespace :api do
+ scope module: :v1 do
+ end
+end
+ ROUTES_RB
+
+ @parser.scan
+
+ assert_empty @top_level.classes
+ assert_empty @top_level.modules
+ end
+
def test_scan_tomdoc_meta
util_parser <<-RUBY
# :markup: tomdoc
@@ -2953,6 +3225,35 @@ end
assert_equal %w[C::[]], c.method_list.map { |m| m.full_name }
end
+ def test_scan_visibility
+ util_parser <<-RUBY
+class C
+ def a() end
+
+ private :a
+
+ class << self
+ def b() end
+ private :b
+ end
+end
+ RUBY
+
+ @parser.scan
+
+ c = @store.find_class_named 'C'
+
+ c_a = c.find_method_named 'a'
+
+ assert_equal :private, c_a.visibility
+ refute c_a.singleton
+
+ c_b = c.find_method_named 'b'
+
+ assert_equal :private, c_b.visibility
+ refute c_b.singleton
+ end
+
def test_stopdoc_after_comment
util_parser <<-EOS
module Bar
diff --git a/test/rdoc/test_rdoc_rd_block_parser.rb b/test/rdoc/test_rdoc_rd_block_parser.rb
index 8bb1c27c2d..7aa44925e8 100644
--- a/test/rdoc/test_rdoc_rd_block_parser.rb
+++ b/test/rdoc/test_rdoc_rd_block_parser.rb
@@ -8,13 +8,6 @@ class TestRDocRdBlockParser < RDoc::TestCase
@block_parser = RDoc::RD::BlockParser.new
end
- def mu_pp(obj)
- s = ""
- s = PP.pp obj, s
- s = s.force_encoding(Encoding.default_external) if defined? Encoding
- s.chomp
- end
-
def test_add_footnote
index = @block_parser.add_footnote 'context'
@@ -538,4 +531,3 @@ two
end
end
-
diff --git a/test/rdoc/test_rdoc_rd_inline_parser.rb b/test/rdoc/test_rdoc_rd_inline_parser.rb
index 6f8c9557c4..e4a765b4fb 100644
--- a/test/rdoc/test_rdoc_rd_inline_parser.rb
+++ b/test/rdoc/test_rdoc_rd_inline_parser.rb
@@ -175,4 +175,3 @@ class TestRDocRdInlineParser < RDoc::TestCase
end
end
-
diff --git a/test/rdoc/test_rdoc_rdoc.rb b/test/rdoc/test_rdoc_rdoc.rb
index 9a13569f01..b36e47398b 100644
--- a/test/rdoc/test_rdoc_rdoc.rb
+++ b/test/rdoc/test_rdoc_rdoc.rb
@@ -108,7 +108,13 @@ class TestRDocRDoc < RDoc::TestCase
end
def test_normalized_file_list
- files = @rdoc.normalized_file_list [__FILE__]
+ files = temp_dir do |dir|
+ flag_file = @rdoc.output_flag_file dir
+
+ FileUtils.touch flag_file
+
+ @rdoc.normalized_file_list [__FILE__, flag_file]
+ end
files = files.map { |file| File.expand_path file }
@@ -162,6 +168,23 @@ class TestRDocRDoc < RDoc::TestCase
end
end
+ def test_parse_file_binary
+ @rdoc.store = RDoc::Store.new
+
+ root = File.dirname __FILE__
+
+ @rdoc.options.root = Pathname root
+
+ out, err = capture_io do
+ Dir.chdir root do
+ assert_nil @rdoc.parse_file 'binary.dat'
+ end
+ end
+
+ assert_empty out
+ assert_empty err
+ end
+
def test_parse_file_include_root
@rdoc.store = RDoc::Store.new
diff --git a/test/rdoc/test_rdoc_ri_driver.rb b/test/rdoc/test_rdoc_ri_driver.rb
index 92403e12f4..d0987a01c3 100644
--- a/test/rdoc/test_rdoc_ri_driver.rb
+++ b/test/rdoc/test_rdoc_ri_driver.rb
@@ -46,13 +46,6 @@ class TestRDocRIDriver < RDoc::TestCase
ENV['RI_PAGER'] = pager_env
end
- def mu_pp(obj)
- s = ''
- s = PP.pp obj, s
- s = s.force_encoding(Encoding.default_external) if defined? Encoding
- s.chomp
- end
-
def test_self_dump
util_store
@@ -696,6 +689,14 @@ Foo::Bar#bother
assert_equal expected, out
end
+ def test_display_name_not_found_special
+ util_store
+
+ assert_raises RDoc::RI::Driver::NotFoundError do
+ assert_equal false, @driver.display_name('Set#[]')
+ end
+ end
+
def test_display_method_params
util_store
@@ -939,7 +940,10 @@ Foo::Bar#bother
tty = Object.new
def tty.tty?() true; end
- driver = RDoc::RI::Driver.new
+ @options.delete :use_stdout
+ @options.delete :formatter
+
+ driver = RDoc::RI::Driver.new @options
assert_instance_of @RM::ToAnsi, driver.formatter(tty)
@@ -1094,6 +1098,17 @@ Foo::Bar#bother
assert_equal expected, @driver.load_methods_matching('Bar#inherit')
end
+ def test_load_method_missing
+ util_store
+
+ FileUtils.rm @store1.method_file 'Foo', '#inherit'
+
+ method = @driver.load_method(@store1, :instance_methods, 'Foo', '#',
+ 'inherit')
+
+ assert_equal '(unknown)#inherit', method.full_name
+ end
+
def _test_page # this test doesn't do anything anymore :(
@driver.use_stdout = false
diff --git a/test/rdoc/test_rdoc_ruby_lex.rb b/test/rdoc/test_rdoc_ruby_lex.rb
index 0dcb42565d..e1500c554d 100644
--- a/test/rdoc/test_rdoc_ruby_lex.rb
+++ b/test/rdoc/test_rdoc_ruby_lex.rb
@@ -8,13 +8,6 @@ class TestRDocRubyLex < RDoc::TestCase
@TK = RDoc::RubyToken
end
- def mu_pp obj
- s = ''
- s = PP.pp obj, s
- s = s.force_encoding(Encoding.default_external) if defined? Encoding
- s.chomp
- end
-
def test_class_tokenize
tokens = RDoc::RubyLex.tokenize "def x() end", nil
@@ -47,8 +40,8 @@ class TestRDocRubyLex < RDoc::TestCase
tokens = RDoc::RubyLex.tokenize "?\\", nil
expected = [
- @TK::TkSTRING.new( 0, 1, 0, "\\"),
- @TK::TkNL .new( 2, 1, 2, "\n"),
+ @TK::TkCHAR.new( 0, 1, 0, "?\\"),
+ @TK::TkNL .new( 2, 1, 2, "\n"),
]
assert_equal expected, tokens
@@ -162,6 +155,18 @@ Line 2
assert_equal expected, tokens
end
+ def test_class_tokenize_heredoc_missing_end
+ e = assert_raises RDoc::RubyLex::Error do
+ RDoc::RubyLex.tokenize <<-'RUBY', nil
+>> string1 = <<-TXT
+>" That's swell
+>" TXT
+ RUBY
+ end
+
+ assert_equal 'Missing terminating TXT for string', e.message
+ end
+
def test_class_tokenize_heredoc_percent_N
tokens = RDoc::RubyLex.tokenize <<-'RUBY', nil
a b <<-U
@@ -270,6 +275,100 @@ U
assert_equal expected, tokens
end
+ def test_class_tokenize_string_escape
+ tokens = RDoc::RubyLex.tokenize '"\\n"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\n\""), tokens.first
+
+ tokens = RDoc::RubyLex.tokenize '"\\r"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\r\""), tokens.first
+
+ tokens = RDoc::RubyLex.tokenize '"\\f"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\f\""), tokens.first
+
+ tokens = RDoc::RubyLex.tokenize '"\\\\"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\\\\""), tokens.first
+
+ tokens = RDoc::RubyLex.tokenize '"\\t"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\t\""), tokens.first
+
+ tokens = RDoc::RubyLex.tokenize '"\\v"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\v\""), tokens.first
+
+ tokens = RDoc::RubyLex.tokenize '"\\a"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\a\""), tokens.first
+
+ tokens = RDoc::RubyLex.tokenize '"\\e"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\e\""), tokens.first
+
+ tokens = RDoc::RubyLex.tokenize '"\\b"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\b\""), tokens.first
+
+ tokens = RDoc::RubyLex.tokenize '"\\s"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\s\""), tokens.first
+
+ tokens = RDoc::RubyLex.tokenize '"\\d"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\d\""), tokens.first
+
+ end
+
+ def test_class_tokenize_string_escape_control
+ tokens = RDoc::RubyLex.tokenize '"\\C-a"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\C-a\""), tokens.first
+
+ tokens = RDoc::RubyLex.tokenize '"\\c\\a"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\c\\a\""), tokens.first
+
+ tokens = RDoc::RubyLex.tokenize '"\\C-\\M-a"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\C-\\M-a\""), tokens.first
+ end
+
+ def test_class_tokenize_string_escape_meta
+ tokens = RDoc::RubyLex.tokenize '"\\M-a"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\M-a\""), tokens.first
+
+ tokens = RDoc::RubyLex.tokenize '"\\M-\\C-a"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\M-\\C-a\""), tokens.first
+ end
+
+ def test_class_tokenize_string_escape_hexadecimal
+ tokens = RDoc::RubyLex.tokenize '"\\x0"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\x0\""), tokens.first
+
+ tokens = RDoc::RubyLex.tokenize '"\\x00"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\x00\""), tokens.first
+
+ tokens = RDoc::RubyLex.tokenize '"\\x000"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\x000\""), tokens.first
+ end
+
+ def test_class_tokenize_string_escape_octal
+ tokens = RDoc::RubyLex.tokenize '"\\0"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\0\""), tokens.first
+
+ tokens = RDoc::RubyLex.tokenize '"\\00"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\00\""), tokens.first
+
+ tokens = RDoc::RubyLex.tokenize '"\\000"', nil
+ assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\000\""), tokens.first
+ end
+
+ def test_class_tokenize_symbol
+ tokens = RDoc::RubyLex.tokenize 'scope module: :v1', nil
+
+ expected = [
+ @TK::TkIDENTIFIER.new( 0, 1, 0, 'scope'),
+ @TK::TkSPACE .new( 5, 1, 5, ' '),
+ @TK::TkIDENTIFIER.new( 6, 1, 6, 'module'),
+ @TK::TkCOLON .new(12, 1, 12, ':'),
+ @TK::TkSPACE .new(13, 1, 13, ' '),
+ @TK::TkSYMBEG .new(14, 1, 14, ':'),
+ @TK::TkIDENTIFIER.new(15, 1, 15, 'v1'),
+ @TK::TkNL .new(17, 1, 17, "\n"),
+ ]
+
+ assert_equal expected, tokens
+ end
+
def test_unary_minus
ruby_lex = RDoc::RubyLex.new("-1", nil)
assert_equal("-1", ruby_lex.token.value)
diff --git a/test/rdoc/test_rdoc_servlet.rb b/test/rdoc/test_rdoc_servlet.rb
index 40de171b6b..143e2f225b 100644
--- a/test/rdoc/test_rdoc_servlet.rb
+++ b/test/rdoc/test_rdoc_servlet.rb
@@ -23,7 +23,9 @@ class TestRDocServlet < RDoc::TestCase
@stores = {}
@cache = Hash.new { |hash, store| hash[store] = {} }
- @s = RDoc::Servlet.new @server, @stores, @cache
+ @extra_dirs = [File.join(@tempdir, 'extra1'), File.join(@tempdir, 'extra2')]
+
+ @s = RDoc::Servlet.new @server, @stores, @cache, nil, @extra_dirs
@req = WEBrick::HTTPRequest.new :Logger => nil
@res = WEBrick::HTTPResponse.new :HTTPVersion => '1.0'
@@ -145,6 +147,16 @@ class TestRDocServlet < RDoc::TestCase
end
end
+ def do_GET_not_found
+ touch_system_cache_path
+
+ @req.path = "/#{@spec.full_name}"
+
+ @s.do_GET @req, @res
+
+ assert_equal 404, @res.status
+ end
+
def test_do_GET_not_modified
touch_system_cache_path
@req.header['if-modified-since'] = [(Time.now + 10).httpdate]
@@ -187,8 +199,8 @@ class TestRDocServlet < RDoc::TestCase
@s.documentation_page store, generator, 'Klass::Sub.html', @req, @res
- assert_match %r%<title>class Klass::Sub - </title>%, @res.body
- assert_match %r%<body id="top" class="class">%, @res.body
+ assert_match %r%<title>class Klass::Sub - </title>%, @res.body
+ assert_match %r%<body id="top" role="document" class="class">%, @res.body
end
def test_documentation_page_not_found
@@ -214,7 +226,7 @@ class TestRDocServlet < RDoc::TestCase
@s.documentation_page store, generator, 'README_rdoc.html', @req, @res
assert_match %r%<title>README - </title>%, @res.body
- assert_match %r%<body class="file">%, @res.body
+ assert_match %r%<body [^>]+ class="file">%, @res.body
end
def test_documentation_source
@@ -298,8 +310,13 @@ class TestRDocServlet < RDoc::TestCase
def test_installed_docs
touch_system_cache_path
+ touch_extra_cache_path
expected = [
+ ['My Extra Documentation', 'extra-1/', true, :extra,
+ @extra_dirs[0]],
+ ['Extra Documentation', 'extra-2/', false, :extra,
+ @extra_dirs[1]],
['Ruby Documentation', 'ruby/', true, :system,
@system_dir],
['Site Documentation', 'site/', false, :site,
@@ -325,10 +342,24 @@ class TestRDocServlet < RDoc::TestCase
assert_match %r%<kbd>/ruby/Missing\.html</kbd>%, @res.body
end
+ def test_not_found_message
+ generator = @s.generator_for RDoc::Store.new
+
+ @req.path = '/ruby/Missing.html'
+
+ @s.not_found generator, @req, @res, 'woo, this is a message'
+
+ assert_equal 404, @res.status
+ assert_match %r%<title>Not Found</title>%, @res.body
+ assert_match %r%woo, this is a message%, @res.body
+ end
+
def test_ri_paths
paths = @s.ri_paths
expected = [
+ [@extra_dirs[0], :extra],
+ [@extra_dirs[1], :extra],
[@system_dir, :system],
[File.join(@base, 'site'), :site],
[RDoc::RI::Paths::HOMEDIR, :home],
@@ -347,6 +378,7 @@ class TestRDocServlet < RDoc::TestCase
def test_root_search
touch_system_cache_path
+ touch_extra_cache_path
@s.root_search @req, @res
@@ -359,12 +391,16 @@ class TestRDocServlet < RDoc::TestCase
expected = {
'index' => {
'searchIndex' => %w[
+ My\ Extra\ Documentation
Ruby\ Documentation
],
'longSearchIndex' => %w[
+ My\ Extra\ Documentation
Ruby\ Documentation
],
'info' => [
+ ['My Extra Documentation', '', @extra_dirs[0], '',
+ 'My Extra Documentation'],
['Ruby Documentation', '', 'ruby', '',
'Documentation for the Ruby standard library'],
],
@@ -419,6 +455,10 @@ class TestRDocServlet < RDoc::TestCase
end
def test_store_for_gem
+ ri_dir = File.join @gem_doc_dir, 'spec-1.0', 'ri'
+ FileUtils.mkdir_p ri_dir
+ FileUtils.touch File.join ri_dir, 'cache.ri'
+
store = @s.store_for 'spec-1.0'
assert_equal File.join(@gem_doc_dir, 'spec-1.0', 'ri'), store.path
@@ -432,12 +472,24 @@ class TestRDocServlet < RDoc::TestCase
assert_equal :home, store.type
end
- def test_store_for_missing
- e = assert_raises RDoc::Error do
+ def test_store_for_missing_documentation
+ FileUtils.mkdir_p(File.join @gem_doc_dir, 'spec-1.0', 'ri')
+
+ e = assert_raises WEBrick::HTTPStatus::NotFound do
+ @s.store_for 'spec-1.0'
+ end
+
+ assert_equal 'Could not find documentation for "spec-1.0". Please run `gem rdoc --ri gem_name`',
+ e.message
+ end
+
+ def test_store_for_missing_gem
+ e = assert_raises WEBrick::HTTPStatus::NotFound do
@s.store_for 'missing'
end
- assert_equal 'could not find ri documentation for missing', e.message
+ assert_equal 'Could not find gem "missing". Are you sure you installed it?',
+ e.message
end
def test_store_for_ruby
@@ -454,6 +506,13 @@ class TestRDocServlet < RDoc::TestCase
assert_equal :site, store.type
end
+ def test_store_for_extra
+ store = @s.store_for 'extra-1'
+
+ assert_equal @extra_dirs.first, store.path
+ assert_equal :extra, store.type
+ end
+
def touch_system_cache_path
store = RDoc::Store.new @system_dir
store.title = 'Standard Library Documentation'
@@ -463,5 +522,14 @@ class TestRDocServlet < RDoc::TestCase
store.save
end
+ def touch_extra_cache_path
+ store = RDoc::Store.new @extra_dirs.first
+ store.title = 'My Extra Documentation'
+
+ FileUtils.mkdir_p File.dirname store.cache_path
+
+ store.save
+ end
+
end
diff --git a/test/rdoc/test_rdoc_stats.rb b/test/rdoc/test_rdoc_stats.rb
index 5073e53b7e..7d336bedc8 100644
--- a/test/rdoc/test_rdoc_stats.rb
+++ b/test/rdoc/test_rdoc_stats.rb
@@ -44,14 +44,17 @@ class TestRDocStats < RDoc::TestCase
report = @s.report
- expected = <<-EXPECTED
-The following items are not documented:
-
-class C # is documented
-
- attr_accessor :a # in file file.rb
-end
- EXPECTED
+ expected =
+ doc(
+ para('The following items are not documented:'),
+ blank_line,
+ verb(
+ "class C # is documented\n",
+ "\n",
+ " attr_accessor :a # in file file.rb\n",
+ "\n",
+ "end\n"),
+ blank_line)
assert_equal expected, report
end
@@ -84,7 +87,7 @@ end
@store.complete :public
- assert_match '# in file file.rb:3', @s.report
+ assert_match '# in file file.rb:3', @s.report.accept(to_rdoc)
end
def test_report_constant
@@ -100,15 +103,18 @@ end
report = @s.report
- expected = <<-EXPECTED
-The following items are not documented:
-
-module M # is documented
-
- # in file file.rb
- C = nil
-end
- EXPECTED
+ expected =
+ doc(
+ para('The following items are not documented:'),
+ blank_line,
+ verb(
+ "module M # is documented\n",
+ "\n",
+ " # in file file.rb\n",
+ " C = nil\n",
+ "\n",
+ "end\n"),
+ blank_line)
assert_equal expected, report
end
@@ -130,13 +136,13 @@ end
# TODO change this to refute match, aliases should be ignored as they are
# programmer convenience constructs
- assert_match(/class Object/, report)
+ assert_match 'class Object', report.accept(to_rdoc)
end
def test_report_constant_documented
m = @tl.add_module RDoc::NormalModule, 'M'
m.record_location @tl
- m.comment = 'M'
+ m.add_comment 'M', @tl
c = RDoc::Constant.new 'C', nil, 'C'
c.record_location @tl
@@ -161,7 +167,7 @@ end
@store.complete :public
- assert_match '# in file file.rb:5', @s.report
+ assert_match '# in file file.rb:5', @s.report.accept(to_rdoc)
end
def test_report_class
@@ -177,15 +183,16 @@ end
report = @s.report
- expected = <<-EXPECTED
-The following items are not documented:
-
-# in files:
-# file.rb
-
-class C
-end
- EXPECTED
+ expected =
+ doc(
+ para('The following items are not documented:'),
+ blank_line,
+ para('In files:'),
+ list(:BULLET, *[
+ item(nil, para('file.rb'))]),
+ blank_line,
+ verb("class C\n", "end\n"),
+ blank_line)
assert_equal expected, report
end
@@ -201,7 +208,7 @@ end
@store.complete :public
- refute_match %r%^class Object$%, @s.report
+ refute_match %r%^class Object$%, @s.report.accept(to_rdoc)
end
def test_report_class_documented
@@ -245,16 +252,16 @@ end
report = @s.report
- expected = <<-EXPECTED
-The following items are not documented:
-
-
-# in files:
-# file.rb
-
-class C2
-end
- EXPECTED
+ expected =
+ doc(
+ para('The following items are not documented:'),
+ blank_line,
+ para('In files:'),
+ list(:BULLET, *[
+ item(nil, para('file.rb'))]),
+ blank_line,
+ verb("class C2\n", "end\n"),
+ blank_line)
assert_equal expected, report
end
@@ -266,13 +273,13 @@ end
report = @s.report
- expected = <<-EXPECTED
-The following items are not documented:
-
-# class C is referenced but empty.
-#
-# It probably came from another project. I'm sorry I'm holding it against you.
- EXPECTED
+ expected =
+ doc(
+ para('The following items are not documented:'),
+ blank_line,
+ para('class C is referenced but empty.'),
+ para("It probably came from another project. I'm sorry I'm holding it against you."),
+ blank_line)
assert_equal expected, report
end
@@ -290,16 +297,16 @@ The following items are not documented:
@s.coverage_level = 1
report = @s.report
- expected = <<-EXPECTED
-The following items are not documented:
-
-# in files:
-# file.rb
-
-class C1
-end
-
- EXPECTED
+ expected =
+ doc(
+ para('The following items are not documented:'),
+ blank_line,
+ para('In files:'),
+ list(:BULLET, *[
+ item(nil, para('file.rb'))]),
+ blank_line,
+ verb("class C1\n", "end\n"),
+ blank_line)
assert_equal expected, report
end
@@ -317,15 +324,16 @@ end
report = @s.report
- expected = <<-EXPECTED
-The following items are not documented:
-
-# in files:
-# file.rb
-
-class C
-end
- EXPECTED
+ expected =
+ doc(
+ para('The following items are not documented:'),
+ blank_line,
+ para('In files:'),
+ list(:BULLET, *[
+ item(nil, para('file.rb'))]),
+ blank_line,
+ verb("class C\n", "end\n"),
+ blank_line)
assert_equal expected, report
end
@@ -367,16 +375,18 @@ end
report = @s.report
- expected = <<-EXPECTED
-The following items are not documented:
-
-class C # is documented
-
- # in file file.rb
- def m1; end
-
-end
- EXPECTED
+ expected =
+ doc(
+ para('The following items are not documented:'),
+ blank_line,
+ verb(*[
+ "class C # is documented\n",
+ "\n",
+ " # in file file.rb\n",
+ " def m1; end\n",
+ "\n",
+ "end\n"]),
+ blank_line)
assert_equal expected, report
end
@@ -401,16 +411,18 @@ end
report = @s.report
- expected = <<-EXPECTED
-The following items are not documented:
-
-class C # is documented
-
- # in file file.rb
- def self.m1; end
-
-end
- EXPECTED
+ expected =
+ doc(
+ para('The following items are not documented:'),
+ blank_line,
+ verb(*[
+ "class C # is documented\n",
+ "\n",
+ " # in file file.rb\n",
+ " def self.m1; end\n",
+ "\n",
+ "end\n"]),
+ blank_line)
assert_equal expected, report
end
@@ -444,7 +456,7 @@ end
@store.complete :public
- assert_match '# in file file.rb:4', @s.report
+ assert_match '# in file file.rb:4', @s.report.accept(to_rdoc)
end
def test_report_method_parameters
@@ -468,17 +480,19 @@ end
@s.coverage_level = 1
report = @s.report
- expected = <<-EXPECTED
-The following items are not documented:
-
-class C # is documented
-
- # in file file.rb
- # +p2+ is not documented
- def m1(p1, p2); end
-
-end
- EXPECTED
+ expected =
+ doc(
+ para('The following items are not documented:'),
+ blank_line,
+ verb(*[
+ "class C # is documented\n",
+ "\n",
+ " # in file file.rb\n",
+ " # +p2+ is not documented\n",
+ " def m1(p1, p2); end\n",
+ "\n",
+ "end\n"]),
+ blank_line)
assert_equal expected, report
end
@@ -522,17 +536,19 @@ m(a, b) { |c, d| ... }
@s.coverage_level = 1
report = @s.report
- expected = <<-EXPECTED
-The following items are not documented:
-
-class C # is documented
-
- # in file file.rb
- # +b+, +d+ is not documented
- def m; end
-
-end
- EXPECTED
+ expected =
+ doc(
+ para('The following items are not documented:'),
+ blank_line,
+ verb(
+ "class C # is documented\n",
+ "\n",
+ " # in file file.rb\n",
+ " # +b+, +d+ is not documented\n",
+ " def m; end\n",
+ "\n",
+ "end\n"),
+ blank_line)
assert_equal expected, report
end
@@ -558,20 +574,20 @@ end
@store.complete :public
- summary = @s.summary
- summary.sub!(/Elapsed:.*/, '')
+ summary = @s.summary.accept to_rdoc
+ summary.sub!(/ Elapsed:.*/m, '')
expected = <<-EXPECTED
-Files: 0
+ Files: 0
-Classes: 1 (1 undocumented)
-Modules: 1 (1 undocumented)
-Constants: 1 (1 undocumented)
-Attributes: 1 (1 undocumented)
-Methods: 1 (1 undocumented)
+ Classes: 1 (1 undocumented)
+ Modules: 1 (1 undocumented)
+ Constants: 1 (1 undocumented)
+ Attributes: 1 (1 undocumented)
+ Methods: 1 (1 undocumented)
-Total: 5 (5 undocumented)
- 0.00% documented
+ Total: 5 (5 undocumented)
+ 0.00% documented
EXPECTED
@@ -586,20 +602,20 @@ Total: 5 (5 undocumented)
@s.coverage_level = false
- summary = @s.summary
- summary.sub!(/Elapsed:.*/, '')
+ summary = @s.summary.accept to_rdoc
+ summary.sub!(/ Elapsed:.*/m, '')
expected = <<-EXPECTED
-Files: 0
+ Files: 0
-Classes: 1 (1 undocumented)
-Modules: 0 (0 undocumented)
-Constants: 0 (0 undocumented)
-Attributes: 0 (0 undocumented)
-Methods: 0 (0 undocumented)
+ Classes: 1 (1 undocumented)
+ Modules: 0 (0 undocumented)
+ Constants: 0 (0 undocumented)
+ Attributes: 0 (0 undocumented)
+ Methods: 0 (0 undocumented)
-Total: 1 (1 undocumented)
- 0.00% documented
+ Total: 1 (1 undocumented)
+ 0.00% documented
EXPECTED
@@ -622,26 +638,30 @@ Total: 1 (1 undocumented)
@s.coverage_level = 1
@s.report
- summary = @s.summary
- summary.sub!(/Elapsed:.*/, '')
+ summary = @s.summary.accept to_rdoc
+ summary.sub!(/ Elapsed:.*/m, '')
expected = <<-EXPECTED
-Files: 0
+ Files: 0
-Classes: 1 (0 undocumented)
-Modules: 0 (0 undocumented)
-Constants: 0 (0 undocumented)
-Attributes: 0 (0 undocumented)
-Methods: 1 (0 undocumented)
-Parameters: 2 (1 undocumented)
+ Classes: 1 (0 undocumented)
+ Modules: 0 (0 undocumented)
+ Constants: 0 (0 undocumented)
+ Attributes: 0 (0 undocumented)
+ Methods: 1 (0 undocumented)
+ Parameters: 2 (1 undocumented)
-Total: 4 (1 undocumented)
- 75.00% documented
+ Total: 4 (1 undocumented)
+ 75.00% documented
EXPECTED
assert_equal summary, expected
end
+ def to_rdoc
+ RDoc::Markup::ToRdoc.new
+ end
+
end
diff --git a/test/rdoc/test_rdoc_store.rb b/test/rdoc/test_rdoc_store.rb
index 3b92707987..bd565e7149 100644
--- a/test/rdoc/test_rdoc_store.rb
+++ b/test/rdoc/test_rdoc_store.rb
@@ -9,6 +9,7 @@ class TestRDocStore < XrefTestCase
@tmpdir = File.join Dir.tmpdir, "test_rdoc_ri_store_#{$$}"
@s = RDoc::RI::Store.new @tmpdir
+ @s.rdoc = @rdoc
@top_level = @s.add_file 'file.rb'
@@ -71,13 +72,6 @@ class TestRDocStore < XrefTestCase
FileUtils.rm_rf @tmpdir
end
- def mu_pp obj
- s = ''
- s = PP.pp obj, s
- s.force_encoding Encoding.default_external if defined? Encoding
- s.chomp
- end
-
def assert_cache imethods, cmethods, attrs, modules,
ancestors = {}, pages = [], main = nil, title = nil
imethods ||= { 'Object' => %w[method method! method_bang] }
@@ -106,18 +100,6 @@ class TestRDocStore < XrefTestCase
assert_equal expected, @s.cache
end
- def assert_directory path
- assert File.directory?(path), "#{path} is not a directory"
- end
-
- def assert_file path
- assert File.file?(path), "#{path} is not a file"
- end
-
- def refute_file path
- refute File.exist?(path), "#{path} exists"
- end
-
def test_add_c_enclosure
@s.add_c_enclosure 'cC1', @c1
@@ -249,6 +231,16 @@ class TestRDocStore < XrefTestCase
refute_empty a1.aliases
end
+ def test_complete_nodoc
+ c_nodoc = @top_level.add_class RDoc::NormalClass, 'Nodoc'
+ c_nodoc.record_location @top_level
+ c_nodoc.document_self = nil
+
+ @s.complete :nodoc
+
+ assert_includes @s.classes_hash.keys, 'Nodoc'
+ end
+
def test_find_c_enclosure
assert_nil @s.find_c_enclosure 'cC1'
diff --git a/test/rdoc/test_rdoc_text.rb b/test/rdoc/test_rdoc_text.rb
index 473bd3cadd..b0c464a659 100644
--- a/test/rdoc/test_rdoc_text.rb
+++ b/test/rdoc/test_rdoc_text.rb
@@ -14,13 +14,6 @@ class TestRDocText < RDoc::TestCase
@top_level = @store.add_file 'file.rb'
end
- def mu_pp obj
- s = ''
- s = PP.pp obj, s
- s = s.force_encoding Encoding.default_external if defined? Encoding
- s.chomp
- end
-
def test_self_encode_fallback
skip "Encoding not implemented" unless Object.const_defined? :Encoding
@@ -261,42 +254,31 @@ Examples
assert_equal RDoc::Markup::Document.new, parse("\n")
end
-# def test_snippet
-# text = <<-TEXT
-#This is one-hundred characters or more of text in a single paragraph. This
-#paragraph will be cut off some point after the one-hundredth character.
-# TEXT
-#
-# expected = text.gsub(/\r?\n/, ' ').sub(/ some point.*/, '')
-#
-# assert_equal expected, snippet(text)
-# end
-#
-# def test_snippet_comment
-# c = comment 'This is a comment'
-#
-# assert_equal 'This is a comment', snippet(c)
-# end
-#
-# def test_snippet_no_space
-# text = <<-TEXT.strip
-#This is one-hundred characters or more of text in a single paragraph. This
-#paragraph will not be cut
-# TEXT
-#
-# expected = <<-EXPECTED.strip.gsub(/\r?\n/, ' ')
-#This is one-hundred characters or more of text in a single paragraph. This
-#paragraph will not be cut
-# EXPECTED
-#
-# assert_equal expected, snippet(text)
-# end
-#
-# def test_snippet_short
-# text = 'This is a comment'
-#
-# assert_equal text.dup, snippet(text)
-# end
+ def test_snippet
+ text = <<-TEXT
+This is one-hundred characters or more of text in a single paragraph. This
+paragraph will be cut off some point after the one-hundredth character.
+ TEXT
+
+ expected = <<-EXPECTED
+<p>This is one-hundred characters or more of text in a single paragraph. This
+paragraph will be cut off …
+ EXPECTED
+
+ assert_equal expected, snippet(text)
+ end
+
+ def test_snippet_comment
+ c = comment 'This is a comment'
+
+ assert_equal "<p>This is a comment\n", snippet(c)
+ end
+
+ def test_snippet_short
+ text = 'This is a comment'
+
+ assert_equal "<p>#{text}\n", snippet(text)
+ end
def test_strip_hashes
text = <<-TEXT
@@ -560,9 +542,13 @@ The comments associated with
assert_equal "mismatched <tt> tag\n", err
end
- def formatter()
+ def formatter
RDoc::Markup::ToHtml.new @options
end
+ def options
+ @options
+ end
+
end
diff --git a/test/rdoc/test_rdoc_tom_doc.rb b/test/rdoc/test_rdoc_tom_doc.rb
index b22411f89f..63d3a5e79e 100644
--- a/test/rdoc/test_rdoc_tom_doc.rb
+++ b/test/rdoc/test_rdoc_tom_doc.rb
@@ -11,13 +11,6 @@ class TestRDocTomDoc < RDoc::TestCase
@td = @TD.new
end
- def mu_pp obj
- s = ''
- s = PP.pp obj, s
- s = s.force_encoding Encoding.default_external if defined? Encoding
- s.chomp
- end
-
def test_class_add_post_processor
RDoc::TomDoc.add_post_processor
@@ -135,6 +128,17 @@ here - something
assert_equal expected, @TD.parse(text)
end
+ def test_parse_multiline_paragraph
+ text = "Public: Do some stuff\n"
+ text << "On a new line\n"
+
+ expected =
+ doc(
+ para('Do some stuff', ' ', 'On a new line'))
+
+ assert_equal expected, @TD.parse(text)
+ end
+
def test_parse_arguments
text = <<-TEXT
Create new Arg object.
@@ -188,7 +192,7 @@ foo - A comment goes here
blank_line,
list(:NOTE,
item(%w[foo],
- para('A comment goes here', 'and is more than one line'))))
+ para('A comment goes here', ' ', 'and is more than one line'))))
assert_equal expected, @TD.parse(text)
end
@@ -279,13 +283,19 @@ Signature
Do some stuff
Returns a thing
+
+Returns another thing
TEXT
expected =
- @RM::Document.new(
- @RM::Paragraph.new('Do some stuff'),
- @RM::BlankLine.new,
- @RM::Paragraph.new('Returns a thing'))
+ doc(
+ para('Do some stuff'),
+ blank_line,
+ head(3, 'Returns'),
+ blank_line,
+ para('Returns a thing'),
+ blank_line,
+ para('Returns another thing'))
assert_equal expected, @TD.parse(text)
end
@@ -299,10 +309,12 @@ Returns a thing
TEXT
expected =
- @RM::Document.new(
- @RM::Paragraph.new('Do some stuff'),
- @RM::BlankLine.new,
- @RM::Paragraph.new('Returns a thing', 'that is multiline'))
+ doc(
+ para('Do some stuff'),
+ blank_line,
+ head(3, 'Returns'),
+ blank_line,
+ para('Returns a thing', ' ', 'that is multiline'))
assert_equal expected, @TD.parse(text)
end
@@ -338,6 +350,22 @@ Signature
assert_equal expected, @td.tokens
end
+ def test_tokenize_multiline_paragraph
+ text = "Public: Do some stuff\n"
+ text << "On a new line\n"
+
+ @td.tokenize text
+
+ expected = [
+ [:TEXT, "Do some stuff", 0, 0],
+ [:NEWLINE, "\n", 13, 0],
+ [:TEXT, "On a new line", 0, 1],
+ [:NEWLINE, "\n", 13, 1]
+ ]
+
+ assert_equal expected, @td.tokens
+ end
+
def test_tokenize_arguments
@td.tokenize <<-TEXT
Create new Arg object.
diff --git a/test/rdoc/xref_test_case.rb b/test/rdoc/xref_test_case.rb
index 29021a301c..a56fa71268 100644
--- a/test/rdoc/xref_test_case.rb
+++ b/test/rdoc/xref_test_case.rb
@@ -11,6 +11,8 @@ class XrefTestCase < RDoc::TestCase
@options = RDoc::Options.new
@options.quiet = true
+ @rdoc.options = @options
+
@file_name = 'xref_data.rb'
@xref_data = @store.add_file @file_name
@top_level = @xref_data