Skip to content

Commit 8e3f81d

Browse files
committed
Support shortening lambda notation
1 parent d6f3448 commit 8e3f81d

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/irb/ruby-lex.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def check_newline_depth_difference
398398
next
399399
end
400400
case t[1]
401-
when :on_lbracket, :on_lbrace, :on_lparen
401+
when :on_lbracket, :on_lbrace, :on_lparen, :on_tlambeg
402402
depth_difference += 1
403403
open_brace_on_line += 1
404404
when :on_rbracket, :on_rbrace, :on_rparen
@@ -481,7 +481,7 @@ def check_corresponding_token_depth
481481
next
482482
end
483483
case t[1]
484-
when :on_lbracket, :on_lbrace, :on_lparen
484+
when :on_lbracket, :on_lbrace, :on_lparen, :on_tlambeg
485485
spaces_of_nest.push(spaces_at_line_head + open_brace_on_line * 2)
486486
open_brace_on_line += 1
487487
when :on_rbracket, :on_rbrace, :on_rparen

test/irb/test_ruby_lex.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,5 +234,21 @@ def test_oneliner_method_definition
234234
assert_indenting(lines, row.new_line_spaces, true)
235235
end
236236
end
237+
238+
def test_tlambda
239+
input_with_correct_indents = [
240+
Row.new(%q(if true), nil, 2),
241+
Row.new(%q( -> {), nil, 4),
242+
Row.new(%q( }), 2, 2),
243+
Row.new(%q(end), 0, 0),
244+
]
245+
246+
lines = []
247+
input_with_correct_indents.each do |row|
248+
lines << row.content
249+
assert_indenting(lines, row.current_line_spaces, false)
250+
assert_indenting(lines, row.new_line_spaces, true)
251+
end
252+
end
237253
end
238254
end

0 commit comments

Comments
 (0)