diff options
author | aycabta <aycabta@gmail.com> | 2020-08-16 22:25:31 +0900 |
---|---|---|
committer | aycabta <aycabta@gmail.com> | 2020-08-18 14:38:02 +0900 |
commit | 43c648c8325db536715a8e827951ac48114eb6bd (patch) | |
tree | 0a7125760975e4a898e4fc25ff45853821b9fad0 | |
parent | b3f84b4a5b7c78339c28baa11f75ed4c121bd5ca (diff) | |
download | ruby-43c648c8325db536715a8e827951ac48114eb6bd.tar.gz |
[ruby/irb] Support shortening lambda notation
https://github.com/ruby/irb/commit/8e3f81d428
-rw-r--r-- | lib/irb/ruby-lex.rb | 4 | ||||
-rw-r--r-- | 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 |