[前][次][番号順一覧][スレッド一覧]

ruby-changes:62618

From: aycabta <ko1@a...>
Date: Tue, 18 Aug 2020 18:57:12 +0900 (JST)
Subject: [ruby-changes:62618] a30dea5852 (master): [ruby/irb] Support shortening lambda notetion for nesting level of prompt

https://git.ruby-lang.org/ruby.git/commit/?id=a30dea5852

From a30dea5852b5ece74e435d912596983d2654580a Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Mon, 17 Aug 2020 10:41:31 +0900
Subject: [ruby/irb] Support shortening lambda notetion for nesting level of
 prompt

https://github.com/ruby/irb/commit/f1a775af47

diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb
index a90c97c..7be77fd 100644
--- a/lib/irb/ruby-lex.rb
+++ b/lib/irb/ruby-lex.rb
@@ -329,7 +329,7 @@ class RubyLex https://github.com/ruby/ruby/blob/trunk/lib/irb/ruby-lex.rb#L329
       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 51a0bd1..14b43f5 100644
--- a/test/irb/test_ruby_lex.rb
+++ b/test/irb/test_ruby_lex.rb
@@ -5,7 +5,7 @@ require 'ostruct' https://github.com/ruby/ruby/blob/trunk/test/irb/test_ruby_lex.rb#L5
 
 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 https://github.com/ruby/ruby/blob/trunk/test/irb/test_ruby_lex.rb#L34
       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 https://github.com/ruby/ruby/blob/trunk/test/irb/test_ruby_lex.rb#L246
 
     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 https://github.com/ruby/ruby/blob/trunk/test/irb/test_ruby_lex.rb#L257
         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
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]