diff options
Diffstat (limited to 'test/rdoc')
52 files changed, 636 insertions, 102 deletions
diff --git a/test/rdoc/support/test_case.rb b/test/rdoc/support/test_case.rb index 36009111e2..d98dbe0d7b 100644 --- a/test/rdoc/support/test_case.rb +++ b/test/rdoc/support/test_case.rb @@ -37,7 +37,8 @@ class RDoc::TestCase < Test::Unit::TestCase super @orig_home = ENV["HOME"] - ENV["HOME"] = Dir.tmpdir + FileUtils.mkdir_p(@test_home = Dir.mktmpdir("test_rdoc_")) + ENV["HOME"] = @test_home @top_level = nil @@ -64,6 +65,7 @@ class RDoc::TestCase < Test::Unit::TestCase def teardown ENV["HOME"] = @orig_home if defined?(@orig_home) + defined?(@test_home) and FileUtils.rm_rf @test_home super end diff --git a/test/rdoc/support/text_formatter_test_case.rb b/test/rdoc/support/text_formatter_test_case.rb index 22a762b5f0..e359028a29 100644 --- a/test/rdoc/support/text_formatter_test_case.rb +++ b/test/rdoc/support/text_formatter_test_case.rb @@ -112,4 +112,3 @@ class RDoc::Markup::TextFormatterTestCase < RDoc::Markup::FormatterTestCase end end - diff --git a/test/rdoc/test_rdoc_any_method.rb b/test/rdoc/test_rdoc_any_method.rb index 6915b466f0..b11c15420c 100644 --- a/test/rdoc/test_rdoc_any_method.rb +++ b/test/rdoc/test_rdoc_any_method.rb @@ -69,6 +69,20 @@ each_line(foo) assert_equal 'C1::m', @c1.method_list.first.full_name end + def test_has_call_seq? + m = RDoc::AnyMethod.new nil, "each_line" + m2 = RDoc::AnyMethod.new nil, "each" + assert_equal false, m.has_call_seq? + m.call_seq = "each_line()" + assert_equal true, m.has_call_seq? + + m = RDoc::AnyMethod.new nil, "each_line" + m.is_alias_for = m2 + assert_equal false, m.has_call_seq? + m2.call_seq = "each_line()" + assert_equal true, m.has_call_seq? + end + def test_is_alias_for assert_equal @c2_b, @c2_a.is_alias_for @@ -515,6 +529,30 @@ method(a, b) { |c, d| ... } assert_equal 'C1', @c1.method_list.last.parent_name end + def test_skip_description? + m = RDoc::AnyMethod.new nil, "each_line" + m2 = RDoc::AnyMethod.new nil, "each" + assert_equal false, m.skip_description? + assert_equal false, m2.skip_description? + + m.is_alias_for = m2 + m2.aliases << m + assert_equal false, m.skip_description? + assert_equal false, m2.skip_description? + + m2.call_seq = "each()" + assert_equal true, m.skip_description? + assert_equal false, m2.skip_description? + + m2.call_seq = "each_line()" + assert_equal false, m.skip_description? + assert_equal true, m2.skip_description? + + m2.call_seq = "each()\neach_line()" + assert_equal false, m.skip_description? + assert_equal false, m2.skip_description? + end + def test_store_equals loaded = Marshal.load Marshal.dump(@c1.method_list.last) diff --git a/test/rdoc/test_rdoc_comment.rb b/test/rdoc/test_rdoc_comment.rb index d3c16bceca..28e8cf76b4 100644 --- a/test/rdoc/test_rdoc_comment.rb +++ b/test/rdoc/test_rdoc_comment.rb @@ -206,6 +206,15 @@ lines, one line per element. Lines are assumed to be separated by _sep_. assert_equal expected, comment.text end + def test_extract_call_linear_performance + pre = ->(n) {[n, RDoc::Comment.new("\n"*n + 'call-seq:' + 'a'*n)]} + method_obj = RDoc::AnyMethod.new nil, 'blah' + assert_linear_performance((2..5).map {|i| 10**i}, pre: pre) do |n, comment| + comment.extract_call_seq method_obj + assert_equal n, method_obj.call_seq.size + end + end + def test_force_encoding @comment = RDoc::Encoding.change_encoding @comment, Encoding::UTF_8 diff --git a/test/rdoc/test_rdoc_context.rb b/test/rdoc/test_rdoc_context.rb index 85665599fb..c4de04e083 100644 --- a/test/rdoc/test_rdoc_context.rb +++ b/test/rdoc/test_rdoc_context.rb @@ -927,6 +927,12 @@ class TestRDocContext < XrefTestCase assert_equal :private, @c6.find_method_named('priv6').visibility assert_equal :protected, @c6.find_method_named('prot6').visibility assert_equal :public, @c6.find_method_named('pub6').visibility + assert_equal :public, @c6.find_method_named('s_pub1').visibility + assert_equal :public, @c6.find_method_named('s_pub2').visibility + assert_equal :public, @c6.find_method_named('s_pub3').visibility + assert_equal :public, @c6.find_method_named('s_pub4').visibility + assert_equal :private, @c6.find_method_named('s_priv1').visibility + assert_equal :protected, @c6.find_method_named('s_prot1').visibility end def util_visibilities diff --git a/test/rdoc/test_rdoc_context_section.rb b/test/rdoc/test_rdoc_context_section.rb index 24c68c49dd..6834cccafb 100644 --- a/test/rdoc/test_rdoc_context_section.rb +++ b/test/rdoc/test_rdoc_context_section.rb @@ -144,4 +144,3 @@ class TestRDocContextSection < RDoc::TestCase end end - diff --git a/test/rdoc/test_rdoc_generator_darkfish.rb b/test/rdoc/test_rdoc_generator_darkfish.rb index ae3a4c5ebf..96319bb4f7 100644 --- a/test/rdoc/test_rdoc_generator_darkfish.rb +++ b/test/rdoc/test_rdoc_generator_darkfish.rb @@ -73,6 +73,22 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase top_level = @store.add_file 'file.rb' top_level.add_class @klass.class, @klass.name @klass.add_class RDoc::NormalClass, 'Inner' + @klass.add_comment <<~RDOC, top_level + = Heading 1 + Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod + == Heading 1.1 + tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, + === Heading 1.1.1 + quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo + ==== Heading 1.1.1.1 + consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse + == Heading 1.2 + cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat + == Heading 1.3 + non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + === Heading 1.3.1 + etc etc... + RDOC @g.generate @@ -91,12 +107,31 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase encoding = Regexp.escape Encoding::UTF_8.name - assert_match %r%<meta charset="#{encoding}">%, File.read('index.html') - assert_match %r%<meta charset="#{encoding}">%, File.read('Object.html') + assert_match %r%<meta charset="#{encoding}">%, File.binread('index.html') + assert_match %r%<meta charset="#{encoding}">%, File.binread('Object.html') - refute_match(/Ignored/, File.read('index.html')) - summary = File.read('index.html')[%r[<summary.*Klass\.html.*</summary>.*</details>]m] + refute_match(/Ignored/, File.binread('index.html')) + summary = File.binread('index.html')[%r[<summary.*Klass\.html.*</summary>.*</details>]m] assert_match(%r[Klass/Inner\.html".*>Inner<], summary) + + klass = File.binread('Klass.html') + klassnav = klass[%r[<div class="nav-section">.*<div id="class-metadata">]m] + assert_match( + %r[<li>\s*<details open>\s*<summary>\s*<a href=\S+>Heading 1</a>\s*</summary>\s*<ul]m, + klassnav + ) + assert_match( + %r[<li>\s*<a href=\S+>Heading 1.1.1.1</a>\s*</ul>\s*</details>\s*</li>]m, + klassnav + ) + + assert_match(/<h1 id="class-Klass-label-Heading\+1">Heading 1(?!\.)/, + klass[%r[<section class=\"description\">.*</section>]m]) + toc = File.binread('table_of_contents.html') + assert_match( + %r[<a\s+href="Klass\.html#class-Klass-label-Heading\+1">Heading 1</a>]m, + toc[%r[<h2\s+id=\"classes\">.*(?=<h2\b)]m][%r[<a\s+href="Klass\.html".*(?=</li\b)]m] + ) end def test_generate_page @@ -105,15 +140,15 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase @g.generate assert_file 'outer_rdoc.html' assert_file 'outer/inner_rdoc.html' - index = File.read('index.html') + index = File.binread('index.html') re = %r[<summary><a href="\./outer_rdoc\.html">outer</a></summary>.*?</details>]m assert_match(re, index) summary = index[re] assert_match %r[<a href="\./outer/inner_rdoc.html">inner</a>], summary re = %r[<details open><summary><a href="\./outer_rdoc\.html">outer</a></summary>.*?</details>]m - assert_match(re, File.read('outer_rdoc.html')) + assert_match(re, File.binread('outer_rdoc.html')) re = %r[<details open><summary><a href="\.\./outer_rdoc\.html">outer</a></summary>.*?</details>]m - assert_match(re, File.read('outer/inner_rdoc.html')) + assert_match(re, File.binread('outer/inner_rdoc.html')) end def test_generate_dry_run @@ -233,6 +268,29 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase assert_includes method_name, '{ |%<<script>alert("atui")</script>>, yield_arg| ... }' end + def test_generated_filename_with_html_tag + filename = '"><em>should be escaped' + begin # in @tmpdir + File.write(filename, '') + rescue SystemCallError + # ", <, > chars are prohibited as filename + return + else + File.unlink(filename) + end + @store.add_file filename + doc = @store.all_files.last + doc.parser = RDoc::Parser::Simple + + @g.generate + + Dir.glob("*.html", base: @tmpdir) do |html| + File.binread(File.join(@tmpdir, html)).scan(/.*should be escaped.*/) do |line| + assert_not_include line, "<em>", html + end + end + end + def test_template_stylesheets css = Tempfile.create(%W'hoge .css', Dir.mktmpdir('tmp', '.')) File.write(css, '') @@ -245,7 +303,23 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase @g.generate assert_file base - assert_include File.read('index.html'), %Q[href="./#{base}"] + assert_include File.binread('index.html'), %Q[href="./#{base}"] + end + + def test_title + title = "RDoc Test".freeze + @options.title = title + @g.generate + + assert_main_title(File.binread('index.html'), title) + end + + def test_title_escape + title = %[<script>alert("RDoc")</script>].freeze + @options.title = title + @g.generate + + assert_main_title(File.binread('index.html'), title) end ## @@ -271,4 +345,9 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase "#{filename} is not hard-linked" end + def assert_main_title(content, title) + title = CGI.escapeHTML(title) + assert_equal(title, content[%r[<title>(.*?)<\/title>]im, 1]) + assert_include(content[%r[<main\s[^<>]*+>\s*(.*?)</main>]im, 1], title) + end end diff --git a/test/rdoc/test_rdoc_generator_json_index.rb b/test/rdoc/test_rdoc_generator_json_index.rb index 6b69337b45..62d1ccec95 100644 --- a/test/rdoc/test_rdoc_generator_json_index.rb +++ b/test/rdoc/test_rdoc_generator_json_index.rb @@ -104,8 +104,20 @@ class TestRDocGeneratorJsonIndex < RDoc::TestCase orig_file = Pathname(File.join srcdir, 'generator/template/json_index/js/navigation.js') generated_file = Pathname(File.join @tmpdir, 'js/navigation.js') + # The following assertion for the generated file's modified time randomly + # fails in a ppc64le environment. + # https://github.com/ruby/rdoc/issues/1048 + if orig_file.mtime.inspect != generated_file.mtime.inspect && + RUBY_PLATFORM =~ /powerpc64le/ + pend <<~EOC + Unstable test in ppc64le. + <#{orig_file.mtime.inspect}> expected but was + <#{generated_file.mtime.inspect}>. + EOC + end + # This is dirty hack on JRuby - assert orig_file.mtime.inspect == generated_file.mtime.inspect, + assert_equal orig_file.mtime.inspect, generated_file.mtime.inspect, '.js files should be the same timestamp of original' json = File.read 'js/search_index.js' diff --git a/test/rdoc/test_rdoc_generator_markup.rb b/test/rdoc/test_rdoc_generator_markup.rb index 5491b7c61e..7c021e432e 100644 --- a/test/rdoc/test_rdoc_generator_markup.rb +++ b/test/rdoc/test_rdoc_generator_markup.rb @@ -57,4 +57,3 @@ class TestRDocGeneratorMarkup < RDoc::TestCase end end - diff --git a/test/rdoc/test_rdoc_markdown.rb b/test/rdoc/test_rdoc_markdown.rb index ca76c34f43..31d5b068f9 100644 --- a/test/rdoc/test_rdoc_markdown.rb +++ b/test/rdoc/test_rdoc_markdown.rb @@ -305,6 +305,25 @@ that also extends to two lines assert_equal expected, doc end + def test_parse_definition_list_rich_label + doc = parse <<-MD +`one` +: This is a definition + +**two** +: This is another definition + MD + + expected = doc( + list(:NOTE, + item(%w[<code>one</code>], + para("This is a definition")), + item(%w[*two*], + para("This is another definition")))) + + assert_equal expected, doc + end + def test_parse_definition_list_no @parser.definition_lists = false @@ -1062,6 +1081,27 @@ and an extra note.[^2] assert_equal expected, doc end + def test_gfm_table_2 + doc = parse <<~'MD' + | Cmd | Returns | Meaning + ----- | :-----: | ------- + |"b" | boolean | True if file1 is a block device + "c" | boolean | True if file1 is a character device + |"\|" | boolean | escaped bar \| test + MD + + head = %w[Cmd Returns Meaning] + align = [nil, :center, nil] + body = [ + ['"b"', 'boolean', 'True if file1 is a block device'], + ['"c"', 'boolean', 'True if file1 is a character device'], + ['"|"', 'boolean', 'escaped bar | test'], + ] + expected = doc(@RM::Table.new(head, align, body)) + + assert_equal expected, doc + end + def parse text @parser.parse text end diff --git a/test/rdoc/test_rdoc_markup.rb b/test/rdoc/test_rdoc_markup.rb index b9bdafab2a..4d79f8bc3f 100644 --- a/test/rdoc/test_rdoc_markup.rb +++ b/test/rdoc/test_rdoc_markup.rb @@ -93,4 +93,3 @@ the time end end - diff --git a/test/rdoc/test_rdoc_markup_attribute_manager.rb b/test/rdoc/test_rdoc_markup_attribute_manager.rb index e8ff602f96..dcae48525d 100644 --- a/test/rdoc/test_rdoc_markup_attribute_manager.rb +++ b/test/rdoc/test_rdoc_markup_attribute_manager.rb @@ -393,4 +393,3 @@ class TestRDocMarkupAttributeManager < RDoc::TestCase end end - diff --git a/test/rdoc/test_rdoc_markup_attributes.rb b/test/rdoc/test_rdoc_markup_attributes.rb index 0dfd72bdb6..1ab408d801 100644 --- a/test/rdoc/test_rdoc_markup_attributes.rb +++ b/test/rdoc/test_rdoc_markup_attributes.rb @@ -37,4 +37,3 @@ class TestRDocMarkupAttributes < RDoc::TestCase end end - diff --git a/test/rdoc/test_rdoc_markup_document.rb b/test/rdoc/test_rdoc_markup_document.rb index 3db834b85d..e4f3b9daf1 100644 --- a/test/rdoc/test_rdoc_markup_document.rb +++ b/test/rdoc/test_rdoc_markup_document.rb @@ -205,4 +205,3 @@ class TestRDocMarkupDocument < RDoc::TestCase end end - diff --git a/test/rdoc/test_rdoc_markup_formatter.rb b/test/rdoc/test_rdoc_markup_formatter.rb index 8702db379d..af19d832ca 100644 --- a/test/rdoc/test_rdoc_markup_formatter.rb +++ b/test/rdoc/test_rdoc_markup_formatter.rb @@ -104,6 +104,12 @@ class TestRDocMarkupFormatter < RDoc::TestCase formatted = document.accept @to assert_equal '<{foo}[rdoc-label:bar]>.', formatted + + document = doc(para('<tt>{abc}</tt>: {foo}[rdoc-label:bar].')) + + formatted = document.accept @to + + assert_equal '<code>{abc}</code>: <{foo}[rdoc-label:bar]>.', formatted end def test_parse_url diff --git a/test/rdoc/test_rdoc_markup_hard_break.rb b/test/rdoc/test_rdoc_markup_hard_break.rb index adebfdc311..ac67c68d10 100644 --- a/test/rdoc/test_rdoc_markup_hard_break.rb +++ b/test/rdoc/test_rdoc_markup_hard_break.rb @@ -29,4 +29,3 @@ class TestRDocMarkupHardBreak < RDoc::TestCase end end - diff --git a/test/rdoc/test_rdoc_markup_heading.rb b/test/rdoc/test_rdoc_markup_heading.rb index 05a8e005ba..de92af91a0 100644 --- a/test/rdoc/test_rdoc_markup_heading.rb +++ b/test/rdoc/test_rdoc_markup_heading.rb @@ -27,4 +27,3 @@ class TestRDocMarkupHeading < RDoc::TestCase end end - diff --git a/test/rdoc/test_rdoc_markup_include.rb b/test/rdoc/test_rdoc_markup_include.rb index 9126526b73..b3e9b845c3 100644 --- a/test/rdoc/test_rdoc_markup_include.rb +++ b/test/rdoc/test_rdoc_markup_include.rb @@ -17,4 +17,3 @@ class TestRDocMarkupInclude < RDoc::TestCase end end - diff --git a/test/rdoc/test_rdoc_markup_indented_paragraph.rb b/test/rdoc/test_rdoc_markup_indented_paragraph.rb index 7b5758998f..d2a9cbe5ca 100644 --- a/test/rdoc/test_rdoc_markup_indented_paragraph.rb +++ b/test/rdoc/test_rdoc_markup_indented_paragraph.rb @@ -51,4 +51,3 @@ class TestRDocMarkupIndentedParagraph < RDoc::TestCase end end - diff --git a/test/rdoc/test_rdoc_markup_paragraph.rb b/test/rdoc/test_rdoc_markup_paragraph.rb index ca89a74fc3..1b26846eb3 100644 --- a/test/rdoc/test_rdoc_markup_paragraph.rb +++ b/test/rdoc/test_rdoc_markup_paragraph.rb @@ -30,4 +30,3 @@ class TestRDocMarkupParagraph < RDoc::TestCase end end - diff --git a/test/rdoc/test_rdoc_markup_raw.rb b/test/rdoc/test_rdoc_markup_raw.rb index c7795b24e1..52887e6f6c 100644 --- a/test/rdoc/test_rdoc_markup_raw.rb +++ b/test/rdoc/test_rdoc_markup_raw.rb @@ -20,4 +20,3 @@ class TestRDocMarkupRaw < RDoc::TestCase end end - diff --git a/test/rdoc/test_rdoc_markup_to_ansi.rb b/test/rdoc/test_rdoc_markup_to_ansi.rb index 1d1fc7db46..81372c64d2 100644 --- a/test/rdoc/test_rdoc_markup_to_ansi.rb +++ b/test/rdoc/test_rdoc_markup_to_ansi.rb @@ -367,4 +367,3 @@ bar: end end - diff --git a/test/rdoc/test_rdoc_markup_to_html.rb b/test/rdoc/test_rdoc_markup_to_html.rb index a5927dccae..e3affa533c 100644 --- a/test/rdoc/test_rdoc_markup_to_html.rb +++ b/test/rdoc/test_rdoc_markup_to_html.rb @@ -391,11 +391,43 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase end def test_accept_paragraph_newline + hellos = ["hello", "\u{393 3b5 3b9 3ac} \u{3c3 3bf 3c5}"] + worlds = ["world", "\u{3ba 3cc 3c3 3bc 3bf 3c2}"] + ohayo, sekai = %W"\u{304a 306f 3088 3046} \u{4e16 754c}" + + hellos.product(worlds) do |hello, world| + @to.start_accepting + @to.accept_paragraph para("#{hello}\n", "#{world}\n") + assert_equal "\n<p>#{hello} #{world}</p>\n", @to.res.join + end + + hellos.each do |hello| + @to.start_accepting + @to.accept_paragraph para("#{hello}\n", "#{sekai}\n") + assert_equal "\n<p>#{hello}#{sekai}</p>\n", @to.res.join + end + + worlds.each do |world| + @to.start_accepting + @to.accept_paragraph para("#{ohayo}\n", "#{world}\n") + assert_equal "\n<p>#{ohayo}#{world}</p>\n", @to.res.join + end + @to.start_accepting + @to.accept_paragraph para("#{ohayo}\n", "#{sekai}\n") + assert_equal "\n<p>#{ohayo}#{sekai}</p>\n", @to.res.join - @to.accept_paragraph para("hello\n", "world\n") + @to.start_accepting + @to.accept_paragraph para("+hello+\n", "world\n") + assert_equal "\n<p><code>hello</code> world</p>\n", @to.res.join - assert_equal "\n<p>hello world </p>\n", @to.res.join + @to.start_accepting + @to.accept_paragraph para("hello\n", "+world+\n") + assert_equal "\n<p>hello <code>world</code></p>\n", @to.res.join + + @to.start_accepting + @to.accept_paragraph para("+hello+\n", "+world+\n") + assert_equal "\n<p><code>hello</code> <code>world</code></p>\n", @to.res.join end def test_accept_heading_output_decoration @@ -602,9 +634,9 @@ end end def test_accept_verbatim_redefinable_operators - functions = %w[| ^ & <=> == === =~ > >= < <= << >> + - * / % ** ~ +@ -@ [] []= ` ! != !~].map { |redefinable_op| + functions = %w[| ^ & <=> == === =~ > >= < <= << >> + - * / % ** ~ +@ -@ [] []= ` ! != !~].flat_map { |redefinable_op| ["def #{redefinable_op}\n", "end\n"] - }.flatten + } verb = @RM::Verbatim.new(*functions) @@ -665,6 +697,26 @@ EXPECTED assert_equal "\n<p>C</p>\n", result end + def test_convert_RDOCLINK_escape_image + assert_escaped '<script>', 'rdoc-image:"><script>alert(`rdoc-image`)</script>"' + end + + def test_convert_RDOCLINK_escape_label_id + assert_escaped '<script>', 'rdoc-label::path::"><script>alert(`rdoc-label_id`)</script>"' + end + + def test_convert_RDOCLINK_escape_label_path + assert_escaped '<script>', 'rdoc-label::"><script>alert(`rdoc-label_path`)</script>"' + end + + def test_convert_RDOCLINK_escape_ref + assert_escaped '<script>', 'rdoc-ref:"><script>alert(`rdoc-ref`)</script>"' + end + + def test_convert_RDOCLINK_escape_xxx + assert_escaped '<script>', 'rdoc-xxx:"><script>alert(`rdoc-xxx`)</script>"' + end + def test_convert_TIDYLINK_footnote result = @to.convert 'text{*1}[rdoc-label:foottext-1:footmark-1]' @@ -690,6 +742,11 @@ EXPECTED "\n<p><a href=\"http://example.com\"><img src=\"path/to/image.jpg\"></a></p>\n" assert_equal expected, result + + result = + @to.convert '{rdoc-image:<script>alert`link text`</script>}[http://example.com]' + + assert_not_include result, "<script>" end def test_convert_TIDYLINK_rdoc_label @@ -704,6 +761,23 @@ EXPECTED assert_equal "\n<p><a href=\"irc://irc.freenode.net/#ruby-lang\">ruby-lang</a></p>\n", result end + def test_convert_TIDYLINK_escape_text + assert_escaped '<script>', '{<script>alert`link text`</script>}[a]' + assert_escaped '<script>', 'x:/<script>alert(1);</script>[[]' + end + + def test_convert_TIDYLINK_escape_javascript + assert_not_include '{click}[javascript:alert`javascript_scheme`]', '<a href="javascript:' + end + + def test_convert_TIDYLINK_escape_onmouseover + assert_escaped '"/onmouseover="', '{onmouseover}[http://"/onmouseover="alert`on_mouse_link`"]' + end + + def test_convert_TIDYLINK_escape_onerror + assert_escaped '"onerror="', '{link_image}[http://"onerror="alert`link_image`".png]' + end + def test_convert_with_exclude_tag assert_equal "\n<p><code>aaa</code>[:symbol]</p>\n", @to.convert('+aaa+[:symbol]') assert_equal "\n<p><code>aaa[:symbol]</code></p>\n", @to.convert('+aaa[:symbol]+') @@ -794,6 +868,11 @@ EXPECTED assert_equal '<a href="irc://irc.freenode.net/#ruby-lang">irc.freenode.net/#ruby-lang</a>', link end + def test_handle_regexp_HYPERLINK_escape + code = 'irc://irc.freenode.net/"><script>alert(`irc`)</script><a"' + assert_escaped '<script>', code + end + def test_list_verbatim_2 str = "* one\n verb1\n verb2\n* two\n" @@ -876,5 +955,37 @@ EXPECTED @to.end_accepting end + def test_accept_table + header = %w[Col1 Col2 Col3] + body = [ + %w[cell1_1 cell1_2 cell1_3], + %w[cell2_1 cell2_2 cell2_3], + ['<script>alert("foo");</script>',], + %w[+code+ _em_ **strong**], + ] + aligns = [:left, :right, nil] + @to.start_accepting + @to.accept_table(header, body, aligns) + res = @to.end_accepting + assert_include(res[%r<<th[^<>]*>Col1</th>>], 'align="left"') + assert_include(res[%r<<th[^<>]*>Col2</th>>], 'align="right"') + assert_not_include(res[%r<<th[^<>]*>Col3</th>>], 'align=') + assert_include(res[%r<<td[^<>]*>cell1_1</td>>], 'align="left"') + assert_include(res[%r<<td[^<>]*>cell1_2</td>>], 'align="right"') + assert_not_include(res[%r<<td[^<>]*>cell1_3</td>>], 'align=') + assert_include(res[%r<<td[^<>]*>cell2_1</td>>], 'align="left"') + assert_include(res[%r<<td[^<>]*>cell2_2</td>>], 'align="right"') + assert_not_include(res[%r<<td[^<>]*>cell2_3</td>>], 'align=') + assert_not_include(res, '<script>') + assert_include(res[%r<<td[^<>]*>.*script.*</td>>], '<script>') + assert_include(res[%r<<td[^<>]*>.*code.*</td>>], '<code>code</code>') + assert_include(res[%r<<td[^<>]*>.*em.*</td>>], '<em>em</em>') + assert_include(res[%r<<td[^<>]*>.*strong.*</td>>], '<strong>strong</strong>') + end + + def assert_escaped(unexpected, code) + result = @to.convert(code) + assert_not_include result, unexpected + assert_include result, CGI.escapeHTML(unexpected) + end end - diff --git a/test/rdoc/test_rdoc_markup_to_html_crossref.rb b/test/rdoc/test_rdoc_markup_to_html_crossref.rb index 4b87dd5da5..dc4488195a 100644 --- a/test/rdoc/test_rdoc_markup_to_html_crossref.rb +++ b/test/rdoc/test_rdoc_markup_to_html_crossref.rb @@ -133,6 +133,18 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase 'rdoc-ref:C1@foo' end + def test_convert_RDOCLINK_rdoc_ref_label_in_current_file + result = @to.convert 'rdoc-ref:@foo' + + assert_equal para("<a href=\"#label-foo\">foo</a>"), result, + 'rdoc-ref:@foo' + + result = @to.convert '{Foo}[rdoc-ref:@foo]' + + assert_equal para("<a href=\"#label-foo\">Foo</a>"), result, + '{Foo}[rdoc-ref:@foo]' + end + def test_gen_url assert_equal '<a href="C1.html">Some class</a>', @to.gen_url('rdoc-ref:C1', 'Some class') diff --git a/test/rdoc/test_rdoc_markup_to_joined_paragraph.rb b/test/rdoc/test_rdoc_markup_to_joined_paragraph.rb index cbaf75a04e..8bd2d67247 100644 --- a/test/rdoc/test_rdoc_markup_to_joined_paragraph.rb +++ b/test/rdoc/test_rdoc_markup_to_joined_paragraph.rb @@ -30,4 +30,3 @@ class TestRDocMarkupToJoinedParagraph < RDoc::TestCase end end - diff --git a/test/rdoc/test_rdoc_markup_to_label.rb b/test/rdoc/test_rdoc_markup_to_label.rb index 70ea7f0f1b..2bf2e0ecdf 100644 --- a/test/rdoc/test_rdoc_markup_to_label.rb +++ b/test/rdoc/test_rdoc_markup_to_label.rb @@ -110,4 +110,3 @@ class TestRDocMarkupToLabel < RDoc::Markup::FormatterTestCase end end - diff --git a/test/rdoc/test_rdoc_markup_to_markdown.rb b/test/rdoc/test_rdoc_markup_to_markdown.rb index c8c5fd4d52..92ed37bc50 100644 --- a/test/rdoc/test_rdoc_markup_to_markdown.rb +++ b/test/rdoc/test_rdoc_markup_to_markdown.rb @@ -69,7 +69,7 @@ class TestRDocMarkupToMarkdown < RDoc::Markup::TextFormatterTestCase end def accept_list_item_end_label - assert_equal "cat\n: ", @to.res.join + assert_equal "cat\n: \n", @to.res.join assert_equal 0, @to.indent, 'indent' end @@ -79,7 +79,7 @@ class TestRDocMarkupToMarkdown < RDoc::Markup::TextFormatterTestCase end def accept_list_item_end_note - assert_equal "cat\n: ", @to.res.join + assert_equal "cat\n: \n", @to.res.join assert_equal 0, @to.indent, 'indent' end @@ -319,9 +319,7 @@ words words words words expected = <<-EXPECTED * l1 * l1.1 - * l2 - EXPECTED assert_equal expected, @to.end_accepting @@ -343,7 +341,6 @@ words words words words * second - EXPECTED assert_equal expected, @to.end_accepting @@ -387,4 +384,3 @@ words words words words end end - diff --git a/test/rdoc/test_rdoc_markup_to_rdoc.rb b/test/rdoc/test_rdoc_markup_to_rdoc.rb index 1d833b156a..50f4b6dc8b 100644 --- a/test/rdoc/test_rdoc_markup_to_rdoc.rb +++ b/test/rdoc/test_rdoc_markup_to_rdoc.rb @@ -69,7 +69,7 @@ class TestRDocMarkupToRDoc < RDoc::Markup::TextFormatterTestCase end def accept_list_item_end_label - assert_equal "cat:\n", @to.res.join + assert_equal "[cat]\n", @to.res.join assert_equal 0, @to.indent, 'indent' end @@ -79,7 +79,7 @@ class TestRDocMarkupToRDoc < RDoc::Markup::TextFormatterTestCase end def accept_list_item_end_note - assert_equal "cat:\n", @to.res.join + assert_equal "cat::\n", @to.res.join assert_equal 0, @to.indent, 'indent' end @@ -100,7 +100,7 @@ class TestRDocMarkupToRDoc < RDoc::Markup::TextFormatterTestCase def accept_list_item_start_label assert_equal [""], @to.res - assert_equal "cat:\n ", @to.prefix + assert_equal "[cat]\n ", @to.prefix assert_equal 2, @to.indent end @@ -115,7 +115,7 @@ class TestRDocMarkupToRDoc < RDoc::Markup::TextFormatterTestCase def accept_list_item_start_note assert_equal [""], @to.res - assert_equal "cat:\n ", @to.prefix + assert_equal "cat::\n ", @to.prefix assert_equal 2, @to.indent end @@ -243,16 +243,16 @@ class TestRDocMarkupToRDoc < RDoc::Markup::TextFormatterTestCase end def accept_list_item_start_note_2 - assert_equal "<tt>teletype</tt>:\n teletype description\n\n", @to.res.join + assert_equal "<tt>teletype</tt>::\n teletype description\n\n", @to.res.join end def accept_list_item_start_note_multi_description - assert_equal "label:\n description one\n\n description two\n\n", + assert_equal "label::\n description one\n\n description two\n\n", @to.res.join end def accept_list_item_start_note_multi_label - assert_equal "one\ntwo:\n two headers\n\n", @to.res.join + assert_equal "one::\ntwo::\n two headers\n\n", @to.res.join end def accept_paragraph_b @@ -355,8 +355,8 @@ bar :: NOTE_LIST expected = <<-EXPECTED -foo -bar: +foo:: +bar:: hi EXPECTED @@ -375,4 +375,3 @@ bar: end end - diff --git a/test/rdoc/test_rdoc_markup_to_table_of_contents.rb b/test/rdoc/test_rdoc_markup_to_table_of_contents.rb index 11ab6f197b..7512495aec 100644 --- a/test/rdoc/test_rdoc_markup_to_table_of_contents.rb +++ b/test/rdoc/test_rdoc_markup_to_table_of_contents.rb @@ -124,4 +124,3 @@ class TestRDocMarkupToTableOfContents < RDoc::Markup::FormatterTestCase end end - diff --git a/test/rdoc/test_rdoc_markup_to_tt_only.rb b/test/rdoc/test_rdoc_markup_to_tt_only.rb index 8508f823df..c709d7a4d5 100644 --- a/test/rdoc/test_rdoc_markup_to_tt_only.rb +++ b/test/rdoc/test_rdoc_markup_to_tt_only.rb @@ -244,4 +244,3 @@ class TestRDocMarkupToTtOnly < RDoc::Markup::FormatterTestCase end end - diff --git a/test/rdoc/test_rdoc_markup_verbatim.rb b/test/rdoc/test_rdoc_markup_verbatim.rb index 1a650c44ef..2f8a57266a 100644 --- a/test/rdoc/test_rdoc_markup_verbatim.rb +++ b/test/rdoc/test_rdoc_markup_verbatim.rb @@ -27,4 +27,3 @@ class TestRDocMarkupVerbatim < RDoc::TestCase end end - diff --git a/test/rdoc/test_rdoc_options.rb b/test/rdoc/test_rdoc_options.rb index 009dcdd998..5e8b1ae3d8 100644 --- a/test/rdoc/test_rdoc_options.rb +++ b/test/rdoc/test_rdoc_options.rb @@ -68,7 +68,6 @@ class TestRDocOptions < RDoc::TestCase 'exclude' => %w[~\z \.orig\z \.rej\z \.bak\z \.gemspec\z], 'hyperlink_all' => false, 'line_numbers' => false, - 'locale' => nil, 'locale_dir' => 'locale', 'locale_name' => nil, 'main_page' => nil, @@ -83,6 +82,7 @@ class TestRDocOptions < RDoc::TestCase 'title' => nil, 'visibility' => :protected, 'webcvs' => nil, + 'skip_tests' => true, } assert_equal expected, coder @@ -208,6 +208,13 @@ rdoc_include: assert @options.force_update end + def test_parse_coverage_C + @options.parse %w[-C] + + assert @options.coverage_report + assert @options.force_update + end + def test_parse_coverage_no @options.parse %w[--no-dcov] @@ -220,6 +227,19 @@ rdoc_include: assert_equal 1, @options.coverage_report end + def test_parse_coverage_C_level_1 + @options.parse %w[-C1] + + assert_equal 1, @options.coverage_report + end + + def test_parse_coverage_C_level_0 + @options.parse %w[-C0] + + assert_equal 0, @options.coverage_report + assert @options.force_update + end + def test_parse_dash_p out, err = capture_output do @options.parse %w[-p] @@ -699,6 +719,28 @@ rdoc_include: assert_empty err end + def test_parse_locale_name_default + temp_dir do + @options.parse %w[] + assert_equal 'locale', @options.instance_variable_get(:@locale_dir) + assert_nil @options.instance_variable_get(:@locale_name) + assert_nil @options.locale + @options.finish + assert_nil @options.locale + end + end + + def test_parse_locale_name + temp_dir do + @options.parse %w[--locale fr] + assert_equal 'locale', @options.instance_variable_get(:@locale_dir) + assert_equal 'fr', @options.instance_variable_get(:@locale_name) + assert_nil @options.locale + @options.finish + assert_equal 'fr', @options.locale.name + end + end + def test_setup_generator test_generator = Class.new do def self.setup_options op @@ -871,6 +913,16 @@ rdoc_include: end end + def test_skip_test_default_value + @options.parse %w[] + assert_equal true, @options.skip_tests + end + + def test_no_skip_test_value + @options.parse %w[--no-skipping-tests] + assert_equal false, @options.skip_tests + end + class DummyCoder < Hash alias add :[]= def tag=(tag) diff --git a/test/rdoc/test_rdoc_parser.rb b/test/rdoc/test_rdoc_parser.rb index 7cc3c2d926..fa6443f3d3 100644 --- a/test/rdoc/test_rdoc_parser.rb +++ b/test/rdoc/test_rdoc_parser.rb @@ -151,6 +151,20 @@ class TestRDocParser < RDoc::TestCase File.unlink readme_ext end + def test_can_parse_modeline_c + readme_inc = File.join Dir.tmpdir, "README.inc.#{$$}" + + File.open readme_inc, 'w' do |io| + io.puts "/* README.inc - -*- c -*- created at: Mon Aug 7 16:45:54 JST 1995 */" + io.puts + io.puts "/* This document explains how to make extension libraries for Ruby. */" + end + + assert_equal RDoc::Parser::C, @RP.can_parse(readme_inc) + ensure + File.unlink readme_inc + end + ## # Selenium hides a .jar file using a .txt extension. diff --git a/test/rdoc/test_rdoc_parser_c.rb b/test/rdoc/test_rdoc_parser_c.rb index b65561b2bb..ab4f149869 100644 --- a/test/rdoc/test_rdoc_parser_c.rb +++ b/test/rdoc/test_rdoc_parser_c.rb @@ -460,7 +460,7 @@ VALUE mFoo = rb_define_module_under(rb_mKernel, "Foo"); end def test_do_constants - content = <<-EOF + content = <<-'EOF' #include <ruby.h> void Init_foo(){ @@ -475,6 +475,9 @@ void Init_foo(){ /* TEST\:TEST: Checking to see if escaped colon works */ rb_define_const(cFoo, "TEST", rb_str_new2("TEST:TEST")); + /* TEST: TEST:Checking to see if only word-ending colon works */ + rb_define_const(cFoo, "TEST2", rb_str_new2("TEST:TEST")); + /* \\: The file separator on MS Windows */ rb_define_const(cFoo, "MSEPARATOR", rb_str_new2("\\")); @@ -538,6 +541,9 @@ void Init_foo(){ assert_equal ['TEST', 'TEST:TEST', 'Checking to see if escaped colon works '], constants.shift + assert_equal ['TEST2', 'TEST', + 'TEST:Checking to see if only word-ending colon works '], + constants.shift assert_equal ['MSEPARATOR', '\\', 'The file separator on MS Windows '], constants.shift @@ -577,8 +583,6 @@ void Init_curses(){ mCurses = rb_define_module("Curses"); /* - * Document-const: Curses::COLOR_BLACK - * * Value of the color black */ rb_curses_define_const(COLOR_BLACK); @@ -603,8 +607,7 @@ void Init_curses(){ def test_do_constants_file content = <<-EOF void Init_File(void) { - /* Document-const: LOCK_SH - * + /* * Shared lock */ rb_file_const("LOCK_SH", INT2FIX(LOCK_SH)); @@ -1373,6 +1376,36 @@ Init_Foo(void) { assert_equal "DLL_LOCAL VALUE\nother_function() {\n}", code end + def test_find_body_static_inline + content = <<-EOF +/* + * a comment for other_function + */ +static inline 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 "static inline VALUE\nother_function() {\n}", code + end + def test_find_modifiers_call_seq comment = RDoc::Comment.new <<-COMMENT call-seq: @@ -2068,4 +2101,3 @@ void Init_Blah(void) { end end - diff --git a/test/rdoc/test_rdoc_parser_changelog.rb b/test/rdoc/test_rdoc_parser_changelog.rb index 6584840572..587a156d3a 100644 --- a/test/rdoc/test_rdoc_parser_changelog.rb +++ b/test/rdoc/test_rdoc_parser_changelog.rb @@ -482,4 +482,3 @@ ChangeLog RDoc::Parser::ChangeLog::Git::LogEntry.new(*a) end end - diff --git a/test/rdoc/test_rdoc_parser_markdown.rb b/test/rdoc/test_rdoc_parser_markdown.rb index 06c6700d96..cca9c1ddfd 100644 --- a/test/rdoc/test_rdoc_parser_markdown.rb +++ b/test/rdoc/test_rdoc_parser_markdown.rb @@ -59,4 +59,3 @@ class TestRDocParserMarkdown < RDoc::TestCase end end - diff --git a/test/rdoc/test_rdoc_parser_rd.rb b/test/rdoc/test_rdoc_parser_rd.rb index bac9c65592..48663e6d7d 100644 --- a/test/rdoc/test_rdoc_parser_rd.rb +++ b/test/rdoc/test_rdoc_parser_rd.rb @@ -53,4 +53,3 @@ class TestRDocParserRd < RDoc::TestCase end end - diff --git a/test/rdoc/test_rdoc_parser_ruby.rb b/test/rdoc/test_rdoc_parser_ruby.rb index ef8ad91668..3e2a85ffba 100644 --- a/test/rdoc/test_rdoc_parser_ruby.rb +++ b/test/rdoc/test_rdoc_parser_ruby.rb @@ -1960,10 +1960,10 @@ end def test_parse_method_bracket util_parser <<-RUBY class C - def [] end - def self.[] end - def []= end - def self.[]= end + def []; end + def self.[]; end + def []=; end + def self.[]=; end end RUBY @@ -3065,6 +3065,28 @@ RUBY assert_nil m.params, 'Module parameter not removed' end + def test_parse_statements_nodoc_identifier_alias + klass = @top_level.add_class RDoc::NormalClass, 'Foo' + + util_parser "\nalias :old :new # :nodoc:" + + @parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil + + assert_empty klass.aliases + assert_empty klass.unmatched_alias_lists + end + + def test_parse_statements_nodoc_identifier_alias_method + klass = @top_level.add_class RDoc::NormalClass, 'Foo' + + util_parser "\nalias_method :old :new # :nodoc:" + + @parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil + + assert_empty klass.aliases + assert_empty klass.unmatched_alias_lists + end + def test_parse_statements_stopdoc_alias klass = @top_level.add_class RDoc::NormalClass, 'Foo' @@ -3205,6 +3227,14 @@ RUBY assert_nil @parser.parse_symbol_in_arg end + def test_parse_percent_symbol + content = '%s[foo bar]' + util_parser content + tk = @parser.get_tk + assert_equal :on_symbol, tk[:kind] + assert_equal content, tk[:text] + end + def test_parse_statements_alias_method content = <<-CONTENT class A @@ -3350,6 +3380,13 @@ end assert_equal :on_const, parser.get_tk[:kind] end + def test_read_directive_linear_performance + pre = ->(i) {util_parser '# ' + '0'*i + '=000:'} + assert_linear_performance((1..5).map{|i|10**i}, pre: pre) do |parser| + assert_nil parser.read_directive [] + end + end + def test_read_documentation_modifiers c = RDoc::Context.new diff --git a/test/rdoc/test_rdoc_parser_simple.rb b/test/rdoc/test_rdoc_parser_simple.rb index 2f1ad00de4..4255cb97d8 100644 --- a/test/rdoc/test_rdoc_parser_simple.rb +++ b/test/rdoc/test_rdoc_parser_simple.rb @@ -113,4 +113,3 @@ contents of a string. end end - diff --git a/test/rdoc/test_rdoc_rd.rb b/test/rdoc/test_rdoc_rd.rb index 83ee423455..38de575bb0 100644 --- a/test/rdoc/test_rdoc_rd.rb +++ b/test/rdoc/test_rdoc_rd.rb @@ -28,4 +28,3 @@ class TestRDocRd < RDoc::TestCase end end - diff --git a/test/rdoc/test_rdoc_rd_block_parser.rb b/test/rdoc/test_rdoc_rd_block_parser.rb index 22f432eaf4..ca0ac9f9e9 100644 --- a/test/rdoc/test_rdoc_rd_block_parser.rb +++ b/test/rdoc/test_rdoc_rd_block_parser.rb @@ -168,6 +168,27 @@ class TestRDocRdBlockParser < RDoc::TestCase tf.close! end +=begin + def test_parse_include_other_format + @block_parser.include_path = [Dir.tmpdir] + + expected = + doc( + blank_line, + para("include ((*worked*))"), + blank_line, + blank_line) + + str = <<~STR + =begin nonrd + <<< worked + =end + STR + + assert_equal(expected, @block_parser.parse str.lines.to_a) + end +=end + def test_parse_heading assert_equal doc(head(1, "H")), parse("= H") assert_equal doc(head(2, "H")), parse("== H") diff --git a/test/rdoc/test_rdoc_rd_inline.rb b/test/rdoc/test_rdoc_rd_inline.rb index 13ab86d3d9..6bfb229933 100644 --- a/test/rdoc/test_rdoc_rd_inline.rb +++ b/test/rdoc/test_rdoc_rd_inline.rb @@ -61,4 +61,3 @@ class TestRDocRdInline < RDoc::TestCase end end - diff --git a/test/rdoc/test_rdoc_rdoc.rb b/test/rdoc/test_rdoc_rdoc.rb index e958e5f2f6..5168932430 100644 --- a/test/rdoc/test_rdoc_rdoc.rb +++ b/test/rdoc/test_rdoc_rdoc.rb @@ -165,12 +165,7 @@ class TestRDocRDoc < RDoc::TestCase b = Dir.glob(b).first c = Dir.glob(c).first - dot_doc = File.expand_path('.document') - FileUtils.touch dot_doc - open(dot_doc, 'w') do |f| - f.puts 'a.rb' - f.puts 'b.rb' - end + File.write('.document', "a.rb\n""b.rb\n") expected_files << a expected_files << b @@ -196,12 +191,7 @@ class TestRDocRDoc < RDoc::TestCase b = Dir.glob(b).first c = Dir.glob(c).first - dot_doc = File.expand_path('.document') - FileUtils.touch dot_doc - open(dot_doc, 'w') do |f| - f.puts 'a.rb' - f.puts 'b.rb' - end + File.write('.document', "a.rb\n""b.rb\n") expected_files << a @rdoc.options.exclude = Regexp.new(['b.rb'].join('|')) @@ -213,6 +203,48 @@ class TestRDocRDoc < RDoc::TestCase assert_equal expected_files, files end + def test_normalized_file_list_with_skipping_tests_enabled + files = temp_dir do |dir| + @a = File.expand_path('a.rb') + spec_dir = File.expand_path('spec') + spec_file = File.expand_path(File.join('spec', 'my_spec.rb')) + test_dir = File.expand_path('test') + test_file = File.expand_path(File.join('test', 'my_test.rb')) + FileUtils.touch @a + FileUtils.mkdir_p spec_dir + FileUtils.touch spec_file + FileUtils.mkdir_p test_dir + FileUtils.touch test_file + + @rdoc.options.skip_tests = true + @rdoc.normalized_file_list [File.realpath(dir)] + end + + files = files.map { |file, *| File.expand_path file } + assert_equal [@a], files + end + + def test_normalized_file_list_with_skipping_tests_disabled + files = temp_dir do |dir| + @a = File.expand_path('a.rb') + spec_dir = File.expand_path('spec') + @spec_file = File.expand_path(File.join('spec', 'my_spec.rb')) + test_dir = File.expand_path('test') + @test_file = File.expand_path(File.join('test', 'my_test.rb')) + FileUtils.touch @a + FileUtils.mkdir_p spec_dir + FileUtils.touch @spec_file + FileUtils.mkdir_p test_dir + FileUtils.touch @test_file + + @rdoc.options.skip_tests = false + @rdoc.normalized_file_list [File.realpath(dir)] + end + + files = files.map { |file, *| File.expand_path file } + assert_equal [@a, @spec_file, @test_file], files.sort + end + def test_parse_file @rdoc.store = RDoc::Store.new diff --git a/test/rdoc/test_rdoc_ri_driver.rb b/test/rdoc/test_rdoc_ri_driver.rb index fc15c25cea..39e6e67759 100644 --- a/test/rdoc/test_rdoc_ri_driver.rb +++ b/test/rdoc/test_rdoc_ri_driver.rb @@ -6,17 +6,13 @@ class TestRDocRIDriver < RDoc::TestCase def setup super - @tmpdir = File.join Dir.tmpdir, "test_rdoc_ri_driver_#{$$}" - @home_ri = File.join @tmpdir, 'dot_ri' + @home_ri = File.join @test_home, 'dot_ri' - FileUtils.mkdir_p @tmpdir FileUtils.mkdir_p @home_ri - @orig_ri = ENV['RI'] - ENV['HOME'] = @tmpdir - @rdoc_home = File.join ENV["HOME"], ".rdoc" + @orig_ri = ENV.delete('RI') + @rdoc_home = File.join @test_home, ".rdoc" FileUtils.mkdir_p @rdoc_home - ENV.delete 'RI' @options = RDoc::RI::Driver.default_options @options[:use_system] = false @@ -24,7 +20,7 @@ class TestRDocRIDriver < RDoc::TestCase @options[:use_home] = false @options[:use_gems] = false - @options[:home] = @tmpdir + @options[:home] = @rdoc_home @options[:use_stdout] = true @options[:formatter] = @RM::ToRdoc @@ -33,7 +29,6 @@ class TestRDocRIDriver < RDoc::TestCase def teardown defined?(@orig_ri) and ENV['RI'] = @orig_ri - defined?(@tmpdir) and FileUtils.rm_rf @tmpdir super end @@ -603,7 +598,7 @@ class TestRDocRIDriver < RDoc::TestCase assert_match %r%^= Attributes:%, out assert_match %r%^ attr_accessor attr%, out - assert_equal 1, out.scan(/-\n/).length + assert_equal 1, out.scan(/^-{50,}$/).length, out refute_match %r%Foo::Bar#blah%, out end @@ -627,7 +622,7 @@ class TestRDocRIDriver < RDoc::TestCase assert_match %r%^= Attributes:%, out assert_match %r%^ attr_accessor attr%, out - assert_equal 6, out.scan(/-\n/).length + assert_equal 6, out.scan(/^-{50,}$/).length, out assert_match %r%Foo::Bar#blah%, out end diff --git a/test/rdoc/test_rdoc_ri_paths.rb b/test/rdoc/test_rdoc_ri_paths.rb index c01a4711ee..6dccd6dbdd 100644 --- a/test/rdoc/test_rdoc_ri_paths.rb +++ b/test/rdoc/test_rdoc_ri_paths.rb @@ -155,4 +155,3 @@ class TestRDocRIPaths < RDoc::TestCase end end - diff --git a/test/rdoc/test_rdoc_single_class.rb b/test/rdoc/test_rdoc_single_class.rb index ee242d7bc9..e81a1498ba 100644 --- a/test/rdoc/test_rdoc_single_class.rb +++ b/test/rdoc/test_rdoc_single_class.rb @@ -18,4 +18,3 @@ class TestRDocSingleClass < RDoc::TestCase end end - diff --git a/test/rdoc/test_rdoc_stats.rb b/test/rdoc/test_rdoc_stats.rb index b9918e4fd3..ce272d36cf 100644 --- a/test/rdoc/test_rdoc_stats.rb +++ b/test/rdoc/test_rdoc_stats.rb @@ -720,4 +720,3 @@ m(a, b) { |c, d| ... } end end - diff --git a/test/rdoc/test_rdoc_store.rb b/test/rdoc/test_rdoc_store.rb index aa4db4c65e..50e8667d81 100644 --- a/test/rdoc/test_rdoc_store.rb +++ b/test/rdoc/test_rdoc_store.rb @@ -319,8 +319,7 @@ class TestRDocStore < XrefTestCase end def test_friendly_path - @orig_xdg_data_home = ENV['XDG_DATA_HOME'] - ENV.delete('XDG_DATA_HOME') + @orig_xdg_data_home = ENV.delete('XDG_DATA_HOME') @s.path = @tmpdir @s.type = nil @@ -374,9 +373,9 @@ class TestRDocStore < XrefTestCase assert_equal [@mod], s.all_modules.sort assert_equal [@page, @top_level], s.all_files.sort - methods = s.all_classes_and_modules.map do |mod| + methods = s.all_classes_and_modules.flat_map do |mod| mod.method_list - end.flatten.sort + end.sort _meth_bang_alias = RDoc::AnyMethod.new nil, 'method_bang' _meth_bang_alias.parent = @klass @@ -389,9 +388,9 @@ class TestRDocStore < XrefTestCase assert_equal @klass, methods.last.parent - attributes = s.all_classes_and_modules.map do |mod| + attributes = s.all_classes_and_modules.flat_map do |mod| mod.attributes - end.flatten.sort + end.sort assert_equal [@attr], attributes diff --git a/test/rdoc/test_rdoc_task.rb b/test/rdoc/test_rdoc_task.rb index 23add7d5fe..67d223087b 100644 --- a/test/rdoc/test_rdoc_task.rb +++ b/test/rdoc/test_rdoc_task.rb @@ -50,6 +50,7 @@ class TestRDocTask < RDoc::TestCase assert Rake::Task[:rdoc] assert Rake::Task[:clobber_rdoc] assert Rake::Task[:rerdoc] + assert Rake::Task[:"rdoc:coverage"] assert_equal ["html/created.rid"], Rake::Task[:rdoc].prerequisites end @@ -58,6 +59,7 @@ class TestRDocTask < RDoc::TestCase assert Rake::Task[:rdoc_dev] assert Rake::Task[:clobber_rdoc_dev] assert Rake::Task[:rerdoc_dev] + assert Rake::Task[:"rdoc_dev:coverage"] assert_equal :rdoc_dev, rd.name end @@ -110,11 +112,16 @@ class TestRDocTask < RDoc::TestCase assert_equal 'Rebuild RDoc HTML files', @t.rerdoc_task_description end + def test_coverage_task_description + assert_equal 'Print RDoc coverage report', @t.coverage_task_description + end + def test_tasks_creation_with_custom_name_string rd = RDoc::Task.new("rdoc_dev") assert Rake::Task[:rdoc_dev] assert Rake::Task[:clobber_rdoc_dev] assert Rake::Task[:rerdoc_dev] + assert Rake::Task[:"rdoc_dev:coverage"] assert_equal "rdoc_dev", rd.name end @@ -131,6 +138,7 @@ class TestRDocTask < RDoc::TestCase assert Rake::Task[:"rdoc"] assert Rake::Task[:"rdoc:clean"] assert Rake::Task[:"rdoc:force"] + assert Rake::Task[:"rdoc:coverage"] assert_raise(RuntimeError) { Rake::Task[:clobber_rdoc] } assert_equal options, rd.name end @@ -140,6 +148,7 @@ class TestRDocTask < RDoc::TestCase assert Rake::Task[:rdoc] assert Rake::Task[:"rdoc:clean"] assert Rake::Task[:rerdoc] + assert Rake::Task[:"rdoc:coverage"] end def test_tasks_creation_with_custom_name_hash_raises_exception_if_invalid_option_given diff --git a/test/rdoc/test_rdoc_token_stream.rb b/test/rdoc/test_rdoc_token_stream.rb index cdfa615dae..8fcd3d8f68 100644 --- a/test/rdoc/test_rdoc_token_stream.rb +++ b/test/rdoc/test_rdoc_token_stream.rb @@ -39,6 +39,49 @@ class TestRDocTokenStream < RDoc::TestCase assert_equal '', RDoc::TokenStream.to_html([]) end + def test_add_tokens + foo = Class.new do + include RDoc::TokenStream + end.new + foo.collect_tokens + foo.add_tokens([:token]) + assert_equal [:token], foo.token_stream + end + + def test_add_token + foo = Class.new do + include RDoc::TokenStream + end.new + foo.collect_tokens + foo.add_token(:token) + assert_equal [:token], foo.token_stream + end + + def test_collect_tokens + foo = Class.new do + include RDoc::TokenStream + end.new + foo.collect_tokens + assert_equal [], foo.token_stream + end + + def test_pop_token + foo = Class.new do + include RDoc::TokenStream + end.new + foo.collect_tokens + foo.add_token(:token) + foo.pop_token + assert_equal [], foo.token_stream + end + + def test_token_stream + foo = Class.new do + include RDoc::TokenStream + end.new + assert_equal nil, foo.token_stream + end + def test_tokens_to_s foo = Class.new do include RDoc::TokenStream @@ -53,6 +96,14 @@ class TestRDocTokenStream < RDoc::TestCase end.new assert_equal "foo 'bar'", foo.tokens_to_s + + foo = Class.new do + include RDoc::TokenStream + + def initialize + @token_stream = nil + end + end.new + assert_equal "", foo.tokens_to_s end end - diff --git a/test/rdoc/xref_data.rb b/test/rdoc/xref_data.rb index de76a90602..257b821f4f 100644 --- a/test/rdoc/xref_data.rb +++ b/test/rdoc/xref_data.rb @@ -74,6 +74,12 @@ class C6 def priv4() end public def pub5() end def priv5() end + def self.s_pub1() end + class << self + def s_pub2() end + private + def s_priv1() end + end protected private def priv6() end @@ -82,6 +88,12 @@ class C6 def prot5() end public def pub6() end def prot6() end + def self.s_pub3() end + class << self + def s_pub4() end + protected + def s_prot1() end + end end class C7 @@ -149,4 +161,3 @@ class Child < Parent end XREF_DATA - diff --git a/test/rdoc/xref_test_case.rb b/test/rdoc/xref_test_case.rb index 22b00d04bc..0f7395e516 100644 --- a/test/rdoc/xref_test_case.rb +++ b/test/rdoc/xref_test_case.rb @@ -91,4 +91,3 @@ class XrefTestCase < RDoc::TestCase end end - |