From 7aed8fe3b1c2bbdb5c51d191e32425ab5e2aaa00 Mon Sep 17 00:00:00 2001 From: Nobuhiro IMAI Date: Tue, 24 Mar 2020 15:24:01 +0900 Subject: [PATCH] follow up the actual line number --- 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 938e9d42a..ce94797da 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -223,7 +223,10 @@ def each_top_level_statement 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 63e71e586..71e8ad1c0 100644 --- a/test/irb/test_context.rb +++ b/test/irb/test_context.rb @@ -572,5 +572,26 @@ def test_eval_input_with_long_exception 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