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:
parent
a604fd6972
commit
703f42b1ee
3 changed files with 24 additions and 10 deletions
|
@ -20,6 +20,7 @@ class Pry
|
||||||
raise CommandError, "No input to amend." if eval_string.empty?
|
raise CommandError, "No input to amend." if eval_string.empty?
|
||||||
|
|
||||||
eval_string.replace amended_input(eval_string)
|
eval_string.replace amended_input(eval_string)
|
||||||
|
run "fix-indent"
|
||||||
run "show-input"
|
run "show-input"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,7 @@ class Pry
|
||||||
Usage: play [OPTIONS] [--help]
|
Usage: play [OPTIONS] [--help]
|
||||||
|
|
||||||
The play command enables you to replay code from files and methods as if they
|
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
|
were entered directly in the Pry REPL.
|
||||||
the provided string variable.
|
|
||||||
|
|
||||||
play --lines 149..153
|
play --lines 149..153
|
||||||
play -i 20 --lines 1..3
|
play -i 20 --lines 1..3
|
||||||
|
@ -22,8 +21,8 @@ class Pry
|
||||||
def options(opt)
|
def options(opt)
|
||||||
CodeCollector.inject_options(opt)
|
CodeCollector.inject_options(opt)
|
||||||
|
|
||||||
opt.on :open, 'When used with the -m switch, it plays the entire method except' \
|
opt.on :open, 'Plays the select content except except' \
|
||||||
' the last line, leaving the method definition "open". `amend-line`' \
|
' the last line. Useful for replaying methods and leaving the method definition "open". `amend-line`' \
|
||||||
' can then be used to modify the method.'
|
' can then be used to modify the method.'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -36,13 +35,18 @@ class Pry
|
||||||
|
|
||||||
def perform_play
|
def perform_play
|
||||||
eval_string << (opts.present?(:open) ? restrict_to_lines(content, (0..-2)) : content)
|
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
|
end
|
||||||
|
|
||||||
def content
|
def content
|
||||||
if args.first
|
if should_use_default_file?
|
||||||
@cc.content
|
|
||||||
else
|
|
||||||
file_content
|
file_content
|
||||||
|
else
|
||||||
|
@cc.content
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,15 @@ describe "play" do
|
||||||
@eval_str.should == ":test_method_content\n"
|
@eval_str.should == ":test_method_content\n"
|
||||||
end
|
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
|
it 'should APPEND to the input buffer when playing a method line, not replace it' do
|
||||||
@eval_str = unindent(<<-STR)
|
@eval_str = unindent(<<-STR)
|
||||||
def another_test_method
|
def another_test_method
|
||||||
|
@ -98,7 +107,7 @@ describe "play" do
|
||||||
STR
|
STR
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should play a method with the (multiple lines)' do
|
it 'should play a method (multiple lines)' do
|
||||||
def @o.test_method
|
def @o.test_method
|
||||||
@var0 = 10
|
@var0 = 10
|
||||||
@var1 = 20
|
@var1 = 20
|
||||||
|
@ -108,7 +117,7 @@ describe "play" do
|
||||||
|
|
||||||
pry_tester(@o).process_command 'play test_method --lines 3..4', @eval_str
|
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
|
@var1 = 20
|
||||||
@var2 = 30
|
@var2 = 30
|
||||||
STR
|
STR
|
||||||
|
|
Loading…
Reference in a new issue