From 1c279a7d2753949c725754e1302f791b76358114 Mon Sep 17 00:00:00 2001 From: drbrain Date: Tue, 27 Nov 2012 04:28:14 +0000 Subject: * lib/rdoc*: Updated to RDoc 4.0 (pre-release) * bin/rdoc: ditto * test/rdoc: ditto * NEWS: Updated with RDoc 4.0 information git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37889 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rdoc/test_rdoc_context_section.rb | 123 +++++++++++++++++++++++++++------ 1 file changed, 103 insertions(+), 20 deletions(-) (limited to 'test/rdoc/test_rdoc_context_section.rb') diff --git a/test/rdoc/test_rdoc_context_section.rb b/test/rdoc/test_rdoc_context_section.rb index d37a4d222e..716d3ae6bb 100644 --- a/test/rdoc/test_rdoc_context_section.rb +++ b/test/rdoc/test_rdoc_context_section.rb @@ -1,14 +1,49 @@ -require 'rubygems' -require 'cgi' -require 'minitest/autorun' -require 'rdoc' -require 'rdoc/code_objects' +require 'rdoc/test_case' -class TestRDocContextSection < MiniTest::Unit::TestCase +class TestRDocContextSection < RDoc::TestCase def setup + super + + @top_level = @store.add_file 'file.rb' + + @klass = @top_level.add_class RDoc::NormalClass, 'Object' + @S = RDoc::Context::Section - @s = @S.new nil, 'section', '# comment' + @s = @S.new @klass, 'section', comment('# comment', @top_level) + end + + def mu_pp obj + s = '' + s = PP.pp obj, s + s.force_encoding Encoding.default_external if defined? Encoding + s.chomp + end + + def test_add_comment + file1 = @store.add_file 'file1.rb' + + klass = file1.add_class RDoc::NormalClass, 'Klass' + + c1 = RDoc::Comment.new "# :section: section\n", file1 + c2 = RDoc::Comment.new "# hello\n", file1 + c3 = RDoc::Comment.new "# world\n", file1 + + s = @S.new klass, 'section', c1 + + assert_empty s.comments + + s.add_comment nil + + assert_empty s.comments + + s.add_comment c2 + + assert_equal [c2], s.comments + + s.add_comment c3 + + assert_equal [c2, c3], s.comments end def test_aref @@ -19,27 +54,75 @@ class TestRDocContextSection < MiniTest::Unit::TestCase assert_equal 'one+two', @S.new(nil, 'one two', nil).aref end - def test_comment_equals - @s.comment = "# :section: section\n" + def test_extract_comment + assert_equal '', @s.extract_comment(comment('')).text + assert_equal '', @s.extract_comment(comment("# :section: b\n")).text + assert_equal '# c', @s.extract_comment(comment("# :section: b\n# c")).text + assert_equal '# c', + @s.extract_comment(comment("# a\n# :section: b\n# c")).text + end + + def test_marshal_dump + loaded = Marshal.load Marshal.dump @s - assert_equal "# comment", @s.comment + expected = RDoc::Comment.new('comment', @top_level).parse + expected = doc(expected) - @s.comment = "# :section: section\n# other" + assert_equal 'section', loaded.title + assert_equal expected, loaded.comments + assert_nil loaded.parent, 'parent is set manually' + end - assert_equal "# comment\n# ---\n# other", @s.comment + def test_marshal_dump_no_comment + s = @S.new @klass, 'section', comment('') - s = @S.new nil, nil, nil + loaded = Marshal.load Marshal.dump s + + assert_equal 'section', loaded.title + assert_empty loaded.comments + assert_nil loaded.parent, 'parent is set manually' + end - s.comment = "# :section:\n# other" + def test_marshal_load_version_0 + loaded = Marshal.load "\x04\bU:\eRDoc::Context::Section" + + "[\bi\x00I\"\fsection\x06:\x06EFo" + + ":\eRDoc::Markup::Document\a:\v@parts" + + "[\x06o;\a\a;\b[\x06o" + + ":\x1CRDoc::Markup::Paragraph\x06;\b" + + "[\x06I\"\fcomment\x06;\x06F:\n@fileI" + + "\"\ffile.rb\x06;\x06F;\n0" - assert_equal "# other", s.comment + expected = doc RDoc::Comment.new('comment', @top_level).parse + + assert_equal 'section', loaded.title + assert_equal expected, loaded.comments + assert_nil loaded.parent, 'parent is set manually' 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") + def test_remove_comment_array + other = @store.add_file 'other.rb' + + other_comment = comment('bogus', other) + + @s.add_comment other_comment + + @s.remove_comment comment('bogus', @top_level) + + assert_equal [other_comment], @s.comments + end + + def test_remove_comment_document + other = @store.add_file 'other.rb' + + other_comment = comment('bogus', other) + + @s.add_comment other_comment + + loaded = Marshal.load Marshal.dump @s + + loaded.remove_comment comment('bogus', @top_level) + + assert_equal doc(other_comment.parse), loaded.comments end def test_sequence -- cgit v1.2.3