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

ruby-changes:65121

From: Nobuhiro <ko1@a...>
Date: Wed, 3 Feb 2021 00:09:47 +0900 (JST)
Subject: [ruby-changes:65121] b0fb208218 (master): [ruby/irb] follow up the actual line number

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

From b0fb2082187fe3cd247a92471aa42d3e6f779e51 Mon Sep 17 00:00:00 2001
From: Nobuhiro IMAI <nov@y...>
Date: Tue, 24 Mar 2020 15:24:01 +0900
Subject: [ruby/irb] follow up the actual line number

https://github.com/ruby/irb/commit/7aed8fe3b1
---
 lib/irb/ruby-lex.rb      |  5 ++++-
 test/irb/test_context.rb | 21 +++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb
index 938e9d4..ce94797 100644
--- a/lib/irb/ruby-lex.rb
+++ b/lib/irb/ruby-lex.rb
@@ -223,7 +223,10 @@ class RubyLex https://github.com/ruby/ruby/blob/trunk/lib/irb/ruby-lex.rb#L223
             throw :TERM_INPUT if @line == ''
           else
             @line_no += l.count("\n")
-            next if l == "\n"
+            if l == "\n"
+              @exp_line_no += 1
+              next
+            end
             @line.concat l
             if @code_block_open or @ltype or @continue or @indent > 0
               next
diff --git a/test/irb/test_context.rb b/test/irb/test_context.rb
index 63e71e5..71e8ad1 100644
--- a/test/irb/test_context.rb
+++ b/test/irb/test_context.rb
@@ -572,5 +572,26 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_context.rb#L572
     ensure
       $VERBOSE = verbose
     end
+
+    def test_lineno
+      input = TestInputMethod.new([
+        "\n",
+        "__LINE__\n",
+        "__LINE__\n",
+        "\n",
+        "\n",
+        "__LINE__\n",
+      ])
+      irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
+      out, err = capture_output do
+        irb.eval_input
+      end
+      assert_empty err
+      assert_pattern_list([
+          :*, /\b2\n/,
+          :*, /\b3\n/,
+          :*, /\b6\n/,
+        ], out)
+    end
   end
 end
-- 
cgit v1.1


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

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