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

Rename accept_line to eval

This commit is contained in:
Ryan Fitzgerald 2012-12-27 22:06:50 -08:00
parent 06370d6c86
commit 1ea1927b43
11 changed files with 43 additions and 38 deletions

View file

@ -233,22 +233,25 @@ class Pry
@eval_string = ""
end
# Pass a line of input to pry.
# Pass a line of input to Pry.
#
# This is the equivalent of `Binding#eval` but with extra Pry!
#
# This is the equivalent of `binding.eval` but with extra pry!
# In particular:
# 1. Pry-commands will be executed immediately if the line matches,
# 2. Partial lines of input will be queued up until a complete expression has been
# accepted,
# 1. Pry commands will be executed immediately if the line matches.
# 2. Partial lines of input will be queued up until a complete expression has
# been accepted.
# 3. Output is written to {#output} in pretty colours, not returned.
#
# Once this method has raised an exception or returned false, this instance of pry
# is no longer usable. You can return pry.exit_value to your caller.
# Once this method has raised an exception or returned false, this instance
# is no longer usable. {#exit_value} will return the session's breakout
# value if applicable.
#
# @param [String, nil] line The line of input, nil if the user types <ctrl-d>
# @return [Boolean] true if pry is ready for more input, false otherwise
# @raise [Exception] if the user has explicitly 'raise-up'd an exception
def accept_line(line)
# @param [String?] line The line of input; `nil` if the user types `<Ctrl-D>`
# @return [Boolean] Is Pry ready to accept more input?
# @raise [Exception] If the user uses the `raise-up` command, this method
# will raise that exception.
def eval(line)
return false if @stopped
exit_value = nil

View file

@ -50,7 +50,7 @@ class Pry
break
else
output.puts "" if val.nil? && output.tty?
return pry.exit_value unless pry.accept_line(val)
return pry.exit_value unless pry.eval(val)
end
end
end

View file

@ -105,7 +105,7 @@ class PryTester
attr_reader :pry, :out
def_delegators :@pry, :eval_string, :eval_string=, :accept_line
def_delegators :@pry, :eval_string, :eval_string=
def initialize(target = TOPLEVEL_BINDING, options = {})
@pry = Pry.new(options.merge(:target => target))
@ -132,8 +132,10 @@ class PryTester
result
end
def accept_lines(*lines)
lines.each(&method(:accept_line))
def push(*lines)
Array(lines).flatten.each do |line|
@pry.eval(line)
end
end
def push_binding(context)

View file

@ -218,7 +218,7 @@ describe "commands" do
describe "Pry#run_command" do
it 'should run a command that modifies the passed in eval_string' do
p = Pry.new(:output => @str_output)
p.accept_line "def hello\npeter pan\n"
p.eval "def hello\npeter pan\n"
p.run_command "amend-line !"
p.eval_string.should =~ /def hello/
p.eval_string.should.not =~ /peter pan/

View file

@ -6,7 +6,7 @@ describe "amend-line" do
end
it 'should amend the last line of input when no line number specified' do
@t.accept_lines *unindent(<<-STR).split("\n")
@t.push *unindent(<<-STR).split("\n")
def hello
puts :bing
STR
@ -20,7 +20,7 @@ describe "amend-line" do
end
it 'should amend the specified line of input when line number given' do
@t.accept_lines *unindent(<<-STR).split("\n")
@t.push *unindent(<<-STR).split("\n")
def hello
puts :bing
puts :bang
@ -36,7 +36,7 @@ describe "amend-line" do
end
it 'should amend the first line of input when 0 given as line number' do
@t.accept_lines *unindent(<<-STR).split("\n")
@t.push *unindent(<<-STR).split("\n")
def hello
puts :bing
puts :bang
@ -52,7 +52,7 @@ describe "amend-line" do
end
it 'should amend a specified line when negative number given' do
@t.accept_lines *unindent(<<-STR).split("\n")
@t.push *unindent(<<-STR).split("\n")
def hello
puts :bing
puts :bang
@ -76,7 +76,7 @@ describe "amend-line" do
end
it 'should amend a range of lines of input when negative numbers given' do
@t.accept_lines *unindent(<<-STR).split("\n")
@t.push *unindent(<<-STR).split("\n")
def hello
puts :bing
puts :bang
@ -93,7 +93,7 @@ describe "amend-line" do
end
it 'should correctly amend the specified line with interpolated text' do
@t.accept_lines *unindent(<<-STR).split("\n")
@t.push *unindent(<<-STR).split("\n")
def hello
puts :bing
puts :bang
@ -122,7 +122,7 @@ describe "amend-line" do
end
it 'should correctly amend the specified range of lines' do
@t.accept_lines *unindent(<<-STR).split("\n")
@t.push *unindent(<<-STR).split("\n")
def hello
puts :bing
puts :bang
@ -139,7 +139,7 @@ describe "amend-line" do
end
it 'should correctly delete a specific line using the ! for content' do
@t.accept_lines *unindent(<<-STR).split("\n")
@t.push *unindent(<<-STR).split("\n")
def hello
puts :bing
puts :bang
@ -158,7 +158,7 @@ describe "amend-line" do
end
it 'should correctly delete a range of lines using the ! for content' do
@t.accept_lines *unindent(<<-STR).split("\n")
@t.push *unindent(<<-STR).split("\n")
def hello
puts :bing
puts :bang
@ -175,7 +175,7 @@ describe "amend-line" do
end
it 'should correctly delete the previous line using the ! for content' do
@t.accept_lines *unindent(<<-STR).split("\n")
@t.push *unindent(<<-STR).split("\n")
def hello
puts :bing
puts :bang
@ -194,7 +194,7 @@ describe "amend-line" do
end
it 'should amend the specified range of lines, with numbers < 0 in range' do
@t.accept_lines *unindent(<<-STR).split("\n")
@t.push *unindent(<<-STR).split("\n")
def hello
puts :bing
puts :bang
@ -212,7 +212,7 @@ describe "amend-line" do
end
it 'should correctly insert a line before a specified line using >' do
@t.accept_lines *unindent(<<-STR).split("\n")
@t.push *unindent(<<-STR).split("\n")
def hello
puts :bing
puts :bang
@ -229,7 +229,7 @@ describe "amend-line" do
end
it 'should ignore second value of range with > syntax' do
@t.accept_lines *unindent(<<-STR).split("\n")
@t.push *unindent(<<-STR).split("\n")
def hello
puts :bing
puts :bang

View file

@ -6,7 +6,7 @@ describe "!" do
end
it 'should correctly clear the input buffer ' do
@t.accept_line unindent(<<-STR)
@t.push unindent(<<-STR)
def hello
puts :bing
STR

View file

@ -234,7 +234,7 @@ describe "edit" do
end
it "should edit the current expression if it's incomplete" do
@t.accept_line 'def a'
@t.push 'def a'
@t.process_command 'edit'
@contents.should == "def a\n"
end
@ -250,7 +250,7 @@ describe "edit" do
end
it "should use a blank file if -t given, even during an expression" do
@t.accept_line 'def a;'
@t.push 'def a;'
@t.process_command 'edit -t'
@contents.should == "\n"
end

View file

@ -109,7 +109,7 @@ describe "play" do
end
it 'should APPEND to the input buffer when playing a line with play -m, not replace it' do
@t.accept_line 'def another_test_method'
@t.push 'def another_test_method'
@t.process_command 'play -m test_method --lines 2'
@t.eval_string.should == unindent(<<-STR)
def another_test_method

View file

@ -6,7 +6,7 @@ describe "show-input" do
end
it 'should correctly show the current lines in the input buffer' do
@t.accept_lines *unindent(<<-STR).split("\n")
@t.push *unindent(<<-STR).split("\n")
def hello
puts :bing
STR

View file

@ -19,7 +19,7 @@ describe Pry::DEFAULT_CONTROL_D_HANDLER do
it 'should break out of a REPL loop' do
instance = Pry.new
instance.binding_stack.should.not.be.empty
instance.accept_line(nil).should.be.false
instance.eval(nil).should.be.false
instance.binding_stack.should.be.empty
end
end
@ -29,7 +29,7 @@ describe Pry::DEFAULT_CONTROL_D_HANDLER do
t = pry_tester
t.eval "cd Object.new"
t.eval("_pry_.binding_stack.size").should == 2
t.eval("_pry_.accept_line(nil)").should.be.true
t.eval("_pry_.eval(nil)").should.be.true
t.eval("_pry_.binding_stack.size").should == 1
end
end

View file

@ -140,9 +140,9 @@ describe "test Pry defaults" do
def get_prompts(pry)
a = pry.select_prompt
pry.accept_line "["
pry.eval "["
b = pry.select_prompt
pry.accept_line "]"
pry.eval "]"
[a, b]
end