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 notetion for nesting level of prompt

https://github.com/ruby/irb/commit/f1a775af47
This commit is contained in:
aycabta 2020-08-17 10:41:31 +09:00
parent 43c648c832
commit a30dea5852
2 changed files with 16 additions and 6 deletions

View file

@ -329,7 +329,7 @@ class RubyLex
end end
case t[1] case t[1]
when :on_lbracket, :on_lbrace, :on_lparen when :on_lbracket, :on_lbrace, :on_lparen, :on_tlambeg
indent += 1 indent += 1
when :on_rbracket, :on_rbrace, :on_rparen when :on_rbracket, :on_rbrace, :on_rparen
indent -= 1 indent -= 1

View file

@ -5,7 +5,7 @@ require 'ostruct'
module TestIRB module TestIRB
class TestRubyLex < Test::Unit::TestCase class TestRubyLex < Test::Unit::TestCase
Row = Struct.new(:content, :current_line_spaces, :new_line_spaces) Row = Struct.new(:content, :current_line_spaces, :new_line_spaces, :nesting_level)
class MockIO class MockIO
def initialize(params, &assertion) def initialize(params, &assertion)
@ -34,6 +34,15 @@ module TestIRB
ruby_lex.set_auto_indent(context) ruby_lex.set_auto_indent(context)
end end
def assert_nesting_level(lines, expected)
ruby_lex = RubyLex.new()
io = proc{ lines.join("\n") }
ruby_lex.set_input(io, io)
ruby_lex.lex
error_message = "Calculated the wrong number of nesting level for:\n #{lines.join("\n")}"
assert_equal(expected, ruby_lex.instance_variable_get(:@indent), error_message)
end
def test_auto_indent def test_auto_indent
input_with_correct_indents = [ input_with_correct_indents = [
Row.new(%q(def each_top_level_statement), nil, 2), Row.new(%q(def each_top_level_statement), nil, 2),
@ -237,10 +246,10 @@ module TestIRB
def test_tlambda def test_tlambda
input_with_correct_indents = [ input_with_correct_indents = [
Row.new(%q(if true), nil, 2), Row.new(%q(if true), nil, 2, 1),
Row.new(%q( -> {), nil, 4), Row.new(%q( -> {), nil, 4, 2),
Row.new(%q( }), 2, 2), Row.new(%q( }), 2, 2, 1),
Row.new(%q(end), 0, 0), Row.new(%q(end), 0, 0, 0),
] ]
lines = [] lines = []
@ -248,6 +257,7 @@ module TestIRB
lines << row.content lines << row.content
assert_indenting(lines, row.current_line_spaces, false) assert_indenting(lines, row.current_line_spaces, false)
assert_indenting(lines, row.new_line_spaces, true) assert_indenting(lines, row.new_line_spaces, true)
assert_nesting_level(lines, row.nesting_level)
end end
end end
end end