2019-03-08 19:08:53 -05:00
|
|
|
describe 'Pry::Config.defaults.control_d_handler' do
|
2012-12-14 20:23:24 -05:00
|
|
|
describe "control-d press" do
|
2012-06-16 14:12:10 -04:00
|
|
|
before do
|
2012-12-14 20:23:24 -05:00
|
|
|
# Simulates a ^D press.
|
2019-03-22 18:44:56 -04:00
|
|
|
@control_d = "Pry::Config.defaults.control_d_handler.call('', pry_instance)"
|
2012-06-16 14:12:10 -04:00
|
|
|
end
|
|
|
|
|
2012-12-14 20:23:24 -05:00
|
|
|
describe "in an expression" do
|
|
|
|
it "should clear out passed string" do
|
|
|
|
str = 'hello world'
|
2019-03-08 19:08:53 -05:00
|
|
|
Pry::Config.defaults.control_d_handler.call(str, nil)
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(str).to eq ''
|
2012-06-16 14:12:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'at top-level session' do
|
|
|
|
it 'should break out of a REPL loop' do
|
2012-12-20 04:28:04 -05:00
|
|
|
instance = Pry.new
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(instance.binding_stack).not_to be_empty
|
|
|
|
expect(instance.eval(nil)).to equal false
|
|
|
|
expect(instance.binding_stack).to be_empty
|
2012-06-16 14:12:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'in a nested session' do
|
|
|
|
it 'should pop last binding from the binding stack' do
|
2012-12-20 04:28:04 -05:00
|
|
|
t = pry_tester
|
|
|
|
t.eval "cd Object.new"
|
2019-03-22 18:44:56 -04:00
|
|
|
expect(t.eval("pry_instance.binding_stack.size")).to eq 2
|
|
|
|
expect(t.eval("pry_instance.eval(nil)")).to equal true
|
|
|
|
expect(t.eval("pry_instance.binding_stack.size")).to eq 1
|
2012-06-16 14:12:10 -04:00
|
|
|
end
|
|
|
|
|
2012-12-14 20:23:24 -05:00
|
|
|
it "breaks out of the parent session" do
|
2012-12-28 13:00:33 -05:00
|
|
|
ReplTester.start do
|
2019-03-22 18:44:56 -04:00
|
|
|
input 'Pry::REPL.new(pry_instance, :target => 10).start'
|
2012-12-28 13:00:33 -05:00
|
|
|
output ''
|
|
|
|
prompt(/10.*> $/)
|
|
|
|
|
|
|
|
input 'self'
|
|
|
|
output '=> 10'
|
|
|
|
|
|
|
|
input nil # Ctrl-D
|
|
|
|
output ''
|
|
|
|
|
|
|
|
input 'self'
|
|
|
|
output '=> main'
|
|
|
|
|
|
|
|
input nil # Ctrl-D
|
|
|
|
output '=> nil' # Exit value of nested REPL.
|
|
|
|
assert_exited
|
2012-06-16 14:12:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|