ruby-changes:64748
From: aycabta <ko1@a...>
Date: Tue, 5 Jan 2021 18:13:48 +0900 (JST)
Subject: [ruby-changes:64748] cce72a2411 (master): [ruby/irb] Newline in oneliner def doesn't reset indent
https://git.ruby-lang.org/ruby.git/commit/?id=cce72a2411 From cce72a24119b5c2177100865f52376ca4b32bd9d Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Sat, 26 Dec 2020 23:34:27 +0900 Subject: [ruby/irb] Newline in oneliner def doesn't reset indent This closes ruby/irb#132. https://github.com/ruby/irb/commit/43456dcf5e diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index 9914aec..68751b4 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -410,7 +410,7 @@ class RubyLex https://github.com/ruby/ruby/blob/trunk/lib/irb/ruby-lex.rb#L410 case t[1] when :on_ignored_nl, :on_nl, :on_comment - if index != (@tokens.size - 1) + if index != (@tokens.size - 1) and in_oneliner_def != :BODY depth_difference = 0 open_brace_on_line = 0 end @@ -488,11 +488,13 @@ class RubyLex https://github.com/ruby/ruby/blob/trunk/lib/irb/ruby-lex.rb#L488 case t[1] when :on_ignored_nl, :on_nl, :on_comment - corresponding_token_depth = nil - spaces_at_line_head = 0 - is_first_spaces_of_line = true - is_first_printable_of_line = true - open_brace_on_line = 0 + if in_oneliner_def != :BODY + corresponding_token_depth = nil + spaces_at_line_head = 0 + is_first_spaces_of_line = true + is_first_printable_of_line = true + open_brace_on_line = 0 + end next when :on_sp spaces_at_line_head = t[2].count(' ') if is_first_spaces_of_line diff --git a/test/irb/test_ruby_lex.rb b/test/irb/test_ruby_lex.rb index 41b5d49..30bae1e 100644 --- a/test/irb/test_ruby_lex.rb +++ b/test/irb/test_ruby_lex.rb @@ -263,6 +263,23 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_ruby_lex.rb#L263 end end + def test_oneliner_def_in_multiple_lines + input_with_correct_indents = [ + Row.new(%q(def a()=[), nil, 4, 2), + Row.new(%q( 1,), nil, 4, 1), + Row.new(%q(].), 0, 0, 0), + Row.new(%q(to_s), nil, 0, 0), + ] + + lines = [] + input_with_correct_indents.each do |row| + lines << row.content + assert_indenting(lines, row.current_line_spaces, false) + assert_indenting(lines, row.new_line_spaces, true) + assert_nesting_level(lines, row.nesting_level) + end + end + PromptRow = Struct.new(:prompt, :content) class MockIO_DynamicPrompt -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/