summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2020-08-17 10:41:31 +0900
committeraycabta <aycabta@gmail.com>2020-08-18 14:38:02 +0900
commita30dea5852b5ece74e435d912596983d2654580a (patch)
treef466677f437c8aa230e8cec87e1de38b54ed5f1a
parent43c648c8325db536715a8e827951ac48114eb6bd (diff)
[ruby/irb] Support shortening lambda notetion for nesting level of prompt
https://github.com/ruby/irb/commit/f1a775af47
-rw-r--r--lib/irb/ruby-lex.rb2
-rw-r--r--test/irb/test_ruby_lex.rb20
2 files changed, 16 insertions, 6 deletions
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb
index a90c97c6b2..7be77fd12e 100644
--- a/lib/irb/ruby-lex.rb
+++ b/lib/irb/ruby-lex.rb
@@ -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
diff --git a/test/irb/test_ruby_lex.rb b/test/irb/test_ruby_lex.rb
index 51a0bd1351..14b43f5718 100644
--- a/test/irb/test_ruby_lex.rb
+++ b/test/irb/test_ruby_lex.rb
@@ -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