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

ruby-changes:62613

From: aycabta <ko1@a...>
Date: Tue, 18 Aug 2020 18:57:08 +0900 (JST)
Subject: [ruby-changes:62613] 43c648c832 (master): [ruby/irb] Support shortening lambda notation

https://git.ruby-lang.org/ruby.git/commit/?id=43c648c832

From 43c648c8325db536715a8e827951ac48114eb6bd Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Sun, 16 Aug 2020 22:25:31 +0900
Subject: [ruby/irb] Support shortening lambda notation

https://github.com/ruby/irb/commit/8e3f81d428

diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb
index 3568e66..a90c97c 100644
--- a/lib/irb/ruby-lex.rb
+++ b/lib/irb/ruby-lex.rb
@@ -398,7 +398,7 @@ class RubyLex https://github.com/ruby/ruby/blob/trunk/lib/irb/ruby-lex.rb#L398
         next
       end
       case t[1]
-      when :on_lbracket, :on_lbrace, :on_lparen
+      when :on_lbracket, :on_lbrace, :on_lparen, :on_tlambeg
         depth_difference += 1
         open_brace_on_line += 1
       when :on_rbracket, :on_rbrace, :on_rparen
@@ -481,7 +481,7 @@ class RubyLex https://github.com/ruby/ruby/blob/trunk/lib/irb/ruby-lex.rb#L481
         next
       end
       case t[1]
-      when :on_lbracket, :on_lbrace, :on_lparen
+      when :on_lbracket, :on_lbrace, :on_lparen, :on_tlambeg
         spaces_of_nest.push(spaces_at_line_head + open_brace_on_line * 2)
         open_brace_on_line += 1
       when :on_rbracket, :on_rbrace, :on_rparen
diff --git a/test/irb/test_ruby_lex.rb b/test/irb/test_ruby_lex.rb
index db15593..51a0bd1 100644
--- a/test/irb/test_ruby_lex.rb
+++ b/test/irb/test_ruby_lex.rb
@@ -234,5 +234,21 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_ruby_lex.rb#L234
         assert_indenting(lines, row.new_line_spaces, true)
       end
     end
+
+    def test_tlambda
+      input_with_correct_indents = [
+        Row.new(%q(if true), nil, 2),
+        Row.new(%q(  -> {), nil, 4),
+        Row.new(%q(  }), 2, 2),
+        Row.new(%q(end), 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/

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