1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

play and amend-line: now use fix-indent to correct broken indentation

This commit is contained in:
John Mair 2013-01-12 22:15:51 +01:00
parent a604fd6972
commit 703f42b1ee
3 changed files with 24 additions and 10 deletions

View file

@ -20,6 +20,7 @@ class Pry
raise CommandError, "No input to amend." if eval_string.empty?
eval_string.replace amended_input(eval_string)
run "fix-indent"
run "show-input"
end

View file

@ -8,8 +8,7 @@ class Pry
Usage: play [OPTIONS] [--help]
The play command enables you to replay code from files and methods as if they
were entered directly in the Pry REPL. Default action (no options) is to play
the provided string variable.
were entered directly in the Pry REPL.
play --lines 149..153
play -i 20 --lines 1..3
@ -22,8 +21,8 @@ class Pry
def options(opt)
CodeCollector.inject_options(opt)
opt.on :open, 'When used with the -m switch, it plays the entire method except' \
' the last line, leaving the method definition "open". `amend-line`' \
opt.on :open, 'Plays the select content except except' \
' the last line. Useful for replaying methods and leaving the method definition "open". `amend-line`' \
' can then be used to modify the method.'
end
@ -36,13 +35,18 @@ class Pry
def perform_play
eval_string << (opts.present?(:open) ? restrict_to_lines(content, (0..-2)) : content)
run "fix-indent"
end
def should_use_default_file?
!args.first && !opts.present?(:in) && !opts.present?(:out)
end
def content
if args.first
@cc.content
else
if should_use_default_file?
file_content
else
@cc.content
end
end

View file

@ -82,7 +82,16 @@ describe "play" do
it 'should play a method (a single line)' do
pry_tester(@o).process_command 'play test_method --lines 2', @eval_str
@eval_str.should == " :test_method_content\n"
@eval_str.should == ":test_method_content\n"
end
it 'should properly reindent lines' do
def @o.test_method
'hello world'
end
pry_tester(@o).process_command 'play test_method --lines 2', @eval_str
@eval_str.should == "'hello world'\n"
end
it 'should APPEND to the input buffer when playing a method line, not replace it' do
@ -98,7 +107,7 @@ describe "play" do
STR
end
it 'should play a method with the (multiple lines)' do
it 'should play a method (multiple lines)' do
def @o.test_method
@var0 = 10
@var1 = 20
@ -108,7 +117,7 @@ describe "play" do
pry_tester(@o).process_command 'play test_method --lines 3..4', @eval_str
@eval_str.should == unindent(<<-STR, 2)
@eval_str.should == unindent(<<-STR, 0)
@var1 = 20
@var2 = 30
STR