[前][次][番号順一覧][スレッド一覧]

ruby-changes:60006

From: aycabta <ko1@a...>
Date: Wed, 12 Feb 2020 13:15:04 +0900 (JST)
Subject: [ruby-changes:60006] 8b8cc01229 (master): [ruby/irb] Fix auto indent with closed brace

https://git.ruby-lang.org/ruby.git/commit/?id=8b8cc01229

From 8b8cc01229c2849236e7b43e1b5b5d33ccfb6b1e Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Tue, 11 Feb 2020 02:11:35 +0900
Subject: [ruby/irb] Fix auto indent with closed brace

A closed brace in auto-indent shouldn't affect the next brace in the same line,
but it behaves like below:

  p() {
    }

It's a bug.

https://github.com/ruby/irb/commit/fbe59e344f

diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb
index 3d1478d..251db9e 100644
--- a/lib/irb/ruby-lex.rb
+++ b/lib/irb/ruby-lex.rb
@@ -394,6 +394,7 @@ class RubyLex https://github.com/ruby/ruby/blob/trunk/lib/irb/ruby-lex.rb#L394
           spaces_of_nest.pop
           corresponding_token_depth = nil
         end
+        open_brace_on_line -= 1
       when :on_kw
         next if index > 0 and @tokens[index - 1][3].allbits?(Ripper::EXPR_FNAME)
         case t[2]
diff --git a/test/irb/test_ruby_lex.rb b/test/irb/test_ruby_lex.rb
index 65fc7d4..886891c 100644
--- a/test/irb/test_ruby_lex.rb
+++ b/test/irb/test_ruby_lex.rb
@@ -112,5 +112,19 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_ruby_lex.rb#L112
         assert_indenting(lines, row.new_line_spaces, true)
       end
     end
+
+    def test_a_closed_brace_and_not_closed_brace_in_a_line
+      input_with_correct_indents = [
+        Row.new(%q(p() {), nil, 2),
+        Row.new(%q(}), 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)
+      end
+    end
   end
 end
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]