Skip to content

Commit

Permalink
improve regex for amend-line command
Browse files Browse the repository at this point in the history
* accurate spacing in front of the replacement line when there's no line number
* remove legacy "amend-line-N" syntax
  • Loading branch information
rf- committed Sep 8, 2011
1 parent 375dfbe commit 9252e6c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/pry/default_commands/input.rb
Expand Up @@ -12,7 +12,7 @@ module DefaultCommands
render_output(false, 1, Pry.color ? CodeRay.scan(eval_string, :ruby).term : eval_string)
end

command(/amend-line.?(-?\d+)?(?:\.\.(-?\d+))?/, "Amend a line of input in multi-line mode. Type `amend-line --help` for more information. Aliases %",
command(/amend-line(?: (-?\d+)(?:\.\.(-?\d+))?)?/, "Amend a line of input in multi-line mode. Type `amend-line --help` for more information. Aliases %",
:interpolate => false, :listing => "amend-line") do |*args|
start_line_number, end_line_number, replacement_line = *args

Expand Down Expand Up @@ -52,7 +52,7 @@ module DefaultCommands
run "show-input"
end

alias_command(/%.?(-?\d+)?(?:\.\.(-?\d+))?/, /amend-line.?(-?\d+)?(?:\.\.(-?\d+))?/, "")
alias_command(/%.?(-?\d+)?(?:\.\.(-?\d+))?/, /amend-line(?: (-?\d+)(?:\.\.(-?\d+))?)?/, "")

command "play", "Play back a string variable or a method or a file as input. Type `play --help` for more information." do |*args|
opts = Slop.parse!(args) do |opt|
Expand Down
4 changes: 2 additions & 2 deletions test/test_default_commands/test_input.rb
Expand Up @@ -2,7 +2,7 @@

describe "Pry::DefaultCommands::Input" do

describe "amend-line-N" do
describe "amend-line" do
it 'should correctly amend the last line of input when no line number specified ' do
str_output = StringIO.new
redirect_pry_io(InputTester.new("def hello", "puts :bing", "amend-line puts :blah", "show-input", "exit-all"), str_output) do
Expand Down Expand Up @@ -104,7 +104,7 @@

it 'should correctly amend the specified range of lines, using negative numbers in range' do
str_output = StringIO.new
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "puts :boast", "puts :heart", "amend-line-2..-2 puts :bong", "show-input", "exit-all"), str_output) do
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "puts :boast", "puts :heart", "amend-line 2..-2 puts :bong", "show-input", "exit-all"), str_output) do
pry
end
str_output.string.should =~ /\d+: def hello\n\d+: puts :bong\n\d+: puts :heart/
Expand Down

0 comments on commit 9252e6c

Please sign in to comment.