diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-04-27 03:45:22 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-04-27 03:45:22 +0000 |
commit | 336a8301f725bd8fbf5f1e0c4fee162382a76d0f (patch) | |
tree | 455c5fb8689d09e734a9ca13cdbe3ef9a7651a6e /test/rdoc/test_rdoc_markup_pre_process.rb | |
parent | 3a87c3c5603fce8449f78faccaff5f4be6f372e1 (diff) | |
download | ruby-336a8301f725bd8fbf5f1e0c4fee162382a76d0f.tar.gz |
Import RDoc 2.5.7. Fixes #1318 and ruby-core:29780
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rdoc/test_rdoc_markup_pre_process.rb')
-rw-r--r-- | test/rdoc/test_rdoc_markup_pre_process.rb | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/test/rdoc/test_rdoc_markup_pre_process.rb b/test/rdoc/test_rdoc_markup_pre_process.rb index 5f1b22db4d..9c90a2782a 100644 --- a/test/rdoc/test_rdoc_markup_pre_process.rb +++ b/test/rdoc/test_rdoc_markup_pre_process.rb @@ -2,10 +2,13 @@ require 'tempfile' require 'rubygems' require 'minitest/autorun' require 'rdoc/markup/preprocess' +require 'rdoc/code_objects' class TestRDocMarkupPreProcess < MiniTest::Unit::TestCase def setup + RDoc::Markup::PreProcess.registered.clear + @tempfile = Tempfile.new 'test_rdoc_markup_pre_process' @name = File.basename @tempfile.path @dir = File.dirname @tempfile.path @@ -38,5 +41,140 @@ contents of a string. assert_equal expected, content end + def test_handle + text = "# :x: y\n" + out = @pp.handle text + + assert_same out, text + assert_equal "# :x: y\n", text + end + + def test_handle_block + text = "# :x: y\n" + + @pp.handle text do |directive, param| + false + end + + assert_equal "# :x: y\n", text + + @pp.handle text do |directive, param| + '' + end + + assert_equal "", text + end + + def test_handle_code_object + cd = RDoc::CodeObject.new + text = "# :x: y\n" + @pp.handle text, cd + + assert_equal "# :x: y\n", text + assert_equal 'y', cd.metadata['x'] + + cd.metadata.clear + text = "# :x:\n" + @pp.handle text, cd + + assert_equal "# :x: \n", text + assert_includes cd.metadata, 'x' + end + + def test_handle_code_object_block + cd = RDoc::CodeObject.new + text = "# :x: y\n" + @pp.handle text, cd do + false + end + + assert_equal "# :x: y\n", text + assert_empty cd.metadata + + @pp.handle text, cd do + nil + end + + assert_equal "# :x: y\n", text + assert_equal 'y', cd.metadata['x'] + + cd.metadata.clear + + @pp.handle text, cd do + '' + end + + assert_equal '', text + assert_empty cd.metadata + end + + def test_handle_registered + RDoc::Markup::PreProcess.register 'x' + text = "# :x: y\n" + @pp.handle text + + assert_equal '', text + + text = "# :x: y\n" + + @pp.handle text do |directive, param| + false + end + + assert_equal "# :x: y\n", text + + text = "# :x: y\n" + + @pp.handle text do |directive, param| + '' + end + + assert_equal "", text + end + + def test_handle_registered_block + called = nil + RDoc::Markup::PreProcess.register 'x' do |directive, param| + called = [directive, param] + 'blah' + end + + text = "# :x: y\n" + @pp.handle text + + assert_equal 'blah', text + assert_equal %w[x y], called + end + + def test_handle_registered_code_object + RDoc::Markup::PreProcess.register 'x' + cd = RDoc::CodeObject.new + + text = "# :x: y\n" + @pp.handle text, cd + + assert_equal '', text + assert_equal 'y', cd.metadata['x'] + + cd.metadata.clear + text = "# :x: y\n" + + @pp.handle text do |directive, param| + false + end + + assert_equal "# :x: y\n", text + assert_empty cd.metadata + + text = "# :x: y\n" + + @pp.handle text do |directive, param| + '' + end + + assert_equal "", text + assert_empty cd.metadata + end + end |