mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
added hist --show option + tests
This commit is contained in:
parent
3d14ef6368
commit
dd84c4c0c3
2 changed files with 25 additions and 0 deletions
|
@ -62,6 +62,14 @@ class Pry
|
|||
end
|
||||
end
|
||||
|
||||
opt.on :s, :show, 'Show the history corresponding to the history line (or range of lines).', true, :as => Range do |range|
|
||||
unless opt.grep?
|
||||
start_line = range.is_a?(Range) ? range.first : range
|
||||
lines = text.with_line_numbers Array(history[range]).join("\n"), start_line
|
||||
stagger_output lines
|
||||
end
|
||||
end
|
||||
|
||||
opt.on :e, :exclude, 'Exclude pry commands from the history.' do
|
||||
unless opt.grep?
|
||||
history.map!.with_index do |element, index|
|
||||
|
|
|
@ -98,6 +98,23 @@ describe "Pry::Commands" do
|
|||
str_output.string.each_line.count.should == 4
|
||||
str_output.string.should =~ /a\n\d+:.*b\n\d+:.*c/
|
||||
end
|
||||
|
||||
# strangeness in this test is due to bug in Readline::HISTORY not
|
||||
# always registering first line of input
|
||||
it 'should show lines between lines A and B with the --show switch' do
|
||||
push_first_hist_line.call(@hist, "0")
|
||||
("a".."z").each do |v|
|
||||
@hist.push v
|
||||
end
|
||||
|
||||
str_output = StringIO.new
|
||||
redirect_pry_io(InputTester.new("hist --show 1..4", "exit-all"), str_output) do
|
||||
pry
|
||||
end
|
||||
|
||||
str_output.string.each_line.count.should == 4
|
||||
str_output.string.should =~ /b\n\d+:.*c\n\d+:.*d/
|
||||
end
|
||||
end
|
||||
|
||||
describe "show-method" do
|
||||
|
|
Loading…
Reference in a new issue