mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
edit --in can take a range, added some more tests.
This commit is contained in:
parent
b76fa99f32
commit
0e904ada39
2 changed files with 36 additions and 4 deletions
|
@ -122,7 +122,7 @@ class Pry
|
||||||
USAGE
|
USAGE
|
||||||
|
|
||||||
opt.on :e, :ex, "Open the file that raised the most recent exception (_ex_.file)", :optional => true, :as => Integer
|
opt.on :e, :ex, "Open the file that raised the most recent exception (_ex_.file)", :optional => true, :as => Integer
|
||||||
opt.on :i, :in, "Open a temporary file containing the specified line of _in_.", :optional => true, :as => Integer
|
opt.on :i, :in, "Open a temporary file containing the Nth line of _in_. N may be a range.", :optional => true, :as => Range, :default => -1..-1
|
||||||
opt.on :t, :temp, "Open an empty temporary file"
|
opt.on :t, :temp, "Open an empty temporary file"
|
||||||
opt.on :l, :line, "Jump to this line in the opened file", true, :as => Integer
|
opt.on :l, :line, "Jump to this line in the opened file", true, :as => Integer
|
||||||
opt.on :n, :"no-reload", "Don't automatically reload the edited code"
|
opt.on :n, :"no-reload", "Don't automatically reload the edited code"
|
||||||
|
@ -133,8 +133,8 @@ class Pry
|
||||||
end
|
end
|
||||||
next if opts.h?
|
next if opts.h?
|
||||||
|
|
||||||
if [opts.ex? || nil, opts.t? || nil, !args.empty? || nil].compact.size > 1
|
if [opts.ex?, opts.t?, opts.in?, !args.empty?].count(true) > 1
|
||||||
next output.puts "Only one of --ex, --temp, and FILE may be specified"
|
next output.puts "Only one of --ex, --temp, --in and FILE may be specified"
|
||||||
end
|
end
|
||||||
|
|
||||||
# edit of local code, eval'd within pry.
|
# edit of local code, eval'd within pry.
|
||||||
|
@ -143,7 +143,14 @@ class Pry
|
||||||
content = if opts.t?
|
content = if opts.t?
|
||||||
""
|
""
|
||||||
elsif opts.i?
|
elsif opts.i?
|
||||||
_pry_.input_array[opts[:i] || -1] || ""
|
case opts[:i]
|
||||||
|
when Range
|
||||||
|
(_pry_.input_array[opts[:i]] || []).join
|
||||||
|
when Fixnum
|
||||||
|
_pry_.input_array[opts[:i]] || ""
|
||||||
|
else
|
||||||
|
next output.puts "Not a valid range: #{opts[:i]}"
|
||||||
|
end
|
||||||
elsif eval_string.strip != ""
|
elsif eval_string.strip != ""
|
||||||
eval_string
|
eval_string
|
||||||
else
|
else
|
||||||
|
|
|
@ -211,11 +211,36 @@ describe "Pry::DefaultCommands::Introspection" do
|
||||||
}
|
}
|
||||||
mock_pry("edit -n").should.not =~ /FOO/
|
mock_pry("edit -n").should.not =~ /FOO/
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "with --in" do
|
||||||
it "should edit the nth line of _in_" do
|
it "should edit the nth line of _in_" do
|
||||||
mock_pry("10", "11", "edit --in -2")
|
mock_pry("10", "11", "edit --in -2")
|
||||||
@contents.should == "10\n"
|
@contents.should == "10\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should edit the last line if no argument is given" do
|
||||||
|
mock_pry("10", "11", "edit --in")
|
||||||
|
@contents.should == "11\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should edit a range of lines if a range is given" do
|
||||||
|
mock_pry("10", "11", "edit -i 1,2")
|
||||||
|
@contents.should == "10\n11\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should edit a multi-line expression as it occupies one line of _in_" do
|
||||||
|
mock_pry("class Fixnum", " def invert; -self; end", "end", "edit -i 1")
|
||||||
|
@contents.should == "class Fixnum\n def invert; -self; end\nend\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should not work with a filename" do
|
||||||
|
mock_pry("edit ruby.rb -i").should =~ /Only one of --ex, --temp, --in and FILE may be specified/
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should not work with nonsense" do
|
||||||
|
mock_pry("edit --in three").should =~ /Not a valid range: three/
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue