From 43c648c8325db536715a8e827951ac48114eb6bd Mon Sep 17 00:00:00 2001 From: aycabta Date: Sun, 16 Aug 2020 22:25:31 +0900 Subject: [PATCH] [ruby/irb] Support shortening lambda notation https://github.com/ruby/irb/commit/8e3f81d428 --- lib/irb/ruby-lex.rb | 4 ++-- test/irb/test_ruby_lex.rb | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index 3568e66a66..a90c97c6b2 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -398,7 +398,7 @@ class RubyLex 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 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 db15593f37..51a0bd1351 100644 --- a/test/irb/test_ruby_lex.rb +++ b/test/irb/test_ruby_lex.rb @@ -234,5 +234,21 @@ module TestIRB 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