ruby-changes:48033
From: hsbt <ko1@a...>
Date: Tue, 10 Oct 2017 11:01:06 +0900 (JST)
Subject: [ruby-changes:48033] hsbt:r60146 (trunk): Merge rdoc-6.0.0.beta3.
hsbt 2017-10-10 11:01:00 +0900 (Tue, 10 Oct 2017) New Revision: 60146 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60146 Log: 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] Removed files: trunk/lib/rdoc/ruby_token.rb Modified files: trunk/lib/rdoc/any_method.rb trunk/lib/rdoc/generator/template/darkfish/_footer.rhtml trunk/lib/rdoc/generator/template/darkfish/class.rhtml trunk/lib/rdoc/i18n.rb trunk/lib/rdoc/markdown.rb trunk/lib/rdoc/markup/to_html.rb trunk/lib/rdoc/markup.rb trunk/lib/rdoc/parser/ruby.rb trunk/lib/rdoc/parser.rb trunk/lib/rdoc/rdoc.gemspec trunk/lib/rdoc/ri/driver.rb trunk/lib/rdoc/servlet.rb trunk/lib/rdoc/token_stream.rb trunk/lib/rdoc.rb trunk/test/rdoc/test_rdoc_any_method.rb trunk/test/rdoc/test_rdoc_generator_darkfish.rb trunk/test/rdoc/test_rdoc_markdown.rb trunk/test/rdoc/test_rdoc_markup_to_html_snippet.rb trunk/test/rdoc/test_rdoc_parser_ruby.rb trunk/test/rdoc/test_rdoc_ri_driver.rb Index: lib/rdoc/ruby_token.rb =================================================================== --- lib/rdoc/ruby_token.rb (revision 60145) +++ lib/rdoc/ruby_token.rb (nonexistent) @@ -1,470 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/lib/rdoc/ruby_token.rb#L0 -# frozen_string_literal: false -#-- -# irb/ruby-token.rb - ruby tokens -# $Release Version: 0.9.5$ -# $Revision: 11708 $ -# $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $ -# by Keiju ISHITSUKA(keiju@r...) -#++ -# Definitions of all tokens involved in the lexical analysis. -# -# This class is not documented because it is so deep in the internals. - -module RDoc::RubyToken - # :stopdoc: - - EXPR_BEG = :EXPR_BEG - EXPR_MID = :EXPR_MID - EXPR_END = :EXPR_END - EXPR_ARG = :EXPR_ARG - EXPR_FNAME = :EXPR_FNAME - EXPR_DOT = :EXPR_DOT - EXPR_CLASS = :EXPR_CLASS - - # for ruby 1.4X - if !defined?(Symbol) - Symbol = Integer - end - - def set_token_position(seek, line, char) - @prev_seek = seek - @prev_line_no = line - @prev_char_no = char - end - - class Token - def initialize(seek, line_no, char_no, text = nil) - @seek = seek - @line_no = line_no - @char_no = char_no - @text = text - end - - attr_reader :seek - attr_reader :line_no - attr_reader :char_no - - attr_accessor :text - - def ==(other) - self.class == other.class and - other.line_no == @line_no and - other.char_no == @char_no and - other.text == @text - end - - ## - # Because we're used in contexts that expect to return a token, we set the - # text string and then return ourselves - - def set_text(text) - @text = text - self - end - - def inspect # :nodoc: - klass = self.class.name.split('::').last - "{%s %d, %d:%d %p}" % [klass, @seek, @line_no, @char_no, @text] - end - - end - - class TkNode < Token - def initialize(seek, line_no, char_no, node = nil) - super seek, line_no, char_no - @node = node - end - - attr_reader:node - - def ==(other) - self.class == other.class and - other.line_no == @line_no and - other.char_no == @char_no and - other.node == @node - end - - def set_text text - @node = text - self - end - - alias text node - - def inspect # :nodoc: - klass = self.class.name.split('::').last - "{%s %d, %d:%d %p}" % [klass, @seek, @line_no, @char_no, @node] - end - - end - - class TkId < Token - def initialize(seek, line_no, char_no, name) - super(seek, line_no, char_no) - @name = name - end - attr_reader:name - - def ==(other) - self.class == other.class and - other.line_no == @line_no and - other.char_no == @char_no and - other.name == @name - end - - def set_text text - @name = text - self - end - - alias text name - - def inspect # :nodoc: - klass = self.class.name.split('::').last - "{%s %d, %d:%d %p}" % [klass, @seek, @line_no, @char_no, @name] - end - - end - - class TkKW < TkId - end - - class TkVal < Token - def initialize(seek, line_no, char_no, value = nil) - super(seek, line_no, char_no) - @value = value - end - attr_accessor :value - - def ==(other) - self.class == other.class and - other.line_no == @line_no and - other.char_no == @char_no and - other.value == @value - end - - def set_text text - @value = text - self - end - - alias text value - - def inspect # :nodoc: - klass = self.class.name.split('::').last - "{%s %s, %d:%d %p}" % [klass, @seek, @line_no, @char_no, @value] - end - - end - - class TkOp < Token - def initialize(seek, line_no, char_no, name = nil) - super seek, line_no, char_no - @name = name - end - - attr_accessor :name - - def ==(other) - self.class == other.class and - other.line_no == @line_no and - other.char_no == @char_no and - other.name == @name - end - - def set_text text - @name = text - self - end - - alias text name - - def inspect # :nodoc: - klass = self.class.name.split('::').last - "{%s %d, %d:%d %p}" % [klass, @seek, @line_no, @char_no, @name] - end - - end - - class TkOPASGN < TkOp - def initialize(seek, line_no, char_no, op) - super(seek, line_no, char_no) - op = TkReading2Token[op][0] unless op.kind_of?(Symbol) - @op = op - @text = nil - end - - attr_reader:op - - def ==(other) - self.class == other.class and - other.line_no == @line_no and - other.char_no == @char_no and - other.op == @op - end - - def text - @text ||= "#{TkToken2Reading[op]}=" - end - - def inspect # :nodoc: - klass = self.class.name.split('::').last - "{%s %d, %d:%d %p}" % [klass, @seek, @line_no, @char_no, @op] - end - - end - - class TkUnknownChar < Token - def initialize(seek, line_no, char_no, name) - super(seek, line_no, char_no) - @name = name - end - attr_reader:name - - def ==(other) - self.class == other.class and - other.line_no == @line_no and - other.char_no == @char_no and - other.name == @name - end - - def set_text text - @name = text - self - end - - alias text name - - def inspect # :nodoc: - klass = self.class.name.split('::').last - "{%s %d, %d:%d %p}" % [klass, @seek, @line_no, @char_no, @name] - end - - end - - class TkError < Token - end - - def Token(token, value = nil) - value ||= TkToken2Reading[token] - - case token - when String - if (tk = TkReading2Token[token]).nil? - IRB.fail TkReading2TokenNoKey, token - end - - tk = Token(tk[0], value) - - if tk.kind_of?(TkOp) then - tk.name = token - end - when Symbol - if (tk = TkSymbol2Token[token]).nil? - IRB.fail TkSymbol2TokenNoKey, token - end - - tk = Token(tk[0], value) - else - if token.instance_method(:initialize).arity == 3 then - tk = token.new(@prev_seek, @prev_line_no, @prev_char_no) - tk.set_text value - else - tk = token.new(@prev_seek, @prev_line_no, @prev_char_no, value) - end - end - - tk - end - - TokenDefinitions = [ - [:TkCLASS, TkKW, "class", :EXPR_CLASS], - [:TkMODULE, TkKW, "module", :EXPR_BEG], - [:TkDEF, TkKW, "def", :EXPR_FNAME], - [:TkUNDEF, TkKW, "undef", :EXPR_FNAME], - [:TkBEGIN, TkKW, "begin", :EXPR_BEG], - [:TkRESCUE, TkKW, "rescue", :EXPR_MID], - [:TkENSURE, TkKW, "ensure", :EXPR_BEG], - [:TkEND, TkKW, "end", :EXPR_END], - [:TkIF, TkKW, "if", :EXPR_BEG, :TkIF_MOD], - [:TkUNLESS, TkKW, "unless", :EXPR_BEG, :TkUNLESS_MOD], - [:TkTHEN, TkKW, "then", :EXPR_BEG], - [:TkELSIF, TkKW, "elsif", :EXPR_BEG], - [:TkELSE, TkKW, "else", :EXPR_BEG], - [:TkCASE, TkKW, "case", :EXPR_BEG], - [:TkWHEN, TkKW, "when", :EXPR_BEG], - [:TkWHILE, TkKW, "while", :EXPR_BEG, :TkWHILE_MOD], - [:TkUNTIL, TkKW, "until", :EXPR_BEG, :TkUNTIL_MOD], - [:TkFOR, TkKW, "for", :EXPR_BEG], - [:TkBREAK, TkKW, "break", :EXPR_MID], - [:TkNEXT, TkKW, "next", :EXPR_END], - [:TkREDO, TkKW, "redo", :EXPR_END], - [:TkRETRY, TkKW, "retry", :EXPR_END], - [:TkIN, TkKW, "in", :EXPR_BEG], - [:TkDO, TkKW, "do", :EXPR_BEG], - [:TkRETURN, TkKW, "return", :EXPR_MID], - [:TkYIELD, TkKW, "yield", :EXPR_ARG], - [:TkSUPER, TkKW, "super", :EXPR_ARG], - [:TkSELF, TkKW, "self", :EXPR_END], - [:TkNIL, TkKW, "nil", :EXPR_END], - [:TkTRUE, TkKW, "true", :EXPR_END], - [:TkFALSE, TkKW, "false", :EXPR_END], - [:TkAND, TkKW, "and", :EXPR_BEG], - [:TkOR, TkKW, "or", :EXPR_BEG], - [:TkNOT, TkKW, "not", :EXPR_BEG], - [:TkIF_MOD, TkKW], - [:TkUNLESS_MOD, TkKW], - [:TkWHILE_MOD, TkKW], - [:TkUNTIL_MOD, TkKW], - [:TkALIAS, TkKW, "alias", :EXPR_FNAME], - [:TkDEFINED, TkKW, "defined?", :EXPR_ARG], - [:TklBEGIN, TkKW, "BEGIN", :EXPR_END], - [:TklEND, TkKW, "END", :EXPR_END], - [:Tk__LINE__, TkKW, "__LINE__", :EXPR_END], - [:Tk__FILE__, TkKW, "__FILE__", :EXPR_END], - [:Tk__ENCODING__,TkKW, "__ENCODING__", :EXPR_END], - - [:TkIDENTIFIER, TkId], - [:TkFID, TkId], - [:TkGVAR, TkId], - [:TkCVAR, TkId], - [:TkIVAR, TkId], - [:TkCONSTANT, TkId], - [:TkHEREDOCBEG, TkId], - [:TkHEREDOCEND, TkId], - - [:TkINTEGER, TkVal], - [:TkFLOAT, TkVal], - [:TkRATIONAL, TkVal], - [:TkIMAGINARY, TkVal], - [:TkSTRING, TkVal], - [:TkHEREDOC, TkVal], - [:TkXSTRING, TkVal], - [:TkREGEXP, TkVal], - [:TkSYMBOL, TkVal], - [:TkCHAR, TkVal], - - [:TkDSTRING, TkNode], - [:TkDXSTRING, TkNode], - [:TkDREGEXP, TkNode], - [:TkNTH_REF, TkNode], - [:TkBACK_REF, TkNode], - - [:TkUPLUS, TkOp, "+@"], - [:TkUMINUS, TkOp, "-@"], - [:TkPOW, TkOp, "**"], - [:TkCMP, TkOp, "<=>"], - [:TkEQ, TkOp, "=="], - [:TkEQQ, TkOp, "==="], - [:TkNEQ, TkOp, "!="], - [:TkGEQ, TkOp, ">="], - [:TkLEQ, TkOp, "<="], - [:TkHASHROCKET, TkOp, "=>"], - [:TkANDOP, TkOp, "&&"], - [:TkOROP, TkOp, "||"], - [:TkMATCH, TkOp, "=~"], - [:TkNMATCH, TkOp, "!~"], - [:TkDOT2, TkOp, ".."], - [:TkDOT3, TkOp, "..."], - [:TkAREF, TkOp, "[]"], - [:TkASET, TkOp, "[]="], - [:TkLSHFT, TkOp, "<<"], - [:TkRSHFT, TkOp, ">>"], - [:TkCOLON2, TkOp, '::'], - [:TkCOLON3, TkOp, '::'], - #[:OPASGN, TkOp], # +=, -= etc. # - [:TkASSOC, TkOp, "=>"], - [:TkLAMBDA, TkOp, "->"], - [:TkQUESTION, TkOp, "?"], #? - [:TkCOLON, TkOp, ":"], #: - - [:TkfLPAREN, Token, "("], # func( # - [:TkfLBRACK, Token, "["], # func[ # - [:TkfLBRACE, Token, "{"], # func{ # - [:TkSYMBEG, Token, ":"], # :SYMBOL - - [:TkAMPER, TkOp, "&"], - [:TkGT, TkOp, ">"], - [:TkLT, TkOp, "<"], - [:TkPLUS, TkOp, "+"], - [:TkSTAR, TkOp, "*"], - [:TkMINUS, TkOp, "-"], - [:TkMULT, TkOp, "*"], - [:TkDIV, TkOp, "/"], - [:TkMOD, TkOp, "%"], - [:TkBITOR, TkOp, "|"], - [:TkBITXOR, TkOp, "^"], - [:TkBITAND, TkOp, "&"], - [:TkBITNOT, TkOp, "~"], - [:TkNOTOP, TkOp, "!"], - - [:TkBACKQUOTE, TkOp, "`"], - - [:TkASSIGN, Token, "="], - [:TkDOT, Token, "."], - [:TkSAFENAV, Token, "&."], - [:TkLPAREN, Token, "("], #(exp) - [:TkLBRACK, Token, "["], #[arry] - [:TkLBRACE, Token, "{"], #{hash} - [:TkRPAREN, Token, ")"], - [:TkRBRACK, Token, "]"], - [:TkRBRACE, Token, "}"], - [:TkCOMMA, Token, ","], - [:TkSEMICOLON, Token, ";"], - - [:TkCOMMENT, TkVal], - [:TkSPACE, Token, " "], - [:TkNL, Token, "\n"], - [:TkEND_OF_SCRIPT], - - [:TkBACKSLASH, TkUnknownChar, "\\"], - [:TkAT, TkUnknownChar, "@"], - [:TkDOLLAR, TkUnknownChar, "$"], - ] - - # {reading => token_class} - # {reading => [token_class, *opt]} - TkReading2Token = {} - TkToken2Reading = {} - TkSymbol2Token = {} - - def self.def_token(token_n, super_token = Token, reading = nil, *opts) - token_n = token_n.id2name if token_n.kind_of?(Symbol) - if const_defined?(token_n) - IRB.fail AlreadyDefinedToken, token_n - end - token_c = eval("class #{token_n} < #{super_token}; end; #{token_n}") - - if reading - TkToken2Reading[token_c] = reading - - return if TkReading2Token[reading] - - if opts.empty? - TkReading2Token[reading] = [token_c] - else - TkReading2Token[reading] = [token_c].concat(opts) - end - end - TkSymbol2Token[token_n.intern] = token_c - end - - for defs in TokenDefinitions - def_token(*defs) - end - - def_token :TkRD_COMMENT, TkCOMMENT - - NEWLINE_TOKEN = TkNL.new 0, 0, 0, "\n" - - class TkSYMBOL - - def to_sym - @sym ||= text[1..-1].intern - end - - end - - # :startdoc: -end - Property changes on: lib/rdoc/ruby_token.rb ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -LF \ No newline at end of property Index: test/rdoc/test_rdoc_ri_driver.rb =================================================================== --- test/rdoc/test_rdoc_ri_driver.rb (revision 60145) +++ test/rdoc/test_rdoc_ri_driver.rb (revision 60146) @@ -969,6 +969,27 @@ Foo::Bar#bother https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_ri_driver.rb#L969 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 Index: test/rdoc/test_rdoc_markup_to_html_snippet.rb =================================================================== --- test/rdoc/test_rdoc_markup_to_html_snippet.rb (revision 60145) +++ test/rdoc/test_rdoc_markup_to_html_snippet.rb (revision 60146) @@ -494,9 +494,9 @@ be guessed, raises an error if +name+ co https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_markup_to_html_snippet.rb#L494 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: Index: test/rdoc/test_rdoc_any_method.rb =================================================================== --- test/rdoc/test_rdoc_any_method.rb (revision 60145) +++ test/rdoc/test_rdoc_any_method.rb (revision 60146) @@ -89,6 +89,15 @@ method(a, b) { |c, d| ... } https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_any_method.rb#L89 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' Index: test/rdoc/test_rdoc_markdown.rb =================================================================== --- test/rdoc/test_rdoc_markdown.rb (revision 60145) +++ test/rdoc/test_rdoc_markdown.rb (revision 60146) @@ -973,6 +973,14 @@ and an extra note.[^2] https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_markdown.rb#L973 assert_equal '<b>_emphasis_</b>', @parser.strong('_emphasis_') end + def test_code_fence_with_unintended_array + doc = parse '```<ruby>```' + + expected = doc(verb('<ruby>')) + + assert_equal expected, doc + end + def parse text @parser.parse text end Index: test/rdoc/test_rdoc_parser_ruby.rb =================================================================== --- test/rdoc/test_rdoc_parser_ruby.rb (revision 60145) +++ test/rdoc/test_rdoc_parser_ruby.rb (revision 60146) @@ -778,12 +778,13 @@ end https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_parser_ruby.rb#L778 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 https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_parser_ruby.rb#L1360 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 = <<EXPECTED +<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">foo</span> + <span class="ruby-constant">A</span><span class="ruby-operator">::</span><span class="ruby-constant">B</span><span class="ruby-operator">::</span><span class="ruby-constant">C</span> +<span class="ruby-keyword">end</span> +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 https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_parser_ruby.rb#L1426 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 https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_parser_ruby.rb#L2606 end RUBY - expected = <<EXPTECTED + expected = <<EXPECTED <span class="ruby-keyword">def</span> <span class="ruby-identifier">blah</span>() <span class="ruby-keyword">for</span> <span class="ruby-identifier">i</span> <span class="ruby-keyword">in</span> (<span class="ruby-identifier">k</span>)<span class="ruby-operator">...</span><span class="ruby-identifier">n</span> <span class="ruby-keyword">do</span> <span class="ruby-keyword">end</span> <span class="ruby-keyword">for</span> <span class="ruby-identifier">i</span> <span class="ruby-keyword">in</span> (<span class="ruby-identifier">k</span>)<span class="ruby-operator">...</span><span class="ruby-identifier">n</span> <span class="ruby-keyword">end</span> <span class="ruby-keyword">end</span> -EXPTECTED +EXPECTED expected = expected.rstrip @parser.scan @@ -2578,7 +2623,7 @@ EXPTECTED https://github.com/ (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/