From e2efe8e81dc7e9fce40b024df6a20bbf4b830350 Mon Sep 17 00:00:00 2001 From: drbrain Date: Tue, 28 Dec 2010 22:08:56 +0000 Subject: Import RDoc 3.1 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30413 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rdoc/test.ja.large.rdoc | 3 ++ test/rdoc/test_rdoc_encoding.rb | 27 +++++++++-- test/rdoc/test_rdoc_markup_to_html.rb | 5 ++ test/rdoc/test_rdoc_options.rb | 53 +++++++++++++++++++-- test/rdoc/test_rdoc_parser.rb | 5 ++ test/rdoc/test_rdoc_parser_c.rb | 65 +++++++++++++++++++++++++ test/rdoc/test_rdoc_parser_ruby.rb | 89 +++++++++++++++++++++++++++++++++++ test/rdoc/test_rdoc_ri_paths.rb | 9 +--- test/rdoc/test_rdoc_ruby_lex.rb | 23 +++++++++ test/rdoc/test_rdoc_stats.rb | 38 +++++++++++++++ test/rdoc/test_rdoc_task.rb | 28 +++++++++++ 11 files changed, 330 insertions(+), 15 deletions(-) create mode 100644 test/rdoc/test.ja.large.rdoc create mode 100644 test/rdoc/test_rdoc_ruby_lex.rb create mode 100644 test/rdoc/test_rdoc_stats.rb (limited to 'test') diff --git a/test/rdoc/test.ja.large.rdoc b/test/rdoc/test.ja.large.rdoc new file mode 100644 index 0000000000..a9c6c4691c --- /dev/null +++ b/test/rdoc/test.ja.large.rdoc @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + 吾輩(わがはい)は猫である。名前はまだ無い。 + どこで生れたかとんと見当(けんとう)がつかぬ。何でも薄暗いじめじめした所でニャーニャー泣いていた事だけは記憶している。吾輩はここで始めて人間というものを見た。しかもあとで聞くとそれは書生という人間中で一番獰悪(どうあく)な種族であったそうだ。この書生というのは時々我々を捕(つかま)えて煮(に)て食うという話である。しかしその当時は何という考もなかったから別段恐しいとも思わなかった。ただ彼の掌(てのひら)に載せられてスーと持ち上げられた時何だかフワフワした感じがあったばかりである。掌の上で少し落ちついて書生の顔を見たのがいわゆる人間というものの見始(みはじめ)であろう。この時妙なものだと思った感じが今でも残っている。第一毛をもって装飾されべきはずの顔がつるつるしてまるで薬缶(やかん)だ。その後(ご)猫にもだいぶ逢(あ)ったがこんな片輪(かたわ)には一度も出会(でく)わした事がない。のみならず顔の真中があまりに突起している。そうしてその穴の中から時々ぷうぷうと煙(けむり)を吹く。どうも咽(む)せぽくて実に弱った。これが人間の飲む煙草(たばこ)というものである事はようやくこの頃知った。 diff --git a/test/rdoc/test_rdoc_encoding.rb b/test/rdoc/test_rdoc_encoding.rb index b940d93606..de6c10f678 100644 --- a/test/rdoc/test_rdoc_encoding.rb +++ b/test/rdoc/test_rdoc_encoding.rb @@ -30,7 +30,7 @@ class TestRDocEncoding < MiniTest::Unit::TestCase expected.gsub!("\n", "\r\n") if RUBY_VERSION =~ /^1.9/ && RUBY_PLATFORM =~ /mswin|mingw/ contents = RDoc::Encoding.read_file @tempfile.path, Encoding::UTF_8 - assert_equal expected, contents + assert_equal "hi everybody", contents assert_equal Encoding::UTF_8, contents.encoding end @@ -46,7 +46,7 @@ class TestRDocEncoding < MiniTest::Unit::TestCase contents = RDoc::Encoding.read_file @tempfile.path, Encoding::UTF_8 assert_equal Encoding::UTF_8, contents.encoding - assert_equal "# coding: ISO-8859-1\nhi \u00e9verybody", contents.sub("\r", '') + assert_equal "hi \u00e9verybody", contents.sub("\r", '') end def test_class_read_file_encoding_fancy @@ -62,7 +62,7 @@ class TestRDocEncoding < MiniTest::Unit::TestCase expected.gsub!("\n", "\r\n") if RUBY_VERSION =~ /^1.9/ && RUBY_PLATFORM =~ /win32|mingw32/ contents = RDoc::Encoding.read_file @tempfile.path, Encoding::UTF_8 - assert_equal expected, contents + assert_equal "hi everybody", contents assert_equal Encoding::UTF_8, contents.encoding end @@ -115,6 +115,20 @@ class TestRDocEncoding < MiniTest::Unit::TestCase assert_equal Encoding::UTF_8, s.encoding end + def test_class_set_encoding_strip + s = "# coding: UTF-8\n# more comments" + + RDoc::Encoding.set_encoding s + + assert_equal "# more comments", s + + s = "#!/bin/ruby\n# coding: UTF-8\n# more comments" + + RDoc::Encoding.set_encoding s + + assert_equal "# more comments", s + end + def test_class_set_encoding_bad skip "Encoding not implemented" unless Object.const_defined? :Encoding @@ -141,5 +155,12 @@ class TestRDocEncoding < MiniTest::Unit::TestCase end end + def test_sanity + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + assert_equal Encoding::US_ASCII, ''.encoding, + 'If this file is not ASCII tests may incorrectly pass' + end + end diff --git a/test/rdoc/test_rdoc_markup_to_html.rb b/test/rdoc/test_rdoc_markup_to_html.rb index 8a5860fe25..8a2971155b 100644 --- a/test/rdoc/test_rdoc_markup_to_html.rb +++ b/test/rdoc/test_rdoc_markup_to_html.rb @@ -297,6 +297,11 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase assert_equal '<>', @to.convert_string('<>') end + def test_gen_url + assert_equal 'example', + @to.gen_url('link:example', 'example') + end + def test_list_verbatim_2 str = "* one\n verb1\n verb2\n* two\n" diff --git a/test/rdoc/test_rdoc_options.rb b/test/rdoc/test_rdoc_options.rb index 3d07353c5f..a84503d3f5 100644 --- a/test/rdoc/test_rdoc_options.rb +++ b/test/rdoc/test_rdoc_options.rb @@ -9,6 +9,11 @@ class TestRDocOptions < MiniTest::Unit::TestCase def setup @options = RDoc::Options.new + @generators = RDoc::RDoc::GENERATORS.dup + end + + def teardown + RDoc::RDoc::GENERATORS.replace @generators end def test_check_files @@ -47,6 +52,20 @@ file 'unreadable' not readable assert_equal Encoding.default_external, @options.encoding end + def test_generator_descriptions + # HACK autotest/isolate should take care of this + RDoc::RDoc::GENERATORS.clear + RDoc::RDoc::GENERATORS['darkfish'] = RDoc::Generator::Darkfish + RDoc::RDoc::GENERATORS['ri'] = RDoc::Generator::RI + + expected = <<-EXPECTED.chomp + darkfish - HTML generator, written by Michael Granger + ri - creates ri data files + EXPECTED + + assert_equal expected, @options.generator_descriptions + end + def test_parse_dash_p out, err = capture_io do @options.parse %w[-p] @@ -178,6 +197,27 @@ file 'unreadable' not readable assert_equal 1, out.scan(/ri generator options:/). length end + def test_parse_help_extra_generator + RDoc::RDoc::GENERATORS['test'] = Class.new do + def self.setup_options options + op = options.option_parser + + op.separator 'test generator options:' + end + end + + out, = capture_io do + begin + @options.parse %w[--help] + rescue SystemExit + end + end + + assert_equal 1, out.scan(/HTML generator options:/).length + assert_equal 1, out.scan(/ri generator options:/). length + assert_equal 1, out.scan(/test generator options:/).length + end + def test_parse_ignore_invalid out, err = capture_io do @options.parse %w[--ignore-invalid --bogus] @@ -278,12 +318,13 @@ file 'unreadable' not readable end def test_setup_generator - test_generator = Object.new - def test_generator.setup_options(op) - @op = op - end + test_generator = Class.new do + def self.setup_options op + @op = op + end - def test_generator.op() @op end + def self.op() @op end + end RDoc::RDoc::GENERATORS['TestGenerator'] = test_generator @@ -293,6 +334,8 @@ file 'unreadable' not readable assert_equal [test_generator], @options.generator_options assert_equal @options, test_generator.op + ensure + RDoc::RDoc::GENERATORS.delete 'TestGenerator' end end diff --git a/test/rdoc/test_rdoc_parser.rb b/test/rdoc/test_rdoc_parser.rb index 2eb1ac1a67..e0629e37b6 100644 --- a/test/rdoc/test_rdoc_parser.rb +++ b/test/rdoc/test_rdoc_parser.rb @@ -28,6 +28,11 @@ class TestRDocParser < MiniTest::Unit::TestCase refute @RP.binary?(file_name) end + def test_class_binary_large_japanese_rdoc + file_name = File.expand_path '../test.ja.large.rdoc', __FILE__ + assert !@RP.binary?(file_name) + end + def test_class_binary_japanese_rdoc skip "Encoding not implemented" unless Object.const_defined? :Encoding diff --git a/test/rdoc/test_rdoc_parser_c.rb b/test/rdoc/test_rdoc_parser_c.rb index c6cc42081c..dd856c1bcf 100644 --- a/test/rdoc/test_rdoc_parser_c.rb +++ b/test/rdoc/test_rdoc_parser_c.rb @@ -532,6 +532,46 @@ Init_Foo(void) { assert_equal "VALUE\nother_function() ", code end + def test_find_body_2 + content = <<-CONTENT +/* Copyright (C) 2010 Sven Herzberg + * + * This file is free software; the author(s) gives unlimited + * permission to copy and/or distribute it, with or without + * modifications, as long as this notice is preserved. + */ + +#include + +static VALUE +wrap_initialize (VALUE self) +{ + return self; +} + +/* */ +static VALUE +wrap_shift (VALUE self, + VALUE arg) +{ + return self; +} + +void +init_gi_repository (void) +{ + VALUE mTest = rb_define_module ("Test"); + VALUE cTest = rb_define_class_under (mTest, "Test", rb_cObject); + + rb_define_method (cTest, "initialize", wrap_initialize, 0); + rb_define_method (cTest, "shift", wrap_shift, 0); +} + CONTENT + + klass = util_get_class content, 'cTest' + assert_equal 2, klass.method_list.length + end + def test_find_body_define content = <<-EOF /* @@ -633,6 +673,31 @@ commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9] assert_equal expected, method_obj.call_seq end + def test_find_modifiers_call_seq_no_blank + comment = <<-COMMENT +/* call-seq: + * commercial() -> Date
+ * commercial(cwyear, cweek=41, cwday=5, sg=nil) -> Date [ruby 1.8]
+ * commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9] + */ + + COMMENT + + parser = util_parser '' + method_obj = RDoc::AnyMethod.new nil, 'blah' + + parser.find_modifiers comment, method_obj + + expected = <<-CALL_SEQ.chomp +commercial() -> Date
+commercial(cwyear, cweek=41, cwday=5, sg=nil) -> Date [ruby 1.8]
+commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9] + + CALL_SEQ + + assert_equal expected, method_obj.call_seq + end + def test_find_modifiers_nodoc comment = <<-COMMENT /* :nodoc: diff --git a/test/rdoc/test_rdoc_parser_ruby.rb b/test/rdoc/test_rdoc_parser_ruby.rb index f2fa18c67b..dcaf561369 100644 --- a/test/rdoc/test_rdoc_parser_ruby.rb +++ b/test/rdoc/test_rdoc_parser_ruby.rb @@ -32,6 +32,66 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase @tempfile2.close end + def test_extract_call_seq + m = RDoc::AnyMethod.new nil, 'm' + p = util_parser '' + + comment = <<-COMMENT + # call-seq: + # bla => true or false + # + # moar comment + COMMENT + + p.extract_call_seq comment, m + + assert_equal "bla => true or false\n", m.call_seq + end + + def test_extract_call_seq_blank + m = RDoc::AnyMethod.new nil, 'm' + p = util_parser '' + + comment = <<-COMMENT + # call-seq: + # bla => true or false + # + COMMENT + + p.extract_call_seq comment, m + + assert_equal "bla => true or false\n", m.call_seq + end + + def test_extract_call_seq_no_blank + m = RDoc::AnyMethod.new nil, 'm' + p = util_parser '' + + comment = <<-COMMENT + # call-seq: + # bla => true or false + COMMENT + + p.extract_call_seq comment, m + + assert_equal "bla => true or false\n", m.call_seq + end + + def test_extract_call_seq_undent + m = RDoc::AnyMethod.new nil, 'm' + p = util_parser '' + + comment = <<-COMMENT + # call-seq: + # bla => true or false + # moar comment + COMMENT + + p.extract_call_seq comment, m + + assert_equal "bla => true or false\nmoar comment\n", m.call_seq + end + def test_get_symbol_or_name util_parser "* & | + 5 / 4" @@ -503,6 +563,35 @@ end assert_equal @top_level, blah.file end + def test_parse_class_multi_ghost_methods + util_parser <<-'CLASS' +class Foo + ## + # :method: one + # + # my method + + ## + # :method: two + # + # my method + + [:one, :two].each do |t| + eval("def #{t}; \"#{t}\"; end") + end +end + CLASS + + tk = @parser.get_tk + + @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, '' + + foo = @top_level.classes.first + assert_equal 'Foo', foo.full_name + + assert_equal 2, foo.method_list.length + end + def test_parse_class_nested_superclass util_top_level foo = @top_level.add_module RDoc::NormalModule, 'Foo' diff --git a/test/rdoc/test_rdoc_ri_paths.rb b/test/rdoc/test_rdoc_ri_paths.rb index 91e6abbfbd..e6f33d7d5e 100644 --- a/test/rdoc/test_rdoc_ri_paths.rb +++ b/test/rdoc/test_rdoc_ri_paths.rb @@ -1,11 +1,10 @@ require 'rubygems' -require 'test/unit' +require 'minitest/autorun' require 'tmpdir' require 'fileutils' require 'rdoc/ri/paths' -require_relative '../ruby/envutil' -class TestRDocRIPaths < Test::Unit::TestCase +class TestRDocRIPaths < MiniTest::Unit::TestCase def setup RDoc::RI::Paths.instance_variable_set :@gemdirs, %w[/nonexistent/gemdir] @@ -40,9 +39,5 @@ class TestRDocRIPaths < Test::Unit::TestCase assert_equal '/nonexistent/gemdir', path.shift end - def test_homeless - bug4202 = '[ruby-core:33867]' - assert(assert_in_out_err([{"HOME"=>nil}, *%w"-rrdoc/ri/paths -e;"], bug4202).success?, bug4202) - end end diff --git a/test/rdoc/test_rdoc_ruby_lex.rb b/test/rdoc/test_rdoc_ruby_lex.rb new file mode 100644 index 0000000000..4398f4119f --- /dev/null +++ b/test/rdoc/test_rdoc_ruby_lex.rb @@ -0,0 +1,23 @@ +require 'rubygems' +require 'minitest/autorun' +require 'rdoc/rdoc' +require 'rdoc/ruby_lex' + +class TestRubyLex < MiniTest::Unit::TestCase + def test_unary_minus + ruby_lex = RDoc::RubyLex.new("-1", nil) + assert_equal("-1", ruby_lex.token.value) + + ruby_lex = RDoc::RubyLex.new("a[-2]", nil) + 2.times { ruby_lex.token } # skip "a" and "[" + assert_equal("-2", ruby_lex.token.value) + + ruby_lex = RDoc::RubyLex.new("a[0..-12]", nil) + 4.times { ruby_lex.token } # skip "a", "[", "0", and ".." + assert_equal("-12", ruby_lex.token.value) + + ruby_lex = RDoc::RubyLex.new("0+-0.1", nil) + 2.times { ruby_lex.token } # skip "0" and "+" + assert_equal("-0.1", ruby_lex.token.value) + end +end diff --git a/test/rdoc/test_rdoc_stats.rb b/test/rdoc/test_rdoc_stats.rb new file mode 100644 index 0000000000..0032c75669 --- /dev/null +++ b/test/rdoc/test_rdoc_stats.rb @@ -0,0 +1,38 @@ +require 'rubygems' +require 'minitest/autorun' +require 'rdoc/stats' +require 'rdoc/code_objects' +require 'rdoc/markup' +require 'rdoc/parser' + +class TestRDocStats < MiniTest::Unit::TestCase + + def setup + RDoc::TopLevel.reset + + @s = RDoc::Stats.new 0 + end + + def test_report_constant_alias + tl = RDoc::TopLevel.new 'fake.rb' + mod = tl.add_module RDoc::NormalModule, 'M' + + c = tl.add_class RDoc::NormalClass, 'C' + mod.add_constant c + + ca = RDoc::Constant.new 'CA', nil, nil + ca.is_alias_for = c + + tl.add_constant ca + + RDoc::TopLevel.complete :public + + report = @s.report + + # TODO change this to refute match, aliases should be ignored as they are + # programmer convenience constructs + assert_match(/class Object/, report) + end + +end + diff --git a/test/rdoc/test_rdoc_task.rb b/test/rdoc/test_rdoc_task.rb index 8eaff1f25b..2b72e7f654 100644 --- a/test/rdoc/test_rdoc_task.rb +++ b/test/rdoc/test_rdoc_task.rb @@ -8,6 +8,26 @@ class TestRDocTask < MiniTest::Unit::TestCase Rake::Task.clear end + def test_inline_source + t = RDoc::Task.new + + _, err = capture_io do + assert t.inline_source + end + + assert_equal "RDoc::Task#inline_source is deprecated\n", err + + _, err = capture_io do + t.inline_source = false + end + + assert_equal "RDoc::Task#inline_source is deprecated\n", err + + capture_io do + assert t.inline_source + end + end + def test_tasks_creation RDoc::Task.new assert Rake::Task[:rdoc] @@ -23,6 +43,14 @@ class TestRDocTask < MiniTest::Unit::TestCase assert_equal :rdoc_dev, rd.name end + def test_generator_option + rdoc_task = RDoc::Task.new do |rd| + rd.generator = "ri" + end + + assert_equal %w[-o html -f ri], rdoc_task.option_list + end + def test_tasks_creation_with_custom_name_string rd = RDoc::Task.new("rdoc_dev") assert Rake::Task[:rdoc_dev] -- cgit v1.2.3