summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/irb/ruby-lex.rb5
-rw-r--r--test/irb/test_context.rb21
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb
index 938e9d42a6..ce94797dad 100644
--- a/lib/irb/ruby-lex.rb
+++ b/lib/irb/ruby-lex.rb
@@ -223,7 +223,10 @@ class RubyLex
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 63e71e5867..71e8ad1c0d 100644
--- a/test/irb/test_context.rb
+++ b/test/irb/test_context.rb
@@ -572,5 +572,26 @@ module TestIRB
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