Skip to content

Commit

Permalink
follow up the actual line number
Browse files Browse the repository at this point in the history
  • Loading branch information
no6v committed Jan 29, 2021
1 parent 7248da8 commit 7aed8fe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/irb/ruby-lex.rb
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions test/irb/test_context.rb
Expand Up @@ -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

0 comments on commit 7aed8fe

Please sign in to comment.