diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-05 01:41:25 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-05 01:41:25 +0000 |
commit | d42d6e690e3f553b971322eae783ac6b0d4d9692 (patch) | |
tree | 2004bf4517ee7b81466c300cf30092e62e65467e /test/rdoc | |
parent | 670c6e8ce9d4a12bb4832e10fab27365398649bf (diff) | |
download | ruby-d42d6e690e3f553b971322eae783ac6b0d4d9692.tar.gz |
* lib/rdoc.rb, lib/rdoc, test/rdoc: Update to RDoc 4.2.0.alpha(313287)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rdoc')
-rw-r--r-- | test/rdoc/test.ja.large.rdoc | 3 | ||||
-rw-r--r-- | test/rdoc/test_attribute_manager.rb | 120 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_any_method.rb | 29 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_constant.rb | 30 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_context.rb | 2 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_encoding.rb | 17 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_generator_pot.rb | 92 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_generator_pot_po.rb | 52 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_generator_pot_po_entry.rb | 139 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_i18n_locale.rb | 73 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_i18n_text.rb | 123 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_method_attr.rb | 5 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_options.rb | 19 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_parser.rb | 17 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_parser_c.rb | 71 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_parser_ruby.rb | 58 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_rd_block_parser.rb | 4 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_rdoc.rb | 27 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_rubygems_hook.rb | 3 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_task.rb | 50 |
20 files changed, 779 insertions, 155 deletions
diff --git a/test/rdoc/test.ja.large.rdoc b/test/rdoc/test.ja.large.rdoc deleted file mode 100644 index a9c6c4691c..0000000000 --- a/test/rdoc/test.ja.large.rdoc +++ /dev/null @@ -1,3 +0,0 @@ -# -*- coding: utf-8 -*- - 吾輩(わがはい)は猫である。名前はまだ無い。 - どこで生れたかとんと見当(けんとう)がつかぬ。何でも薄暗いじめじめした所でニャーニャー泣いていた事だけは記憶している。吾輩はここで始めて人間というものを見た。しかもあとで聞くとそれは書生という人間中で一番獰悪(どうあく)な種族であったそうだ。この書生というのは時々我々を捕(つかま)えて煮(に)て食うという話である。しかしその当時は何という考もなかったから別段恐しいとも思わなかった。ただ彼の掌(てのひら)に載せられてスーと持ち上げられた時何だかフワフワした感じがあったばかりである。掌の上で少し落ちついて書生の顔を見たのがいわゆる人間というものの見始(みはじめ)であろう。この時妙なものだと思った感じが今でも残っている。第一毛をもって装飾されべきはずの顔がつるつるしてまるで薬缶(やかん)だ。その後(ご)猫にもだいぶ逢(あ)ったがこんな片輪(かたわ)には一度も出会(でく)わした事がない。のみならず顔の真中があまりに突起している。そうしてその穴の中から時々ぷうぷうと煙(けむり)を吹く。どうも咽(む)せぽくて実に弱った。これが人間の飲む煙草(たばこ)というものである事はようやくこの頃知った。 diff --git a/test/rdoc/test_attribute_manager.rb b/test/rdoc/test_attribute_manager.rb deleted file mode 100644 index 8832a5d515..0000000000 --- a/test/rdoc/test_attribute_manager.rb +++ /dev/null @@ -1,120 +0,0 @@ -require 'rdoc/test_case' - -class TestAttributeManager < RDoc::TestCase # HACK fix test name - - def setup - super - - @options = RDoc::Options.new - - @am = RDoc::Markup::AttributeManager.new - @klass = RDoc::Markup::AttributeManager - @formatter = RDoc::Markup::Formatter.new @options - @formatter.add_tag :BOLD, '<B>', '</B>' - @formatter.add_tag :EM, '<EM>', '</EM>' - @formatter.add_tag :TT, '<CODE>', '</CODE>' - end - - def test_convert_attrs_ignores_code - assert_equal 'foo <CODE>__send__</CODE> bar', output('foo <code>__send__</code> bar') - end - - def test_convert_attrs_ignores_tt - assert_equal 'foo <CODE>__send__</CODE> bar', output('foo <tt>__send__</tt> bar') - end - - def test_convert_attrs_preserves_double - assert_equal 'foo.__send__ :bar', output('foo.__send__ :bar') - assert_equal 'use __FILE__ to', output('use __FILE__ to') - end - - def test_convert_attrs_does_not_ignore_after_tt - assert_equal 'the <CODE>IF:</CODE><EM>key</EM> directive', output('the <tt>IF:</tt>_key_ directive') - end - - def test_initial_word_pairs - word_pairs = @am.matching_word_pairs - assert word_pairs.is_a?(Hash) - assert_equal(3, word_pairs.size) - end - - def test_initial_html - html_tags = @am.html_tags - assert html_tags.is_a?(Hash) - assert_equal(5, html_tags.size) - end - - def test_add_matching_word_pair - @am.add_word_pair("x","x", :TEST) - word_pairs = @am.matching_word_pairs - assert_equal(4,word_pairs.size) - assert(word_pairs.has_key?("x")) - end - - def test_add_invalid_word_pair - assert_raises ArgumentError do - @am.add_word_pair("<", "<", :TEST) - end - end - - def test_add_word_pair_map - @am.add_word_pair("x", "y", :TEST) - word_pair_map = @am.word_pair_map - assert_equal(1,word_pair_map.size) - assert_equal(word_pair_map. keys.first.source, "(x)(\\S+)(y)") - end - - def test_add_html_tag - @am.add_html("Test", :TEST) - tags = @am.html_tags - assert_equal(6, tags.size) - assert(tags.has_key?("test")) - end - - def test_add_special - @am.add_special "WikiWord", :WIKIWORD - specials = @am.special - - assert_equal 1, specials.size - assert specials.assoc "WikiWord" - end - - def test_escapes - assert_equal '<CODE>text</CODE>', output('<tt>text</tt>') - assert_equal '<tt>text</tt>', output('\\<tt>text</tt>') - assert_equal '<tt>', output('\\<tt>') - assert_equal '<CODE><tt></CODE>', output('<tt>\\<tt></tt>') - assert_equal '<CODE>\\<tt></CODE>', output('<tt>\\\\<tt></tt>') - assert_equal '<B>text</B>', output('*text*') - assert_equal '*text*', output('\\*text*') - assert_equal '\\', output('\\') - assert_equal '\\text', output('\\text') - assert_equal '\\\\text', output('\\\\text') - assert_equal 'text \\ text', output('text \\ text') - - assert_equal 'and <CODE>\\s</CODE> matches space', - output('and <tt>\\s</tt> matches space') - assert_equal 'use <CODE><tt>text</CODE></tt> for code', - output('use <tt>\\<tt>text</tt></tt> for code') - assert_equal 'use <CODE><tt>text</tt></CODE> for code', - output('use <tt>\\<tt>text\\</tt></tt> for code') - assert_equal 'use <tt><tt>text</tt></tt> for code', - output('use \\<tt>\\<tt>text</tt></tt> for code') - assert_equal 'use <tt><CODE>text</CODE></tt> for code', - output('use \\<tt><tt>text</tt></tt> for code') - assert_equal 'use <CODE>+text+</CODE> for code', - output('use <tt>\\+text+</tt> for code') - assert_equal 'use <tt><CODE>text</CODE></tt> for code', - output('use \\<tt>+text+</tt> for code') - assert_equal 'illegal <tag>not</tag> changed', - output('illegal <tag>not</tag> changed') - assert_equal 'unhandled <p>tag</p> unchanged', - output('unhandled <p>tag</p> unchanged') - end - - def output str - @formatter.convert_flow @am.flow str - end - -end - diff --git a/test/rdoc/test_rdoc_any_method.rb b/test/rdoc/test_rdoc_any_method.rb index 77acfbee17..90305807f8 100644 --- a/test/rdoc/test_rdoc_any_method.rb +++ b/test/rdoc/test_rdoc_any_method.rb @@ -334,6 +334,35 @@ method(a, b) { |c, d| ... } assert_equal %w[a b c d], m.param_list end + def test_param_list_empty_params_with_block + m = RDoc::AnyMethod.new nil, 'method' + m.parent = @c1 + + m.params = '()' + m.block_params = 'a, b' + + assert_equal %w[a b], m.param_list + end + + def test_param_list_ampersand_param_block_params + m = RDoc::AnyMethod.new nil, 'method' + m.parent = @c1 + + m.params = '(a, b, &block)' + m.block_params = 'c, d' + + assert_equal %w[a b c d], m.param_list + end + + def test_param_list_ampersand_param + m = RDoc::AnyMethod.new nil, 'method' + m.parent = @c1 + + m.params = '(a, b, &block)' + + assert_equal %w[a b block], m.param_list + end + def test_param_seq m = RDoc::AnyMethod.new nil, 'method' m.parent = @c1 diff --git a/test/rdoc/test_rdoc_constant.rb b/test/rdoc/test_rdoc_constant.rb index 5c347f62ae..171963d8e4 100644 --- a/test/rdoc/test_rdoc_constant.rb +++ b/test/rdoc/test_rdoc_constant.rb @@ -8,6 +8,36 @@ class TestRDocConstant < XrefTestCase @const = @c1.constants.first end + def test_documented_eh + top_level = @store.add_file 'file.rb' + + const = RDoc::Constant.new 'CONST', nil, nil + top_level.add_constant const + + refute const.documented? + + const.comment = comment 'comment' + + assert const.documented? + end + + def test_documented_eh_alias + top_level = @store.add_file 'file.rb' + + const = RDoc::Constant.new 'CONST', nil, nil + top_level.add_constant const + + refute const.documented? + + const.is_alias_for = 'C1' + + refute const.documented? + + @c1.add_comment comment('comment'), @top_level + + assert const.documented? + end + def test_full_name assert_equal 'C1::CONST', @const.full_name end diff --git a/test/rdoc/test_rdoc_context.rb b/test/rdoc/test_rdoc_context.rb index c6c5e2f109..c981cf3b11 100644 --- a/test/rdoc/test_rdoc_context.rb +++ b/test/rdoc/test_rdoc_context.rb @@ -621,6 +621,8 @@ class TestRDocContext < XrefTestCase assert_equal 1, @c2_c3.<=>(@c2) assert_equal(-1, @c2_c3.<=>(@c3)) + + assert_nil @c2.<=>(Gem.loaded_specs.values.first) end def test_methods_by_type diff --git a/test/rdoc/test_rdoc_encoding.rb b/test/rdoc/test_rdoc_encoding.rb index f50e2f6012..7ec39f8a9c 100644 --- a/test/rdoc/test_rdoc_encoding.rb +++ b/test/rdoc/test_rdoc_encoding.rb @@ -131,6 +131,23 @@ class TestRDocEncoding < RDoc::TestCase assert_equal "hi everybody", content, bug3360 end + def test_class_read_file_encoding_iso_2022_jp + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + input = "# coding: ISO-2022-JP\n:\e$B%3%^%s%I\e(B:" + + @tempfile.write input + @tempfile.flush + + contents = RDoc::Encoding.read_file @tempfile.path, Encoding::UTF_8 + + expected = ":\xe3\x82\xb3\xe3\x83\x9e\xe3\x83\xb3\xe3\x83\x89:" + expected.force_encoding Encoding::UTF_8 + + assert_equal expected, contents + assert_equal Encoding::UTF_8, contents.encoding + end + def test_class_set_encoding s = "# coding: UTF-8\n" RDoc::Encoding.set_encoding s diff --git a/test/rdoc/test_rdoc_generator_pot.rb b/test/rdoc/test_rdoc_generator_pot.rb new file mode 100644 index 0000000000..99e5404c12 --- /dev/null +++ b/test/rdoc/test_rdoc_generator_pot.rb @@ -0,0 +1,92 @@ +require 'rdoc/test_case' + +class TestRDocGeneratorPOT < RDoc::TestCase + + def setup + super + + @options = RDoc::Options.new + @tmpdir = File.join Dir.tmpdir, "test_rdoc_generator_pot_#{$$}" + FileUtils.mkdir_p @tmpdir + + @generator = RDoc::Generator::POT.new @store, @options + + @top_level = @store.add_file 'file.rb' + @klass = @top_level.add_class RDoc::NormalClass, 'Object' + @klass.add_comment 'This is a class', @top_level + @klass.add_section 'This is a section', comment('This is a section comment') + + @const = RDoc::Constant.new "CONSTANT", "29", "This is a constant" + + @meth = RDoc::AnyMethod.new nil, 'method' + @meth.record_location @top_level + @meth.comment = 'This is a method' + + @attr = RDoc::Attr.new nil, 'attr', 'RW', '' + @attr.record_location @top_level + @attr.comment = 'This is an attribute' + + @klass.add_constant @const + @klass.add_method @meth + @klass.add_attribute @attr + + Dir.chdir @tmpdir + end + + def teardown + super + + Dir.chdir @pwd + FileUtils.rm_rf @tmpdir + end + + def test_generate + @generator.generate + + assert_equal <<-POT, File.read(File.join(@tmpdir, 'rdoc.pot')) +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSEION\\n" +"Report-Msgid-Bugs-To: \\n" +"PO-Revision-Date: YEAR-MO_DA HO:MI+ZONE\\n" +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n" +"Language-Team: LANGUAGE <LL@li.org>\\n" +"Language: \\n" +"MIME-Version: 1.0\\n" +"Content-Type: text/plain; charset=CHARSET\\n" +"Content-Transfer-Encoding: 8bit\\n" +"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n" + +#. Object +msgid "This is a class" +msgstr "" + +#. Object::CONSTANT +msgid "This is a constant" +msgstr "" + +#. Object#method +msgid "This is a method" +msgstr "" + +#. Object: section title +msgid "This is a section" +msgstr "" + +#. Object: This is a section +msgid "This is a section comment" +msgstr "" + +#. Object#attr +msgid "This is an attribute" +msgstr "" + POT + end + +end diff --git a/test/rdoc/test_rdoc_generator_pot_po.rb b/test/rdoc/test_rdoc_generator_pot_po.rb new file mode 100644 index 0000000000..88cfe7e437 --- /dev/null +++ b/test/rdoc/test_rdoc_generator_pot_po.rb @@ -0,0 +1,52 @@ +require 'rdoc/test_case' + +class TestRDocGeneratorPOTPO < RDoc::TestCase + + def setup + super + @po = RDoc::Generator::POT::PO.new + end + + def test_empty + assert_equal header, @po.to_s + end + + def test_have_entry + @po.add(entry("Hello", {})) + assert_equal <<-PO, @po.to_s +#{header} +msgid "Hello" +msgstr "" + PO + end + + private + + def entry(msgid, options) + RDoc::Generator::POT::POEntry.new(msgid, options) + end + + def header + <<-'HEADER' +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSEION\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: YEAR-MO_DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" +"Language-Team: LANGUAGE <LL@li.org>\n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" + HEADER + end + +end diff --git a/test/rdoc/test_rdoc_generator_pot_po_entry.rb b/test/rdoc/test_rdoc_generator_pot_po_entry.rb new file mode 100644 index 0000000000..8620d98bf8 --- /dev/null +++ b/test/rdoc/test_rdoc_generator_pot_po_entry.rb @@ -0,0 +1,139 @@ +require 'rdoc/test_case' + +class TestRDocGeneratorPOTPOEntry < RDoc::TestCase + + def test_msgid_normal + assert_equal <<-'ENTRY', entry("Hello", {}).to_s +msgid "Hello" +msgstr "" + ENTRY + end + + def test_msgid_multiple_lines + assert_equal <<-'ENTRY', entry("Hello\nWorld", {}).to_s +msgid "" +"Hello\n" +"World" +msgstr "" + ENTRY + end + + def test_msgid_tab + assert_equal <<-'ENTRY', entry("Hello\tWorld", {}).to_s +msgid "Hello\tWorld" +msgstr "" + ENTRY + end + + def test_msgid_back_slash + assert_equal <<-'ENTRY', entry("Hello \\ World", {}).to_s +msgid "Hello \\ World" +msgstr "" + ENTRY + end + + def test_msgid_double_quote + assert_equal <<-'ENTRY', entry("Hello \"World\"!", {}).to_s +msgid "Hello \"World\"!" +msgstr "" + ENTRY + end + + def test_translator_comment_normal + options = {:translator_comment => "Greeting"} + assert_equal <<-'ENTRY', entry("Hello", options).to_s +# Greeting +msgid "Hello" +msgstr "" + ENTRY + end + + def test_translator_comment_multiple_lines + options = {:translator_comment => "Greeting\nfor morning"} + assert_equal <<-'ENTRY', entry("Hello", options).to_s +# Greeting +# for morning +msgid "Hello" +msgstr "" + ENTRY + end + + def test_extracted_comment_normal + options = {:extracted_comment => "Object"} + assert_equal <<-'ENTRY', entry("Hello", options).to_s +#. Object +msgid "Hello" +msgstr "" + ENTRY + end + + def test_extracted_comment_multiple_lines + options = {:extracted_comment => "Object\nMorning#greeting"} + assert_equal <<-'ENTRY', entry("Hello", options).to_s +#. Object +#. Morning#greeting +msgid "Hello" +msgstr "" + ENTRY + end + + def test_references_normal + options = {:references => [["lib/rdoc.rb", 29]]} + assert_equal <<-'ENTRY', entry("Hello", options).to_s +#: lib/rdoc.rb:29 +msgid "Hello" +msgstr "" + ENTRY + end + + def test_references_multiple + options = {:references => [["lib/rdoc.rb", 29], ["lib/rdoc/i18n.rb", 9]]} + assert_equal <<-'ENTRY', entry("Hello", options).to_s +#: lib/rdoc.rb:29 +#: lib/rdoc/i18n.rb:9 +msgid "Hello" +msgstr "" + ENTRY + end + + def test_flags_normal + options = {:flags => ["fuzzy"]} + assert_equal <<-'ENTRY', entry("Hello", options).to_s +#, fuzzy +msgid "Hello" +msgstr "" + ENTRY + end + + def test_flags_multiple + options = {:flags => ["fuzzy", "ruby-format"]} + assert_equal <<-'ENTRY', entry("Hello", options).to_s +#, fuzzy,ruby-format +msgid "Hello" +msgstr "" + ENTRY + end + + def test_full + options = { + :translator_comment => "Greeting", + :extracted_comment => "Morning#greeting", + :references => [["lib/rdoc.rb", 29]], + :flags => ["fuzzy"], + } + assert_equal <<-'ENTRY', entry("Hello", options).to_s +# Greeting +#. Morning#greeting +#: lib/rdoc.rb:29 +#, fuzzy +msgid "Hello" +msgstr "" + ENTRY + end + + private + def entry(msgid, options) + RDoc::Generator::POT::POEntry.new(msgid, options) + end + +end diff --git a/test/rdoc/test_rdoc_i18n_locale.rb b/test/rdoc/test_rdoc_i18n_locale.rb new file mode 100644 index 0000000000..69de88a9f2 --- /dev/null +++ b/test/rdoc/test_rdoc_i18n_locale.rb @@ -0,0 +1,73 @@ +require 'rdoc/test_case' + +class TestRDocI18nLocale < RDoc::TestCase + + def setup + super + @locale = locale('fr') + + @tmpdir = File.join Dir.tmpdir, "test_rdoc_i18n_locale_#{$$}" + FileUtils.mkdir_p @tmpdir + + @locale_dir = @tmpdir + end + + def teardown + FileUtils.rm_rf @tmpdir + super + end + + def test_name + assert_equal 'fr', locale('fr').name + end + + def test_load_nonexistent_po + File.stub(:exist?, false) do + refute @locale.load('nonexsitent-locale') + end + end + + def test_load_existent_po + begin + require 'gettext/po_parser' + rescue LoadError + skip 'gettext gem is not found' + end + + fr_locale_dir = File.join @locale_dir, 'fr' + FileUtils.mkdir_p fr_locale_dir + File.open File.join(fr_locale_dir, 'rdoc.po'), 'w' do |po| + po.puts <<-PO +msgid "" +msgstr "" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "Hello" +msgstr "Bonjour" + PO + end + + assert @locale.load(@locale_dir) + assert_equal 'Bonjour', @locale.translate('Hello') + end + + def test_translate_existent_message + messages = @locale.instance_variable_get(:@messages) + messages['Hello'] = 'Bonjour' + assert_equal 'Bonjour', @locale.translate('Hello') + end + + def test_translate_nonexistent_message + assert_equal 'Hello', @locale.translate('Hello') + end + + private + + def locale(name) + RDoc::I18n::Locale.new(name) + end + +end diff --git a/test/rdoc/test_rdoc_i18n_text.rb b/test/rdoc/test_rdoc_i18n_text.rb new file mode 100644 index 0000000000..3168b57d95 --- /dev/null +++ b/test/rdoc/test_rdoc_i18n_text.rb @@ -0,0 +1,123 @@ +require 'rdoc/test_case' + +class TestRDocI18nText < RDoc::TestCase + + def test_multiple_paragraphs + paragraph1 = <<-PARAGRAPH.strip +RDoc produces HTML and command-line documentation for Ruby projects. RDoc +includes the +rdoc+ and +ri+ tools for generating and displaying documentation +from the command-line. + PARAGRAPH + + paragraph2 = <<-PARAGRAPH.strip +This command generates documentation for all the Ruby and C source +files in and below the current directory. These will be stored in a +documentation tree starting in the subdirectory +doc+. + PARAGRAPH + + raw = <<-RAW +#{paragraph1} + +#{paragraph2} + RAW + + expected = [ + { + :type => :paragraph, + :paragraph => paragraph1, + :line_no => 1, + }, + { + :type => :paragraph, + :paragraph => paragraph2, + :line_no => 5, + }, + ] + assert_equal expected, extract_messages(raw) + end + + def test_translate_multiple_paragraphs + paragraph1 = <<-PARAGRAPH.strip +Paragraph 1. + PARAGRAPH + paragraph2 = <<-PARAGRAPH.strip +Paragraph 2. + PARAGRAPH + + raw = <<-RAW +#{paragraph1} + +#{paragraph2} + RAW + + expected = <<-TRANSLATED +Paragraphe 1. + +Paragraphe 2. + TRANSLATED + assert_equal expected, translate(raw) + end + + def test_translate_not_transalted_message + nonexistent_paragraph = <<-PARAGRAPH.strip +Nonexistent paragraph. + PARAGRAPH + + raw = <<-RAW +#{nonexistent_paragraph} + RAW + + expected = <<-TRANSLATED +#{nonexistent_paragraph} + TRANSLATED + assert_equal expected, translate(raw) + end + + def test_translate_keep_empty_lines + raw = <<-RAW +Paragraph 1. + + + + +Paragraph 2. + RAW + + expected = <<-TRANSLATED +Paragraphe 1. + + + + +Paragraphe 2. + TRANSLATED + assert_equal expected, translate(raw) + end + + private + + def extract_messages(raw) + text = RDoc::I18n::Text.new(raw) + messages = [] + text.extract_messages do |message| + messages << message + end + messages + end + + def locale + locale = RDoc::I18n::Locale.new('fr') + messages = locale.instance_variable_get(:@messages) + messages['markdown'] = 'markdown (markdown in fr)' + messages['Hello'] = 'Bonjour (Hello in fr)' + messages['Paragraph 1.'] = 'Paragraphe 1.' + messages['Paragraph 2.'] = 'Paragraphe 2.' + locale + end + + def translate(raw) + text = RDoc::I18n::Text.new(raw) + text.translate(locale) + end + +end diff --git a/test/rdoc/test_rdoc_method_attr.rb b/test/rdoc/test_rdoc_method_attr.rb index a91ebc23d7..0120ea6d9e 100644 --- a/test/rdoc/test_rdoc_method_attr.rb +++ b/test/rdoc/test_rdoc_method_attr.rb @@ -7,7 +7,6 @@ class TestRDocMethodAttr < XrefTestCase end def test_block_params_equal - m = RDoc::MethodAttr.new(nil, 'foo') m.block_params = '' @@ -148,6 +147,10 @@ class TestRDocMethodAttr < XrefTestCase assert_equal expected, @c1_m.search_record end + def test_spaceship + assert_nil @c1_m.<=>(RDoc::CodeObject.new) + end + def test_equals2 assert_equal @c1_m, @c1_m refute_equal @c1_m, @parent_m diff --git a/test/rdoc/test_rdoc_options.rb b/test/rdoc/test_rdoc_options.rb index f4929604f7..67053e3e33 100644 --- a/test/rdoc/test_rdoc_options.rb +++ b/test/rdoc/test_rdoc_options.rb @@ -67,6 +67,9 @@ class TestRDocOptions < RDoc::TestCase 'exclude' => [], 'hyperlink_all' => false, 'line_numbers' => false, + 'locale' => nil, + 'locale_dir' => 'locale', + 'locale_name' => nil, 'main_page' => nil, 'markup' => 'rdoc', 'output_decoration' => true, @@ -334,6 +337,18 @@ rdoc_include: e.message end + def test_parse_h + out, = capture_io do + begin + @options.parse %w[-h] + rescue SystemExit + end + end + + assert_equal 1, out.scan(/HTML generator options:/).length + assert_equal 1, out.scan(/ri generator options:/). length + end + def test_parse_help out, = capture_io do begin @@ -743,5 +758,9 @@ rdoc_include: assert out.include?(RDoc::VERSION) end + def test_visibility + @options.visibility = :all + assert_equal :private, @options.visibility + end end diff --git a/test/rdoc/test_rdoc_parser.rb b/test/rdoc/test_rdoc_parser.rb index e2494a1b06..34d4486cb1 100644 --- a/test/rdoc/test_rdoc_parser.rb +++ b/test/rdoc/test_rdoc_parser.rb @@ -15,6 +15,19 @@ class TestRDocParser < RDoc::TestCase @options = RDoc::Options.new end + def test_class_binary_eh_ISO_2022_JP + iso_2022_jp = File.join Dir.tmpdir, "test_rdoc_parser_#{$$}.rd" + + open iso_2022_jp, 'wb' do |io| + io.write "# coding: ISO-2022-JP\n" + io.write ":\e$B%3%^%s%I\e(B:\n" + end + + refute @RP.binary? iso_2022_jp + ensure + File.unlink iso_2022_jp + end + def test_class_binary_eh_marshal marshal = File.join Dir.tmpdir, "test_rdoc_parser_#{$$}.marshal" open marshal, 'wb' do |io| @@ -96,7 +109,7 @@ class TestRDocParser < RDoc::TestCase def test_class_for_forbidden skip 'chmod not supported' if Gem.win_platform? - Tempfile.create 'forbidden' do |io| + tf = Tempfile.open 'forbidden' do |io| begin File.chmod 0000, io.path forbidden = @store.add_file io.path @@ -107,7 +120,9 @@ class TestRDocParser < RDoc::TestCase ensure File.chmod 0400, io.path end + io end + tf.close! if tf.respond_to? :close! end def test_class_for_modeline diff --git a/test/rdoc/test_rdoc_parser_c.rb b/test/rdoc/test_rdoc_parser_c.rb index 88d4660766..71ffce5f9a 100644 --- a/test/rdoc/test_rdoc_parser_c.rb +++ b/test/rdoc/test_rdoc_parser_c.rb @@ -736,6 +736,47 @@ rb_define_alias(C, "[]", "index"); assert_equal "/*\n * comment\n */\n\n", comment.text end + def test_find_attr_comment_document_attr + parser= util_parser <<-C +/* + * Document-attr: y + * comment + */ + C + + comment = parser.find_attr_comment nil, 'y' + + assert_equal "/*\n * \n * comment\n */", comment.text + end + + def test_find_attr_comment_document_attr_oneline + parser= util_parser <<-C +/* Document-attr: y + * comment + */ + C + + comment = parser.find_attr_comment nil, 'y' + + assert_equal "/* \n * comment\n */", comment.text + end + + def test_find_attr_comment_document_attr_overlap + parser= util_parser <<-C +/* Document-attr: x + * comment + */ + +/* Document-attr: y + * comment + */ + C + + comment = parser.find_attr_comment nil, 'y' + + assert_equal "/* \n * comment\n */", comment.text + end + def test_find_class_comment @options.rdoc_include << File.dirname(__FILE__) @@ -1205,6 +1246,36 @@ Init_Foo(void) { assert_equal "a comment for Foo#bar", bar.comment.text end + def test_find_body_macro + content = <<-EOF +/* + * a comment for other_function + */ +DLL_LOCAL VALUE +other_function() { +} + +void +Init_Foo(void) { + VALUE foo = rb_define_class("Foo", rb_cObject); + + rb_define_method(foo, "my_method", other_function, 0); +} + EOF + + klass = util_get_class content, 'foo' + other_function = klass.method_list.first + + assert_equal 'my_method', other_function.name + assert_equal "a comment for other_function", + other_function.comment.text + assert_equal '()', other_function.params + + code = other_function.token_stream.first.text + + assert_equal "DLL_LOCAL VALUE\nother_function() {\n}", code + end + def test_find_modifiers_call_seq comment = RDoc::Comment.new <<-COMMENT call-seq: diff --git a/test/rdoc/test_rdoc_parser_ruby.rb b/test/rdoc/test_rdoc_parser_ruby.rb index 5306032b98..8750433ff1 100644 --- a/test/rdoc/test_rdoc_parser_ruby.rb +++ b/test/rdoc/test_rdoc_parser_ruby.rb @@ -63,6 +63,21 @@ class C; end assert_equal Encoding::CP852, comment.text.encoding end + def test_collect_first_comment_rd_hash + parser = util_parser <<-CONTENT +=begin +first +=end + +# second +class C; end + CONTENT + + comment = parser.collect_first_comment + + assert_equal RDoc::Comment.new("first\n\n", @top_level), comment + end + def test_get_class_or_module ctxt = RDoc::Context.new ctxt.store = @store @@ -773,7 +788,7 @@ end assert_equal 2, foo.method_list.length end - def test_parse_const_fail_w_meta_method + def test_parse_const_fail_w_meta util_parser <<-CLASS class ConstFailMeta ## @@ -795,27 +810,6 @@ end assert_equal 1, const_fail_meta.attributes.length end - def test_parse_const_third_party - util_parser <<-CLASS -class A - true if B::C - true if D::E::F -end - CLASS - - tk = @parser.get_tk - - @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, @comment - - a = @top_level.classes.first - assert_equal 'A', a.full_name - - visible = @store.all_modules.reject { |mod| mod.suppressed? } - visible = visible.map { |mod| mod.full_name } - - assert_empty visible - end - def test_parse_class_nested_superclass foo = @top_level.add_module RDoc::NormalModule, 'Foo' @@ -3251,7 +3245,25 @@ end c_b = c.find_method_named 'b' assert_equal :private, c_b.visibility - refute c_b.singleton + assert c_b.singleton + end + + def test_singleton_method_via_eigenclass + util_parser <<-RUBY +class C + class << self + def a() end + end +end + RUBY + + @parser.scan + + c = @store.find_class_named 'C' + c_a = c.find_method_named 'a' + + assert_equal :public, c_a.visibility + assert c_a.singleton end def test_stopdoc_after_comment diff --git a/test/rdoc/test_rdoc_rd_block_parser.rb b/test/rdoc/test_rdoc_rd_block_parser.rb index 5158f46b26..956f3d2822 100644 --- a/test/rdoc/test_rdoc_rd_block_parser.rb +++ b/test/rdoc/test_rdoc_rd_block_parser.rb @@ -153,7 +153,7 @@ class TestRDocRdBlockParser < RDoc::TestCase blank_line, blank_line) - Tempfile.create %w[parse_include .rd] do |io| + tf = Tempfile.open %w[parse_include .rd] do |io| io.puts "=begin\ninclude ((*worked*))\n=end" io.flush @@ -162,7 +162,9 @@ class TestRDocRdBlockParser < RDoc::TestCase STR assert_equal expected, parse(str) + io end + tf.close! if tf.respond_to? :close! end def test_parse_heading diff --git a/test/rdoc/test_rdoc_rdoc.rb b/test/rdoc/test_rdoc_rdoc.rb index 8b349a4389..2adfdcc460 100644 --- a/test/rdoc/test_rdoc_rdoc.rb +++ b/test/rdoc/test_rdoc_rdoc.rb @@ -252,14 +252,16 @@ class TestRDocRDoc < RDoc::TestCase @rdoc.options.encoding = Encoding::ISO_8859_1 @rdoc.store = RDoc::Store.new - Tempfile.create 'test.txt' do |io| + tf = Tempfile.open 'test.txt' do |io| io.write 'hi' io.rewind top_level = @rdoc.parse_file io.path assert_equal Encoding::ISO_8859_1, top_level.absolute_name.encoding + io end + tf.close! if tf.respond_to? :close? end def test_parse_file_forbidden @@ -267,7 +269,7 @@ class TestRDocRDoc < RDoc::TestCase @rdoc.store = RDoc::Store.new - Tempfile.create 'test.txt' do |io| + tf = Tempfile.open 'test.txt' do |io| io.write 'hi' io.rewind @@ -286,7 +288,9 @@ class TestRDocRDoc < RDoc::TestCase ensure File.chmod 0400, io.path end + io end + tf.close! if tf.respond_to? :close! end def test_remove_unparseable @@ -382,7 +386,7 @@ class TestRDocRDoc < RDoc::TestCase end def test_setup_output_dir_exists_file - Tempfile.create 'test_rdoc_rdoc' do |tempfile| + tf = Tempfile.open 'test_rdoc_rdoc' do |tempfile| path = tempfile.path e = assert_raises RDoc::Error do @@ -391,7 +395,9 @@ class TestRDocRDoc < RDoc::TestCase assert_match(%r%#{Regexp.escape path} exists and is not a directory%, e.message) + tempfile end + tf.close! if tf.respond_to? :close! end def test_setup_output_dir_exists_not_rdoc @@ -430,5 +436,20 @@ class TestRDocRDoc < RDoc::TestCase end end + def test_normalized_file_list_removes_created_rid_dir + temp_dir do |d| + FileUtils.mkdir "doc" + flag_file = @rdoc.output_flag_file "doc" + file = File.join "doc", "test" + FileUtils.touch flag_file + FileUtils.touch file + + file_list = ["doc"] + + output = @rdoc.normalized_file_list file_list + + assert_empty output + end + end end diff --git a/test/rdoc/test_rdoc_rubygems_hook.rb b/test/rdoc/test_rdoc_rubygems_hook.rb index cee0810ab4..960afc9ed4 100644 --- a/test/rdoc/test_rdoc_rubygems_hook.rb +++ b/test/rdoc/test_rdoc_rubygems_hook.rb @@ -138,9 +138,6 @@ class TestRDocRubygemsHook < Gem::TestCase @a.loaded_from = File.join Gem::Specification.default_specifications_dir, 'a.gemspec' - FileUtils.mkdir_p @a.doc_dir - FileUtils.mkdir_p File.join(@a.gem_dir, 'lib') - @hook.generate refute @hook.rdoc_installed? diff --git a/test/rdoc/test_rdoc_task.rb b/test/rdoc/test_rdoc_task.rb index 8faf3f7d92..43d458981d 100644 --- a/test/rdoc/test_rdoc_task.rb +++ b/test/rdoc/test_rdoc_task.rb @@ -46,6 +46,7 @@ class TestRDocTask < RDoc::TestCase assert Rake::Task[:rdoc] assert Rake::Task[:clobber_rdoc] assert Rake::Task[:rerdoc] + assert_equal ["html/created.rid"], Rake::Task[:rdoc].prerequisites end def test_tasks_creation_with_custom_name_symbol @@ -56,6 +57,23 @@ class TestRDocTask < RDoc::TestCase assert_equal :rdoc_dev, rd.name end + def test_tasks_option_parser + rdoc_task = RDoc::Task.new do |rd| + rd.title = "Test Tasks Option Parser" + rd.main = "README.md" + rd.rdoc_files.include("README.md") + rd.options << "--all" + end + + assert rdoc_task.title, "Test Tasks Option Parser" + assert rdoc_task.main, "README.md" + assert rdoc_task.rdoc_files.include?("README.md") + assert rdoc_task.options.include?("--all") + + args = %w[--all -o html --main README.md] << "--title" << "Test Tasks Option Parser" << "README.md" + assert_equal args, rdoc_task.option_list + rdoc_task.rdoc_files + end + def test_generator_option rdoc_task = RDoc::Task.new do |rd| rd.generator = "ri" @@ -64,6 +82,22 @@ class TestRDocTask < RDoc::TestCase assert_equal %w[-o html -f ri], rdoc_task.option_list end + def test_main_option + rdoc_task = RDoc::Task.new do |rd| + rd.main = "README.md" + end + + assert_equal %w[-o html --main README.md], rdoc_task.option_list + end + + def test_output_dir_option + rdoc_task = RDoc::Task.new do |rd| + rd.rdoc_dir = "zomg" + end + + assert_equal %w[-o zomg], rdoc_task.option_list + end + def test_rdoc_task_description assert_equal 'Build RDoc HTML files', @t.rdoc_task_description end @@ -116,5 +150,21 @@ class TestRDocTask < RDoc::TestCase end end + def test_template_option + rdoc_task = RDoc::Task.new do |rd| + rd.template = "foo" + end + + assert_equal %w[-o html -T foo], rdoc_task.option_list + end + + def test_title_option + rdoc_task = RDoc::Task.new do |rd| + rd.title = "Test Title Option" + end + + assert_equal %w[-o html] << "--title" << "Test Title Option", rdoc_task.option_list + end + end |