1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/irb] Support shortening lambda notation

8e3f81d428
This commit is contained in:
aycabta 2020-08-16 22:25:31 +09:00
parent b3f84b4a5b
commit 43c648c832
2 changed files with 18 additions and 2 deletions

View file

@ -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

View file

@ -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