Skip to content

Commit f1a775a

Browse files
committed
Support shortening lambda notetion for nesting level of prompt
1 parent 8e3f81d commit f1a775a

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

lib/irb/ruby-lex.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def process_nesting_level
329329
end
330330

331331
case t[1]
332-
when :on_lbracket, :on_lbrace, :on_lparen
332+
when :on_lbracket, :on_lbrace, :on_lparen, :on_tlambeg
333333
indent += 1
334334
when :on_rbracket, :on_rbrace, :on_rparen
335335
indent -= 1

test/irb/test_ruby_lex.rb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
module TestIRB
77
class TestRubyLex < Test::Unit::TestCase
8-
Row = Struct.new(:content, :current_line_spaces, :new_line_spaces)
8+
Row = Struct.new(:content, :current_line_spaces, :new_line_spaces, :nesting_level)
99

1010
class MockIO
1111
def initialize(params, &assertion)
@@ -34,6 +34,15 @@ def assert_indenting(lines, correct_space_count, add_new_line)
3434
ruby_lex.set_auto_indent(context)
3535
end
3636

37+
def assert_nesting_level(lines, expected)
38+
ruby_lex = RubyLex.new()
39+
io = proc{ lines.join("\n") }
40+
ruby_lex.set_input(io, io)
41+
ruby_lex.lex
42+
error_message = "Calculated the wrong number of nesting level for:\n #{lines.join("\n")}"
43+
assert_equal(expected, ruby_lex.instance_variable_get(:@indent), error_message)
44+
end
45+
3746
def test_auto_indent
3847
input_with_correct_indents = [
3948
Row.new(%q(def each_top_level_statement), nil, 2),
@@ -237,17 +246,18 @@ def test_oneliner_method_definition
237246

238247
def test_tlambda
239248
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),
249+
Row.new(%q(if true), nil, 2, 1),
250+
Row.new(%q( -> {), nil, 4, 2),
251+
Row.new(%q( }), 2, 2, 1),
252+
Row.new(%q(end), 0, 0, 0),
244253
]
245254

246255
lines = []
247256
input_with_correct_indents.each do |row|
248257
lines << row.content
249258
assert_indenting(lines, row.current_line_spaces, false)
250259
assert_indenting(lines, row.new_line_spaces, true)
260+
assert_nesting_level(lines, row.nesting_level)
251261
end
252262
end
253263
end

0 commit comments

Comments
 (0)