diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-07-31 00:19:00 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-07-31 00:19:00 +0000 |
commit | 89b601d176a64f1293a3d3b5195b6735cbf880af (patch) | |
tree | c7f148e8cf8576202220ce567dc8b9a698e4b114 /test/rdoc/test_rdoc_markup_pre_process.rb | |
parent | 4ac69a57b5e8587a321b052212ae5b9bedeafe55 (diff) | |
download | ruby-89b601d176a64f1293a3d3b5195b6735cbf880af.tar.gz |
* lib/rdoc: Update to RDoc 3.9. Fixed `ri []`, stopdoc creating an
object reference, nodoc for class aliases, verbatim === lines.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32767 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 | 340 |
1 files changed, 269 insertions, 71 deletions
diff --git a/test/rdoc/test_rdoc_markup_pre_process.rb b/test/rdoc/test_rdoc_markup_pre_process.rb index 587a680f28..9a0a302b3e 100644 --- a/test/rdoc/test_rdoc_markup_pre_process.rb +++ b/test/rdoc/test_rdoc_markup_pre_process.rb @@ -5,6 +5,7 @@ require 'rubygems' require 'minitest/autorun' require 'rdoc/markup/pre_process' require 'rdoc/code_objects' +require 'rdoc/options' class TestRDocMarkupPreProcess < MiniTest::Unit::TestCase @@ -19,6 +20,8 @@ class TestRDocMarkupPreProcess < MiniTest::Unit::TestCase end def teardown + RDoc::Markup::PreProcess.registered.clear + @tempfile.close end @@ -73,6 +76,14 @@ contents of a string. end def test_handle + text = "# :main: M\n" + out = @pp.handle text + + assert_same out, text + assert_equal "#\n", text + end + + def test_handle_unregistered text = "# :x: y\n" out = @pp.handle text @@ -80,142 +91,329 @@ contents of a string. assert_equal "# :x: y\n", text end - def test_handle_block - text = "# :x: y\n" + def test_handle_directive_blankline + result = @pp.handle_directive '#', 'arg', 'a, b' + + assert_equal "#\n", result + end + + def test_handle_directive_downcase + method = RDoc::AnyMethod.new nil, 'm' + + @pp.handle_directive '', 'ARG', 'a, b', method + + assert_equal 'a, b', method.params + end + + def test_handle_directive_arg + method = RDoc::AnyMethod.new nil, 'm' + + @pp.handle_directive '', 'arg', 'a, b', method + + assert_equal 'a, b', method.params + end + + def test_handle_directive_arg_no_context + result = @pp.handle_directive '', 'arg', 'a, b', nil + + assert_equal "\n", result + end + + def test_handle_directive_args + method = RDoc::AnyMethod.new nil, 'm' - @pp.handle text do |directive, param| + @pp.handle_directive '', 'args', 'a, b', method + + assert_equal 'a, b', method.params + end + + def test_handle_directive_block + result = @pp.handle_directive '', 'x', 'y' do |directive, param| + '' + end + + assert_empty result + end + + def test_handle_directive_block_false + result = @pp.handle_directive '', 'x', 'y' do |directive, param| false end - assert_equal "# :x: y\n", text + assert_equal ":x: y\n", result + end - @pp.handle text do |directive, param| - '' + def test_handle_directive_block_nil + result = @pp.handle_directive '', 'x', 'y' do |directive, param| + nil end - assert_equal "", text + assert_equal ":x: y\n", result end - def test_handle_category + def test_handle_directive_category context = RDoc::Context.new original_section = context.current_section - text = "# :category: other\n" - - @pp.handle text, context + @pp.handle_directive '', 'category', 'other', context refute_equal original_section, context.current_section end - def test_handle_code_object - cd = RDoc::CodeObject.new - text = "# :x: y\n" - @pp.handle text, cd + def test_handle_directive_doc + code_object = RDoc::CodeObject.new + code_object.document_self = false + code_object.force_documentation = false - assert_equal "# :x: y\n", text - assert_equal 'y', cd.metadata['x'] + @pp.handle_directive '', 'doc', nil, code_object + + assert code_object.document_self + assert code_object.force_documentation + end - cd.metadata.clear - text = "# :x:\n" - @pp.handle text, cd + def test_handle_directive_doc_no_context + result = @pp.handle_directive '', 'doc', nil - assert_equal "# :x: \n", text - assert_includes cd.metadata, 'x' + assert_equal "\n", result end - def test_handle_code_object_block - cd = RDoc::CodeObject.new - text = "# :x: y\n" - @pp.handle text, cd do - false - end + def test_handle_directive_enddoc + code_object = RDoc::CodeObject.new - assert_equal "# :x: y\n", text - assert_empty cd.metadata + @pp.handle_directive '', 'enddoc', nil, code_object - @pp.handle text, cd do - nil - end + assert code_object.done_documenting + end - assert_equal "# :x: y\n", text - assert_equal 'y', cd.metadata['x'] + def test_handle_directive_include + @tempfile.write 'included' + @tempfile.flush - cd.metadata.clear + result = @pp.handle_directive '', 'include', @file_name - @pp.handle text, cd do - '' - end + assert_equal 'included', result + end + + def test_handle_directive_main + @pp.options = RDoc::Options.new + + @pp.handle_directive '', 'main', 'M' + + assert_equal 'M', @pp.options.main_page + end + + def test_handle_directive_notnew + m = RDoc::AnyMethod.new nil, 'm' + + @pp.handle_directive '', 'notnew', nil, m + + assert m.dont_rename_initialize + end + + def test_handle_directive_not_new + m = RDoc::AnyMethod.new nil, 'm' + + @pp.handle_directive '', 'not_new', nil, m + + assert m.dont_rename_initialize + end + + def test_handle_directive_not_dash_new + m = RDoc::AnyMethod.new nil, 'm' + + @pp.handle_directive '', 'not-new', nil, m + + assert m.dont_rename_initialize + end + + def test_handle_directive_nodoc + code_object = RDoc::CodeObject.new + code_object.document_self = true + code_object.document_children = true - assert_equal '', text - assert_empty cd.metadata + @pp.handle_directive '', 'nodoc', nil, code_object + + refute code_object.document_self + assert code_object.document_children + end + + def test_handle_directive_nodoc_all + code_object = RDoc::CodeObject.new + code_object.document_self = true + code_object.document_children = true + + @pp.handle_directive '', 'nodoc', 'all', code_object + + refute code_object.document_self + refute code_object.document_children end - def test_handle_registered + def test_handle_directive_nodoc_no_context + result = @pp.handle_directive '', 'nodoc', nil + + assert_equal "\n", result + end + + def test_handle_directive_registered RDoc::Markup::PreProcess.register 'x' - text = "# :x: y\n" - @pp.handle text - assert_equal '', text + result = @pp.handle_directive '', 'x', 'y' - text = "# :x: y\n" + assert_nil result - @pp.handle text do |directive, param| + result = @pp.handle_directive '', 'x', 'y' do |directive, param| false end - assert_equal "# :x: y\n", text - - text = "# :x: y\n" + assert_equal ":x: y\n", result - @pp.handle text do |directive, param| + result = @pp.handle_directive '', 'x', 'y' do |directive, param| '' end - assert_equal "", text + assert_equal '', result end - def test_handle_registered_block + def test_handle_directive_registered_block called = nil + RDoc::Markup::PreProcess.register 'x' do |directive, param| called = [directive, param] 'blah' end - text = "# :x: y\n" - @pp.handle text + result = @pp.handle_directive '', 'x', 'y' - assert_equal 'blah', text + assert_equal 'blah', result assert_equal %w[x y], called end - def test_handle_registered_code_object + def test_handle_directive_registered_code_object RDoc::Markup::PreProcess.register 'x' - cd = RDoc::CodeObject.new + code_object = RDoc::CodeObject.new - text = "# :x: y\n" - @pp.handle text, cd + @pp.handle_directive '', 'x', 'y', code_object - assert_equal '', text - assert_equal 'y', cd.metadata['x'] + assert_equal 'y', code_object.metadata['x'] - cd.metadata.clear - text = "# :x: y\n" + code_object.metadata.clear - @pp.handle text do |directive, param| + result = @pp.handle_directive '', 'x', 'y' do |directive, param| false end - assert_equal "# :x: y\n", text - assert_empty cd.metadata + assert_equal ":x: y\n", result + assert_empty code_object.metadata - text = "# :x: y\n" + result = @pp.handle_directive '', 'x', 'y' do |directive, param| + '' + end + + assert_equal '', result + assert_empty code_object.metadata + end + + def test_handle_directive_startdoc + code_object = RDoc::CodeObject.new + code_object.stop_doc + code_object.force_documentation = false + + @pp.handle_directive '', 'startdoc', nil, code_object + + assert code_object.document_self + assert code_object.document_children + assert code_object.force_documentation + end + + def test_handle_directive_stopdoc + code_object = RDoc::CodeObject.new + + @pp.handle_directive '', 'stopdoc', nil, code_object + + refute code_object.document_self + refute code_object.document_children + end + + def test_handle_directive_title + @pp.options = RDoc::Options.new + + @pp.handle_directive '', 'title', 'T' + + assert_equal 'T', @pp.options.title + end + + def test_handle_directive_unhandled + code_object = RDoc::CodeObject.new + + @pp.handle_directive '', 'x', 'y', code_object + + assert_equal 'y', code_object.metadata['x'] + + code_object.metadata.clear + + @pp.handle_directive '', 'x', '', code_object + + assert_includes code_object.metadata, 'x' + end + + def test_handle_directive_unhandled_block + code_object = RDoc::CodeObject.new + + @pp.handle_directive '', 'x', 'y', code_object do + false + end + + assert_empty code_object.metadata + + @pp.handle_directive '', 'x', 'y', code_object do + nil + end + + assert_equal 'y', code_object.metadata['x'] - @pp.handle text do |directive, param| + code_object.metadata.clear + + @pp.handle_directive '', 'x', 'y', code_object do '' end - assert_equal "", text - assert_empty cd.metadata + assert_empty code_object.metadata + end + + def test_handle_directive_yield + method = RDoc::AnyMethod.new nil, 'm' + method.params = 'index, &block' + + @pp.handle_directive '', 'yield', 'item', method + + assert_equal 'item', method.block_params + assert_equal 'index', method.params + end + + def test_handle_directive_yield_block_param + method = RDoc::AnyMethod.new nil, 'm' + method.params = '&block' + + @pp.handle_directive '', 'yield', 'item', method + + assert_equal 'item', method.block_params + assert_empty method.params + end + + def test_handle_directive_yield_no_context + method = RDoc::AnyMethod.new nil, 'm' + + @pp.handle_directive '', 'yield', 'item', method + + assert_equal 'item', method.block_params + end + + def test_handle_directive_yields + method = RDoc::AnyMethod.new nil, 'm' + + @pp.handle_directive '', 'yields', 'item', method + + assert_equal 'item', method.block_params end end |