diff options
author | Conrad Irwin <conrad.irwin@gmail.com> | 2013-03-24 21:22:43 -0700 |
---|---|---|
committer | Conrad Irwin <conrad.irwin@gmail.com> | 2013-03-24 21:22:43 -0700 |
commit | d24e95f7fdc3903a4d8316c5a5e7c75a220505d4 (patch) | |
tree | d4a7f0d6e0484808aeff7852d1300399dc9605f6 | |
parent | bd320550c537dc0e2813e5f584905a63a2ae99fd (diff) | |
download | pry-d24e95f7fdc3903a4d8316c5a5e7c75a220505d4.tar.gz |
Handle negativity in Pry::Code#take_lines [Fixes #886]
-rw-r--r-- | lib/pry/code.rb | 2 | ||||
-rw-r--r-- | spec/commands/hist_spec.rb | 6 |
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" |