From 6e43a7b5f2d31cec3ac757f6dbb286f2592f70a6 Mon Sep 17 00:00:00 2001 From: hsbt Date: Tue, 29 Aug 2017 11:52:50 +0000 Subject: Merge rdoc-6.0.0.beta1. This version fixed strange behavior of ruby code parser. We will list all of impromovement to Changelog when 6.0.0 releasing. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59686 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rdoc/test_rdoc_parser_ruby.rb | 336 ++++++++++++++++++++++++++++++++++--- 1 file changed, 314 insertions(+), 22 deletions(-) (limited to 'test/rdoc/test_rdoc_parser_ruby.rb') diff --git a/test/rdoc/test_rdoc_parser_ruby.rb b/test/rdoc/test_rdoc_parser_ruby.rb index 44b38c28aa..55c03d4628 100644 --- a/test/rdoc/test_rdoc_parser_ruby.rb +++ b/test/rdoc/test_rdoc_parser_ruby.rb @@ -74,7 +74,7 @@ class C; end comment = parser.collect_first_comment - assert_equal RDoc::Comment.new("first\n\n", @top_level), comment + assert_equal RDoc::Comment.new("=begin\nfirst\n=end\n\n", @top_level), comment end def test_get_class_or_module @@ -282,6 +282,31 @@ class C; end assert_equal 'blah', @top_level.metadata['unhandled'] end + def test_parse_for_in + klass = RDoc::NormalClass.new 'Foo' + klass.parent = @top_level + + comment = RDoc::Comment.new '', @top_level + + util_parser < == === =~ > >= < <= << >> + - * / % ** ~ +@ -@ [] []= ` ! != !~] + redefinable_ops.each do |redefinable_op| + util_parser "def #{redefinable_op}\nend\n" + tk = @parser.get_tk + @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment + end + + klass.method_list.each do |method| + assert_kind_of RDoc::RubyToken::TkId, method.token_stream[5] + assert_includes redefinable_ops, method.token_stream[5].text + end + end + + def test_parse_method_bracket + util_parser <<-RUBY +class C + def [] end + def self.[] end + def []= end + def self.[]= end +end + RUBY + + @parser.scan + + c = @store.find_class_named 'C' + + assert_equal 4, c.method_list.size + assert_equal 'C#[]', c.method_list[0].full_name + assert_equal 'C::[]', c.method_list[1].full_name + assert_equal 'C#[]=', c.method_list[2].full_name + assert_equal 'C::[]=', c.method_list[3].full_name + assert c.aliases.empty? + end + def test_parse_method_alias klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level @@ -1978,6 +2042,30 @@ end assert_equal 'Foo#blah', methods.first.full_name end + def test_parse_statements_postfix_if_unless + util_parser <<-CODE +class C + def foo + 1 if nil + end + + def bar + 2 unless nil + end +end + CODE + + @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil + + c = @top_level.classes.first + assert_equal 'C', c.full_name, 'class C' + + methods = c.method_list + assert_equal 2, methods.length + assert_equal 'C#foo', methods[0].full_name + assert_equal 'C#bar', methods[1].full_name + end + def test_parse_statements_class_nested comment = RDoc::Comment.new "##\n# my method\n", @top_level @@ -1994,7 +2082,7 @@ end end def test_parse_statements_def_percent_string_pound - util_parser "class C\ndef a\n%r{#}\nend\ndef b() end\nend" + util_parser "class C\ndef a\n%r{#}\n%r{\#{}}\nend\ndef b() end\nend" @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL @@ -2011,9 +2099,11 @@ end tk(:SPACE, 11, 2, 3, nil, ' '), tk(:IDENTIFIER, 12, 2, 4, 'a', 'a'), tk(:NL, 13, 2, 5, nil, "\n"), - tk(:DREGEXP, 14, 3, 0, nil, '%r{#}'), + tk(:REGEXP, 14, 3, 0, nil, '%r{#}'), tk(:NL, 19, 3, 5, nil, "\n"), - tk(:END, 20, 4, 0, 'end', 'end'), + tk(:DREGEXP, 20, 4, 0, nil, '%r{#{}}'), + tk(:NL, 27, 4, 7, nil, "\n"), + tk(:END, 28, 5, 0, 'end', 'end'), ] assert_equal expected, a.token_stream @@ -2377,6 +2467,162 @@ end assert_equal :private, date_time_now.visibility, date_time_now.full_name end + def test_parse_statements_complex_condition_in_for + util_parser <def blah() + for i in (k)...n do + end + for i in (k)...n + end +end +EXPTECTED + expected = expected.rstrip + + @parser.scan + + foo = @top_level.classes.first + assert_equal 'Foo', foo.full_name + + blah = foo.method_list.first + markup_code = blah.markup_code.sub(/^.*\n/, '') + assert_equal markup_code, expected + end + + def test_parse_statements_postfix_if_after_heredocbeg + @filename = 'file.rb' + util_parser <def blah() + <<~EOM if true + EOM + end +EXPTECTED + expected = expected.rstrip + + @parser.scan + + foo = @top_level.classes.first + assert_equal 'Foo', foo.full_name + + blah = foo.method_list.first + markup_code = blah.markup_code.sub(/^.*\n/, '') + assert_equal markup_code, expected + end + + def test_parse_statements_method_oneliner_with_regexp + util_parser <def blah() /bar/ end +EXPTECTED + expected = expected.rstrip + + @parser.scan + + foo = @top_level.classes.first + assert_equal 'Foo', foo.full_name + + blah = foo.method_list.first + markup_code = blah.markup_code.sub(/^.*\n/, '') + assert_equal expected, markup_code + end + + def test_parse_statements_embdoc_in_document + @filename = 'file.rb' + util_parser <doc + +
=begin
+test embdoc
+=end
+
+EXPTECTED + + @parser.scan + + foo = @top_level.classes.first + assert_equal 'Foo', foo.full_name + + blah = foo.method_list.first + markup_comment = blah.search_record[6] + assert_equal markup_comment, expected + end + + def test_parse_require_dynamic_string + content = <<-RUBY +prefix = 'path' +require "\#{prefix}/a_library" +require 'test' +RUBY + + util_parser content + + @parser.parse_statements @top_level + + assert_equal 1, @top_level.requires.length + end + + def test_parse_postfix_nodoc + util_parser <<-RUBY +class A +end # :nodoc: + +class B + def a + end # :nodoc: + + def b + end +end +RUBY + + @parser.parse_statements @top_level + + c_a = @top_level.classes.select(&:document_self).first + assert_equal 'B', c_a.full_name + + assert_equal 2, @top_level.classes.length + assert_equal 1, @top_level.classes.count(&:document_self) + assert_equal 1, c_a.method_list.length + assert_equal 'B#b', c_a.method_list.first.full_name + end + def test_parse_statements_identifier_require content = "require 'bar'" @@ -2504,6 +2750,25 @@ end assert_equal 'A#b', m_b.full_name end + + def test_parse_symbol_in_paren_arg + util_parser <