summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConrad Irwin <conrad.irwin@gmail.com>2013-03-24 21:22:43 -0700
committerConrad Irwin <conrad.irwin@gmail.com>2013-03-24 21:22:43 -0700
commitd24e95f7fdc3903a4d8316c5a5e7c75a220505d4 (patch)
treed4a7f0d6e0484808aeff7852d1300399dc9605f6
parentbd320550c537dc0e2813e5f584905a63a2ae99fd (diff)
downloadpry-d24e95f7fdc3903a4d8316c5a5e7c75a220505d4.tar.gz
Handle negativity in Pry::Code#take_lines [Fixes #886]
-rw-r--r--lib/pry/code.rb2
-rw-r--r--spec/commands/hist_spec.rb6
2 files changed, 7 insertions, 1 deletions
diff --git a/lib/pry/code.rb b/lib/pry/code.rb
index 82fe05d9..c8c9c52d 100644
--- a/lib/pry/code.rb
+++ b/lib/pry/code.rb
@@ -197,7 +197,7 @@ class Pry
if start_line >= 0
@lines.index { |loc| loc.lineno >= start_line } || @lines.length
else
- @lines.length + start_line
+ [@lines.length + start_line, 0].max
end
alter do
diff --git a/spec/commands/hist_spec.rb b/spec/commands/hist_spec.rb
index ca01adc8..0b5ea252 100644
--- a/spec/commands/hist_spec.rb
+++ b/spec/commands/hist_spec.rb
@@ -79,6 +79,12 @@ describe "hist" do
out.should =~ /x\n\d+:.*y\n\d+:.*z/
end
+ it "should start from beginning if tail number is longer than history" do
+ @hist.push 'Hyacinth'
+ out = @t.eval 'hist --tail'
+ out.should =~ /Hyacinth/
+ end
+
it 'should apply --tail after --grep' do
@hist.push "print 1"
@hist.push "print 2"