diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-12-20 03:22:49 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-12-20 03:22:49 +0000 |
commit | 2ef9c50c6e405717d06362787c4549ca4f1c6485 (patch) | |
tree | ee99486567461dd5796f3d6edcc9e204187f2666 /test | |
parent | d7effd506f5b91a636f2e6452ef1946b923007c7 (diff) |
Import RDoc 3
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30249 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
37 files changed, 2648 insertions, 970 deletions
diff --git a/test/rdoc/test.ja.rdoc b/test/rdoc/test.ja.rdoc index 96e1db93d3..cd01cab37a 100644 --- a/test/rdoc/test.ja.rdoc +++ b/test/rdoc/test.ja.rdoc @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + こんにちは! 初めまして。アーロンと申します。 diff --git a/test/rdoc/test_attribute_manager.rb b/test/rdoc/test_attribute_manager.rb index e908b86b02..25e8ca5e04 100644 --- a/test/rdoc/test_attribute_manager.rb +++ b/test/rdoc/test_attribute_manager.rb @@ -2,29 +2,35 @@ require 'rubygems' require 'minitest/autorun' require 'rdoc' require 'rdoc/markup' +require 'rdoc/markup/formatter' require 'rdoc/markup/attribute_manager' -class TestAttributeManager < MiniTest::Unit::TestCase +class TestAttributeManager < MiniTest::Unit::TestCase # HACK fix test name def setup @am = RDoc::Markup::AttributeManager.new @klass = RDoc::Markup::AttributeManager + @formatter = RDoc::Markup::Formatter.new + @formatter.add_tag :BOLD, '<B>', '</B>' + @formatter.add_tag :EM, '<EM>', '</EM>' + @formatter.add_tag :TT, '<TT>', '</TT>' end def test_convert_attrs_ignores_code - collector = RDoc::Markup::AttrSpan.new 10 - str = 'foo <code>__send__</code> bar' - @am.convert_html str, collector - @am.convert_attrs str, collector - assert_match(/__send__/, str) + assert_equal 'foo <TT>__send__</TT> bar', output('foo <code>__send__</code> bar') end def test_convert_attrs_ignores_tt - collector = RDoc::Markup::AttrSpan.new 10 - str = 'foo <tt>__send__</tt> bar' - @am.convert_html str, collector - @am.convert_attrs str, collector - assert_match(/__send__/, str) + assert_equal 'foo <TT>__send__</TT> 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 <TT>IF:</TT><EM>key</EM> directive', output('the <tt>IF:</tt>_key_ directive') end def test_initial_word_pairs @@ -73,12 +79,41 @@ class TestAttributeManager < MiniTest::Unit::TestCase assert(specials.has_key?("WikiWord")) end - def silently(&block) - warn_level = $VERBOSE - $VERBOSE = nil - result = block.call - $VERBOSE = warn_level - result + def test_escapes + assert_equal '<TT>text</TT>', output('<tt>text</tt>') + assert_equal '<tt>text</tt>', output('\\<tt>text</tt>') + assert_equal '<tt>', output('\\<tt>') + assert_equal '<TT><tt></TT>', output('<tt>\\<tt></tt>') + assert_equal '<TT>\\<tt></TT>', 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 <TT>\\s</TT> matches space', + output('and <tt>\\s</tt> matches space') + assert_equal 'use <TT><tt>text</TT></tt> 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><tt>text</tt></tt> 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>+text+</TT> for code', + output('use <tt>\\+text+</tt> for code') + assert_equal 'use <tt><TT>text</TT></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 output str + @formatter.convert_flow @am.flow str end end diff --git a/test/rdoc/test_rdoc_alias.rb b/test/rdoc/test_rdoc_alias.rb new file mode 100644 index 0000000000..ff499af962 --- /dev/null +++ b/test/rdoc/test_rdoc_alias.rb @@ -0,0 +1,13 @@ +require File.expand_path '../xref_test_case', __FILE__ + +class TestRDocAlias < XrefTestCase + + def test_to_s + a = RDoc::Alias.new nil, 'a', 'b', '' + a.parent = @c2 + + assert_equal 'alias: b -> #a in: RDoc::NormalClass C2 < Object', a.to_s + end + +end + diff --git a/test/rdoc/test_rdoc_any_method.rb b/test/rdoc/test_rdoc_any_method.rb index a4c3eec48c..2a7ae9042a 100644 --- a/test/rdoc/test_rdoc_any_method.rb +++ b/test/rdoc/test_rdoc_any_method.rb @@ -1,15 +1,17 @@ require File.expand_path '../xref_test_case', __FILE__ +require 'rdoc/code_objects' +require 'rdoc/generator/markup' class RDocAnyMethodTest < XrefTestCase def test_aref m = RDoc::AnyMethod.new nil, 'method?' - assert_equal 'method-i-method%3F', m.aref + assert_equal 'method-i-method-3F', m.aref m.singleton = true - assert_equal 'method-c-method%3F', m.aref + assert_equal 'method-c-method-3F', m.aref end def test_arglists @@ -36,6 +38,45 @@ method(a, b) { |c, d| ... } assert_equal 'C1::m', @c1.method_list.first.full_name end + def test_markup_code + tokens = [ + RDoc::RubyToken::TkCONSTANT. new(0, 0, 0, 'CONSTANT'), + RDoc::RubyToken::TkKW. new(0, 0, 0, 'KW'), + RDoc::RubyToken::TkIVAR. new(0, 0, 0, 'IVAR'), + RDoc::RubyToken::TkOp. new(0, 0, 0, 'Op'), + RDoc::RubyToken::TkId. new(0, 0, 0, 'Id'), + RDoc::RubyToken::TkNode. new(0, 0, 0, 'Node'), + RDoc::RubyToken::TkCOMMENT. new(0, 0, 0, 'COMMENT'), + RDoc::RubyToken::TkREGEXP. new(0, 0, 0, 'REGEXP'), + RDoc::RubyToken::TkSTRING. new(0, 0, 0, 'STRING'), + RDoc::RubyToken::TkVal. new(0, 0, 0, 'Val'), + RDoc::RubyToken::TkBACKSLASH.new(0, 0, 0, '\\'), + ] + + @c2_a.collect_tokens + @c2_a.add_tokens(*tokens) + + expected = [ + '<span class="ruby-constant">CONSTANT</span>', + '<span class="ruby-keyword">KW</span>', + '<span class="ruby-ivar">IVAR</span>', + '<span class="ruby-operator">Op</span>', + '<span class="ruby-identifier">Id</span>', + '<span class="ruby-node">Node</span>', + '<span class="ruby-comment">COMMENT</span>', + '<span class="ruby-regexp">REGEXP</span>', + '<span class="ruby-string">STRING</span>', + '<span class="ruby-value">Val</span>', + '\\' + ].join + + assert_equal expected, @c2_a.markup_code + end + + def test_markup_code_empty + assert_equal '', @c2_a.markup_code + end + def test_marshal_load instance_method = Marshal.load Marshal.dump(@c1.method_list.last) diff --git a/test/rdoc/test_rdoc_attr.rb b/test/rdoc/test_rdoc_attr.rb index 10965d00b6..9751cc175d 100644 --- a/test/rdoc/test_rdoc_attr.rb +++ b/test/rdoc/test_rdoc_attr.rb @@ -8,6 +8,12 @@ class TestRDocAttr < MiniTest::Unit::TestCase @a = RDoc::Attr.new nil, 'attr', 'RW', '' end + def test_aref + m = RDoc::Attr.new nil, 'attr', 'RW', nil + + assert_equal 'attribute-i-attr', m.aref + end + def test_arglists assert_nil @a.arglists end @@ -20,6 +26,18 @@ class TestRDocAttr < MiniTest::Unit::TestCase assert_nil @a.call_seq end + def test_definition + assert_equal 'attr_accessor', @a.definition + + @a.rw = 'R' + + assert_equal 'attr_reader', @a.definition + + @a.rw = 'W' + + assert_equal 'attr_writer', @a.definition + end + def test_full_name assert_equal '(unknown)#attr', @a.full_name end @@ -33,15 +51,10 @@ class TestRDocAttr < MiniTest::Unit::TestCase end def test_type - assert_equal 'attr_accessor', @a.type - - @a.rw = 'R' - - assert_equal 'attr_reader', @a.type - - @a.rw = 'W' + assert_equal 'instance', @a.type - assert_equal 'attr_writer', @a.type + @a.singleton = true + assert_equal 'class', @a.type end end diff --git a/test/rdoc/test_rdoc_class_module.rb b/test/rdoc/test_rdoc_class_module.rb index 23291b969e..aa9bab5ec9 100644 --- a/test/rdoc/test_rdoc_class_module.rb +++ b/test/rdoc/test_rdoc_class_module.rb @@ -92,9 +92,142 @@ class TestRDocClassModule < XrefTestCase assert_equal expected, cm1.method_list.sort end + def test_remove_nodoc_children + parent = RDoc::ClassModule.new 'A' + parent.modules_hash.replace 'B' => true, 'C' => true + RDoc::TopLevel.all_modules_hash.replace 'A::B' => true + + parent.classes_hash.replace 'D' => true, 'E' => true + RDoc::TopLevel.all_classes_hash.replace 'A::D' => true + + parent.remove_nodoc_children + + assert_equal %w[B], parent.modules_hash.keys + assert_equal %w[D], parent.classes_hash.keys + end + def test_superclass assert_equal @c3_h1, @c3_h2.superclass end + def test_update_aliases_class + n1 = @xref_data.add_module RDoc::NormalClass, 'N1' + n1_k2 = n1.add_module RDoc::NormalClass, 'N2' + + n1.add_module_alias n1_k2, 'A1' + + n1_a1_c = n1.constants.find { |c| c.name == 'A1' } + refute_nil n1_a1_c + assert_equal n1_k2, n1_a1_c.is_alias_for, 'sanity check' + + n1.update_aliases + + n1_a1_k = @xref_data.find_class_or_module 'N1::A1' + refute_nil n1_a1_k + assert_equal n1_k2, n1_a1_k.is_alias_for + refute_equal n1_k2, n1_a1_k + + assert_equal 1, n1_k2.aliases.length + assert_equal n1_a1_k, n1_k2.aliases.first + + assert_equal 'N1::N2', n1_k2.full_name + assert_equal 'N1::A1', n1_a1_k.full_name + end + + def test_update_aliases_module + n1 = @xref_data.add_module RDoc::NormalModule, 'N1' + n1_n2 = n1.add_module RDoc::NormalModule, 'N2' + + n1.add_module_alias n1_n2, 'A1' + + n1_a1_c = n1.constants.find { |c| c.name == 'A1' } + refute_nil n1_a1_c + assert_equal n1_n2, n1_a1_c.is_alias_for, 'sanity check' + + n1.update_aliases + + n1_a1_m = @xref_data.find_class_or_module 'N1::A1' + refute_nil n1_a1_m + assert_equal n1_n2, n1_a1_m.is_alias_for + refute_equal n1_n2, n1_a1_m + + assert_equal 1, n1_n2.aliases.length + assert_equal n1_a1_m, n1_n2.aliases.first + + assert_equal 'N1::N2', n1_n2.full_name + assert_equal 'N1::A1', n1_a1_m.full_name + end + + def test_update_aliases_reparent + l1 = @xref_data.add_module RDoc::NormalModule, 'L1' + l1_l2 = l1.add_module RDoc::NormalModule, 'L2' + o1 = @xref_data.add_module RDoc::NormalModule, 'O1' + + o1.add_module_alias l1_l2, 'A1' + + o1_a1_c = o1.constants.find { |c| c.name == 'A1' } + refute_nil o1_a1_c + assert_equal l1_l2, o1_a1_c.is_alias_for + refute_equal l1_l2, o1_a1_c + + o1.update_aliases + + o1_a1_m = @xref_data.find_class_or_module 'O1::A1' + refute_nil o1_a1_m + assert_equal l1_l2, o1_a1_m.is_alias_for + + assert_equal 1, l1_l2.aliases.length + assert_equal o1_a1_m, l1_l2.aliases[0] + + assert_equal 'L1::L2', l1_l2.full_name + assert_equal 'O1::A1', o1_a1_m.full_name + end + + def test_update_includes + a = RDoc::Include.new 'M1', nil + b = RDoc::Include.new 'M2', nil + c = RDoc::Include.new 'C', nil + + @c1.add_include a + @c1.add_include b + @c1.add_include c + @c1.ancestors # cache included modules + + @m1_m2.document_self = nil + assert @m1_m2.remove_from_documentation? + + assert RDoc::TopLevel.all_modules_hash.key? @m1_m2.full_name + refute RDoc::TopLevel.all_modules_hash[@m1_m2.full_name].nil? + RDoc::TopLevel.remove_nodoc RDoc::TopLevel.all_modules_hash + refute RDoc::TopLevel.all_modules_hash.key? @m1_m2.full_name + + @c1.update_includes + + assert_equal [a, c], @c1.includes + end + + def test_update_includes_with_colons + a = RDoc::Include.new 'M1', nil + b = RDoc::Include.new 'M1::M2', nil + c = RDoc::Include.new 'C', nil + + @c1.add_include a + @c1.add_include b + @c1.add_include c + @c1.ancestors # cache included modules + + @m1_m2.document_self = nil + assert @m1_m2.remove_from_documentation? + + assert RDoc::TopLevel.all_modules_hash.key? @m1_m2.full_name + refute RDoc::TopLevel.all_modules_hash[@m1_m2.full_name].nil? + RDoc::TopLevel.remove_nodoc RDoc::TopLevel.all_modules_hash + refute RDoc::TopLevel.all_modules_hash.key? @m1_m2.full_name + + @c1.update_includes + + assert_equal [a, c], @c1.includes + end + end diff --git a/test/rdoc/test_rdoc_code_object.rb b/test/rdoc/test_rdoc_code_object.rb index 907bb7a3d5..8ae2d8b91e 100644 --- a/test/rdoc/test_rdoc_code_object.rb +++ b/test/rdoc/test_rdoc_code_object.rb @@ -16,6 +16,7 @@ class TestRDocCodeObject < XrefTestCase assert @co.document_children, 'document_children' refute @co.force_documentation, 'force_documentation' refute @co.done_documenting, 'done_documenting' + refute @co.received_nodoc, 'received_nodoc' assert_equal '', @co.comment, 'comment is empty' end @@ -33,16 +34,20 @@ class TestRDocCodeObject < XrefTestCase @co.document_children = false refute @co.document_children - @c2.document_children = false - assert_empty @c2.classes + # TODO this is not true anymore: + # test all the nodoc stuff etc... + #@c2.document_children = false + #assert_empty @c2.classes end def test_document_self_equals @co.document_self = false refute @co.document_self - @c1.document_self = false - assert_empty @c1.method_list + # TODO this is not true anymore: + # test all the nodoc stuff etc... + #@c1.document_self = false + #assert_empty @c1.method_list end def test_documented_eh @@ -56,11 +61,46 @@ class TestRDocCodeObject < XrefTestCase refute @co.documented? - @co.document_self = false + @co.document_self = nil # notify :nodoc: assert @co.documented? end + def test_done_documenting + # once done_documenting is set, other properties refuse to go to "true" + @co.done_documenting = true + + @co.document_self = true + refute @co.document_self + + @co.document_children = true + refute @co.document_children + + @co.force_documentation = true + refute @co.force_documentation + + @co.start_doc + refute @co.document_self + refute @co.document_children + + # turning done_documenting on + # resets others to true + + @co.done_documenting = false + assert @co.document_self + assert @co.document_children + end + + def test_full_name_equals + @co.full_name = 'hi' + + assert_equal 'hi', @co.instance_variable_get(:@full_name) + + @co.full_name = nil + + assert_nil @co.instance_variable_get(:@full_name) + end + def test_metadata assert_empty @co.metadata @@ -84,6 +124,23 @@ class TestRDocCodeObject < XrefTestCase assert_equal 'C2', @c2_c3.parent_name end + def test_received_ndoc + @co.document_self = false + refute @co.received_nodoc + + @co.document_self = nil + assert @co.received_nodoc + + @co.document_self = true + end + + def test_record_location + c = RDoc::CodeObject.new + c.record_location @xref_data + + assert_equal 'xref_data.rb', c.file.relative_name + end + def test_start_doc @co.document_self = false @co.document_children = false diff --git a/test/rdoc/test_rdoc_context.rb b/test/rdoc/test_rdoc_context.rb index cd0ad0fae3..6961f7d214 100644 --- a/test/rdoc/test_rdoc_context.rb +++ b/test/rdoc/test_rdoc_context.rb @@ -34,13 +34,38 @@ class TestRDocContext < XrefTestCase @context.add_alias as - assert_equal [as], @context.aliases - assert_equal [as], @context.unmatched_alias_lists['old_name'] + assert_equal [as], @context.external_aliases + assert_equal [as], @context.unmatched_alias_lists['#old_name'] + end + + def test_add_alias_method_attr + top_level = RDoc::TopLevel.new 'file.rb' + + attr = RDoc::Attr.new nil, 'old_name', 'R', '' + + as = RDoc::Alias.new nil, 'old_name', 'new_name', 'comment' + as.record_location top_level + as.parent = @context + + @context.add_attribute attr + @context.add_alias as + + assert_empty @context.aliases + assert_empty @context.unmatched_alias_lists + assert_equal %w[old_name new_name], @context.attributes.map { |m| m.name } + + new = @context.attributes.last + assert_equal top_level, new.file end def test_add_alias_method + top_level = RDoc::TopLevel.new 'file.rb' + meth = RDoc::AnyMethod.new nil, 'old_name' + meth.singleton = false + as = RDoc::Alias.new nil, 'old_name', 'new_name', 'comment' + as.record_location top_level as.parent = @context @context.add_method meth @@ -49,28 +74,28 @@ class TestRDocContext < XrefTestCase assert_empty @context.aliases assert_empty @context.unmatched_alias_lists assert_equal %w[old_name new_name], @context.method_list.map { |m| m.name } + + new = @context.method_list.last + assert_equal top_level, new.file end - def test_add_alias_impl + def test_add_alias_method_singleton meth = RDoc::AnyMethod.new nil, 'old_name' - meth.comment = 'old comment' - meth.singleton = false - meth.visibility = :private + meth.singleton = true - alas = RDoc::Alias.new nil, 'old_name', 'new_name', 'new comment' + as = RDoc::Alias.new nil, 'old_name', 'new_name', 'comment' + as.singleton = true - @context.add_alias_impl alas, meth + as.parent = @context - assert_equal 1, @context.method_list.length + @context.add_method meth + @context.add_alias as - alas_meth = @context.method_list.first - assert_equal 'new_name', alas_meth.name - assert_equal 'new comment', alas_meth.comment - assert_equal false, alas_meth.singleton - assert_equal meth, alas_meth.is_alias_for - assert_equal :private, alas_meth.visibility + assert_empty @context.aliases + assert_empty @context.unmatched_alias_lists + assert_equal %w[old_name new_name], @context.method_list.map { |m| m.name } - assert_equal [alas_meth], meth.aliases + assert @context.method_list.last.singleton end def test_add_class @@ -133,11 +158,11 @@ class TestRDocContext < XrefTestCase meth = RDoc::AnyMethod.new nil, 'old_name' @context.add_alias as - refute_empty @context.aliases + refute_empty @context.external_aliases @context.add_method meth - assert_empty @context.aliases + assert_empty @context.external_aliases assert_empty @context.unmatched_alias_lists assert_equal %w[old_name new_name], @context.method_list.map { |m| m.name } end @@ -292,6 +317,46 @@ class TestRDocContext < XrefTestCase assert_equal @c1__m, @c1.find_symbol('::m') end + def test_fully_documented_eh + context = RDoc::Context.new + + refute context.fully_documented? + + context.comment = 'hi' + + assert context.fully_documented? + + m = @c1_m + + context.add_method m + + refute context.fully_documented? + + m.comment = 'hi' + + assert context.fully_documented? + + c = RDoc::Constant.new 'C', '0', nil + + context.add_constant c + + refute context.fully_documented? + + c.comment = 'hi' + + assert context.fully_documented? + + a = RDoc::Attr.new '', 'a', 'RW', nil + + context.add_attribute a + + refute context.fully_documented? + + a.comment = 'hi' + + assert context.fully_documented? + end + def test_spaceship assert_equal(-1, @c2.<=>(@c3)) assert_equal 0, @c2.<=>(@c2) diff --git a/test/rdoc/test_rdoc_encoding.rb b/test/rdoc/test_rdoc_encoding.rb new file mode 100644 index 0000000000..b940d93606 --- /dev/null +++ b/test/rdoc/test_rdoc_encoding.rb @@ -0,0 +1,145 @@ +require 'rubygems' +require 'minitest/autorun' +require 'rdoc' +require 'rdoc/encoding' + +require 'tempfile' + +class TestRDocEncoding < MiniTest::Unit::TestCase + + def setup + @tempfile = Tempfile.new 'test_rdoc_encoding' + end + + def test_class_read_file + @tempfile.write "hi everybody" + @tempfile.flush + + assert_equal "hi everybody", RDoc::Encoding.read_file(@tempfile.path, nil) + end + + def test_class_read_file_encoding + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + expected = "# coding: utf-8\nhi everybody" + + @tempfile.write expected + @tempfile.flush + + # FIXME 1.9 fix on windoze + expected.gsub!("\n", "\r\n") if RUBY_VERSION =~ /^1.9/ && RUBY_PLATFORM =~ /mswin|mingw/ + + contents = RDoc::Encoding.read_file @tempfile.path, Encoding::UTF_8 + assert_equal expected, contents + assert_equal Encoding::UTF_8, contents.encoding + end + + def test_class_read_file_encoding_convert + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + content = "" + content.encode! 'ISO-8859-1' + content << "# coding: ISO-8859-1\nhi \xE9verybody" + + @tempfile.write content + @tempfile.flush + + contents = RDoc::Encoding.read_file @tempfile.path, Encoding::UTF_8 + assert_equal Encoding::UTF_8, contents.encoding + assert_equal "# coding: ISO-8859-1\nhi \u00e9verybody", contents.sub("\r", '') + end + + def test_class_read_file_encoding_fancy + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + expected = "# -*- coding: utf-8; fill-column: 74 -*-\nhi everybody" + expected.encode! Encoding::UTF_8 + + @tempfile.write expected + @tempfile.flush + + # FIXME 1.9 fix on windoze + expected.gsub!("\n", "\r\n") if RUBY_VERSION =~ /^1.9/ && RUBY_PLATFORM =~ /win32|mingw32/ + + contents = RDoc::Encoding.read_file @tempfile.path, Encoding::UTF_8 + assert_equal expected, contents + assert_equal Encoding::UTF_8, contents.encoding + end + + def test_class_read_file_encoding_guess + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + path = File.expand_path '../test.ja.txt', __FILE__ + content = RDoc::Encoding.read_file path, Encoding::UTF_8 + + assert_equal Encoding::UTF_8, content.encoding + end + + def test_class_read_file_encoding_with_signature + skip "Encoding not implemented" unless defined? ::Encoding + + @tempfile.write "\xEF\xBB\xBFhi everybody" + @tempfile.flush + + bug3360 = '[ruby-dev:41452]' + content = RDoc::Encoding.read_file @tempfile.path, Encoding::UTF_8 + assert_equal Encoding::UTF_8, content.encoding, bug3360 + assert_equal "hi everybody", content, bug3360 + end + + def test_class_set_encoding + s = "# coding: UTF-8\n" + RDoc::Encoding.set_encoding s + + # sanity check for 1.8 + + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + assert_equal Encoding::UTF_8, s.encoding + + s = "#!/bin/ruby\n# coding: UTF-8\n" + RDoc::Encoding.set_encoding s + + assert_equal Encoding::UTF_8, s.encoding + + s = "<?xml version='1.0' encoding='UTF-8'?>\n" + expected = s.encoding + RDoc::Encoding.set_encoding s + + assert_equal Encoding::UTF_8, s.encoding + + s = "<?xml version='1.0' encoding=\"UTF-8\"?>\n" + expected = s.encoding + RDoc::Encoding.set_encoding s + + assert_equal Encoding::UTF_8, s.encoding + end + + def test_class_set_encoding_bad + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + s = "" + expected = s.encoding + RDoc::Encoding.set_encoding s + + assert_equal expected, s.encoding + + s = "# vim:set fileencoding=utf-8:\n" + expected = s.encoding + RDoc::Encoding.set_encoding s + + assert_equal expected, s.encoding + + s = "# vim:set fileencoding=utf-8:\n" + expected = s.encoding + RDoc::Encoding.set_encoding s + + assert_equal expected, s.encoding + + assert_raises ArgumentError do + RDoc::Encoding.set_encoding "# -*- encoding: undecided -*-\n" + end + end + +end + diff --git a/test/rdoc/test_rdoc_generator_darkfish.rb b/test/rdoc/test_rdoc_generator_darkfish.rb new file mode 100644 index 0000000000..b99803bac1 --- /dev/null +++ b/test/rdoc/test_rdoc_generator_darkfish.rb @@ -0,0 +1,119 @@ +require 'minitest/autorun' +require 'rdoc/rdoc' +require 'rdoc/generator/darkfish' +require 'tmpdir' +require 'fileutils' + +class TestRDocGeneratorDarkfish < MiniTest::Unit::TestCase + + def setup + @pwd = Dir.pwd + @lib_dir = "#{@pwd}/lib" + $LOAD_PATH.unshift @lib_dir # ensure we load from this RDoc + RDoc::TopLevel.reset + + @options = RDoc::Options.new + @options.option_parser = OptionParser.new + + @tmpdir = File.join Dir.tmpdir, "test_rdoc_generator_darkfish_#{$$}" + FileUtils.mkdir_p @tmpdir + Dir.chdir @tmpdir + @options.op_dir = @tmpdir + @options.generator = RDoc::Generator::Darkfish + + $LOAD_PATH.each do |path| + darkfish_dir = File.join path, 'rdoc/generator/template/darkfish' + next unless File.directory? darkfish_dir + @options.template_dir = darkfish_dir + break + end + + rd = RDoc::RDoc.new + rd.options = @options + RDoc::RDoc.current = rd + + @g = @options.generator.new @options + + rd.generator = @g + + @top_level = RDoc::TopLevel.new 'file.rb' + @klass = @top_level.add_class RDoc::NormalClass, 'Object' + @meth = RDoc::AnyMethod.new nil, 'method' + @meth_bang = RDoc::AnyMethod.new nil, 'method!' + @attr = RDoc::Attr.new nil, 'attr', 'RW', '' + + @klass.add_method @meth + @klass.add_method @meth_bang + @klass.add_attribute @attr + end + + def teardown + $LOAD_PATH.shift + Dir.chdir @pwd + 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 + top_level = RDoc::TopLevel.new 'file.rb' + top_level.add_class @klass.class, @klass.name + + @g.generate [top_level] + + assert_file 'index.html' + assert_file 'Object.html' + assert_file 'file_rb.html' + + encoding = if Object.const_defined? :Encoding then + Regexp.escape Encoding.default_external.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(/<meta content="text\/html; charset=#{encoding}"/, + File.read('file_rb.html')) + end + + def test_generate_dry_run + @options.dry_run = true + top_level = RDoc::TopLevel.new 'file.rb' + top_level.add_class @klass.class, @klass.name + + @g.generate [top_level] + + refute_file 'index.html' + refute_file 'Object.html' + refute_file 'file_rb.html' + end + + def test_template_for + classpage = Pathname.new @options.template_dir + '/classpage.rhtml' + + template = @g.send(:template_for, classpage) + assert_kind_of RDoc::ERBIO, template + + assert_same template, @g.send(:template_for, classpage) + end + + def test_template_for_dry_run + classpage = Pathname.new @options.template_dir + '/classpage.rhtml' + + template = @g.send(:template_for, classpage) + assert_kind_of ERB, template + + assert_same template, @g.send(:template_for, classpage) + end + +end + diff --git a/test/rdoc/test_rdoc_generator_ri.rb b/test/rdoc/test_rdoc_generator_ri.rb index 7027080c9b..780d9cc570 100644 --- a/test/rdoc/test_rdoc_generator_ri.rb +++ b/test/rdoc/test_rdoc_generator_ri.rb @@ -1,21 +1,23 @@ require 'rubygems' require 'minitest/autorun' require 'rdoc/rdoc' +require 'rdoc/generator/ri' require 'tmpdir' require 'fileutils' class TestRDocGeneratorRI < MiniTest::Unit::TestCase def setup + @options = RDoc::Options.new + @pwd = Dir.pwd RDoc::TopLevel.reset @tmpdir = File.join Dir.tmpdir, "test_rdoc_generator_ri_#{$$}" FileUtils.mkdir_p @tmpdir Dir.chdir @tmpdir - options = RDoc::Options.new - @g = RDoc::Generator::RI.new options + @g = RDoc::Generator::RI.new @options @top_level = RDoc::TopLevel.new 'file.rb' @klass = @top_level.add_class RDoc::NormalClass, 'Object' @@ -37,6 +39,10 @@ class TestRDocGeneratorRI < MiniTest::Unit::TestCase assert File.file?(path), "#{path} is not a file" end + def refute_file path + refute File.exist?(path), "#{path} exists" + end + def test_generate top_level = RDoc::TopLevel.new 'file.rb' top_level.add_class @klass.class, @klass.name @@ -52,5 +58,19 @@ class TestRDocGeneratorRI < MiniTest::Unit::TestCase assert_file File.join(@tmpdir, 'Object', 'method%21-i.ri') end + def test_generate_dry_run + @options.dry_run = true + @g = RDoc::Generator::RI.new @options + + top_level = RDoc::TopLevel.new 'file.rb' + top_level.add_class @klass.class, @klass.name + + @g.generate nil + + refute_file File.join(@tmpdir, 'cache.ri') + + refute_file File.join(@tmpdir, 'Object') + end + end diff --git a/test/rdoc/test_rdoc_include.rb b/test/rdoc/test_rdoc_include.rb index e4a44b4358..71eaf9abf8 100644 --- a/test/rdoc/test_rdoc_include.rb +++ b/test/rdoc/test_rdoc_include.rb @@ -6,6 +6,7 @@ class TestRDocInclude < XrefTestCase super @inc = RDoc::Include.new 'M1', 'comment' + @inc.parent = @m1 end def test_module @@ -13,5 +14,83 @@ class TestRDocInclude < XrefTestCase assert_equal 'Unknown', RDoc::Include.new('Unknown', 'comment').module end + def test_module_extended + m1 = @xref_data.add_module RDoc::NormalModule, 'Mod1' + m1_m3 = m1.add_module RDoc::NormalModule, 'Mod3' + m1_m2 = m1.add_module RDoc::NormalModule, 'Mod2' + m1_m2_m3 = m1_m2.add_module RDoc::NormalModule, 'Mod3' + m1_m2_m3_m4 = m1_m2_m3.add_module RDoc::NormalModule, 'Mod4' + m1_m2_m4 = m1_m2.add_module RDoc::NormalModule, 'Mod4' + m1_m2_k0 = m1_m2.add_class RDoc::NormalClass, 'Klass0' + m1_m2_k0_m4 = m1_m2_k0.add_module RDoc::NormalModule, 'Mod4' + #m1_m2_k0_m4_m5 = m1_m2_k0_m4.add_module RDoc::NormalModule, 'Mod5' + m1_m2_k0_m4_m6 = m1_m2_k0_m4.add_module RDoc::NormalModule, 'Mod6' + m1_m2_k0_m5 = m1_m2_k0.add_module RDoc::NormalModule, 'Mod5' + + i0_m4 = RDoc::Include.new 'Mod4', nil + i0_m5 = RDoc::Include.new 'Mod5', nil + i0_m6 = RDoc::Include.new 'Mod6', nil + i0_m1 = RDoc::Include.new 'Mod1', nil + i0_m2 = RDoc::Include.new 'Mod2', nil + i0_m3 = RDoc::Include.new 'Mod3', nil + + m1_m2_k0.add_include i0_m4 + m1_m2_k0.add_include i0_m5 + m1_m2_k0.add_include i0_m6 + m1_m2_k0.add_include i0_m1 + m1_m2_k0.add_include i0_m2 + m1_m2_k0.add_include i0_m3 + + assert_equal [i0_m4, i0_m5, i0_m6, i0_m1, i0_m2, i0_m3], m1_m2_k0.includes + assert_equal [m1_m2_m3, m1_m2, m1, m1_m2_k0_m4_m6, m1_m2_k0_m5, + m1_m2_k0_m4, 'Object'], m1_m2_k0.ancestors + + m1_k1 = m1.add_class RDoc::NormalClass, 'Klass1' + + i1_m1 = RDoc::Include.new 'Mod1', nil + i1_m2 = RDoc::Include.new 'Mod2', nil + i1_m3 = RDoc::Include.new 'Mod3', nil + i1_m4 = RDoc::Include.new 'Mod4', nil + i1_k0_m4 = RDoc::Include.new 'Klass0::Mod4', nil + + m1_k1.add_include i1_m1 + m1_k1.add_include i1_m2 + m1_k1.add_include i1_m3 + m1_k1.add_include i1_m4 + m1_k1.add_include i1_k0_m4 + + assert_equal [i1_m1, i1_m2, i1_m3, i1_m4, i1_k0_m4], m1_k1.includes + assert_equal [m1_m2_k0_m4, m1_m2_m3_m4, m1_m2_m3, m1_m2, m1, 'Object'], + m1_k1.ancestors + + m1_k2 = m1.add_class RDoc::NormalClass, 'Klass2' + + i2_m1 = RDoc::Include.new 'Mod1', nil + i2_m2 = RDoc::Include.new 'Mod2', nil + i2_m3 = RDoc::Include.new 'Mod3', nil + i2_k0_m4 = RDoc::Include.new 'Klass0::Mod4', nil + + m1_k2.add_include i2_m1 + m1_k2.add_include i2_m3 + m1_k2.add_include i2_m2 + m1_k2.add_include i2_k0_m4 + + assert_equal [i2_m1, i2_m3, i2_m2, i2_k0_m4], m1_k2.includes + assert_equal [m1_m2_k0_m4, m1_m2, m1_m3, m1, 'Object'], m1_k2.ancestors + + m1_k3 = m1.add_class RDoc::NormalClass, 'Klass3' + + i3_m1 = RDoc::Include.new 'Mod1', nil + i3_m2 = RDoc::Include.new 'Mod2', nil + i3_m4 = RDoc::Include.new 'Mod4', nil + + m1_k3.add_include i3_m1 + m1_k3.add_include i3_m2 + m1_k3.add_include i3_m4 + + assert_equal [i3_m1, i3_m2, i3_m4], m1_k3.includes + assert_equal [m1_m2_m4, m1_m2, m1, 'Object'], m1_k3.ancestors + end + end diff --git a/test/rdoc/test_rdoc_markup_attribute_manager.rb b/test/rdoc/test_rdoc_markup_attribute_manager.rb index f6b1b6cf17..b65457fc7e 100644 --- a/test/rdoc/test_rdoc_markup_attribute_manager.rb +++ b/test/rdoc/test_rdoc_markup_attribute_manager.rb @@ -1,9 +1,9 @@ -require "rubygems" -require "minitest/autorun" +require 'rubygems' +require 'minitest/autorun' require 'rdoc' require 'rdoc/markup' -require "rdoc/markup/inline" -require "rdoc/markup/to_html_crossref" +require 'rdoc/markup/inline' +require 'rdoc/markup/to_html_crossref' class TestRDocMarkupAttributeManager < MiniTest::Unit::TestCase diff --git a/test/rdoc/test_rdoc_markup_parser.rb b/test/rdoc/test_rdoc_markup_parser.rb index d418900116..a7951d9d01 100644 --- a/test/rdoc/test_rdoc_markup_parser.rb +++ b/test/rdoc/test_rdoc_markup_parser.rb @@ -1,8 +1,9 @@ +# coding: utf-8 + require 'pp' require 'rubygems' require 'minitest/autorun' require 'rdoc/markup' -require 'rdoc/markup/to_test' class TestRDocMarkupParser < MiniTest::Unit::TestCase @@ -53,6 +54,19 @@ class TestRDocMarkupParser < MiniTest::Unit::TestCase assert_equal expected, @RMP.parse(str).parts end + def test_parse_bullet_utf_8 + str = <<-STR +* 新しい機能 + STR + + expected = [ + @RM::List.new(:BULLET, *[ + @RM::ListItem.new(nil, + @RM::Paragraph.new('新しい機能'))])] + + assert_equal expected, @RMP.parse(str).parts + end + def test_parse_bullet_verbatim_heading str = <<-STR * l1 @@ -65,7 +79,7 @@ class TestRDocMarkupParser < MiniTest::Unit::TestCase @RM::List.new(:BULLET, *[ @RM::ListItem.new(nil, @RM::Paragraph.new('l1'), - @RM::Verbatim.new(' ', 'v', "\n"))]), + @RM::Verbatim.new("v\n"))]), @RM::Heading.new(1, 'H')] assert_equal expected, @RMP.parse(str).parts @@ -183,8 +197,7 @@ the time @RM::List.new(:BULLET, *[ @RM::ListItem.new(nil, @RM::Paragraph.new('l1.1', 'text'), - @RM::Verbatim.new(' ', 'code', "\n", - ' ', 'code', "\n"), + @RM::Verbatim.new("code\n", " code\n"), @RM::Paragraph.new('text'))])), @RM::ListItem.new(nil, @RM::Paragraph.new('l2'))])] @@ -400,6 +413,68 @@ A. l4 assert_equal expected, @RMP.parse(str).parts end + def test_parse_lalpha_utf_8 + str = <<-STR +a. 新しい機能 + STR + + expected = [ + @RM::List.new(:LALPHA, *[ + @RM::ListItem.new(nil, + @RM::Paragraph.new('新しい機能'))])] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_list_list_1 + str = <<-STR +10. para 1 + + [label 1] + para 1.1 + + code + + para 1.2 + STR + + expected = [ + @RM::List.new(:NUMBER, *[ + @RM::ListItem.new(nil, *[ + @RM::Paragraph.new('para 1'), + @RM::BlankLine.new, + @RM::List.new(:LABEL, *[ + @RM::ListItem.new('label 1', *[ + @RM::Paragraph.new('para 1.1'), + @RM::BlankLine.new, + @RM::Verbatim.new("code\n"), + @RM::Paragraph.new('para 1.2')])])])])] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_list_list_2 + str = <<-STR +6. para + + label 1:: text 1 + label 2:: text 2 + STR + + expected = [ + @RM::List.new(:NUMBER, *[ + @RM::ListItem.new(nil, *[ + @RM::Paragraph.new('para'), + @RM::BlankLine.new, + @RM::List.new(:NOTE, *[ + @RM::ListItem.new('label 1', + @RM::Paragraph.new('text 1')), + @RM::ListItem.new('label 2', + @RM::Paragraph.new('text 2'))])])])] + + assert_equal expected, @RMP.parse(str).parts + end + def test_parse_list_verbatim str = <<-STR * one @@ -412,8 +487,7 @@ A. l4 @RM::List.new(:BULLET, *[ @RM::ListItem.new(nil, @RM::Paragraph.new('one'), - @RM::Verbatim.new(' ', 'verb1', "\n", - ' ', 'verb2', "\n")), + @RM::Verbatim.new("verb1\n", "verb2\n")), @RM::ListItem.new(nil, @RM::Paragraph.new('two'))])] @@ -545,7 +619,7 @@ for all good men expected = [ @RM::Paragraph.new('now is the time'), - @RM::Verbatim.new(' ', 'code _line_ here', "\n"), + @RM::Verbatim.new("code _line_ here\n"), @RM::Paragraph.new('for all good men'), ] assert_equal expected, @RMP.parse(str).parts @@ -567,6 +641,12 @@ B. l2 assert_equal expected, @RMP.parse(str).parts end + def test_parse_trailing_cr + expected = [ @RM::Paragraph.new('Text') ] + # FIXME hangs the parser: + assert_equal expected, @RMP.parse("Text\r").parts + end + def test_parse_verbatim str = <<-STR now is @@ -576,7 +656,7 @@ the time expected = [ @RM::Paragraph.new('now is'), - @RM::Verbatim.new(' ', 'code', "\n"), + @RM::Verbatim.new("code\n"), @RM::Paragraph.new('the time'), ] @@ -589,7 +669,18 @@ the time STR expected = [ - @RM::Verbatim.new(' ', '*', ' ', 'blah', "\n")] + @RM::Verbatim.new("* blah\n")] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_verbatim_dash + str = <<-STR + - blah + STR + + expected = [ + @RM::Verbatim.new("- blah\n")] assert_equal expected, @RMP.parse(str).parts end @@ -607,9 +698,7 @@ the time expected = [ @RM::Paragraph.new('now is'), - @RM::Verbatim.new(' ', 'code', "\n", - "\n", - ' ', 'code1', "\n"), + @RM::Verbatim.new("code\n", "\n", "code1\n"), @RM::Paragraph.new('the time'), ] @@ -624,7 +713,7 @@ text expected = [ @RM::Paragraph.new('text'), - @RM::Verbatim.new(' ', '===', ' ', 'heading three', "\n")] + @RM::Verbatim.new("=== heading three\n")] assert_equal expected, @RMP.parse(str).parts end @@ -634,7 +723,7 @@ text expected = [ @RM::Paragraph.new('text'), - @RM::Verbatim.new(' ', 'code', "\n"), + @RM::Verbatim.new("code\n"), @RM::Heading.new(3, 'heading three')] assert_equal expected, @RMP.parse(str).parts @@ -646,7 +735,7 @@ text STR expected = [ - @RM::Verbatim.new(' ', '[blah]', ' ', 'blah', "\n")] + @RM::Verbatim.new("[blah] blah\n")] assert_equal expected, @RMP.parse(str).parts end @@ -657,7 +746,7 @@ text STR expected = [ - @RM::Verbatim.new(' ', 'b.', ' ', 'blah', "\n")] + @RM::Verbatim.new("b. blah\n")] assert_equal expected, @RMP.parse(str).parts end @@ -671,8 +760,7 @@ text expected = [ @RM::Paragraph.new('text'), - @RM::Verbatim.new(' ', 'code', "\n", - ' ', '===', ' ', 'heading three', "\n")] + @RM::Verbatim.new("code\n", "=== heading three\n")] assert_equal expected, @RMP.parse(str).parts end @@ -688,9 +776,7 @@ the time expected = [ @RM::Paragraph.new('now is'), - @RM::Verbatim.new(' ', 'code', "\n", - "\n", - ' ', 'code1', "\n"), + @RM::Verbatim.new("code\n", "\n", "code1\n"), @RM::Paragraph.new('the time'), ] @@ -710,11 +796,7 @@ the time expected = [ @RM::Paragraph.new('now is'), - @RM::Verbatim.new(' ', 'code', "\n", - "\n", - ' ', 'code1', "\n", - "\n", - ' ', 'code2', "\n"), + @RM::Verbatim.new("code\n", "\n", "code1\n", "\n", "code2\n"), @RM::Paragraph.new('the time'), ] @@ -731,8 +813,7 @@ the time expected = [ @RM::Paragraph.new('now is'), - @RM::Verbatim.new(' ', 'code', "\n", - ' ', 'code1', "\n"), + @RM::Verbatim.new("code\n", "code1\n"), @RM::Paragraph.new('the time'), ] @@ -749,8 +830,8 @@ for all good men expected = [ @RM::Paragraph.new('now is the time'), - @RM::Verbatim.new(' ', 'code', "\n", - ' ', 'more code', "\n"), + @RM::Verbatim.new(" code\n", + "more code\n"), @RM::Paragraph.new('for all good men'), ] @@ -763,7 +844,7 @@ for all good men STR expected = [ - @RM::Verbatim.new(' ', 'blah::', ' ', 'blah', "\n")] + @RM::Verbatim.new("blah:: blah\n")] assert_equal expected, @RMP.parse(str).parts end @@ -774,7 +855,7 @@ for all good men STR expected = [ - @RM::Verbatim.new(' ', '2.', ' ', 'blah', "\n")] + @RM::Verbatim.new("2. blah\n")] assert_equal expected, @RMP.parse(str).parts end @@ -790,8 +871,8 @@ text expected = [ @RM::Paragraph.new('text'), @RM::BlankLine.new, - @RM::Verbatim.new(' ', '---', ' ', 'lib/blah.rb.orig', "\n", - ' ', '+++', ' ', 'lib/blah.rb', "\n")] + @RM::Verbatim.new("--- lib/blah.rb.orig\n", + "+++ lib/blah.rb\n")] assert_equal expected, @RMP.parse(str).parts end @@ -806,7 +887,7 @@ text expected = [ @RM::Paragraph.new('text'), @RM::BlankLine.new, - @RM::Verbatim.new(' ', '---', '')] + @RM::Verbatim.new("---")] assert_equal expected, @RMP.parse(str).parts end @@ -823,9 +904,9 @@ the time expected = [ @RM::Paragraph.new('now is'), - @RM::Verbatim.new(' ', 'code', "\n", + @RM::Verbatim.new("code\n", "\n", - ' ', 'code1', "\n"), + "code1\n"), @RM::Paragraph.new('the time'), ] @@ -838,7 +919,7 @@ the time STR expected = [ - @RM::Verbatim.new(' ', 'B.', ' ', 'blah', "\n")] + @RM::Verbatim.new("B. blah\n")] assert_equal expected, @RMP.parse(str).parts end @@ -851,58 +932,57 @@ the time assert_equal expected, @RMP.parse('hello').parts expected = [ - @RM::Verbatim.new(' ', 'hello '), + @RM::Verbatim.new('hello '), ] - assert_equal expected, @RMP.parse(' hello ').parts + assert_equal expected, @RMP.parse(' hello ').parts expected = [ - @RM::Verbatim.new(' ', 'hello '), + @RM::Verbatim.new('hello '), ] - assert_equal expected, @RMP.parse(" hello ").parts + assert_equal expected, @RMP.parse(' hello ').parts expected = [ @RM::Paragraph.new('1'), - @RM::Verbatim.new(' ', '2', "\n", - ' ', '3'), + @RM::Verbatim.new("2\n", ' 3'), ] assert_equal expected, @RMP.parse("1\n 2\n 3").parts expected = [ - @RM::Verbatim.new(' ', '1', "\n", - ' ', '2', "\n", - ' ', '3'), + @RM::Verbatim.new("1\n", + " 2\n", + " 3"), ] assert_equal expected, @RMP.parse(" 1\n 2\n 3").parts expected = [ @RM::Paragraph.new('1'), - @RM::Verbatim.new(' ', '2', "\n", - ' ', '3', "\n"), + @RM::Verbatim.new("2\n", + " 3\n"), @RM::Paragraph.new('1'), - @RM::Verbatim.new(' ', '2'), + @RM::Verbatim.new('2'), ] assert_equal expected, @RMP.parse("1\n 2\n 3\n1\n 2").parts expected = [ - @RM::Verbatim.new(' ', '1', "\n", - ' ', '2', "\n", - ' ', '3', "\n", - ' ', '1', "\n", - ' ', '2'), + @RM::Verbatim.new("1\n", + " 2\n", + " 3\n", + "1\n", + ' 2'), ] assert_equal expected, @RMP.parse(" 1\n 2\n 3\n 1\n 2").parts expected = [ - @RM::Verbatim.new(' ', '1', "\n", - ' ', '2', "\n", + @RM::Verbatim.new("1\n", + " 2\n", "\n", - ' ', '3'), + ' 3'), ] assert_equal expected, @RMP.parse(" 1\n 2\n\n 3").parts @@ -942,8 +1022,7 @@ the time STR expected = [ - [:BULLET, :BULLET, 0, 0], - [:SPACE, 2, 0, 0], + [:BULLET, '*', 0, 0], [:TEXT, 'l1', 2, 0], [:NEWLINE, "\n", 4, 0], ] @@ -958,13 +1037,10 @@ the time STR expected = [ - [:BULLET, :BULLET, 0, 0], - [:SPACE, 2, 0, 0], + [:BULLET, '*', 0, 0], [:TEXT, 'l1', 2, 0], [:NEWLINE, "\n", 4, 0], - [:INDENT, 2, 0, 1], - [:BULLET, :BULLET, 2, 1], - [:SPACE, 2, 2, 1], + [:BULLET, '*', 2, 1], [:TEXT, 'l1.1', 4, 1], [:NEWLINE, "\n", 8, 1], ] @@ -1030,11 +1106,9 @@ the time expected = [ [:LABEL, 'cat', 0, 0], - [:SPACE, 6, 0, 0], [:TEXT, 'l1', 6, 0], [:NEWLINE, "\n", 8, 0], [:LABEL, 'dog', 0, 1], - [:SPACE, 6, 0, 1], [:TEXT, 'l1.1', 6, 1], [:NEWLINE, "\n", 10, 1], ] @@ -1050,11 +1124,8 @@ the time expected = [ [:LABEL, 'label', 0, 0], - [:SPACE, 7, 0, 0], [:NEWLINE, "\n", 7, 0], - [:INDENT, 2, 0, 1], [:NOTE, 'note', 2, 1], - [:SPACE, 6, 2, 1], [:NEWLINE, "\n", 8, 1], ] @@ -1069,11 +1140,9 @@ b. l1.1 expected = [ [:LALPHA, 'a', 0, 0], - [:SPACE, 3, 0, 0], [:TEXT, 'l1', 3, 0], [:NEWLINE, "\n", 5, 0], [:LALPHA, 'b', 0, 1], - [:SPACE, 3, 0, 1], [:TEXT, 'l1.1', 3, 1], [:NEWLINE, "\n", 7, 1], ] @@ -1089,11 +1158,9 @@ dog:: l1.1 expected = [ [:NOTE, 'cat', 0, 0], - [:SPACE, 6, 0, 0], [:TEXT, 'l1', 6, 0], [:NEWLINE, "\n", 8, 0], [:NOTE, 'dog', 0, 1], - [:SPACE, 6, 0, 1], [:TEXT, 'l1.1', 6, 1], [:NEWLINE, "\n", 10, 1], ] @@ -1109,10 +1176,8 @@ dog:: expected = [ [:NOTE, 'cat', 0, 0], - [:SPACE, 5, 0, 0], [:NEWLINE, "\n", 5, 0], [:NOTE, 'dog', 0, 1], - [:SPACE, 5, 0, 1], [:NEWLINE, "\n", 5, 1], ] @@ -1140,11 +1205,9 @@ Cat::Dog expected = [ [:NUMBER, '1', 0, 0], - [:SPACE, 3, 0, 0], [:TEXT, 'l1', 3, 0], [:NEWLINE, "\n", 5, 0], [:NUMBER, '2', 0, 1], - [:SPACE, 3, 0, 1], [:TEXT, 'l1.1', 3, 1], [:NEWLINE, "\n", 7, 1], ] @@ -1162,20 +1225,16 @@ Cat::Dog expected = [ [:NUMBER, "1", 0, 0], - [:SPACE, 3, 0, 0], [:TEXT, "blah blah blah", 3, 0], [:NEWLINE, "\n", 17, 0], - [:INDENT, 3, 0, 1], [:TEXT, "l.", 3, 1], [:NEWLINE, "\n", 5, 1], [:NUMBER, "2", 0, 2], - [:SPACE, 3, 0, 2], [:TEXT, "blah blah blah blah", 3, 2], [:NEWLINE, "\n", 22, 2], - [:INDENT, 3, 0, 3], [:TEXT, "d.", 3, 3], [:NEWLINE, "\n", 5, 3] ] @@ -1193,24 +1252,18 @@ Cat::Dog expected = [ [:NUMBER, "1", 0, 0], - [:SPACE, 3, 0, 0], [:TEXT, "blah blah blah", 3, 0], [:NEWLINE, "\n", 17, 0], - [:INDENT, 3, 0, 1], [:LALPHA, "l", 3, 1], - [:SPACE, 4, 3, 1], [:TEXT, "more stuff", 7, 1], [:NEWLINE, "\n", 17, 1], [:NUMBER, "2", 0, 2], - [:SPACE, 3, 0, 2], [:TEXT, "blah blah blah blah", 3, 2], [:NEWLINE, "\n", 22, 2], - [:INDENT, 3, 0, 3], [:LALPHA, "d", 3, 3], - [:SPACE, 3, 3, 3], [:TEXT, "other stuff", 6, 3], [:NEWLINE, "\n", 17, 3] ] @@ -1241,14 +1294,14 @@ for all def test_tokenize_rule str = <<-STR ---- +--- --- blah --- STR expected = [ [:RULE, 1, 0, 0], - [:NEWLINE, "\n", 4, 0], + [:NEWLINE, "\n", 3, 0], [:NEWLINE, "\n", 0, 1], [:TEXT, "--- blah ---", 0, 2], [:NEWLINE, "\n", 12, 2], @@ -1265,11 +1318,9 @@ B. l1.1 expected = [ [:UALPHA, 'A', 0, 0], - [:SPACE, 3, 0, 0], [:TEXT, 'l1', 3, 0], [:NEWLINE, "\n", 5, 0], [:UALPHA, 'B', 0, 1], - [:SPACE, 3, 0, 1], [:TEXT, 'l1.1', 3, 1], [:NEWLINE, "\n", 7, 1], ] @@ -1288,7 +1339,6 @@ Example heading: [:TEXT, 'Example heading:', 0, 0], [:NEWLINE, "\n", 16, 0], [:NEWLINE, "\n", 0, 1], - [:INDENT, 3, 0, 2], [:HEADER, 3, 3, 2], [:TEXT, 'heading three', 7, 2], [:NEWLINE, "\n", 20, 2], @@ -1299,17 +1349,17 @@ Example heading: # HACK move to Verbatim test case def test_verbatim_normalize - v = @RM::Verbatim.new ' ', 'foo', "\n", "\n", "\n", ' ', 'bar', "\n" + v = @RM::Verbatim.new "foo\n", "\n", "\n", "bar\n" v.normalize - assert_equal [' ', 'foo', "\n", "\n", ' ', 'bar', "\n"], v.parts + assert_equal ["foo\n", "\n", "bar\n"], v.parts - v = @RM::Verbatim.new ' ', 'foo', "\n", "\n" + v = @RM::Verbatim.new "foo\n", "\n" v.normalize - assert_equal [' ', 'foo', "\n"], v.parts + assert_equal ["foo\n"], v.parts end def test_unget diff --git a/test/rdoc/test_rdoc_markup_pre_process.rb b/test/rdoc/test_rdoc_markup_pre_process.rb index cae4da9e05..b4db512ce3 100644 --- a/test/rdoc/test_rdoc_markup_pre_process.rb +++ b/test/rdoc/test_rdoc_markup_pre_process.rb @@ -1,7 +1,7 @@ require 'tempfile' require 'rubygems' require 'minitest/autorun' -require 'rdoc/markup/preprocess' +require 'rdoc/markup/pre_process' require 'rdoc/code_objects' class TestRDocMarkupPreProcess < MiniTest::Unit::TestCase @@ -10,8 +10,7 @@ class TestRDocMarkupPreProcess < MiniTest::Unit::TestCase RDoc::Markup::PreProcess.registered.clear @tempfile = Tempfile.new 'test_rdoc_markup_pre_process' - @tempfile.binmode - @name = File.basename @tempfile.path + @file_name = File.basename @tempfile.path @dir = File.dirname @tempfile.path @pp = RDoc::Markup::PreProcess.new __FILE__, [@dir] @@ -32,13 +31,18 @@ contents of a string. @tempfile.flush @tempfile.rewind - content = @pp.include_file @name, '' + content = @pp.include_file @file_name, '', nil expected = <<-EXPECTED Regular expressions (<i>regexp</i>s) are patterns which describe the contents of a string. EXPECTED + # FIXME 1.9 fix on windoze + # preprocessor uses binread, so line endings are \r\n + expected.gsub!("\n", "\r\n") if + RUBY_VERSION =~ /^1.9/ && RUBY_PLATFORM =~ /mswin|mingw/ + assert_equal expected, content end diff --git a/test/rdoc/test_rdoc_markup_to_ansi.rb b/test/rdoc/test_rdoc_markup_to_ansi.rb index a8fab98d19..1334ac71c4 100644 --- a/test/rdoc/test_rdoc_markup_to_ansi.rb +++ b/test/rdoc/test_rdoc_markup_to_ansi.rb @@ -1,11 +1,12 @@ require 'rubygems' -require 'rdoc/markup/formatter_test_case' +require 'rdoc/markup/text_formatter_test_case' require 'rdoc/markup/to_ansi' require 'minitest/autorun' -class TestRDocMarkupToAnsi < RDoc::Markup::FormatterTestCase +class TestRDocMarkupToAnsi < RDoc::Markup::TextFormatterTestCase add_visitor_tests + add_text_tests def setup super @@ -62,7 +63,7 @@ class TestRDocMarkupToAnsi < RDoc::Markup::FormatterTestCase end def accept_list_item_end_label - assert_equal "\e[0m\n", @to.res.join + assert_equal "\e[0m", @to.res.join assert_equal 0, @to.indent, 'indent' end @@ -72,7 +73,7 @@ class TestRDocMarkupToAnsi < RDoc::Markup::FormatterTestCase end def accept_list_item_end_note - assert_equal "\e[0m\n", @to.res.join + assert_equal "\e[0m", @to.res.join assert_equal 0, @to.indent, 'indent' end @@ -191,8 +192,8 @@ class TestRDocMarkupToAnsi < RDoc::Markup::FormatterTestCase assert_equal "\e[0m#{'-' * 78}\n", @to.res.join end - def accept_verbatim # FormatterTestCase doesn't set indent for ToAnsi - assert_equal "\e[0m hi\n world\n\n", @to.res.join + def accept_verbatim + assert_equal "\e[0m hi\n world\n\n", @to.res.join end def end_accepting @@ -207,214 +208,103 @@ class TestRDocMarkupToAnsi < RDoc::Markup::FormatterTestCase assert_empty @to.list_width end - def test_accept_heading_1 - @to.start_accepting - @to.accept_heading @RM::Heading.new(1, 'Hello') - + def accept_heading_1 assert_equal "\e[0m\e[1;32mHello\e[m\n", @to.end_accepting end - def test_accept_heading_2 - @to.start_accepting - @to.accept_heading @RM::Heading.new(2, 'Hello') - + def accept_heading_2 assert_equal "\e[0m\e[4;32mHello\e[m\n", @to.end_accepting end - def test_accept_heading_3 - @to.start_accepting - @to.accept_heading @RM::Heading.new(3, 'Hello') - + def accept_heading_3 assert_equal "\e[0m\e[32mHello\e[m\n", @to.end_accepting end - def test_accept_heading_4 - @to.start_accepting - @to.accept_heading @RM::Heading.new(4, 'Hello') - + def accept_heading_4 assert_equal "\e[0mHello\n", @to.end_accepting end - def test_accept_heading_indent - @to.start_accepting - @to.indent = 3 - @to.accept_heading @RM::Heading.new(1, 'Hello') - + def accept_heading_indent assert_equal "\e[0m \e[1;32mHello\e[m\n", @to.end_accepting end - def test_accept_heading_b - @to.start_accepting - @to.indent = 3 - @to.accept_heading @RM::Heading.new(1, '*Hello*') - - assert_equal "\e[0m \e[1;32m\e[1mHello\e[m\e[m\n", @to.end_accepting + def accept_heading_b + assert_equal "\e[0m\e[1;32m\e[1mHello\e[m\e[m\n", @to.end_accepting end - def test_accept_list_item_start_note_2 - list = @RM::List.new(:NOTE, - @RM::ListItem.new('<tt>teletype</tt>', - @RM::Paragraph.new('teletype description'))) - - @to.start_accepting - - list.accept @to - - expected = "\e[0m\e[7mteletype\e[m:\n teletype description\n\n" - - assert_equal expected, @to.end_accepting + def accept_heading_suppressed_crossref + assert_equal "\e[0m\e[1;32mHello\e[m\n", @to.end_accepting end - def test_accept_paragraph_b - @to.start_accepting - @to.accept_paragraph @RM::Paragraph.new('reg <b>bold words</b> reg') - - expected = "\e[0mreg \e[1mbold words\e[m reg\n" - - assert_equal expected, @to.end_accepting + def accept_list_item_start_note_2 + assert_equal "\e[0m\e[7mteletype\e[m:\n teletype description\n\n", + @to.res.join end - def test_accept_paragraph_i - @to.start_accepting - @to.accept_paragraph @RM::Paragraph.new('reg <em>italic words</em> reg') - - expected = "\e[0mreg \e[4mitalic words\e[m reg\n" - - assert_equal expected, @to.end_accepting + def accept_paragraph_b + assert_equal "\e[0mreg \e[1mbold words\e[m reg\n", @to.end_accepting end - def test_accept_paragraph_indent - @to.start_accepting - @to.indent = 3 - @to.accept_paragraph @RM::Paragraph.new('words ' * 30) + def accept_paragraph_i + assert_equal "\e[0mreg \e[4mitalic words\e[m reg\n", @to.end_accepting + end + def accept_paragraph_indent expected = <<-EXPECTED \e[0m words words words words words words words words words words words words words words words words words words words words words words words words - words words words words words words + words words words words words words EXPECTED assert_equal expected, @to.end_accepting end - def test_accept_paragraph_plus - @to.start_accepting - @to.accept_paragraph @RM::Paragraph.new('regular +teletype+ regular') - - expected = "\e[0mregular \e[7mteletype\e[m regular\n" - - assert_equal expected, @to.end_accepting + def accept_paragraph_plus + assert_equal "\e[0mreg \e[7mteletype\e[m reg\n", @to.end_accepting end - def test_accept_paragraph_star - @to.start_accepting - @to.accept_paragraph @RM::Paragraph.new('regular *bold* regular') - - expected = "\e[0mregular \e[1mbold\e[m regular\n" - - assert_equal expected, @to.end_accepting + def accept_paragraph_star + assert_equal "\e[0mreg \e[1mbold\e[m reg\n", @to.end_accepting end - def test_accept_paragraph_underscore - @to.start_accepting - @to.accept_paragraph @RM::Paragraph.new('regular _italic_ regular') - - expected = "\e[0mregular \e[4mitalic\e[m regular\n" - - assert_equal expected, @to.end_accepting + def accept_paragraph_underscore + assert_equal "\e[0mreg \e[4mitalic\e[m reg\n", @to.end_accepting end - def test_accept_paragraph_wrap - @to.start_accepting - @to.accept_paragraph @RM::Paragraph.new('words ' * 30) - + def accept_paragraph_wrap expected = <<-EXPECTED \e[0mwords words words words words words words words words words words words words words words words words words words words words words words words words words -words words words words +words words words words EXPECTED assert_equal expected, @to.end_accepting end - def test_accept_rule_indent - @to.start_accepting - @to.indent = 3 - - @to.accept_rule @RM::Rule.new(1) - + def accept_rule_indent assert_equal "\e[0m #{'-' * 75}\n", @to.end_accepting end - def test_accept_verbatim_indent - @to.start_accepting - - @to.indent = 2 - - @to.accept_verbatim @RM::Verbatim.new(' ', 'hi', "\n", - ' ', 'world', "\n") - + def accept_verbatim_indent assert_equal "\e[0m hi\n world\n\n", @to.end_accepting end - def test_accept_verbatim_big_indent - @to.start_accepting - - @to.indent = 2 - - @to.accept_verbatim @RM::Verbatim.new(' ', 'hi', "\n", - ' ', 'world', "\n") - + def accept_verbatim_big_indent assert_equal "\e[0m hi\n world\n\n", @to.end_accepting end - def test_attributes - assert_equal 'Dog', @to.attributes("\\Dog") - end - - def test_list_nested - doc = @RM::Document.new( - @RM::List.new(:BULLET, - @RM::ListItem.new(nil, - @RM::Paragraph.new('l1'), - @RM::List.new(:BULLET, - @RM::ListItem.new(nil, - @RM::Paragraph.new('l1.1')))), - @RM::ListItem.new(nil, - @RM::Paragraph.new('l2')))) - - output = doc.accept @to - + def list_nested expected = <<-EXPECTED \e[0m* l1 * l1.1 * l2 EXPECTED - assert_equal expected, output - end - - def test_list_verbatim # HACK overblown - doc = @RM::Document.new( - @RM::List.new(:BULLET, - @RM::ListItem.new(nil, - @RM::Paragraph.new('list', 'stuff'), - @RM::BlankLine.new(), - @RM::Verbatim.new(' ', '*', ' ', 'list', "\n", - ' ', 'with', "\n", - "\n", - ' ', 'second', "\n", - "\n", - ' ', '1.', ' ', 'indented', "\n", - ' ', '2.', ' ', 'numbered', "\n", - "\n", - ' ', 'third', "\n", - "\n", - ' ', '*', ' ', 'second', "\n")))) - - output = doc.accept @to + assert_equal expected, @to.end_accepting + end - expected = <<-EXPECTED + def list_verbatim + expected = <<-EXPECTED # HACK overblown \e[0m* list stuff * list @@ -431,7 +321,7 @@ words words words words EXPECTED - assert_equal expected, output + assert_equal expected, @to.end_accepting end end diff --git a/test/rdoc/test_rdoc_markup_to_bs.rb b/test/rdoc/test_rdoc_markup_to_bs.rb index c042452637..3d2e4da8de 100644 --- a/test/rdoc/test_rdoc_markup_to_bs.rb +++ b/test/rdoc/test_rdoc_markup_to_bs.rb @@ -1,11 +1,12 @@ require 'rubygems' -require 'rdoc/markup/formatter_test_case' +require 'rdoc/markup/text_formatter_test_case' require 'rdoc/markup/to_bs' require 'minitest/autorun' -class TestRDocMarkupToBs < RDoc::Markup::FormatterTestCase +class TestRDocMarkupToBs < RDoc::Markup::TextFormatterTestCase add_visitor_tests + add_text_tests def setup super @@ -63,6 +64,7 @@ class TestRDocMarkupToBs < RDoc::Markup::FormatterTestCase end def accept_list_item_end_label + assert_equal "\n", @to.res.join assert_equal 0, @to.indent, 'indent' end @@ -72,6 +74,7 @@ class TestRDocMarkupToBs < RDoc::Markup::FormatterTestCase end def accept_list_item_end_note + assert_equal "\n", @to.res.join assert_equal 0, @to.indent, 'indent' end @@ -190,8 +193,8 @@ class TestRDocMarkupToBs < RDoc::Markup::FormatterTestCase assert_equal "#{'-' * 78}\n", @to.res.join end - def accept_verbatim # FormatterTestCase doesn't set indent for ToAnsi - assert_equal " hi\n world\n\n", @to.res.join + def accept_verbatim + assert_equal " hi\n world\n\n", @to.res.join end def end_accepting @@ -206,232 +209,115 @@ class TestRDocMarkupToBs < RDoc::Markup::FormatterTestCase assert_empty @to.list_width end - def test_accept_heading_1 + def accept_heading_1 skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars - @to.start_accepting - @to.accept_heading @RM::Heading.new(1, 'Hello') - assert_equal "= H\bHe\bel\bll\blo\bo\n", @to.end_accepting end - def test_accept_heading_2 + def accept_heading_2 skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars - @to.start_accepting - @to.accept_heading @RM::Heading.new(2, 'Hello') - assert_equal "== H\bHe\bel\bll\blo\bo\n", @to.end_accepting end - def test_accept_heading_3 + def accept_heading_3 skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars - @to.start_accepting - @to.accept_heading @RM::Heading.new(3, 'Hello') - assert_equal "=== H\bHe\bel\bll\blo\bo\n", @to.end_accepting end - def test_accept_heading_4 + def accept_heading_4 skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars - @to.start_accepting - @to.accept_heading @RM::Heading.new(4, 'Hello') - assert_equal "==== H\bHe\bel\bll\blo\bo\n", @to.end_accepting end - def test_accept_heading_indent + def accept_heading_indent skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars - @to.start_accepting - @to.indent = 3 - @to.accept_heading @RM::Heading.new(1, 'Hello') - assert_equal " = H\bHe\bel\bll\blo\bo\n", @to.end_accepting end - def test_accept_heading_b + def accept_heading_b skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars - @to.start_accepting - @to.indent = 3 - @to.accept_heading @RM::Heading.new(1, '*Hello*') - - assert_equal " = H\bHe\bel\bll\blo\bo\n", @to.end_accepting + assert_equal "= H\bHe\bel\bll\blo\bo\n", @to.end_accepting end - def test_accept_heading_suppressed_crossref + def accept_heading_suppressed_crossref skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars - @to.start_accepting - @to.accept_heading @RM::Heading.new(1, '\\Hello') - assert_equal "= H\bHe\bel\bll\blo\bo\n", @to.end_accepting end - def test_accept_list_item_start_note_2 - list = @RM::List.new(:NOTE, - @RM::ListItem.new('<tt>teletype</tt>', - @RM::Paragraph.new('teletype description'))) - - @to.start_accepting - - list.accept @to - - expected = "teletype:\n teletype description\n\n" - - assert_equal expected, @to.end_accepting + def accept_list_item_start_note_2 + assert_equal "teletype:\n teletype description\n\n", @to.res.join end - def test_accept_paragraph_b + def accept_paragraph_b skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars - @to.start_accepting - @to.accept_paragraph @RM::Paragraph.new('reg <b>bold words</b> reg') - - expected = "reg b\bbo\bol\bld\bd \b w\bwo\bor\brd\bds\bs reg\n" - - assert_equal expected, @to.end_accepting + assert_equal "reg b\bbo\bol\bld\bd \b w\bwo\bor\brd\bds\bs reg\n", + @to.end_accepting end - def test_accept_paragraph_i + def accept_paragraph_i skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars - @to.start_accepting - @to.accept_paragraph @RM::Paragraph.new('reg <em>italic words</em> reg') - - expected = "reg _\bi_\bt_\ba_\bl_\bi_\bc_\b _\bw_\bo_\br_\bd_\bs reg\n" - - assert_equal expected, @to.end_accepting + assert_equal "reg _\bi_\bt_\ba_\bl_\bi_\bc_\b _\bw_\bo_\br_\bd_\bs reg\n", + @to.end_accepting end - def test_accept_paragraph_indent - @to.start_accepting - @to.indent = 3 - @to.accept_paragraph @RM::Paragraph.new('words ' * 30) - + def accept_paragraph_indent expected = <<-EXPECTED words words words words words words words words words words words words words words words words words words words words words words words words - words words words words words words + words words words words words words EXPECTED assert_equal expected, @to.end_accepting end - def test_accept_paragraph_plus - @to.start_accepting - @to.accept_paragraph @RM::Paragraph.new('regular +teletype+ regular') - - expected = "regular teletype regular\n" - - assert_equal expected, @to.end_accepting + def accept_paragraph_plus + assert_equal "reg teletype reg\n", @to.end_accepting end - def test_accept_paragraph_star + def accept_paragraph_star skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars - @to.start_accepting - @to.accept_paragraph @RM::Paragraph.new('regular *bold* regular') - - expected = "regular b\bbo\bol\bld\bd regular\n" - - assert_equal expected, @to.end_accepting + assert_equal "reg b\bbo\bol\bld\bd reg\n", @to.end_accepting end - def test_accept_paragraph_underscore + def accept_paragraph_underscore skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars - @to.start_accepting - @to.accept_paragraph @RM::Paragraph.new('regular _italic_ regular') - - expected = "regular _\bi_\bt_\ba_\bl_\bi_\bc regular\n" - - assert_equal expected, @to.end_accepting + assert_equal "reg _\bi_\bt_\ba_\bl_\bi_\bc reg\n", @to.end_accepting end - def test_accept_paragraph_wrap - @to.start_accepting - @to.accept_paragraph @RM::Paragraph.new('words ' * 30) - + def accept_paragraph_wrap expected = <<-EXPECTED words words words words words words words words words words words words words words words words words words words words words words words words words words -words words words words +words words words words EXPECTED assert_equal expected, @to.end_accepting end - def test_accept_rule_indent - @to.start_accepting - @to.indent = 3 - - @to.accept_rule @RM::Rule.new(1) - + def accept_rule_indent assert_equal " #{'-' * 75}\n", @to.end_accepting end - def test_accept_verbatim_indent - @to.start_accepting - - @to.indent = 2 - - @to.accept_verbatim @RM::Verbatim.new(' ', 'hi', "\n", - ' ', 'world', "\n") - + def accept_verbatim_indent assert_equal " hi\n world\n\n", @to.end_accepting end - def test_accept_verbatim_big_indent - @to.start_accepting - - @to.indent = 2 - - @to.accept_verbatim @RM::Verbatim.new(' ', 'hi', "\n", - ' ', 'world', "\n") - + def accept_verbatim_big_indent assert_equal " hi\n world\n\n", @to.end_accepting end - def test_attributes - assert_equal 'Dog', @to.attributes("\\Dog") - end - - def test_list_nested - doc = @RM::Document.new( - @RM::List.new(:BULLET, - @RM::ListItem.new(nil, - @RM::Paragraph.new('l1'), - @RM::List.new(:BULLET, - @RM::ListItem.new(nil, - @RM::Paragraph.new('l1.1')))), - @RM::ListItem.new(nil, - @RM::Paragraph.new('l2')))) - - output = doc.accept @to - + def list_nested expected = <<-EXPECTED * l1 * l1.1 * l2 EXPECTED - assert_equal expected, output - end - - def test_list_verbatim # HACK overblown - doc = @RM::Document.new( - @RM::List.new(:BULLET, - @RM::ListItem.new(nil, - @RM::Paragraph.new('list', 'stuff'), - @RM::BlankLine.new(), - @RM::Verbatim.new(' ', '*', ' ', 'list', "\n", - ' ', 'with', "\n", - "\n", - ' ', 'second', "\n", - "\n", - ' ', '1.', ' ', 'indented', "\n", - ' ', '2.', ' ', 'numbered', "\n", - "\n", - ' ', 'third', "\n", - "\n", - ' ', '*', ' ', 'second', "\n")))) - - output = doc.accept @to + assert_equal expected, @to.end_accepting + end - expected = <<-EXPECTED + def list_verbatim + expected = <<-EXPECTED # HACK overblown * list stuff * list @@ -448,7 +334,7 @@ words words words words EXPECTED - assert_equal expected, output + assert_equal expected, @to.end_accepting end end diff --git a/test/rdoc/test_rdoc_markup_to_html.rb b/test/rdoc/test_rdoc_markup_to_html.rb index f6014391c8..8a5860fe25 100644 --- a/test/rdoc/test_rdoc_markup_to_html.rb +++ b/test/rdoc/test_rdoc_markup_to_html.rb @@ -31,49 +31,73 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase end def accept_heading - assert_equal "<h5>Hello</h5>\n", @to.res.join + assert_equal "\n<h5>Hello</h5>\n", @to.res.join + end + + def accept_heading_1 + assert_equal "\n<h1>Hello</h1>\n", @to.res.join + end + + def accept_heading_2 + assert_equal "\n<h2>Hello</h2>\n", @to.res.join + end + + def accept_heading_3 + assert_equal "\n<h3>Hello</h3>\n", @to.res.join + end + + def accept_heading_4 + assert_equal "\n<h4>Hello</h4>\n", @to.res.join + end + + def accept_heading_b + assert_equal "\n<h1><b>Hello</b></h1>\n", @to.res.join + end + + def accept_heading_suppressed_crossref + assert_equal "\n<h1>Hello</h1>\n", @to.res.join end def accept_list_end_bullet assert_equal [], @to.list assert_equal [], @to.in_list_entry - assert_equal "<ul>\n</ul>\n", @to.res.join + assert_equal "<ul></ul>\n", @to.res.join end def accept_list_end_label assert_equal [], @to.list assert_equal [], @to.in_list_entry - assert_equal "<dl>\n</dl>\n", @to.res.join + assert_equal "<dl></dl>\n", @to.res.join end def accept_list_end_lalpha assert_equal [], @to.list assert_equal [], @to.in_list_entry - assert_equal "<ol style=\"display: lower-alpha\">\n</ol>\n", @to.res.join + assert_equal "<ol style=\"display: lower-alpha\"></ol>\n", @to.res.join end def accept_list_end_number assert_equal [], @to.list assert_equal [], @to.in_list_entry - assert_equal "<ol>\n</ol>\n", @to.res.join + assert_equal "<ol></ol>\n", @to.res.join end def accept_list_end_note assert_equal [], @to.list assert_equal [], @to.in_list_entry - assert_equal "<table>\n</table>\n", @to.res.join + assert_equal "<table class=\"rdoc-list\"></table>\n", @to.res.join end def accept_list_end_ualpha assert_equal [], @to.list assert_equal [], @to.in_list_entry - assert_equal "<ol style=\"display: upper-alpha\">\n</ol>\n", @to.res.join + assert_equal "<ol style=\"display: upper-alpha\"></ol>\n", @to.res.join end def accept_list_item_end_bullet @@ -101,73 +125,105 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase end def accept_list_item_start_bullet - assert_equal "<ul>\n<li>", @to.res.join + assert_equal "<ul><li>", @to.res.join end def accept_list_item_start_label - assert_equal "<dl>\n<dt>cat</dt><dd>", @to.res.join + assert_equal "<dl><dt>cat</dt>\n<dd>", @to.res.join end def accept_list_item_start_lalpha - assert_equal "<ol style=\"display: lower-alpha\">\n<li>", @to.res.join + assert_equal "<ol style=\"display: lower-alpha\"><li>", @to.res.join end def accept_list_item_start_note - assert_equal "<table>\n<tr><td valign=\"top\">cat</td><td>", @to.res.join + assert_equal "<table class=\"rdoc-list\"><tr><td class=\"rdoc-term\"><p>cat</p></td>\n<td>", + @to.res.join + end + + def accept_list_item_start_note_2 + expected = <<-EXPECTED +<table class="rdoc-list"><tr><td class="rdoc-term"><p><tt>teletype</tt></p></td> +<td> +<p>teletype description</p> +</td></tr></table> + EXPECTED + + assert_equal expected, @to.res.join end def accept_list_item_start_number - assert_equal "<ol>\n<li>", @to.res.join + assert_equal "<ol><li>", @to.res.join end def accept_list_item_start_ualpha - assert_equal "<ol style=\"display: upper-alpha\">\n<li>", @to.res.join + assert_equal "<ol style=\"display: upper-alpha\"><li>", @to.res.join end def accept_list_start_bullet assert_equal [:BULLET], @to.list assert_equal [false], @to.in_list_entry - assert_equal "<ul>\n", @to.res.join + assert_equal "<ul>", @to.res.join end def accept_list_start_label assert_equal [:LABEL], @to.list assert_equal [false], @to.in_list_entry - assert_equal "<dl>\n", @to.res.join + assert_equal "<dl>", @to.res.join end def accept_list_start_lalpha assert_equal [:LALPHA], @to.list assert_equal [false], @to.in_list_entry - assert_equal "<ol style=\"display: lower-alpha\">\n", @to.res.join + assert_equal "<ol style=\"display: lower-alpha\">", @to.res.join end def accept_list_start_note assert_equal [:NOTE], @to.list assert_equal [false], @to.in_list_entry - assert_equal "<table>\n", @to.res.join + assert_equal "<table class=\"rdoc-list\">", @to.res.join end def accept_list_start_number assert_equal [:NUMBER], @to.list assert_equal [false], @to.in_list_entry - assert_equal "<ol>\n", @to.res.join + assert_equal "<ol>", @to.res.join end def accept_list_start_ualpha assert_equal [:UALPHA], @to.list assert_equal [false], @to.in_list_entry - assert_equal "<ol style=\"display: upper-alpha\">\n", @to.res.join + assert_equal "<ol style=\"display: upper-alpha\">", @to.res.join end def accept_paragraph - assert_equal "<p>\nhi\n</p>\n", @to.res.join + assert_equal "\n<p>hi</p>\n", @to.res.join + end + + def accept_paragraph_b + assert_equal "\n<p>reg <b>bold words</b> reg</p>\n", @to.res.join + end + + def accept_paragraph_i + assert_equal "\n<p>reg <em>italic words</em> reg</p>\n", @to.res.join + end + + def accept_paragraph_plus + assert_equal "\n<p>reg <tt>teletype</tt> reg</p>\n", @to.res.join + end + + def accept_paragraph_star + assert_equal "\n<p>reg <b>bold</b> reg</p>\n", @to.res.join + end + + def accept_paragraph_underscore + assert_equal "\n<p>reg <em>italic</em> reg</p>\n", @to.res.join end def accept_raw @@ -183,11 +239,11 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase end def accept_rule - assert_equal '<hr style="height: 4px"></hr>', @to.res.join + assert_equal "<hr style=\"height: 4px\">\n", @to.res.join end def accept_verbatim - assert_equal "<pre>\n hi\n world\n</pre>\n", @to.res.join + assert_equal "\n<pre>hi\n world</pre>\n", @to.res.join end def end_accepting @@ -200,54 +256,70 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase assert_equal [], @to.list end - def test_list_verbatim - str = "* one\n verb1\n verb2\n* two\n" - + def list_nested expected = <<-EXPECTED -<ul> -<li><p> -one -</p> -<pre> - verb1 - verb2 -</pre> -</li> -<li><p> -two -</p> -</li> -</ul> +<ul><li> +<p>l1</p> +<ul><li> +<p>l1.1</p> +</li></ul> +</li><li> +<p>l2</p> +</li></ul> EXPECTED - assert_equal expected, @m.convert(str, @to) + assert_equal expected, @to.res.join end - def test_tt_formatting - assert_equal "<p>\n<tt>--</tt> — <tt>cats'</tt> cats’\n</p>\n", - util_format("<tt>--</tt> -- <tt>cats'</tt> cats'") + def list_verbatim + expected = <<-EXPECTED +<ul><li> +<p>list stuff</p> + +<pre>* list + with + + second + + 1. indented + 2. numbered - assert_equal "<p>\n<b>—</b>\n</p>\n", util_format("<b>--</b>") + third + +* second</pre> +</li></ul> + EXPECTED + + assert_equal expected, @to.end_accepting end - def test_convert_string_fancy - # - # The HTML typesetting is broken in a number of ways, but I have fixed - # the most glaring issues for single and double quotes. Note that - # "strange" symbols (periods or dashes) need to be at the end of the - # test case strings in order to suppress cross-references. - # - assert_equal "<p>\n“cats”.\n</p>\n", util_format("\"cats\".") - assert_equal "<p>\n‘cats’.\n</p>\n", util_format("\'cats\'.") - assert_equal "<p>\ncat’s-\n</p>\n", util_format("cat\'s-") + def test_convert_string + assert_equal '<>', @to.convert_string('<>') + end + + def test_list_verbatim_2 + str = "* one\n verb1\n verb2\n* two\n" + + expected = <<-EXPECTED +<ul><li> +<p>one</p> + +<pre>verb1 +verb2</pre> +</li><li> +<p>two</p> +</li></ul> + EXPECTED + + assert_equal expected, @m.convert(str, @to) end - def util_paragraph(text) - RDoc::Markup::Paragraph.new text + def test_to_html + assert_equal "\n<p><tt>--</tt></p>\n", util_format("<tt>--</tt>") end - def util_format(text) - paragraph = util_paragraph text + def util_format text + paragraph = RDoc::Markup::Paragraph.new text @to.start_accepting @to.accept_paragraph paragraph diff --git a/test/rdoc/test_rdoc_markup_to_html_crossref.rb b/test/rdoc/test_rdoc_markup_to_html_crossref.rb index 67dfc0cbc9..8c97941727 100644 --- a/test/rdoc/test_rdoc_markup_to_html_crossref.rb +++ b/test/rdoc/test_rdoc_markup_to_html_crossref.rb @@ -14,12 +14,11 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase end def assert_ref(path, ref) - assert_equal "<p>\n<a href=\"#{path}\">#{ref}</a>\n</p>\n", - @xref.convert(ref) + assert_equal "\n<p><a href=\"#{path}\">#{ref}</a></p>\n", @xref.convert(ref) end def refute_ref(body, ref) - assert_equal "<p>\n#{body}\n</p>\n", @xref.convert(ref) + assert_equal "\n<p>#{body}</p>\n", @xref.convert(ref) end def test_handle_special_CROSSREF_C2 @@ -108,16 +107,16 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase assert_ref 'C1.html#method-c-m', '::m' assert_ref 'C1.html#method-i-m', 'C1#m' - assert_ref 'C1.html#method-i-m', 'C1.m' + assert_ref 'C1.html#method-c-m', 'C1.m' assert_ref 'C1.html#method-c-m', 'C1::m' assert_ref 'C1.html#method-i-m', 'C1#m' assert_ref 'C1.html#method-i-m', 'C1#m()' assert_ref 'C1.html#method-i-m', 'C1#m(*)' - assert_ref 'C1.html#method-i-m', 'C1.m' - assert_ref 'C1.html#method-i-m', 'C1.m()' - assert_ref 'C1.html#method-i-m', 'C1.m(*)' + assert_ref 'C1.html#method-c-m', 'C1.m' + assert_ref 'C1.html#method-c-m', 'C1.m()' + assert_ref 'C1.html#method-c-m', 'C1.m(*)' assert_ref 'C1.html#method-c-m', 'C1::m' assert_ref 'C1.html#method-c-m', 'C1::m()' @@ -127,7 +126,8 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase assert_ref 'C2/C3.html#method-i-m', 'C2::C3.m' - assert_ref 'C2/C3/H1.html#method-i-m%3F', 'C2::C3::H1#m?' + # TODO stop escaping - HTML5 allows anything but space + assert_ref 'C2/C3/H1.html#method-i-m-3F', 'C2::C3::H1#m?' assert_ref 'C2/C3.html#method-i-m', '::C2::C3#m' assert_ref 'C2/C3.html#method-i-m', '::C2::C3#m()' @@ -153,8 +153,15 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase refute_ref '::C3::H1#n', '\::C3::H1#n' end + def test_handle_special_CROSSREF_show_hash_false + @xref.show_hash = false + + assert_equal "\n<p><a href=\"C1.html#method-i-m\">m</a></p>\n", + @xref.convert('#m') + end + def test_handle_special_CROSSREF_special - assert_equal "<p>\n<a href=\"C2/C3.html\">C2::C3</a>;method(*)\n</p>\n", + assert_equal "\n<p><a href=\"C2/C3.html\">C2::C3</a>;method(*)</p>\n", @xref.convert('C2::C3;method(*)') end diff --git a/test/rdoc/test_rdoc_markup_to_rdoc.rb b/test/rdoc/test_rdoc_markup_to_rdoc.rb index ac6884ba58..20ff937c5a 100644 --- a/test/rdoc/test_rdoc_markup_to_rdoc.rb +++ b/test/rdoc/test_rdoc_markup_to_rdoc.rb @@ -1,11 +1,12 @@ require 'rubygems' -require 'rdoc/markup/formatter_test_case' +require 'rdoc/markup/text_formatter_test_case' require 'rdoc/markup/to_rdoc' require 'minitest/autorun' -class TestRDocMarkupToRdoc < RDoc::Markup::FormatterTestCase +class TestRDocMarkupToRDoc < RDoc::Markup::TextFormatterTestCase add_visitor_tests + add_text_tests def setup super @@ -191,8 +192,8 @@ class TestRDocMarkupToRdoc < RDoc::Markup::FormatterTestCase assert_equal "#{'-' * 78}\n", @to.res.join end - def accept_verbatim # FormatterTestCase doesn't set indent for ToAnsi - assert_equal " hi\n world\n\n", @to.res.join + def accept_verbatim + assert_equal " hi\n world\n\n", @to.res.join end def end_accepting @@ -207,214 +208,102 @@ class TestRDocMarkupToRdoc < RDoc::Markup::FormatterTestCase assert_empty @to.list_width end - def test_accept_heading_1 - @to.start_accepting - @to.accept_heading @RM::Heading.new(1, 'Hello') - + def accept_heading_1 assert_equal "= Hello\n", @to.end_accepting end - def test_accept_heading_2 - @to.start_accepting - @to.accept_heading @RM::Heading.new(2, 'Hello') - + def accept_heading_2 assert_equal "== Hello\n", @to.end_accepting end - def test_accept_heading_3 - @to.start_accepting - @to.accept_heading @RM::Heading.new(3, 'Hello') - + def accept_heading_3 assert_equal "=== Hello\n", @to.end_accepting end - def test_accept_heading_4 - @to.start_accepting - @to.accept_heading @RM::Heading.new(4, 'Hello') - + def accept_heading_4 assert_equal "==== Hello\n", @to.end_accepting end - def test_accept_heading_indent - @to.start_accepting - @to.indent = 3 - @to.accept_heading @RM::Heading.new(1, 'Hello') - + def accept_heading_indent assert_equal " = Hello\n", @to.end_accepting end - def test_accept_heading_b - @to.start_accepting - @to.indent = 3 - @to.accept_heading @RM::Heading.new(1, '*Hello*') - - assert_equal " = <b>Hello</b>\n", @to.end_accepting + def accept_heading_b + assert_equal "= <b>Hello</b>\n", @to.end_accepting end - def test_accept_list_item_start_note_2 - list = @RM::List.new(:NOTE, - @RM::ListItem.new('<tt>teletype</tt>', - @RM::Paragraph.new('teletype description'))) - - @to.start_accepting - - list.accept @to - - expected = "<tt>teletype</tt>:\n teletype description\n\n" - - assert_equal expected, @to.end_accepting + def accept_heading_suppressed_crossref + assert_equal "= Hello\n", @to.end_accepting end - def test_accept_paragraph_b - @to.start_accepting - @to.accept_paragraph @RM::Paragraph.new('reg <b>bold words</b> reg') - - expected = "reg <b>bold words</b> reg\n" - - assert_equal expected, @to.end_accepting + def accept_list_item_start_note_2 + assert_equal "<tt>teletype</tt>:\n teletype description\n\n", @to.res.join end - def test_accept_paragraph_i - @to.start_accepting - @to.accept_paragraph @RM::Paragraph.new('reg <em>italic words</em> reg') - - expected = "reg <em>italic words</em> reg\n" - - assert_equal expected, @to.end_accepting + def accept_paragraph_b + assert_equal "reg <b>bold words</b> reg\n", @to.end_accepting end - def test_accept_paragraph_indent - @to.start_accepting - @to.indent = 3 - @to.accept_paragraph @RM::Paragraph.new('words ' * 30) + def accept_paragraph_i + assert_equal "reg <em>italic words</em> reg\n", @to.end_accepting + end + def accept_paragraph_indent expected = <<-EXPECTED words words words words words words words words words words words words words words words words words words words words words words words words - words words words words words words + words words words words words words EXPECTED assert_equal expected, @to.end_accepting end - def test_accept_paragraph_plus - @to.start_accepting - @to.accept_paragraph @RM::Paragraph.new('regular +teletype+ regular') - - expected = "regular <tt>teletype</tt> regular\n" - - assert_equal expected, @to.end_accepting + def accept_paragraph_plus + assert_equal "reg <tt>teletype</tt> reg\n", @to.end_accepting end - def test_accept_paragraph_star - @to.start_accepting - @to.accept_paragraph @RM::Paragraph.new('regular *bold* regular') - - expected = "regular <b>bold</b> regular\n" - - assert_equal expected, @to.end_accepting + def accept_paragraph_star + assert_equal "reg <b>bold</b> reg\n", @to.end_accepting end - def test_accept_paragraph_underscore - @to.start_accepting - @to.accept_paragraph @RM::Paragraph.new('regular _italic_ regular') - - expected = "regular <em>italic</em> regular\n" - - assert_equal expected, @to.end_accepting + def accept_paragraph_underscore + assert_equal "reg <em>italic</em> reg\n", @to.end_accepting end - def test_accept_paragraph_wrap - @to.start_accepting - @to.accept_paragraph @RM::Paragraph.new('words ' * 30) - + def accept_paragraph_wrap expected = <<-EXPECTED words words words words words words words words words words words words words words words words words words words words words words words words words words -words words words words +words words words words EXPECTED assert_equal expected, @to.end_accepting end - def test_accept_rule_indent - @to.start_accepting - @to.indent = 3 - - @to.accept_rule @RM::Rule.new(1) - + def accept_rule_indent assert_equal " #{'-' * 75}\n", @to.end_accepting end - def test_accept_verbatim_indent - @to.start_accepting - - @to.indent = 2 - - @to.accept_verbatim @RM::Verbatim.new(' ', 'hi', "\n", - ' ', 'world', "\n") - + def accept_verbatim_indent assert_equal " hi\n world\n\n", @to.end_accepting end - def test_accept_verbatim_big_indent - @to.start_accepting - - @to.indent = 2 - - @to.accept_verbatim @RM::Verbatim.new(' ', 'hi', "\n", - ' ', 'world', "\n") - + def accept_verbatim_big_indent assert_equal " hi\n world\n\n", @to.end_accepting end - def test_attributes - assert_equal 'Dog', @to.attributes("\\Dog") - end - - def test_list_nested - doc = @RM::Document.new( - @RM::List.new(:BULLET, - @RM::ListItem.new(nil, - @RM::Paragraph.new('l1'), - @RM::List.new(:BULLET, - @RM::ListItem.new(nil, - @RM::Paragraph.new('l1.1')))), - @RM::ListItem.new(nil, - @RM::Paragraph.new('l2')))) - - output = doc.accept @to - + def list_nested expected = <<-EXPECTED * l1 * l1.1 * l2 EXPECTED - assert_equal expected, output - end - - def test_list_verbatim # HACK overblown - doc = @RM::Document.new( - @RM::List.new(:BULLET, - @RM::ListItem.new(nil, - @RM::Paragraph.new('list', 'stuff'), - @RM::BlankLine.new(), - @RM::Verbatim.new(' ', '*', ' ', 'list', "\n", - ' ', 'with', "\n", - "\n", - ' ', 'second', "\n", - "\n", - ' ', '1.', ' ', 'indented', "\n", - ' ', '2.', ' ', 'numbered', "\n", - "\n", - ' ', 'third', "\n", - "\n", - ' ', '*', ' ', 'second', "\n")))) - - output = doc.accept @to + assert_equal expected, @to.end_accepting + end - expected = <<-EXPECTED + def list_verbatim + expected = <<-EXPECTED # HACK overblown * list stuff * list @@ -431,7 +320,7 @@ words words words words EXPECTED - assert_equal expected, output + assert_equal expected, @to.end_accepting end end diff --git a/test/rdoc/test_rdoc_method_attr.rb b/test/rdoc/test_rdoc_method_attr.rb new file mode 100644 index 0000000000..007a3f6b35 --- /dev/null +++ b/test/rdoc/test_rdoc_method_attr.rb @@ -0,0 +1,122 @@ +require File.expand_path '../xref_test_case', __FILE__ + +class TestRDocMethodAttr < XrefTestCase + + def test_block_params_equal + + m = RDoc::MethodAttr.new(nil, 'foo') + + m.block_params = '' + assert_equal '', m.block_params + + m.block_params = 'a_var' + assert_equal 'a_var', m.block_params + + m.block_params = '()' + assert_equal '', m.block_params + + m.block_params = '(a_var, b_var)' + assert_equal 'a_var, b_var', m.block_params + + m.block_params = '.to_s + "</#{element.upcase}>"' + assert_equal '', m.block_params + + m.block_params = 'i.name' + assert_equal 'name', m.block_params + + m.block_params = 'attr.expanded_name, attr.value' + assert_equal 'expanded_name, value', m.block_params + + m.block_params = 'expanded_name, attr.value' + assert_equal 'expanded_name, value', m.block_params + + m.block_params = 'attr.expanded_name, value' + assert_equal 'expanded_name, value', m.block_params + + m.block_params = '(@base_notifier)' + assert_equal 'base_notifier', m.block_params + + m.block_params = 'if @signal_status == :IN_LOAD' + assert_equal '', m.block_params + + m.block_params = 'e if e.kind_of? Element' + assert_equal 'e', m.block_params + + m.block_params = '(e, f) if e.kind_of? Element' + assert_equal 'e, f', m.block_params + + m.block_params = 'back_path, back_name' + assert_equal 'back_path, back_name', m.block_params + + m.block_params = '(*a[1..-1])' + assert_equal '*a', m.block_params + + m.block_params = '@@context[:node] if defined? @@context[:node].namespace' + assert_equal 'context', m.block_params + + m.block_params = '(result, klass.const_get(constant_name))' + assert_equal 'result, const', m.block_params + + m.block_params = 'name.to_s if (bitmap & bit) != 0' + assert_equal 'name', m.block_params + + m.block_params = 'line unless line.deleted' + assert_equal 'line', m.block_params + + m.block_params = 'str + rs' + assert_equal 'str', m.block_params + + m.block_params = 'f+rs' + assert_equal 'f', m.block_params + + m.block_params = '[user, realm, hash[user]]' + assert_equal 'user, realm, hash', m.block_params + + m.block_params = 'proc{|rc| rc == "rc" ? irbrc : irbrc+rc| ... }' + assert_equal 'proc', m.block_params + + m.block_params = 'lambda { |x| x.to_i }' + assert_equal 'lambda', m.block_params + + m.block_params = '$&' + assert_equal 'str', m.block_params + + m.block_params = 'Inflections.instance' + assert_equal 'instance', m.block_params + + m.block_params = 'self.class::STARTED' + assert_equal 'STARTED', m.block_params + + m.block_params = 'Test::Unit::TestCase::STARTED' + assert_equal 'STARTED', m.block_params + + m.block_params = 'ActiveSupport::OptionMerger.new(self, options)' + assert_equal 'option_merger', m.block_params + + m.block_params = ', msg' + assert_equal '', m.block_params + + m.block_params = '[size.to_s(16), term, chunk, term].join' + assert_equal '[size, term, chunk, term].join', m.block_params + + m.block_params = 'YPath.new( path )' + assert_equal 'y_path', m.block_params + + end + + def test_find_method_or_attribute_recursive + inc = RDoc::Include.new 'M1', nil + @m1.add_include inc # M1 now includes itself + + assert_nil @m1_m.find_method_or_attribute 'm' + end + + def test_to_s + assert_equal 'RDoc::AnyMethod: C1#m', @c1_m.to_s + assert_equal 'RDoc::AnyMethod: C2#b', @c2_b.to_s + assert_equal 'RDoc::AnyMethod: C1::m', @c1__m.to_s + end + + +end + diff --git a/test/rdoc/test_rdoc_normal_class.rb b/test/rdoc/test_rdoc_normal_class.rb index b7471f654f..db07ecb9c7 100644 --- a/test/rdoc/test_rdoc_normal_class.rb +++ b/test/rdoc/test_rdoc_normal_class.rb @@ -10,7 +10,7 @@ class TestRDocNormalClass < XrefTestCase sub_klass = klass.add_class RDoc::NormalClass, 'SubClass', 'Klass' sub_klass.add_include incl - assert_equal [incl, klass], sub_klass.ancestors + assert_equal [incl.name, klass], sub_klass.ancestors end end diff --git a/test/rdoc/test_rdoc_normal_module.rb b/test/rdoc/test_rdoc_normal_module.rb index da48d33f55..570b2765c6 100644 --- a/test/rdoc/test_rdoc_normal_module.rb +++ b/test/rdoc/test_rdoc_normal_module.rb @@ -15,7 +15,12 @@ class TestRDocNormalModule < XrefTestCase mod.add_include incl - assert_equal [incl], mod.ancestors + assert_equal [incl.name], mod.ancestors + + mod2 = top_level.add_module RDoc::NormalModule, 'Inc2' + inc2 = RDoc::Include.new 'Inc2', '' + mod.add_include inc2 + assert_equal [mod2, incl.name], mod.ancestors end def test_module_eh diff --git a/test/rdoc/test_rdoc_options.rb b/test/rdoc/test_rdoc_options.rb index f4a8d51c8e..3d07353c5f 100644 --- a/test/rdoc/test_rdoc_options.rb +++ b/test/rdoc/test_rdoc_options.rb @@ -2,12 +2,182 @@ require 'rubygems' require 'minitest/autorun' require 'rdoc/options' +require 'fileutils' +require 'tmpdir' + class TestRDocOptions < MiniTest::Unit::TestCase def setup @options = RDoc::Options.new end + def test_check_files + out, err = capture_io do + Dir.mktmpdir do |dir| + Dir.chdir dir do + FileUtils.touch 'unreadable' + FileUtils.chmod 0, 'unreadable' + + @options.files = %w[nonexistent unreadable] + + @options.check_files + end + end + end + + assert_empty @options.files + + assert_equal '', out + + expected = <<-EXPECTED +file 'nonexistent' not found +file 'unreadable' not readable + EXPECTED + + assert_equal expected, err + end + + def test_dry_run_default + refute @options.dry_run + end + + def test_encoding_default + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + assert_equal Encoding.default_external, @options.encoding + end + + def test_parse_dash_p + out, err = capture_io do + @options.parse %w[-p] + end + + assert @options.pipe + refute_match %r%^Usage: %, err + refute_match %r%^invalid options%, err + + assert_empty out + end + + def test_parse_dash_p_files + out, err = capture_io do + @options.parse ['-p', File.expand_path(__FILE__)] + end + + refute @options.pipe + refute_match %r%^Usage: %, err + assert_match %r%^invalid options: -p .with files.%, err + + assert_empty out + end + + def test_parse_default + @options.parse [] + + assert_equal RDoc::Generator::Darkfish, @options.generator + assert_equal 'darkfish', @options.template + assert_match %r%rdoc/generator/template/darkfish$%, @options.template_dir + end + + def test_parse_deprecated + dep_hash = RDoc::Options::DEPRECATED + options = dep_hash.keys.sort + + out, err = capture_io do + @options.parse options + end + + dep_hash.each_pair do |opt, message| + assert_match %r%.*#{opt}.+#{message}%, err + end + + assert_empty out + end + + def test_parse_dry_run + @options.parse %w[--dry-run] + + assert @options.dry_run + end + + def test_parse_encoding + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + @options.parse %w[--encoding Big5] + + assert_equal Encoding::Big5, @options.encoding + assert_equal 'Big5', @options.charset + end + + def test_parse_encoding_invalid + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + out, err = capture_io do + @options.parse %w[--encoding invalid] + end + + assert_match %r%^invalid options: --encoding invalid%, err + + assert_empty out + end + + def test_parse_formatter + e = assert_raises OptionParser::InvalidOption do + @options.parse %w[--format darkfish --format ri] + end + + assert_equal 'invalid option: --format generator already set to darkfish', + e.message + end + + def test_parse_formatter_ri + e = assert_raises OptionParser::InvalidOption do + @options.parse %w[--format darkfish --ri] + end + + assert_equal 'invalid option: --ri generator already set to darkfish', + e.message + + @options = RDoc::Options.new + + e = assert_raises OptionParser::InvalidOption do + @options.parse %w[--format darkfish -r] + end + + assert_equal 'invalid option: -r generator already set to darkfish', + e.message + end + + def test_parse_formatter_ri_site + e = assert_raises OptionParser::InvalidOption do + @options.parse %w[--format darkfish --ri-site] + end + + assert_equal 'invalid option: --ri-site generator already set to darkfish', + e.message + + @options = RDoc::Options.new + + e = assert_raises OptionParser::InvalidOption do + @options.parse %w[--format darkfish -R] + end + + assert_equal 'invalid option: -R generator already set to darkfish', + e.message + end + + def test_parse_help + out, = capture_io do + begin + @options.parse %w[--help] + rescue SystemExit + end + end + + assert_equal 1, out.scan(/HTML generator options:/).length + assert_equal 1, out.scan(/ri generator options:/). length + end + def test_parse_ignore_invalid out, err = capture_io do @options.parse %w[--ignore-invalid --bogus] @@ -15,6 +185,8 @@ class TestRDocOptions < MiniTest::Unit::TestCase refute_match %r%^Usage: %, err assert_match %r%^invalid options: --bogus%, err + + assert_empty out end def test_parse_ignore_invalid_default @@ -26,17 +198,21 @@ class TestRDocOptions < MiniTest::Unit::TestCase assert_match %r%^invalid options: --bogus%, err assert_equal 'BLAH', @options.main_page + + assert_empty out end def test_parse_ignore_invalid_no out, err = capture_io do assert_raises SystemExit do - @options.parse %w[--no-ignore-invalid --bogus] + @options.parse %w[--no-ignore-invalid --bogus=arg --bobogus --visibility=extended] end end assert_match %r%^Usage: %, err - assert_match %r%^invalid option: --bogus%, err + assert_match %r%^invalid options: --bogus=arg, --bobogus, --visibility=extended%, err + + assert_empty out end def test_parse_main @@ -50,24 +226,73 @@ class TestRDocOptions < MiniTest::Unit::TestCase assert_equal 'MAIN', @options.main_page end - def test_parse_dash_p + def test_parse_template out, err = capture_io do - @options.parse %w[-p] + @options.parse %w[--template darkfish] end - assert @options.pipe - refute_match %r%^Usage: %, err - refute_match %r%^invalid options%, err + assert_empty out + assert_empty err + + assert_equal 'darkfish', @options.template + + assert_match %r%rdoc/generator/template/darkfish$%, @options.template_dir end - def test_parse_dash_p_files + def test_parse_template_nonexistent out, err = capture_io do - @options.parse %w[-p README] + @options.parse %w[--template NONEXISTENT] end - refute @options.pipe - refute_match %r%^Usage: %, err - assert_match %r%^invalid options: -p .with files.%, err + assert_empty out + assert_equal "could not find template NONEXISTENT\n", err + + assert_equal 'darkfish', @options.template + assert_match %r%rdoc/generator/template/darkfish$%, @options.template_dir + end + + def test_parse_template_load_path + orig_LOAD_PATH = $LOAD_PATH.dup + + template_dir = nil + + Dir.mktmpdir do |dir| + $LOAD_PATH << dir + + template_dir = File.join dir, 'rdoc', 'generator', 'template', 'load_path' + + FileUtils.mkdir_p template_dir + + out, err = capture_io do + @options.parse %w[--template load_path] + end + + assert_empty out + assert_empty err + end + + assert_equal 'load_path', @options.template + assert_equal template_dir, @options.template_dir + ensure + $LOAD_PATH.replace orig_LOAD_PATH + end + + def test_setup_generator + test_generator = Object.new + def test_generator.setup_options(op) + @op = op + end + + def test_generator.op() @op end + + RDoc::RDoc::GENERATORS['TestGenerator'] = test_generator + + @options.setup_generator 'TestGenerator' + + assert_equal test_generator, @options.generator + assert_equal [test_generator], @options.generator_options + + assert_equal @options, test_generator.op end end diff --git a/test/rdoc/test_rdoc_parser.rb b/test/rdoc/test_rdoc_parser.rb index ebb520032d..2eb1ac1a67 100644 --- a/test/rdoc/test_rdoc_parser.rb +++ b/test/rdoc/test_rdoc_parser.rb @@ -11,25 +11,6 @@ class TestRDocParser < MiniTest::Unit::TestCase @binary_dat = File.expand_path '../binary.dat', __FILE__ end - def test_class_binary_eh_erb - erb = File.join Dir.tmpdir, "test_rdoc_parser_#{$$}.erb" - open erb, 'wb' do |io| - io.write 'blah blah <%= stuff %> <% more stuff %>' - end - - assert @RP.binary?(erb) - - erb_rb = File.join Dir.tmpdir, "test_rdoc_parser_#{$$}.erb.rb" - open erb_rb, 'wb' do |io| - io.write 'blah blah <%= stuff %>' - end - - refute @RP.binary?(erb_rb) - ensure - File.unlink erb - File.unlink erb_rb if erb_rb - end - def test_class_binary_eh_marshal marshal = File.join Dir.tmpdir, "test_rdoc_parser_#{$$}.marshal" open marshal, 'wb' do |io| @@ -42,6 +23,18 @@ class TestRDocParser < MiniTest::Unit::TestCase File.unlink marshal end + def test_class_binary_japanese_text + file_name = File.expand_path '../test.ja.txt', __FILE__ + refute @RP.binary?(file_name) + end + + def test_class_binary_japanese_rdoc + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + file_name = File.expand_path '../test.ja.rdoc', __FILE__ + refute @RP.binary?(file_name) + end + def test_class_can_parse assert_equal @RP.can_parse(__FILE__), @RP::Ruby @@ -72,6 +65,10 @@ class TestRDocParser < MiniTest::Unit::TestCase def test_class_for_binary rp = @RP.dup + class << rp + alias old_can_parse can_parse + end + def rp.can_parse(*args) nil end assert_nil @RP.for(nil, @binary_dat, nil, nil, nil) diff --git a/test/rdoc/test_rdoc_parser_c.rb b/test/rdoc/test_rdoc_parser_c.rb index 4f5d9e3171..c6cc42081c 100644 --- a/test/rdoc/test_rdoc_parser_c.rb +++ b/test/rdoc/test_rdoc_parser_c.rb @@ -1,12 +1,52 @@ require 'stringio' require 'tempfile' require 'rubygems' -require 'minitest/unit' +require 'minitest/autorun' require 'rdoc/options' require 'rdoc/parser/c' +=begin + TODO: test call-seq parsing + +/* + * call-seq: + * ARGF.readlines(sep=$/) -> array + * ARGF.readlines(limit) -> array + * ARGF.readlines(sep, limit) -> array + * + * ARGF.to_a(sep=$/) -> array + * ARGF.to_a(limit) -> array + * ARGF.to_a(sep, limit) -> array + * + * Reads +ARGF+'s current file in its entirety, returning an +Array+ of its + * lines, one line per element. Lines are assumed to be separated by _sep_. + * + * lines = ARGF.readlines + * lines[0] #=> "This is line one\n" + */ + +assert call-seq did not stop at first empty line + +/* + * call-seq: + * + * flt ** other -> float + * + * Raises <code>float</code> the <code>other</code> power. + * + * 2.0**3 #=> 8.0 + */ + +assert call-seq correct (bug: was empty) + +/* call-seq: flt ** other -> float */ + +assert call-seq correct + +=end + class RDoc::Parser::C - attr_accessor :classes + attr_accessor :classes, :singleton_classes public :do_classes, :do_constants end @@ -30,6 +70,129 @@ class TestRDocParserC < MiniTest::Unit::TestCase @tempfile.close end + def test_do_attr_rb_attr + content = <<-EOF +void Init_Blah(void) { + cBlah = rb_define_class("Blah", rb_cObject); + + /* + * This is an accessor + */ + rb_attr(cBlah, rb_intern("accessor"), 1, 1, Qfalse); + + /* + * This is a reader + */ + rb_attr(cBlah, rb_intern("reader"), 1, 0, Qfalse); + + /* + * This is a writer + */ + rb_attr(cBlah, rb_intern("writer"), 0, 1, Qfalse); +} + EOF + + klass = util_get_class content, 'cBlah' + + attrs = klass.attributes + assert_equal 3, attrs.length, attrs.inspect + + accessor = attrs.shift + assert_equal 'accessor', accessor.name + assert_equal 'RW', accessor.rw + assert_equal 'This is an accessor', accessor.comment + + reader = attrs.shift + assert_equal 'reader', reader.name + assert_equal 'R', reader.rw + assert_equal 'This is a reader', reader.comment + + writer = attrs.shift + assert_equal 'writer', writer.name + assert_equal 'W', writer.rw + assert_equal 'This is a writer', writer.comment + end + + def test_do_attr_rb_define_attr + content = <<-EOF +void Init_Blah(void) { + cBlah = rb_define_class("Blah", rb_cObject); + + /* + * This is an accessor + */ + rb_define_attr(cBlah, "accessor", 1, 1); +} + EOF + + klass = util_get_class content, 'cBlah' + + attrs = klass.attributes + assert_equal 1, attrs.length, attrs.inspect + + accessor = attrs.shift + assert_equal 'accessor', accessor.name + assert_equal 'RW', accessor.rw + assert_equal 'This is an accessor', accessor.comment + end + + def test_do_aliases + content = <<-EOF +/* + * This should show up as an alias with documentation + */ +VALUE blah(VALUE klass, VALUE year) { +} + +void Init_Blah(void) { + cDate = rb_define_class("Date", rb_cObject); + + rb_define_method(cDate, "blah", blah, 1); + + rb_define_alias(cDate, "bleh", "blah"); +} + EOF + + klass = util_get_class content, 'cDate' + + methods = klass.method_list + assert_equal 2, methods.length + assert_equal 'bleh', methods.last.name + assert_equal 'blah', methods.last.is_alias_for.name + end + + def test_do_aliases_singleton + content = <<-EOF +/* + * This should show up as a method with documentation + */ +VALUE blah(VALUE klass, VALUE year) { +} + +void Init_Blah(void) { + cDate = rb_define_class("Date", rb_cObject); + sDate = rb_singleton_class(cDate); + + rb_define_method(sDate, "blah", blah, 1); + + /* + * This should show up as an alias + */ + rb_define_alias(sDate, "bleh", "blah"); +} + EOF + + klass = util_get_class content, 'cDate' + + methods = klass.method_list + + assert_equal 2, methods.length + assert_equal 'bleh', methods.last.name + assert methods.last.singleton + assert_equal 'blah', methods.last.is_alias_for.name + assert_equal 'This should show up as an alias', methods.last.comment + end + def test_do_classes_boot_class content = <<-EOF /* Document-class: Foo @@ -68,6 +231,17 @@ VALUE cFoo = rb_define_class("Foo", rb_cObject); assert_equal "this is the Foo class", klass.comment end + def test_do_classes_singleton + content = <<-EOF +VALUE cFoo = rb_define_class("Foo", rb_cObject); +VALUE cFooS = rb_singleton_class(cFoo); + EOF + + util_get_class content, 'cFooS' + + assert_equal 'Foo', @parser.singleton_classes['cFooS'] + end + def test_do_classes_class_under content = <<-EOF /* Document-class: Kernel::Foo @@ -201,6 +375,26 @@ Multiline comment goes here because this comment spans multiple lines. assert constants.empty?, constants.inspect end + def test_find_alias_comment + parser = util_parser '' + + comment = parser.find_alias_comment 'C', '[]', 'index' + + assert_equal '', comment + + parser = util_parser <<-C +/* + * comment + */ + +rb_define_alias(C, "[]", "index"); + C + + comment = parser.find_alias_comment 'C', '[]', 'index' + + assert_equal "/*\n * comment\n */\n\n", comment + end + def test_find_class_comment_include @options.rdoc_include << File.dirname(__FILE__) @@ -406,6 +600,113 @@ Init_Foo(void) { assert_equal "a comment for bar", bar.comment end + def test_find_modifiers_call_seq + comment = <<-COMMENT +/* call-seq: + * commercial() -> Date <br /> + * commercial(cwyear, cweek=41, cwday=5, sg=nil) -> Date [ruby 1.8] <br /> + * commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9] + * + * If no arguments are given: + * * ruby 1.8: returns a +Date+ for 1582-10-15 (the Day of Calendar Reform in + * Italy) + * * ruby 1.9: returns a +Date+ for julian day 0 + * + * Otherwise, returns a +Date+ for the commercial week year, commercial week, + * and commercial week day given. Ignores the 4th argument. + */ + + COMMENT + + parser = util_parser '' + method_obj = RDoc::AnyMethod.new nil, 'blah' + + parser.find_modifiers comment, method_obj + + expected = <<-CALL_SEQ.chomp +commercial() -> Date <br /> +commercial(cwyear, cweek=41, cwday=5, sg=nil) -> Date [ruby 1.8] <br /> +commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9] + + CALL_SEQ + + assert_equal expected, method_obj.call_seq + end + + def test_find_modifiers_nodoc + comment = <<-COMMENT +/* :nodoc: + * + * Blah + */ + + COMMENT + + parser = util_parser '' + method_obj = RDoc::AnyMethod.new nil, 'blah' + + parser.find_modifiers comment, method_obj + + assert_equal nil, method_obj.document_self + end + + def test_find_modifiers_yields + comment = <<-COMMENT +/* :yields: a, b + * + * Blah + */ + + COMMENT + + parser = util_parser '' + method_obj = RDoc::AnyMethod.new nil, 'blah' + + parser.find_modifiers comment, method_obj + + assert_equal 'a, b', method_obj.block_params + + expected = <<-EXPECTED +/* + * + * Blah + */ + + EXPECTED + + assert_equal expected, comment + end + + def test_handle_method + parser = util_parser "Document-method: BasicObject#==\n blah */" + + parser.handle_method 'method', 'rb_cBasicObject', '==', 'rb_obj_equal', 1 + + bo = @top_level.find_module_named 'BasicObject' + + assert_equal 1, bo.method_list.length + + equals2 = bo.method_list.first + + assert_equal '==', equals2.name + end + + def test_handle_method_initialize + parser = util_parser "Document-method: BasicObject::new\n blah */" + + parser.handle_method('private_method', 'rb_cBasicObject', + 'initialize', 'rb_obj_dummy', -1) + + bo = @top_level.find_module_named 'BasicObject' + + assert_equal 1, bo.method_list.length + + new = bo.method_list.first + + assert_equal 'new', new.name + assert_equal :public, new.visibility + end + def test_look_for_directives_in parser = util_parser '' @@ -442,6 +743,7 @@ Init_IO(void) { read_method = klass.method_list.first assert_equal "read", read_method.name assert_equal "Method Comment! ", read_method.comment + assert read_method.singleton end def test_define_method_private @@ -472,6 +774,65 @@ Init_IO(void) { assert_equal "Method Comment! ", read_method.comment end + def test_define_method_private_singleton + content = <<-EOF +/*Method Comment! */ +static VALUE +rb_io_s_read(argc, argv, io) + int argc; + VALUE *argv; + VALUE io; +{ +} + +void +Init_IO(void) { + /* + * a comment for class Foo on rb_define_class + */ + VALUE rb_cIO = rb_define_class("IO", rb_cObject); + VALUE rb_cIO_s = rb_singleton_class(rb_cIO); + rb_define_private_method(rb_cIO_s, "read", rb_io_s_read, -1); +} + EOF + + klass = util_get_class content, 'rb_cIO' + read_method = klass.method_list.first + assert_equal "read", read_method.name + assert_equal "Method Comment! ", read_method.comment + assert_equal :private, read_method.visibility + assert read_method.singleton + end + + def test_define_method_singleton + content = <<-EOF +/*Method Comment! */ +static VALUE +rb_io_s_read(argc, argv, io) + int argc; + VALUE *argv; + VALUE io; +{ +} + +void +Init_IO(void) { + /* + * a comment for class Foo on rb_define_class + */ + VALUE rb_cIO = rb_define_class("IO", rb_cObject); + VALUE rb_cIO_s = rb_singleton_class(rb_cIO); + rb_define_method(rb_cIO_s, "read", rb_io_s_read, -1); +} + EOF + + klass = util_get_class content, 'rb_cIO' + read_method = klass.method_list.first + assert_equal "read", read_method.name + assert_equal "Method Comment! ", read_method.comment + assert read_method.singleton + end + def util_get_class(content, name) @parser = util_parser content @parser.scan @@ -484,4 +845,3 @@ Init_IO(void) { end -MiniTest::Unit.autorun diff --git a/test/rdoc/test_rdoc_parser_perl.rb b/test/rdoc/test_rdoc_parser_perl.rb deleted file mode 100644 index ce4e7d2b65..0000000000 --- a/test/rdoc/test_rdoc_parser_perl.rb +++ /dev/null @@ -1,73 +0,0 @@ -require 'stringio' -require 'tempfile' -require 'rubygems' -require 'minitest/autorun' -require 'rdoc/options' -require 'rdoc/parser/perl' - -class TestRdocParserPerlPOD < MiniTest::Unit::TestCase - - def setup - @tempfile = Tempfile.new self.class.name - filename = @tempfile.path - - @top_level = RDoc::TopLevel.new filename - @fn = filename - @options = RDoc::Options.new - @stats = RDoc::Stats.new 0 - end - - def teardown - @tempfile.close - end - - def test_uncommented_perl - content = <<-EOF -while (<>) { - tr/a-z/A-Z; - print -} - EOF - - comment = util_get_comment content - assert_equal "", comment - end - - def test_perl_without_pod - content = <<-EOF -#!/usr/local/bin/perl -# -#This is a pointless perl program because it does -p. -# -while(<>) {print;}: - EOF - - comment = util_get_comment content - assert_equal "", comment - end - - def test_simple_pod_no_structure - content = <<-EOF -=begin pod - -This just contains plain old documentation - -=end - EOF - comment = util_get_comment content - assert_equal 'This just contains plain old documentation', comment - end - - # Get the comment of the @top_level when it has processed the input. - def util_get_comment(content) - parser = util_parser content - parser.scan.comment - end - - # create a new parser with the supplied content. - def util_parser(content) - RDoc::Parser::PerlPOD.new @top_level, @fn, content, @options, @stats - end - -end - diff --git a/test/rdoc/test_rdoc_parser_ruby.rb b/test/rdoc/test_rdoc_parser_ruby.rb index 33ffded723..f2fa18c67b 100644 --- a/test/rdoc/test_rdoc_parser_ruby.rb +++ b/test/rdoc/test_rdoc_parser_ruby.rb @@ -22,6 +22,8 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase util_top_level @options = RDoc::Options.new @options.quiet = true + @options.option_parser = OptionParser.new + @stats = RDoc::Stats.new 0 end @@ -30,6 +32,30 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase @tempfile2.close end + def test_get_symbol_or_name + util_parser "* & | + 5 / 4" + + assert_equal '*', @parser.get_symbol_or_name + + @parser.skip_tkspace + + assert_equal '&', @parser.get_symbol_or_name + + @parser.skip_tkspace + + assert_equal '|', @parser.get_symbol_or_name + + @parser.skip_tkspace + + assert_equal '+', @parser.get_symbol_or_name + + @parser.skip_tkspace + @parser.get_tk + @parser.skip_tkspace + + assert_equal '/', @parser.get_symbol_or_name + end + def test_look_for_directives_in_attr util_parser "" @@ -52,6 +78,61 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase assert_equal "# :attr_writer: my_method\n", comment end + def test_remove_private_comments + util_parser '' + + comment = <<-EOS +# This is text +#-- +# this is private + EOS + + expected = <<-EOS +# This is text + EOS + + @parser.remove_private_comments(comment) + + assert_equal expected, comment + end + + def test_remove_private_comments_rule + util_parser '' + + comment = <<-EOS +# This is text with a rule: +# --- +# this is also text + EOS + + expected = comment.dup + + @parser.remove_private_comments(comment) + + assert_equal expected, comment + end + + def test_remove_private_comments_toggle + util_parser '' + + comment = <<-EOS +# This is text +#-- +# this is private +#++ +# This is text again. + EOS + + expected = <<-EOS +# This is text +# This is text again. + EOS + + @parser.remove_private_comments(comment) + + assert_equal expected, comment + end + def test_look_for_directives_in_commented util_parser "" @@ -70,9 +151,9 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase def test_look_for_directives_in_enddoc util_parser "" - assert_throws :enddoc do - @parser.look_for_directives_in @top_level, "# :enddoc:\n" - end + @parser.look_for_directives_in @top_level, "# :enddoc:\n" + + assert @top_level.done_documenting end def test_look_for_directives_in_main @@ -105,13 +186,11 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase @top_level.stop_doc assert !@top_level.document_self assert !@top_level.document_children - assert !@top_level.force_documentation @parser.look_for_directives_in @top_level, "# :startdoc:\n" assert @top_level.document_self assert @top_level.document_children - assert @top_level.force_documentation end def test_look_for_directives_in_stopdoc @@ -166,10 +245,29 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase alas = @parser.parse_alias klass, RDoc::Parser::Ruby::NORMAL, tk, 'comment' - assert_equal 'bar', alas.old_name - assert_equal 'next=', alas.new_name - assert_equal klass, alas.parent - assert_equal 'comment', alas.comment + assert_equal 'bar', alas.old_name + assert_equal 'next=', alas.new_name + assert_equal klass, alas.parent + assert_equal 'comment', alas.comment + assert_equal @top_level, alas.file + end + + def test_parse_alias_singleton + klass = RDoc::NormalClass.new 'Foo' + klass.parent = @top_level + + util_parser "alias :next= :bar" + + tk = @parser.get_tk + + alas = @parser.parse_alias klass, RDoc::Parser::Ruby::SINGLE, tk, 'comment' + + assert_equal 'bar', alas.old_name + assert_equal 'next=', alas.new_name + assert_equal klass, alas.parent + assert_equal 'comment', alas.comment + assert_equal @top_level, alas.file + assert alas.singleton end def test_parse_alias_meta @@ -202,6 +300,7 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase foo = klass.attributes.first assert_equal 'foo', foo.name assert_equal 'my attr', foo.comment + assert_equal @top_level, foo.file end def test_parse_attr_accessor @@ -222,6 +321,7 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase assert_equal 'foo', foo.name assert_equal 'RW', foo.rw assert_equal 'my attr', foo.comment + assert_equal @top_level, foo.file bar = klass.attributes.last assert_equal 'bar', bar.name @@ -229,6 +329,21 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase assert_equal 'my attr', bar.comment end + def test_parse_attr_accessor_nodoc + klass = RDoc::NormalClass.new 'Foo' + klass.parent = @top_level + + comment = "##\n# my attr\n" + + util_parser "attr_accessor :foo, :bar # :nodoc:" + + tk = @parser.get_tk + + @parser.parse_attr_accessor klass, RDoc::Parser::Ruby::NORMAL, tk, comment + + assert_equal 0, klass.attributes.length + end + def test_parse_attr_accessor_writer klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level @@ -247,6 +362,7 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase assert_equal 'foo', foo.name assert_equal 'W', foo.rw assert_equal "my attr", foo.comment + assert_equal @top_level, foo.file bar = klass.attributes.last assert_equal 'bar', bar.name @@ -271,6 +387,7 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase assert_equal 'foo', foo.name assert_equal 'RW', foo.rw assert_equal "my method", foo.comment + assert_equal @top_level, foo.file end def test_parse_meta_attr_accessor @@ -290,6 +407,7 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase assert_equal 'foo', foo.name assert_equal 'RW', foo.rw assert_equal 'my method', foo.comment + assert_equal @top_level, foo.file end def test_parse_meta_attr_named @@ -309,6 +427,7 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase assert_equal 'foo', foo.name assert_equal 'RW', foo.rw assert_equal 'my method', foo.comment + assert_equal @top_level, foo.file end def test_parse_meta_attr_reader @@ -327,6 +446,7 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase assert_equal 'foo', foo.name assert_equal 'R', foo.rw assert_equal 'my method', foo.comment + assert_equal @top_level, foo.file end def test_parse_meta_attr_writer @@ -345,12 +465,13 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase assert_equal 'foo', foo.name assert_equal 'W', foo.rw assert_equal "my method", foo.comment + assert_equal @top_level, foo.file end def test_parse_class comment = "##\n# my method\n" - util_parser 'class Foo; end' + util_parser "class Foo\nend" tk = @parser.get_tk @@ -379,11 +500,12 @@ end blah = foo.method_list.first assert_equal 'Foo#blah', blah.full_name + assert_equal @top_level, blah.file end def test_parse_class_nested_superclass - foo = RDoc::NormalModule.new 'Foo' - foo.parent = @top_level + util_top_level + foo = @top_level.add_module RDoc::NormalModule, 'Foo' util_parser "class Bar < Super\nend" @@ -398,7 +520,7 @@ end def test_parse_module comment = "##\n# my module\n" - util_parser 'module Foo; end' + util_parser "module Foo\nend" tk = @parser.get_tk @@ -430,6 +552,8 @@ class A class << B end class << d = Object.new + def foo; end + alias bar foo end end CODE @@ -439,7 +563,40 @@ end @parser.parse_class @top_level, false, @parser.get_tk, '' assert_equal %w[A], RDoc::TopLevel.classes.map { |c| c.full_name } - assert_equal %w[A::B], RDoc::TopLevel.modules.map { |c| c.full_name } + assert_equal %w[A::B A::d], RDoc::TopLevel.modules.map { |c| c.full_name } + + # make sure method/alias was not added to enclosing class/module + a = RDoc::TopLevel.all_classes_hash['A'] + assert_empty a.method_list + + # make sure non-constant-named module will be removed from documentation + d = RDoc::TopLevel.all_modules_hash['A::d'] + assert d.remove_from_documentation? + + end + + # TODO this is really a Context#add_class test + def test_parse_class_object + code = <<-CODE +module A + class B + end + class Object + end + class C < Object + end +end + CODE + + util_parser code + + @parser.parse_module @top_level, false, @parser.get_tk, '' + + assert_equal %w[A], RDoc::TopLevel.modules.map { |c| c.full_name } + assert_equal %w[A::B A::C A::Object], RDoc::TopLevel.classes.map { |c| c.full_name }.sort + assert_equal 'Object', RDoc::TopLevel.classes_hash['A::B'].superclass + assert_equal 'Object', RDoc::TopLevel.classes_hash['A::Object'].superclass + assert_equal 'A::Object', RDoc::TopLevel.classes_hash['A::C'].superclass.full_name end def test_parse_class_mistaken_for_module @@ -447,7 +604,7 @@ end # before Foo::Bar is encountered), but RDoc might encounter Foo::Bar # before Foo if they live in different files. - code = <<-EOF + code = <<-RUBY class Foo::Bar end @@ -456,7 +613,7 @@ end class Foo end - EOF + RUBY util_parser code @@ -542,18 +699,20 @@ EOF @parser.parse_comment klass, tk, comment foo = klass.attributes.first - assert_equal 'foo', foo.name - assert_equal 'RW', foo.rw - assert_equal 'my attr', foo.comment + assert_equal 'foo', foo.name + assert_equal 'RW', foo.rw + assert_equal 'my attr', foo.comment + assert_equal @top_level, foo.file + + assert_equal nil, foo.viewer + assert_equal true, foo.document_children + assert_equal true, foo.document_self + assert_equal false, foo.done_documenting + assert_equal false, foo.force_documentation + assert_equal klass, foo.parent + assert_equal :public, foo.visibility + assert_equal "\n", foo.text - assert_equal nil, foo.viewer - assert_equal true, foo.document_children - assert_equal true, foo.document_self - assert_equal false, foo.done_documenting - assert_equal false, foo.force_documentation - assert_equal klass, foo.parent - assert_equal :public, foo.visibility - assert_equal "\n", foo.text assert_equal klass.current_section, foo.section end @@ -570,8 +729,9 @@ EOF @parser.parse_comment klass, tk, comment foo = klass.method_list.first - assert_equal 'foo', foo.name - assert_equal 'my method', foo.comment + assert_equal 'foo', foo.name + assert_equal 'my method', foo.comment + assert_equal @top_level, foo.file assert_equal [], foo.aliases assert_equal nil, foo.block_params @@ -599,9 +759,23 @@ EOF assert_equal stream, foo.token_stream end + def test_parse_constant_attrasgn + util_top_level + + klass = @top_level.add_class RDoc::NormalClass, 'Foo' + + util_parser "A[k] = v" + + tk = @parser.get_tk + + @parser.parse_constant klass, tk, '' + + assert klass.constants.empty? + end + def test_parse_constant_alias - klass = RDoc::NormalClass.new 'Foo' - klass.parent = @top_level + util_top_level + klass = @top_level.add_class RDoc::NormalClass, 'Foo' cB = klass.add_class RDoc::NormalClass, 'B' util_parser "A = B" @@ -642,8 +816,9 @@ EOF @parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment foo = klass.method_list.first - assert_equal 'foo', foo.name + assert_equal 'foo', foo.name assert_equal 'my method', foo.comment + assert_equal @top_level, foo.file assert_equal [], foo.aliases assert_equal nil, foo.block_params @@ -691,8 +866,9 @@ EOF @parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment foo = klass.method_list.first - assert_equal 'woo_hoo!', foo.name + assert_equal 'woo_hoo!', foo.name assert_equal 'my method', foo.comment + assert_equal @top_level, foo.file end def test_parse_meta_method_singleton @@ -711,6 +887,7 @@ EOF assert_equal 'foo', foo.name assert_equal true, foo.singleton, 'singleton method' assert_equal 'my method', foo.comment + assert_equal @top_level, foo.file end def test_parse_meta_method_singleton_name @@ -729,6 +906,7 @@ EOF assert_equal 'woo_hoo!', foo.name assert_equal true, foo.singleton, 'singleton method' assert_equal 'my method', foo.comment + assert_equal @top_level, foo.file end def test_parse_meta_method_string_name @@ -744,6 +922,7 @@ EOF foo = klass.method_list.first assert_equal 'foo', foo.name assert_equal 'my method', foo.comment + assert_equal @top_level, foo.file end def test_parse_meta_method_unknown @@ -759,6 +938,7 @@ EOF foo = klass.method_list.first assert_equal 'unknown', foo.name assert_equal 'my method', foo.comment + assert_equal @top_level, foo.file end def test_parse_method @@ -774,8 +954,9 @@ EOF @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment foo = klass.method_list.first - assert_equal 'foo', foo.name - assert_equal 'my method', foo.comment + assert_equal 'foo', foo.name + assert_equal 'my method', foo.comment + assert_equal @top_level, foo.file assert_equal [], foo.aliases assert_equal nil, foo.block_params @@ -826,39 +1007,53 @@ EOF assert klass.aliases.empty? end - def test_parse_method_utf8 + def test_parse_method_false + util_parser "def false.foo() :bar end" + + tk = @parser.get_tk + + @parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, '' + + klass = RDoc::TopLevel.find_class_named 'FalseClass' + + foo = klass.method_list.first + assert_equal 'foo', foo.name + end + + def test_parse_method_funky klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level - comment = "##\n# my method\n" + util_parser "def (blah).foo() :bar end" - method = "def ω() end" + tk = @parser.get_tk - assert_equal Encoding::UTF_8, method.encoding if defined? ::Encoding + @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, '' - util_parser method + assert klass.method_list.empty? + end + + def test_parse_method_gvar + util_parser "def $stdout.foo() :bar end" tk = @parser.get_tk - @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment + @parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, '' - omega = klass.method_list.first - assert_equal "def \317\211", omega.text + assert @top_level.method_list.empty? end - def test_parse_method_funky + def test_parse_method_internal_gvar klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level - comment = "##\n# my method\n" - - util_parser "def (blah).foo() :bar end" + util_parser "def foo() def $blah.bar() end end" tk = @parser.get_tk - @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment + @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, '' - assert klass.method_list.empty? + assert_equal 1, klass.method_list.length end def test_parse_method_internal_ivar @@ -887,33 +1082,43 @@ EOF assert_equal 1, klass.method_list.length end + def test_parse_method_nil + util_parser "def nil.foo() :bar end" + + tk = @parser.get_tk + + @parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, '' + + klass = RDoc::TopLevel.find_class_named 'NilClass' + + foo = klass.method_list.first + assert_equal 'foo', foo.name + end + def test_parse_method_no_parens klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level - comment = "##\n# my method\n" - - util_parser "def foo arg1, arg2\nend" + util_parser "def foo arg1, arg2 = {}\nend" tk = @parser.get_tk - @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment + @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, '' foo = klass.method_list.first - assert_equal '(arg1, arg2)', foo.params + assert_equal '(arg1, arg2 = {})', foo.params + assert_equal @top_level, foo.file end def test_parse_method_parameters_comment klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level - comment = "##\n# my method\n" - util_parser "def foo arg1, arg2 # some useful comment\nend" tk = @parser.get_tk - @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment + @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, '' foo = klass.method_list.first assert_equal '(arg1, arg2)', foo.params @@ -923,13 +1128,11 @@ EOF klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level - comment = "##\n# my method\n" - util_parser "def foo arg1, arg2, # some useful comment\narg3\nend" tk = @parser.get_tk - @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment + @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, '' foo = klass.method_list.first assert_equal '(arg1, arg2, arg3)', foo.params @@ -938,18 +1141,17 @@ EOF def test_parse_method_toplevel klass = @top_level - comment = "##\n# my method\n" - util_parser "def foo arg1, arg2\nend" tk = @parser.get_tk - @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment + @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, '' object = RDoc::TopLevel.find_class_named 'Object' foo = object.method_list.first assert_equal 'Object#foo', foo.full_name + assert_equal @top_level, foo.file end def test_parse_method_toplevel_class @@ -967,9 +1169,39 @@ EOF assert_equal 'Object::foo', foo.full_name end - def test_parse_statements_class_if - comment = "##\n# my method\n" + def test_parse_method_true + util_parser "def true.foo() :bar end" + + tk = @parser.get_tk + + @parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, '' + + klass = RDoc::TopLevel.find_class_named 'TrueClass' + + foo = klass.method_list.first + assert_equal 'foo', foo.name + end + + def test_parse_method_utf8 + klass = RDoc::NormalClass.new 'Foo' + klass.parent = @top_level + + method = "def ω() end" + assert_equal Encoding::UTF_8, method.encoding if + Object.const_defined? :Encoding + + util_parser method + + tk = @parser.get_tk + + @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, '' + + omega = klass.method_list.first + assert_equal "def \317\211", omega.text + end + + def test_parse_statements_class_if util_parser <<-CODE module Foo X = if TRUE then @@ -1024,7 +1256,12 @@ end end def test_parse_statements_identifier_alias_method - content = "class Foo def foo() end; alias_method :foo2, :foo end" + content = <<-RUBY +class Foo + def foo() end + alias_method :foo2, :foo +end + RUBY util_parser content @@ -1078,10 +1315,25 @@ EOF assert_equal 'foo4', foo4.name assert_equal 'foo', foo4.is_alias_for.name - assert_equal 'unknown', @top_level.classes.first.aliases[0].old_name + assert_equal 'unknown', @top_level.classes.first.external_aliases[0].old_name end def test_parse_statements_identifier_constant + + sixth_constant = <<-EOF +Class.new do + rule :file do + all(x, y, z) { + def value + find(:require).each {|r| require r.value } + find(:grammar).map {|g| g.value } + end + def min; end + } + end +end + EOF + content = <<-EOF class Foo FIRST_CONSTANT = 5 @@ -1103,6 +1355,10 @@ class Foo end FIFTH_CONSTANT = SECOND_CONSTANT.map { |element| element + 1 } + + SIXTH_CONSTANT = #{sixth_constant} + + SEVENTH_CONSTANT = proc { |i| begin i end } end EOF @@ -1115,26 +1371,43 @@ EOF constant = constants[0] assert_equal 'FIRST_CONSTANT', constant.name assert_equal '5', constant.value + assert_equal @top_level, constant.file constant = constants[1] assert_equal 'SECOND_CONSTANT', constant.name - assert_equal '[ 1, 2, 3 ]', constant.value + assert_equal "[\n1,\n2,\n3\n]", constant.value + assert_equal @top_level, constant.file constant = constants[2] assert_equal 'THIRD_CONSTANT', constant.name - assert_equal "{ :foo => 'bar', :x => 'y' }", constant.value + assert_equal "{\n:foo => 'bar',\n:x => 'y'\n}", constant.value + assert_equal @top_level, constant.file constant = constants[3] assert_equal 'FOURTH_CONSTANT', constant.name - assert_equal 'SECOND_CONSTANT.map do |element| element + 1 element + 2 end', constant.value + assert_equal "SECOND_CONSTANT.map do |element|\nelement + 1\nelement + 2\nend", constant.value + assert_equal @top_level, constant.file - constant = constants.last + constant = constants[4] assert_equal 'FIFTH_CONSTANT', constant.name assert_equal 'SECOND_CONSTANT.map { |element| element + 1 }', constant.value + assert_equal @top_level, constant.file + + # TODO: parse as class + constant = constants[5] + assert_equal 'SIXTH_CONSTANT', constant.name + assert_equal sixth_constant.lines.map(&:strip).join("\n"), constant.value + assert_equal @top_level, constant.file + + # TODO: parse as method + constant = constants[6] + assert_equal 'SEVENTH_CONSTANT', constant.name + assert_equal "proc { |i| begin i end }", constant.value + assert_equal @top_level, constant.file end def test_parse_statements_identifier_attr - content = "class Foo; attr :foo; end" + content = "class Foo\nattr :foo\nend" util_parser content @@ -1146,7 +1419,7 @@ EOF end def test_parse_statements_identifier_attr_accessor - content = "class Foo; attr_accessor :foo; end" + content = "class Foo\nattr_accessor :foo\nend" util_parser content @@ -1158,7 +1431,7 @@ EOF end def test_parse_statements_identifier_include - content = "class Foo; include Bar; end" + content = "class Foo\ninclude Bar\nend" util_parser content @@ -1170,24 +1443,24 @@ EOF end def test_parse_statements_identifier_module_function - content = "module Foo def foo() end; module_function :foo; end" + content = "module Foo\ndef foo() end\nmodule_function :foo\nend" util_parser content @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, '' foo, s_foo = @top_level.modules.first.method_list - assert_equal 'foo', foo.name, 'instance method name' + assert_equal 'foo', foo.name, 'instance method name' assert_equal :private, foo.visibility, 'instance method visibility' - assert_equal false, foo.singleton, 'instance method singleton' + assert_equal false, foo.singleton, 'instance method singleton' - assert_equal 'foo', s_foo.name, 'module function name' + assert_equal 'foo', s_foo.name, 'module function name' assert_equal :public, s_foo.visibility, 'module function visibility' - assert_equal true, s_foo.singleton, 'module function singleton' + assert_equal true, s_foo.singleton, 'module function singleton' end def test_parse_statements_identifier_private - content = "class Foo private; def foo() end end" + content = "class Foo\nprivate\ndef foo() end\nend" util_parser content @@ -1235,6 +1508,24 @@ end assert_equal 'A#b', m_b.full_name end + def test_parse_symbol_in_arg + util_parser ':blah "blah" "#{blah}" blah' + + assert_equal 'blah', @parser.parse_symbol_in_arg + + @parser.skip_tkspace + + assert_equal 'blah', @parser.parse_symbol_in_arg + + @parser.skip_tkspace + + assert_equal nil, @parser.parse_symbol_in_arg + + @parser.skip_tkspace + + assert_equal nil, @parser.parse_symbol_in_arg + end + def test_parse_top_level_statements_alias_method content = <<-CONTENT class A @@ -1252,6 +1543,20 @@ end @parser.parse_statements @top_level end + def test_parse_yield_in_braces_with_parens + klass = RDoc::NormalClass.new 'Foo' + klass.parent = @top_level + + util_parser "def foo\nn.times { |i| yield nth(i) }\nend" + + tk = @parser.get_tk + + @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, '' + + foo = klass.method_list.first + assert_equal 'nth(i)', foo.block_params + end + def test_sanity_integer util_parser '1' assert_equal '1', @parser.get_tk.text @@ -1272,7 +1577,6 @@ end # If you're writing code like this you're doing it wrong def test_sanity_interpolation_crazy - last_tk = nil util_parser '"#{"#{"a")}" if b}"' assert_equal '"#{"#{"a")}" if b}"', @parser.get_tk.text @@ -1280,7 +1584,6 @@ end end def test_sanity_interpolation_curly - last_tk = nil util_parser '%{ #{} }' assert_equal '%{ #{} }', @parser.get_tk.text @@ -1290,13 +1593,39 @@ end def test_sanity_interpolation_format util_parser '"#{stftime("%m-%d")}"' - while tk = @parser.get_tk do end + while @parser.get_tk do end end def test_sanity_symbol_interpolation util_parser ':"#{bar}="' - while tk = @parser.get_tk do end + while @parser.get_tk do end + end + + def test_stopdoc_after_comment + + util_parser <<-EOS + module Bar + # hello + module Foo + # :stopdoc: + end + # there + class Baz + # :stopdoc: + end + end + EOS + + @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, '' + + foo = @top_level.modules.first.modules.first + assert_equal 'Foo', foo.name + assert_equal 'hello', foo.comment + + baz = @top_level.modules.first.classes.first + assert_equal 'Baz', baz.name + assert_equal 'there', baz.comment end def tk(klass, line, char, name, text) diff --git a/test/rdoc/test_rdoc_parser_simple.rb b/test/rdoc/test_rdoc_parser_simple.rb index d09cced5a4..8cedfaa2fc 100644 --- a/test/rdoc/test_rdoc_parser_simple.rb +++ b/test/rdoc/test_rdoc_parser_simple.rb @@ -41,7 +41,6 @@ contents of a string. parser.scan expected = <<-TEXT.strip - Regular expressions (<i>regexp</i>s) are patterns which describe the contents of a string. TEXT @@ -49,6 +48,31 @@ contents of a string. assert_equal expected, @top_level.comment end + # RDoc stops processing comments if it finds a comment line CONTAINING + # '<tt>#--</tt>'. This can be used to separate external from internal + # comments, or to stop a comment being associated with a method, + # class, or module. Commenting CAN be turned back on with + # a line that STARTS '<tt>#++</tt>'. + # + # I've seen guys that comment their code like this: + # # This method.... + # #----------------- + # def method + # + # => either we do it only in ruby code, or we require the leading # + # (to avoid conflict with rules). + # + # TODO: require the leading #, to provide the feature in simple text files. + # Note: in ruby & C code, we require '#--' & '#++' or '*--' & '*++', + # to allow rules: + # + # # this is a comment + # #--- + # # private text + # #+++ + # # this is a rule: + # # --- + def test_remove_private_comments parser = util_parser '' text = "foo\n\n--\nbar\n++\n\nbaz\n" diff --git a/test/rdoc/test_rdoc_rdoc.rb b/test/rdoc/test_rdoc_rdoc.rb index b02ef2ae1a..d65e2f3427 100644 --- a/test/rdoc/test_rdoc_rdoc.rb +++ b/test/rdoc/test_rdoc_rdoc.rb @@ -1,15 +1,21 @@ -require 'tempfile' -require 'tmpdir' require 'rubygems' require 'minitest/autorun' require 'rdoc/rdoc' +require 'fileutils' +require 'tempfile' +require 'tmpdir' + class TestRDocRDoc < MiniTest::Unit::TestCase def setup @rdoc = RDoc::RDoc.new + @rdoc.options = RDoc::Options.new + + @stats = RDoc::Stats.new 0, 0 + @rdoc.instance_variable_set :@stats, @stats + @tempfile = Tempfile.new 'test_rdoc_rdoc' - @tempfile.binmode end def teardown @@ -39,48 +45,6 @@ class TestRDocRDoc < MiniTest::Unit::TestCase assert_empty files end - def test_read_file_contents - @tempfile.write "hi everybody" - @tempfile.flush - - assert_equal "hi everybody", @rdoc.read_file_contents(@tempfile.path) - end - - def test_read_file_contents_encoding - skip "Encoding not implemented" unless defined? ::Encoding - - @tempfile.write "# coding: utf-8\nhi everybody" - @tempfile.flush - - contents = @rdoc.read_file_contents @tempfile.path - assert_equal "# coding: utf-8\nhi everybody", contents - assert_equal Encoding::UTF_8, contents.encoding - end - - def test_read_file_contents_encoding_fancy - skip "Encoding not implemented" unless defined? ::Encoding - - @tempfile.write "# -*- coding: utf-8; fill-column: 74 -*-\nhi everybody" - @tempfile.flush - - contents = @rdoc.read_file_contents @tempfile.path - assert_equal("# -*- coding: utf-8; fill-column: 74 -*-\nhi everybody", - contents) - assert_equal Encoding::UTF_8, contents.encoding - end - - def test_read_file_contents_encoding_with_signature - skip "Encoding not implemented" unless defined? ::Encoding - - @tempfile.write "\xEF\xBB\xBF""hi everybody" - @tempfile.flush - - bug3360 = '[ruby-dev:41452]' - contents = @rdoc.read_file_contents @tempfile.path - assert_equal "hi everybody", contents, bug3360 - assert_equal Encoding::UTF_8, contents.encoding, bug3360 - end - def test_remove_unparsable file_list = %w[ blah.class @@ -108,6 +72,20 @@ class TestRDocRDoc < MiniTest::Unit::TestCase } end + def test_setup_output_dir_dry_run + skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir + + @rdoc.options.dry_run = true + + Dir.mktmpdir do |d| + path = File.join d, 'testdir' + + @rdoc.setup_output_dir path, false + + refute File.exist? path + end + end + def test_setup_output_dir_exists skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir @@ -161,5 +139,26 @@ class TestRDocRDoc < MiniTest::Unit::TestCase end end + def test_update_output_dir + skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir + + Dir.mktmpdir do |d| + @rdoc.update_output_dir d, Time.now, {} + + assert File.exist? "#{d}/created.rid" + end + end + + def test_update_output_dir_dry_run + skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir + + Dir.mktmpdir do |d| + @rdoc.options.dry_run = true + @rdoc.update_output_dir d, Time.now, {} + + refute File.exist? "#{d}/created.rid" + end + end + end diff --git a/test/rdoc/test_rdoc_ri_driver.rb b/test/rdoc/test_rdoc_ri_driver.rb index 9ff89077b6..75ecfefe8e 100644 --- a/test/rdoc/test_rdoc_ri_driver.rb +++ b/test/rdoc/test_rdoc_ri_driver.rb @@ -53,7 +53,7 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase def test_self_dump util_store - out, err = capture_io do + out, = capture_io do RDoc::RI::Driver.dump @store.cache_path end @@ -83,8 +83,8 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase expected = @RM::Document.new( @RM::Rule.new(1), @RM::Paragraph.new('Also found in:'), - @RM::Verbatim.new(' ', 'ruby core', "\n", - ' ', '~/.ri', "\n")) + @RM::Verbatim.new("ruby core\n", + "~/.ri\n")) assert_equal expected, out end @@ -143,7 +143,7 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase @RM::BlankLine.new, @RM::Paragraph.new("Include thingy"), @RM::BlankLine.new, - @RM::Verbatim.new(' ', 'Enumerable', "\n")) + @RM::Verbatim.new("Enumerable\n")) assert_equal expected, out end @@ -163,8 +163,8 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase @RM::Rule.new(1), @RM::Heading.new(1, "Includes:"), @RM::Paragraph.new("(from #{@store.friendly_path})"), - @RM::Verbatim.new(' ', 'Inc', "\n", - ' ', 'Enumerable', "\n")) + @RM::Verbatim.new("Inc\n", + "Enumerable\n")) assert_equal expected, out end @@ -195,7 +195,7 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase expected = @RM::Document.new( @RM::Heading.new(1, 'Class methods:'), @RM::BlankLine.new, - @RM::Verbatim.new(' ', 'new'), + @RM::Verbatim.new('new'), @RM::BlankLine.new) assert_equal expected, out @@ -285,7 +285,7 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase doc = @RM::Document.new( @RM::Paragraph.new('hi')) - out, err = capture_io do + out, = capture_io do @driver.display doc end @@ -295,12 +295,12 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase def test_display_class util_store - out, err = capture_io do + out, = capture_io do @driver.display_class 'Foo::Bar' end assert_match %r%^= Foo::Bar%, out - assert_match %r%^\(from%, out # ) + assert_match %r%^\(from%, out assert_match %r%^= Class methods:%, out assert_match %r%^ new%, out @@ -315,7 +315,7 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase def test_display_class_ambiguous util_multi_store - out, err = capture_io do + out, = capture_io do @driver.display_class 'Ambiguous' end @@ -325,7 +325,7 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase def test_display_class_multi_no_doc util_multi_store - out, err = capture_io do + out, = capture_io do @driver.display_class 'Foo::Baz' end @@ -339,7 +339,7 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase def test_display_class_superclass util_multi_store - out, err = capture_io do + out, = capture_io do @driver.display_class 'Bar' end @@ -349,7 +349,7 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase def test_display_class_module util_store - out, err = capture_io do + out, = capture_io do @driver.display_class 'Inc' end @@ -359,7 +359,7 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase def test_display_method util_store - out, err = capture_io do + out, = capture_io do @driver.display_method 'Foo::Bar#blah' end @@ -371,7 +371,7 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase def test_display_method_attribute util_store - out, err = capture_io do + out, = capture_io do @driver.display_method 'Foo::Bar#attr' end @@ -382,7 +382,7 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase def test_display_method_inherited util_multi_store - out, err = capture_io do + out, = capture_io do @driver.display_method 'Bar#inherit' end @@ -393,7 +393,7 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase def test_display_name_not_found_class util_store - out, err = capture_io do + out, = capture_io do assert_equal false, @driver.display_name('Foo::B') end @@ -410,7 +410,7 @@ Foo::Baz def test_display_name_not_found_method util_store - out, err = capture_io do + out, = capture_io do assert_equal false, @driver.display_name('Foo::Bar#b') end @@ -427,7 +427,7 @@ Foo::Bar#bother def test_display_method_params util_store - out, err = capture_io do + out, = capture_io do @driver.display_method 'Foo::Bar#bother' end @@ -496,24 +496,34 @@ Foo::Bar#bother end def test_formatter - driver = RDoc::RI::Driver.new - - io = Object.new - def io.tty?; false; end + tty = Object.new + def tty.tty?() true; end - assert_instance_of @RM::ToBs, driver.formatter(io) + driver = RDoc::RI::Driver.new - def io.tty?; true; end + assert_instance_of @RM::ToAnsi, driver.formatter(tty) - assert_instance_of @RM::ToAnsi, driver.formatter(io) + assert_instance_of @RM::ToBs, driver.formatter(StringIO.new) driver.instance_variable_set :@paging, true - assert_instance_of @RM::ToBs, driver.formatter(io) + assert_instance_of @RM::ToBs, driver.formatter(StringIO.new) driver.instance_variable_set :@formatter_klass, @RM::ToHtml - assert_instance_of @RM::ToHtml, driver.formatter(io) + assert_instance_of @RM::ToHtml, driver.formatter(tty) + end + + def test_in_path_eh + path = ENV['PATH'] + + refute @driver.in_path?('/nonexistent') + + ENV['PATH'] = File.expand_path '..', __FILE__ + + assert @driver.in_path?(File.basename(__FILE__)) + ensure + ENV['PATH'] = path end def test_method_type @@ -526,8 +536,8 @@ Foo::Bar#bother def test_list_known_classes util_store - out, err = capture_io do - @driver.list_known_classes + out, = capture_io do + @driver.list_known_classes end assert_equal "Ambiguous\nFoo\nFoo::Bar\nFoo::Baz\nInc\n", out diff --git a/test/rdoc/test_rdoc_ri_store.rb b/test/rdoc/test_rdoc_ri_store.rb index 4a52ded989..7c9f4ec80b 100644 --- a/test/rdoc/test_rdoc_ri_store.rb +++ b/test/rdoc/test_rdoc_ri_store.rb @@ -65,6 +65,10 @@ class TestRDocRIStore < MiniTest::Unit::TestCase assert File.file?(path), "#{path} is not a file" end + def refute_file path + refute File.exist?(path), "#{path} exists" + end + def test_attributes @s.cache[:attributes]['Object'] = %w[attr] @@ -94,6 +98,14 @@ class TestRDocRIStore < MiniTest::Unit::TestCase @s.class_path('Object::SubClass') end + def test_dry_run + refute @s.dry_run + + @s.dry_run = true + + assert @s.dry_run + end + def test_friendly_path @s.path = @tmpdir @s.type = nil @@ -198,7 +210,7 @@ class TestRDocRIStore < MiniTest::Unit::TestCase :instance_methods => { 'Object' => %w[method] }, :modules => %w[Object Object::SubClass], :ancestors => { - 'Object' => %w[Object], + 'Object' => %w[], 'Object::SubClass' => %w[Incl Object], }, } @@ -210,6 +222,19 @@ class TestRDocRIStore < MiniTest::Unit::TestCase end end + def test_save_cache_dry_run + @s.dry_run = true + + @s.save_class @klass + @s.save_method @klass, @meth + @s.save_method @klass, @cmeth + @s.save_class @nest_klass + + @s.save_cache + + refute_file File.join(@tmpdir, 'cache.ri') + end + def test_save_cache_duplicate_methods @s.save_method @klass, @meth @s.save_method @klass, @meth @@ -226,7 +251,7 @@ class TestRDocRIStore < MiniTest::Unit::TestCase assert_file File.join(@tmpdir, 'Object', 'cdesc-Object.ri') assert_cache({}, {}, { 'Object' => ['attr_accessor attr'] }, %w[Object], - 'Object' => %w[Object]) + 'Object' => %w[]) assert_equal @klass, @s.load_class('Object') end @@ -245,6 +270,15 @@ class TestRDocRIStore < MiniTest::Unit::TestCase assert_equal @klass, @s.load_class('Object') end + def test_save_class_dry_run + @s.dry_run = true + + @s.save_class @klass + + refute_file File.join(@tmpdir, 'Object') + refute_file File.join(@tmpdir, 'Object', 'cdesc-Object.ri') + end + def test_save_class_merge @s.save_class @klass @@ -270,7 +304,7 @@ class TestRDocRIStore < MiniTest::Unit::TestCase assert_file File.join(@tmpdir, 'Object', 'cdesc-Object.ri') assert_cache({}, {}, { 'Object' => ['attr_accessor attr'] }, %w[Object], - 'Object' => %w[Object]) + 'Object' => %w[]) assert_equal @klass, @s.load_class('Object') end @@ -296,6 +330,15 @@ class TestRDocRIStore < MiniTest::Unit::TestCase assert_equal @meth, @s.load_method('Object', '#method') end + def test_save_method_dry_run + @s.dry_run = true + + @s.save_method @klass, @meth + + refute_file File.join(@tmpdir, 'Object') + refute_file File.join(@tmpdir, 'Object', 'method-i.ri') + end + def test_save_method_nested @s.save_method @nest_klass, @nest_meth diff --git a/test/rdoc/test_rdoc_task.rb b/test/rdoc/test_rdoc_task.rb index e95ac46d4c..8eaff1f25b 100644 --- a/test/rdoc/test_rdoc_task.rb +++ b/test/rdoc/test_rdoc_task.rb @@ -42,7 +42,7 @@ class TestRDocTask < MiniTest::Unit::TestCase end def test_tasks_creation_with_custom_name_hash_will_use_default_if_an_option_isnt_given - rd = RDoc::Task.new(:clobber_rdoc => "rdoc:clean") + RDoc::Task.new(:clobber_rdoc => "rdoc:clean") assert Rake::Task[:rdoc] assert Rake::Task[:"rdoc:clean"] assert Rake::Task[:rerdoc] diff --git a/test/rdoc/test_rdoc_text.rb b/test/rdoc/test_rdoc_text.rb index 7e0f2cf0ba..600de30b0b 100644 --- a/test/rdoc/test_rdoc_text.rb +++ b/test/rdoc/test_rdoc_text.rb @@ -1,3 +1,5 @@ +# coding: utf-8 + require 'rubygems' require 'minitest/autorun' require 'rdoc' @@ -9,6 +11,15 @@ class TestRDocText < MiniTest::Unit::TestCase include RDoc::Text + def test_self_encode_fallback + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + assert_equal '…', + RDoc::Text::encode_fallback('…', Encoding::UTF_8, '...') + assert_equal '...', + RDoc::Text::encode_fallback('…', Encoding::US_ASCII, '...') + end + def test_expand_tabs assert_equal("hello\n dave", expand_tabs("hello\n dave"), 'spaces') @@ -46,9 +57,9 @@ class TestRDocText < MiniTest::Unit::TestCase def test_flush_left text = <<-TEXT - + we don't worry too much. - + The comments associated with TEXT @@ -65,7 +76,7 @@ The comments associated with def test_markup def formatter() RDoc::Markup::ToHtml.new end - assert_equal "<p>\nhi\n</p>\n", markup('hi') + assert_equal "<p>hi</p>", markup('hi').gsub("\n", '') end def test_normalize_comment @@ -114,9 +125,9 @@ The comments associated with TEXT expected = <<-EXPECTED - + we don't worry too much. - + The comments associated with EXPECTED @@ -143,15 +154,98 @@ The comments associated with TEXT expected = <<-EXPECTED - + * we don't worry too much. - + The comments associated with - EXPECTED assert_equal expected, strip_stars(text) end + def test_to_html_apostrophe + assert_equal '‘a', to_html("'a") + assert_equal 'a’', to_html("a'") + + assert_equal '‘a’ ‘', to_html("'a' '") + end + + def test_to_html_backslash + assert_equal 'S', to_html('\\S') + end + + def test_to_html_copyright + assert_equal '©', to_html('(c)') + end + + def test_to_html_dash + assert_equal '-', to_html('-') + assert_equal '–', to_html('--') + assert_equal '—', to_html('---') + assert_equal '—-', to_html('----') + end + + def test_to_html_double_backtick + assert_equal '“a', to_html('``a') + assert_equal '“a“', to_html('``a``') + end + + def test_to_html_double_quote + assert_equal '“a', to_html('"a') + assert_equal '“a”', to_html('"a"') + end + + def test_to_html_double_quote_quot + assert_equal '“a', to_html('"a') + assert_equal '“a”', to_html('"a"') + end + + def test_to_html_double_tick + assert_equal '”a', to_html("''a") + assert_equal '”a”', to_html("''a''") + end + + def test_to_html_ellipsis + assert_equal '..', to_html('..') + assert_equal '…', to_html('...') + assert_equal '.…', to_html('....') + end + + def test_to_html_encoding + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + s = '...(c)'.encode Encoding::Shift_JIS + + html = to_html s + + assert_equal Encoding::Shift_JIS, html.encoding + + expected = '…(c)'.encode Encoding::Shift_JIS + + assert_equal expected, html + end + + def test_to_html_html_tag + assert_equal '<a href="http://example">hi’s</a>', + to_html('<a href="http://example">hi\'s</a>') + end + + def test_to_html_registered_trademark + assert_equal '®', to_html('(r)') + end + + def test_to_html_tt_tag + assert_equal '<tt>hi\'s</tt>', to_html('<tt>hi\'s</tt>') + assert_equal '<tt>hi\\\'s</tt>', to_html('<tt>hi\\\\\'s</tt>') + end + + def test_to_html_tt_tag_mismatch + _, err = capture_io do + assert_equal '<tt>hi', to_html('<tt>hi') + end + + assert_equal "mismatched <tt> tag\n", err + end + end diff --git a/test/rdoc/test_rdoc_top_level.rb b/test/rdoc/test_rdoc_top_level.rb index b96b74c182..f40a42b3f6 100644 --- a/test/rdoc/test_rdoc_top_level.rb +++ b/test/rdoc/test_rdoc_top_level.rb @@ -27,6 +27,17 @@ class TestRDocTopLevel < XrefTestCase assert_equal expected, RDoc::TopLevel.classes.map { |m| m.full_name }.sort end + def test_class_complete + @c2.add_module_alias @c2_c3, 'A1' + + RDoc::TopLevel.complete :public + + a1 = @xref_data.find_class_or_module 'C2::A1' + + assert_equal 'C2::A1', a1.full_name + refute_empty a1.aliases + end + def test_class_files assert_equal %w[path/top_level.rb xref_data.rb], RDoc::TopLevel.files.map { |m| m.full_name }.sort @@ -94,13 +105,11 @@ class TestRDocTopLevel < XrefTestCase end def test_last_modified - assert_equal 'Unknown', @top_level.last_modified - + assert_equal nil, @top_level.last_modified stat = Object.new def stat.mtime() 0 end @top_level.file_stat = stat - - assert_equal '0', @top_level.last_modified + assert_equal 0, @top_level.last_modified end def test_name diff --git a/test/rdoc/xref_data.rb b/test/rdoc/xref_data.rb index ac1c39a915..3afb06bd13 100644 --- a/test/rdoc/xref_data.rb +++ b/test/rdoc/xref_data.rb @@ -13,9 +13,15 @@ class C1 def m foo end + end class C2 + def b + end + + alias a b + class C3 def m end @@ -46,6 +52,8 @@ class C5 end module M1 + def m + end end module M1::M2 diff --git a/test/rdoc/xref_test_case.rb b/test/rdoc/xref_test_case.rb index b40956684b..307e8f3350 100644 --- a/test/rdoc/xref_test_case.rb +++ b/test/rdoc/xref_test_case.rb @@ -38,7 +38,11 @@ class XrefTestCase < MiniTest::Unit::TestCase @c1_m = @c1.method_list.last # C1#m @c1__m = @c1.method_list.first # C1::m + @c2 = @xref_data.find_module_named 'C2' + @c2_a = @c2.method_list.last + @c2_b = @c2.method_list.first + @c2_c3 = @xref_data.find_module_named 'C2::C3' @c3 = @xref_data.find_module_named 'C3' @c4 = @xref_data.find_module_named 'C4' @@ -48,6 +52,8 @@ class XrefTestCase < MiniTest::Unit::TestCase @c3_h2 = @xref_data.find_module_named 'C3::H2' @m1 = @xref_data.find_module_named 'M1' + @m1_m = @m1.method_list.first + @m1_m2 = @xref_data.find_module_named 'M1::M2' end |