Skip to content

Commit 7aed8fe

Browse files
committed
follow up the actual line number
1 parent 7248da8 commit 7aed8fe

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/irb/ruby-lex.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,10 @@ def each_top_level_statement
223223
throw :TERM_INPUT if @line == ''
224224
else
225225
@line_no += l.count("\n")
226-
next if l == "\n"
226+
if l == "\n"
227+
@exp_line_no += 1
228+
next
229+
end
227230
@line.concat l
228231
if @code_block_open or @ltype or @continue or @indent > 0
229232
next

test/irb/test_context.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,5 +572,26 @@ def test_eval_input_with_long_exception
572572
ensure
573573
$VERBOSE = verbose
574574
end
575+
576+
def test_lineno
577+
input = TestInputMethod.new([
578+
"\n",
579+
"__LINE__\n",
580+
"__LINE__\n",
581+
"\n",
582+
"\n",
583+
"__LINE__\n",
584+
])
585+
irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
586+
out, err = capture_output do
587+
irb.eval_input
588+
end
589+
assert_empty err
590+
assert_pattern_list([
591+
:*, /\b2\n/,
592+
:*, /\b3\n/,
593+
:*, /\b6\n/,
594+
], out)
595+
end
575596
end
576597
end

0 commit comments

Comments
 (0)