diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/rdoc/test_rdoc_any_method.rb | 8 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_context.rb | 65 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_context_section.rb | 54 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_options.rb | 26 | ||||
-rw-r--r-- | test/rdoc/xref_data.rb | 5 |
5 files changed, 149 insertions, 9 deletions
diff --git a/test/rdoc/test_rdoc_any_method.rb b/test/rdoc/test_rdoc_any_method.rb index 2104322c91..930d9773bd 100644 --- a/test/rdoc/test_rdoc_any_method.rb +++ b/test/rdoc/test_rdoc_any_method.rb @@ -47,7 +47,7 @@ method(a, b) { |c, d| ... } def test_markup_code tokens = [ RDoc::RubyToken::TkCONSTANT. new(0, 0, 0, 'CONSTANT'), - RDoc::RubyToken::TkKW. new(0, 0, 0, 'KW'), + RDoc::RubyToken::TkDEF. 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'), @@ -90,6 +90,12 @@ method(a, b) { |c, d| ... } assert_equal 'C1', instance_method.parent_name assert_equal '(foo)', instance_method.params + aliased_method = Marshal.load Marshal.dump(@c2.method_list.last) + + assert_equal 'C2#a', aliased_method.full_name + assert_equal 'C2', aliased_method.parent_name + assert_equal '()', aliased_method.params + class_method = Marshal.load Marshal.dump(@c1.method_list.first) assert_equal 'C1::m', class_method.full_name diff --git a/test/rdoc/test_rdoc_context.rb b/test/rdoc/test_rdoc_context.rb index 9f110fc9f8..71870c545f 100644 --- a/test/rdoc/test_rdoc_context.rb +++ b/test/rdoc/test_rdoc_context.rb @@ -251,6 +251,34 @@ class TestRDocContext < XrefTestCase refute_equal @c2_c3, @c3 end + def test_each_section + sects = [] + consts = [] + attrs = [] + + @c1.each_section do |section, constants, attributes| + sects << section + consts << constants + attrs << attributes + end + + assert_equal [nil, 'separate'], sects.map { |section| section.title } + + expected_consts = [ + [@c1.constants.first], + [], + ] + + assert_equal expected_consts, consts + + expected_attrs = [ + [@c1.attributes[0], @c1.attributes[3]], + [@c1.attributes[1], @c1.attributes[2]], + ] + + assert_equal expected_attrs, attrs + end + def test_find_attribute_named assert_equal nil, @c1.find_attribute_named('none') assert_equal 'R', @c1.find_attribute_named('attr').rw @@ -373,5 +401,42 @@ class TestRDocContext < XrefTestCase assert_equal(-1, @c2_c3.<=>(@c3)) end + def test_methods_by_type + expected = { + 'instance' => { + :private => [], + :protected => [], + :public => [@c1_m], + }, + 'class' => { + :private => [], + :protected => [], + :public => [@c1__m], + }, + } + + assert_equal expected, @c1.methods_by_type + end + + def test_methods_by_type_section + separate = @c1.sections_hash['separate'] + @c1_m.section = separate + + expected = { + 'instance' => { + :private => [], + :protected => [], + :public => [@c1_m], + }, + 'class' => { + :private => [], + :protected => [], + :public => [], + }, + } + + assert_equal expected, @c1.methods_by_type(separate) + end + end diff --git a/test/rdoc/test_rdoc_context_section.rb b/test/rdoc/test_rdoc_context_section.rb new file mode 100644 index 0000000000..1636c98246 --- /dev/null +++ b/test/rdoc/test_rdoc_context_section.rb @@ -0,0 +1,54 @@ +require 'rubygems' +require 'cgi' +require 'minitest/autorun' +require 'rdoc' +require 'rdoc/code_objects' + +class TestRDocContextSection < MiniTest::Unit::TestCase + + def setup + @S = RDoc::Context::Section + @s = @S.new nil, 'section', '# comment' + end + + def test_aref + assert_equal 'section', @s.aref + + assert_equal '5Buntitled-5D', @S.new(nil, nil, nil).aref + + assert_equal 'one+two', @S.new(nil, 'one two', nil).aref + end + + def test_comment_equals + @s.comment = "# :section: section\n" + + assert_equal "# comment", @s.comment + + @s.comment = "# :section: section\n# other" + + assert_equal "# comment\n# ---\n# other", @s.comment + + s = @S.new nil, nil, nil + + s.comment = "# :section:\n# other" + + assert_equal "# other", s.comment + end + + def test_extract_comment + assert_equal '', @s.extract_comment('') + assert_equal '', @s.extract_comment("# :section: b\n") + assert_equal '# c', @s.extract_comment("# :section: b\n# c") + assert_equal '# c', @s.extract_comment("# a\n# :section: b\n# c") + end + + def test_sequence + _, err = capture_io do + assert_match(/\ASEC\d{5}\Z/, @s.sequence) + end + + assert_equal "#{@S}#sequence is deprecated, use #aref\n", err + end + +end + diff --git a/test/rdoc/test_rdoc_options.rb b/test/rdoc/test_rdoc_options.rb index 763f50b5f0..8e5ec853cc 100644 --- a/test/rdoc/test_rdoc_options.rb +++ b/test/rdoc/test_rdoc_options.rb @@ -17,16 +17,26 @@ class TestRDocOptions < MiniTest::Unit::TestCase end def test_check_files - skip "assumes UNIX permission model" if /mswin|mingw/ =~ RUBY_PLATFORM 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 + begin + unreadable = nil # variable for windows + + Dir.chdir dir do + if RUBY_PLATFORM =~ /mswin|mingw/ then + unreadable = open 'unreadable' + File.delete 'unreadable' + else + FileUtils.touch 'unreadable' + FileUtils.chmod 0, 'unreadable' + end + + @options.files = %w[nonexistent unreadable] + + @options.check_files + end + ensure + unreadable.close if unreadable end end end diff --git a/test/rdoc/xref_data.rb b/test/rdoc/xref_data.rb index 3afb06bd13..5a7e98d671 100644 --- a/test/rdoc/xref_data.rb +++ b/test/rdoc/xref_data.rb @@ -2,8 +2,13 @@ XREF_DATA = <<-XREF_DATA class C1 attr :attr + + # :section: separate + attr_reader :attr_reader attr_writer :attr_writer + + # :section: attr_accessor :attr_accessor CONST = :const |