From db6c51ec4f9d1b7386215cad5924e6e03733b6d6 Mon Sep 17 00:00:00 2001 From: hsbt Date: Tue, 10 Oct 2017 02:01:00 +0000 Subject: Merge rdoc-6.0.0.beta3. * It version introduced did you mean? feature for ri command: https://github.com/ruby/rdoc/pull/533 * Removed obbsoleted ruby_token.rbb. [Bug #13990][ruby-core:83180] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60146 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rdoc/test_rdoc_any_method.rb | 9 ++++ test/rdoc/test_rdoc_generator_darkfish.rb | 22 +++++++- test/rdoc/test_rdoc_markdown.rb | 8 +++ test/rdoc/test_rdoc_markup_to_html_snippet.rb | 6 +-- test/rdoc/test_rdoc_parser_ruby.rb | 75 +++++++++++++++++++++------ test/rdoc/test_rdoc_ri_driver.rb | 21 ++++++++ 6 files changed, 122 insertions(+), 19 deletions(-) (limited to 'test') diff --git a/test/rdoc/test_rdoc_any_method.rb b/test/rdoc/test_rdoc_any_method.rb index fdfb0f3995..20d041bd7e 100644 --- a/test/rdoc/test_rdoc_any_method.rb +++ b/test/rdoc/test_rdoc_any_method.rb @@ -89,6 +89,15 @@ method(a, b) { |c, d| ... } assert_equal '', @c2_a.markup_code end + def test_markup_code_with_variable_expansion + m = RDoc::AnyMethod.new nil, 'method' + m.parent = @c1 + m.block_params = '"Hello, #{world}", yield_arg' + m.params = 'a' + + assert_equal '(a) { |"Hello, #{world}", yield_arg| ... }', m.param_seq + end + def test_marshal_dump @store.path = Dir.tmpdir top_level = @store.add_file 'file.rb' diff --git a/test/rdoc/test_rdoc_generator_darkfish.rb b/test/rdoc/test_rdoc_generator_darkfish.rb index 6a3e7038e1..352e9336ff 100644 --- a/test/rdoc/test_rdoc_generator_darkfish.rb +++ b/test/rdoc/test_rdoc_generator_darkfish.rb @@ -43,10 +43,13 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase @meth = RDoc::AnyMethod.new nil, 'method' @meth_bang = RDoc::AnyMethod.new nil, 'method!' + @meth_with_html_tag_yield = RDoc::AnyMethod.new nil, 'method_with_html_tag_yield' + @meth_with_html_tag_yield.block_params = '%<>, yield_arg' @attr = RDoc::Attr.new nil, 'attr', 'RW', '' @klass.add_method @meth @klass.add_method @meth_bang + @klass.add_method @meth_with_html_tag_yield @klass.add_attribute @attr @ignored = @top_level.add_class RDoc::NormalClass, 'Ignored' @@ -167,7 +170,7 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase assert_equal [@klass_alias, @ignored, @klass, @object], @g.classes.sort_by { |klass| klass.full_name } assert_equal [@top_level], @g.files - assert_equal [@meth, @meth, @meth_bang, @meth_bang], @g.methods + assert_equal [@meth, @meth, @meth_bang, @meth_bang, @meth_with_html_tag_yield, @meth_with_html_tag_yield], @g.methods assert_equal [@klass_alias, @klass, @object], @g.modsort end @@ -199,6 +202,23 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase assert_same template, @g.send(:template_for, partial) end + def test_generated_method_with_html_tag_yield + top_level = @store.add_file 'file.rb' + top_level.add_class @klass.class, @klass.name + + @g.generate + + path = File.join @tmpdir, 'A.html' + + f = open(path) + internal_file = f.read + method_name_index = internal_file.index('method_with_html_tag_yield') + last_of_method_name_index = method_name_index + internal_file[method_name_index..-1].index('
') - 1 + method_name = internal_file[method_name_index..last_of_method_name_index] + + assert_includes method_name, '{ |%<<script>alert("atui")</script>>, yield_arg| ... }' + end + ## # Asserts that +filename+ has a link count greater than 1 if hard links to # @tmpdir are supported. diff --git a/test/rdoc/test_rdoc_markdown.rb b/test/rdoc/test_rdoc_markdown.rb index 6c7bf4ae32..79b0175293 100644 --- a/test/rdoc/test_rdoc_markdown.rb +++ b/test/rdoc/test_rdoc_markdown.rb @@ -973,6 +973,14 @@ and an extra note.[^2] assert_equal '_emphasis_', @parser.strong('_emphasis_') end + def test_code_fence_with_unintended_array + doc = parse '``````' + + expected = doc(verb('')) + + assert_equal expected, doc + end + def parse text @parser.parse text end diff --git a/test/rdoc/test_rdoc_markup_to_html_snippet.rb b/test/rdoc/test_rdoc_markup_to_html_snippet.rb index d180f551c9..19c534863e 100644 --- a/test/rdoc/test_rdoc_markup_to_html_snippet.rb +++ b/test/rdoc/test_rdoc_markup_to_html_snippet.rb @@ -494,9 +494,9 @@ be guessed, raises an error if +name+ couldn't be guessed. rdoc = <<-RDOC = \RDoc - Ruby Documentation System -* {RDoc Project Page}[https://github.com/rdoc/rdoc/] -* {RDoc Documentation}[https://rdoc.github.io/rdoc] -* {RDoc Bug Tracker}[https://github.com/rdoc/rdoc/issues] +* {RDoc Project Page}[https://github.com/ruby/rdoc] +* {RDoc Documentation}[https://ruby.github.io/rdoc] +* {RDoc Bug Tracker}[https://github.com/ruby/rdoc/issues] == DESCRIPTION: diff --git a/test/rdoc/test_rdoc_parser_ruby.rb b/test/rdoc/test_rdoc_parser_ruby.rb index 5a13cad480..e9e3fcf246 100644 --- a/test/rdoc/test_rdoc_parser_ruby.rb +++ b/test/rdoc/test_rdoc_parser_ruby.rb @@ -778,12 +778,13 @@ end def test_parse_class_lower_name_warning @options.verbosity = 2 - out, err = capture_io do + stds = capture_io do util_parser "class foo\nend" tk = @parser.get_tk @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, @comment end - assert_match /Expected class name or '<<'\. Got/, err + err = stds[1] + assert_match(/Expected class name or '<<'\. Got/, err) end def test_parse_multi_ghost_methods @@ -1359,6 +1360,52 @@ A::B::C = 1 assert_equal 'comment', c.comment end + def test_parse_class_the_same_of_outside + util_parser <<-RUBY +module A + class A::B + end +end + RUBY + + @parser.scan + + assert_includes @store.modules_hash, 'A' + module_a = @store.find_module_named 'A' + refute_empty module_a.classes_hash + assert_includes module_a.classes_hash, 'B' + refute_includes module_a.classes_hash, 'A' + end + + def test_parse_constant_the_same_of_outside + util_parser <<-RUBY +module A + class B + class C + end + end + + def self.foo + A::B::C + end +end + RUBY + + expected = <def self.foo + A::B::C +end +EXPECTED + expected = expected.rstrip + + @parser.scan + + module_a = @store.find_module_named 'A' + foo = module_a.method_list.first + markup_code = foo.markup_code.sub(/^.*\n/, '') + assert_equal expected, markup_code + end + def test_parse_constant_with_bracket util_parser <<-RUBY class Klass @@ -1379,8 +1426,6 @@ end klass = @store.find_class_named 'Klass' klass2 = @store.find_class_named 'Klass2' klass3 = @store.find_class_named 'Klass3' - constant = klass2.find_module_named 'CONSTANT' - constant2 = klass3.find_module_named 'CONSTANT_2' assert_equal klass, klass2.constants.first.is_alias_for refute_equal klass, klass3.constants.first.is_alias_for assert_nil klass3.find_module_named 'CONSTANT_2' @@ -2561,14 +2606,14 @@ class Foo end RUBY - expected = <def blah() for i in (k)...n do end for i in (k)...n end end -EXPTECTED +EXPECTED expected = expected.rstrip @parser.scan @@ -2578,7 +2623,7 @@ EXPTECTED blah = foo.method_list.first markup_code = blah.markup_code.sub(/^.*\n/, '') - assert_equal markup_code, expected + assert_equal expected, markup_code end def test_parse_statements_postfix_if_after_heredocbeg @@ -2592,12 +2637,12 @@ class Foo end RUBY - expected = <def blah() <<-EOM if true EOM end -EXPTECTED +EXPECTED expected = expected.rstrip @parser.scan @@ -2617,9 +2662,9 @@ class Foo end RUBY - expected = <def blah() /bar/ end -EXPTECTED +EXPECTED expected = expected.rstrip @parser.scan @@ -2647,14 +2692,14 @@ class Foo end RUBY - expected = <doc
=begin
 test embdoc
 =end
 
-EXPTECTED +EXPECTED @parser.scan @@ -2663,7 +2708,7 @@ EXPTECTED blah = foo.method_list.first markup_comment = blah.search_record[6] - assert_equal markup_comment, expected + assert_equal expected, markup_comment end def test_parse_require_dynamic_string @@ -3639,7 +3684,7 @@ end @parser.scan c = @store.find_class_named 'C' - const_a, const_b, const_c, const_d = c.constants.sort_by(&:name) + const_a, const_b, const_c = c.constants.sort_by(&:name) assert_equal 'CONST_A', const_a.name assert_equal :public, const_a.visibility diff --git a/test/rdoc/test_rdoc_ri_driver.rb b/test/rdoc/test_rdoc_ri_driver.rb index 1aa4762f92..81c8469e25 100644 --- a/test/rdoc/test_rdoc_ri_driver.rb +++ b/test/rdoc/test_rdoc_ri_driver.rb @@ -969,6 +969,27 @@ Foo::Bar#bother assert_equal 'nonexistent', e.name end + def test_did_you_mean + skip 'skip test with did_you_men' unless defined? DidYouMean::SpellChecker + + util_ancestors_store + + e = assert_raises RDoc::RI::Driver::NotFoundError do + @driver.lookup_method 'Foo.i_methdo' + end + assert_equal "Nothing known about Foo.i_methdo\nDid you mean? i_method", e.message + + e = assert_raises RDoc::RI::Driver::NotFoundError do + @driver.lookup_method 'Foo#i_methdo' + end + assert_equal "Nothing known about Foo#i_methdo\nDid you mean? i_method", e.message + + e = assert_raises RDoc::RI::Driver::NotFoundError do + @driver.lookup_method 'Foo::i_methdo' + end + assert_equal "Nothing known about Foo::i_methdo\nDid you mean? c_method", e.message + end + def test_formatter tty = Object.new def tty.tty?() true; end -- cgit v1.2.3