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:
parent
43c648c832
commit
a30dea5852
2 changed files with 16 additions and 6 deletions
|
@ -329,7 +329,7 @@ class RubyLex
|
|||
end
|
||||
|
||||
case t[1]
|
||||
when :on_lbracket, :on_lbrace, :on_lparen
|
||||
when :on_lbracket, :on_lbrace, :on_lparen, :on_tlambeg
|
||||
indent += 1
|
||||
when :on_rbracket, :on_rbrace, :on_rparen
|
||||
indent -= 1
|
||||
|
|
|
@ -5,7 +5,7 @@ require 'ostruct'
|
|||
|
||||
module TestIRB
|
||||
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
|
||||
def initialize(params, &assertion)
|
||||
|
@ -34,6 +34,15 @@ module TestIRB
|
|||
ruby_lex.set_auto_indent(context)
|
||||
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
|
||||
input_with_correct_indents = [
|
||||
Row.new(%q(def each_top_level_statement), nil, 2),
|
||||
|
@ -237,10 +246,10 @@ module TestIRB
|
|||
|
||||
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),
|
||||
Row.new(%q(if true), nil, 2, 1),
|
||||
Row.new(%q( -> {), nil, 4, 2),
|
||||
Row.new(%q( }), 2, 2, 1),
|
||||
Row.new(%q(end), 0, 0, 0),
|
||||
]
|
||||
|
||||
lines = []
|
||||
|
@ -248,6 +257,7 @@ module TestIRB
|
|||
lines << row.content
|
||||
assert_indenting(lines, row.current_line_spaces, false)
|
||||
assert_indenting(lines, row.new_line_spaces, true)
|
||||
assert_nesting_level(lines, row.nesting_level)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue