summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-27 03:45:22 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-27 03:45:22 +0000
commit336a8301f725bd8fbf5f1e0c4fee162382a76d0f (patch)
tree455c5fb8689d09e734a9ca13cdbe3ef9a7651a6e /test
parent3a87c3c5603fce8449f78faccaff5f4be6f372e1 (diff)
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')
-rw-r--r--test/rdoc/test_rdoc_markup_paragraph.rb18
-rw-r--r--test/rdoc/test_rdoc_markup_pre_process.rb138
-rw-r--r--test/rdoc/test_rdoc_markup_raw.rb27
-rw-r--r--test/rdoc/test_rdoc_markup_to_ansi.rb12
-rw-r--r--test/rdoc/test_rdoc_markup_to_bs.rb12
-rw-r--r--test/rdoc/test_rdoc_markup_to_html.rb12
-rw-r--r--test/rdoc/test_rdoc_markup_to_rdoc.rb12
-rw-r--r--test/rdoc/test_rdoc_options.rb20
-rw-r--r--test/rdoc/test_rdoc_parser_ruby.rb11
-rw-r--r--test/rdoc/test_rdoc_parser_simple.rb7
-rw-r--r--test/rdoc/test_rdoc_rdoc.rb55
11 files changed, 264 insertions, 60 deletions
diff --git a/test/rdoc/test_rdoc_markup_paragraph.rb b/test/rdoc/test_rdoc_markup_paragraph.rb
index 15f3b5f849..a1eba7038d 100644
--- a/test/rdoc/test_rdoc_markup_paragraph.rb
+++ b/test/rdoc/test_rdoc_markup_paragraph.rb
@@ -5,23 +5,5 @@ require 'rdoc/markup'
class TestRDocMarkupParagraph < MiniTest::Unit::TestCase
- def setup
- @RM = RDoc::Markup
- @p = @RM::Paragraph.new
- 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_push
- @p.push 'hi', 'there'
-
- assert_equal @RM::Paragraph.new('hi', 'there'), @p
- end
-
end
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
diff --git a/test/rdoc/test_rdoc_markup_raw.rb b/test/rdoc/test_rdoc_markup_raw.rb
new file mode 100644
index 0000000000..4e57b7df39
--- /dev/null
+++ b/test/rdoc/test_rdoc_markup_raw.rb
@@ -0,0 +1,27 @@
+require 'pp'
+require 'rubygems'
+require 'minitest/autorun'
+require 'rdoc/markup'
+
+class TestRDocMarkupRaw < MiniTest::Unit::TestCase
+
+ def setup
+ @RM = RDoc::Markup
+ @p = @RM::Raw.new
+ 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_push
+ @p.push 'hi', 'there'
+
+ assert_equal @RM::Raw.new('hi', 'there'), @p
+ end
+
+end
+
diff --git a/test/rdoc/test_rdoc_markup_to_ansi.rb b/test/rdoc/test_rdoc_markup_to_ansi.rb
index 97b4959571..a8fab98d19 100644
--- a/test/rdoc/test_rdoc_markup_to_ansi.rb
+++ b/test/rdoc/test_rdoc_markup_to_ansi.rb
@@ -175,6 +175,18 @@ class TestRDocMarkupToAnsi < RDoc::Markup::FormatterTestCase
assert_equal "\e[0mhi\n", @to.res.join
end
+ def accept_raw
+ raw = <<-RAW.rstrip
+\e[0m<table>
+<tr><th>Name<th>Count
+<tr><td>a<td>1
+<tr><td>b<td>2
+</table>
+ RAW
+
+ assert_equal raw, @to.res.join
+ end
+
def accept_rule
assert_equal "\e[0m#{'-' * 78}\n", @to.res.join
end
diff --git a/test/rdoc/test_rdoc_markup_to_bs.rb b/test/rdoc/test_rdoc_markup_to_bs.rb
index a82d462ad8..c042452637 100644
--- a/test/rdoc/test_rdoc_markup_to_bs.rb
+++ b/test/rdoc/test_rdoc_markup_to_bs.rb
@@ -174,6 +174,18 @@ class TestRDocMarkupToBs < RDoc::Markup::FormatterTestCase
assert_equal "hi\n", @to.res.join
end
+ def accept_raw
+ raw = <<-RAW.rstrip
+<table>
+<tr><th>Name<th>Count
+<tr><td>a<td>1
+<tr><td>b<td>2
+</table>
+ RAW
+
+ assert_equal raw, @to.res.join
+ end
+
def accept_rule
assert_equal "#{'-' * 78}\n", @to.res.join
end
diff --git a/test/rdoc/test_rdoc_markup_to_html.rb b/test/rdoc/test_rdoc_markup_to_html.rb
index 29cef00a0c..f6014391c8 100644
--- a/test/rdoc/test_rdoc_markup_to_html.rb
+++ b/test/rdoc/test_rdoc_markup_to_html.rb
@@ -170,6 +170,18 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase
assert_equal "<p>\nhi\n</p>\n", @to.res.join
end
+ def accept_raw
+ raw = <<-RAW.rstrip
+<table>
+<tr><th>Name<th>Count
+<tr><td>a<td>1
+<tr><td>b<td>2
+</table>
+ RAW
+
+ assert_equal raw, @to.res.join
+ end
+
def accept_rule
assert_equal '<hr style="height: 4px"></hr>', @to.res.join
end
diff --git a/test/rdoc/test_rdoc_markup_to_rdoc.rb b/test/rdoc/test_rdoc_markup_to_rdoc.rb
index e2ccc6c62e..ac6884ba58 100644
--- a/test/rdoc/test_rdoc_markup_to_rdoc.rb
+++ b/test/rdoc/test_rdoc_markup_to_rdoc.rb
@@ -175,6 +175,18 @@ class TestRDocMarkupToRdoc < RDoc::Markup::FormatterTestCase
assert_equal "hi\n", @to.res.join
end
+ def accept_raw
+ raw = <<-RAW.rstrip
+<table>
+<tr><th>Name<th>Count
+<tr><td>a<td>1
+<tr><td>b<td>2
+</table>
+ RAW
+
+ assert_equal raw, @to.res.join
+ end
+
def accept_rule
assert_equal "#{'-' * 78}\n", @to.res.join
end
diff --git a/test/rdoc/test_rdoc_options.rb b/test/rdoc/test_rdoc_options.rb
index 62a5b2db54..f4a8d51c8e 100644
--- a/test/rdoc/test_rdoc_options.rb
+++ b/test/rdoc/test_rdoc_options.rb
@@ -50,5 +50,25 @@ class TestRDocOptions < MiniTest::Unit::TestCase
assert_equal 'MAIN', @options.main_page
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
+ end
+
+ def test_parse_dash_p_files
+ out, err = capture_io do
+ @options.parse %w[-p README]
+ end
+
+ refute @options.pipe
+ refute_match %r%^Usage: %, err
+ assert_match %r%^invalid options: -p .with files.%, err
+ end
+
end
diff --git a/test/rdoc/test_rdoc_parser_ruby.rb b/test/rdoc/test_rdoc_parser_ruby.rb
index f4bd50ba16..988bc507cd 100644
--- a/test/rdoc/test_rdoc_parser_ruby.rb
+++ b/test/rdoc/test_rdoc_parser_ruby.rb
@@ -151,16 +151,9 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
def test_look_for_directives_in_unhandled
util_parser ""
- comment = "# :unhandled: \n# :markup: not rdoc\n# :title: hi\n"
+ @parser.look_for_directives_in @top_level, "# :unhandled: blah\n"
- @parser.look_for_directives_in @top_level, comment
-
- assert_equal "# :unhandled: \n# :markup: not rdoc\n", comment
-
- assert_equal nil, @top_level.metadata['unhandled']
- assert_equal 'not rdoc', @top_level.metadata['markup']
-
- assert_equal 'hi', @options.title
+ assert_equal 'blah', @top_level.metadata['unhandled']
end
def test_parse_alias
diff --git a/test/rdoc/test_rdoc_parser_simple.rb b/test/rdoc/test_rdoc_parser_simple.rb
index a83f105edd..d09cced5a4 100644
--- a/test/rdoc/test_rdoc_parser_simple.rb
+++ b/test/rdoc/test_rdoc_parser_simple.rb
@@ -23,12 +23,11 @@ class TestRDocParserSimple < MiniTest::Unit::TestCase
end
def test_initialize_metadata
- parser = util_parser ":unhandled: \n# :markup: not rdoc\n"
+ parser = util_parser ":unhandled: \n"
- assert_equal nil, @top_level.metadata['unhandled']
- assert_equal 'not rdoc', @top_level.metadata['markup']
+ assert_includes @top_level.metadata, 'unhandled'
- assert_equal ":unhandled: \n# :markup: not rdoc\n", parser.content
+ assert_equal ":unhandled: \n", parser.content
end
def test_remove_coding_comment
diff --git a/test/rdoc/test_rdoc_rdoc.rb b/test/rdoc/test_rdoc_rdoc.rb
index 772ba4c3b1..866667c494 100644
--- a/test/rdoc/test_rdoc_rdoc.rb
+++ b/test/rdoc/test_rdoc_rdoc.rb
@@ -82,50 +82,47 @@ class TestRDocRDoc < MiniTest::Unit::TestCase
end
def test_setup_output_dir
- path = @tempfile.path
- @tempfile.unlink
+ skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir
- last = @rdoc.setup_output_dir path, false
+ Dir.mktmpdir {|d|
+ path = File.join(d, 'testdir')
- assert_empty last
+ last = @rdoc.setup_output_dir path, false
- assert File.directory? path
- ensure
- FileUtils.rm_f path
+ assert_empty last
+
+ assert File.directory? path
+ }
end
def test_setup_output_dir_exists
- path = @tempfile.path
- @tempfile.unlink
- FileUtils.mkdir_p path
+ skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir
- open @rdoc.output_flag_file(path), 'w' do |io|
- io.puts Time.at 0
- io.puts "./lib/rdoc.rb\t#{Time.at 86400}"
- end
+ Dir.mktmpdir {|path|
+ open @rdoc.output_flag_file(path), 'w' do |io|
+ io.puts Time.at 0
+ io.puts "./lib/rdoc.rb\t#{Time.at 86400}"
+ end
- last = @rdoc.setup_output_dir path, false
+ last = @rdoc.setup_output_dir path, false
- assert_equal 1, last.size
- assert_equal Time.at(86400), last['./lib/rdoc.rb']
- ensure
- FileUtils.rm_f path
+ assert_equal 1, last.size
+ assert_equal Time.at(86400), last['./lib/rdoc.rb']
+ }
end
def test_setup_output_dir_exists_empty_created_rid
- path = @tempfile.path
- @tempfile.unlink
- FileUtils.mkdir_p path
+ skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir
- open @rdoc.output_flag_file(path), 'w' do end
+ Dir.mktmpdir {|path|
+ open @rdoc.output_flag_file(path), 'w' do end
- e = assert_raises RDoc::Error do
- @rdoc.setup_output_dir path, false
- end
+ e = assert_raises RDoc::Error do
+ @rdoc.setup_output_dir path, false
+ end
- assert_match %r%Directory #{Regexp.escape path} already exists%, e.message
- ensure
- FileUtils.rm_f path
+ assert_match %r%Directory #{Regexp.escape path} already exists%, e.message
+ }
end
def test_setup_output_dir_exists_file