2019-05-03 01:33:56 +03:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-08-24 02:56:39 +01:00
|
|
|
describe Pry::REPL do
|
2012-12-15 14:09:16 -08:00
|
|
|
it "should let you run commands in the middle of multiline expressions" do
|
2012-12-23 22:06:06 -08:00
|
|
|
ReplTester.start do
|
|
|
|
input 'def a'
|
|
|
|
input '!'
|
2015-01-22 22:52:20 +01:00
|
|
|
output(/^Input buffer cleared/)
|
2012-12-23 22:06:06 -08:00
|
|
|
|
|
|
|
input '5'
|
|
|
|
output '=> 5'
|
|
|
|
end
|
2012-12-15 14:09:16 -08:00
|
|
|
end
|
2012-12-23 00:03:29 -08:00
|
|
|
|
2013-03-26 21:23:13 +08:00
|
|
|
it "should rescue exceptions" do
|
|
|
|
ReplTester.start do
|
|
|
|
input 'raise "lorum"'
|
2015-01-22 22:52:20 +01:00
|
|
|
output(/^RuntimeError: lorum/)
|
2013-03-26 21:23:13 +08:00
|
|
|
|
2013-11-23 18:11:29 -08:00
|
|
|
if defined?(java)
|
2018-10-13 00:54:00 +08:00
|
|
|
input 'raise java.lang.Exception.new("foo")'
|
2015-01-22 22:52:20 +01:00
|
|
|
output(/Exception: foo/)
|
2013-03-26 21:23:13 +08:00
|
|
|
|
2018-10-13 00:54:00 +08:00
|
|
|
input 'raise java.io.IOException.new("bar")'
|
2015-01-22 22:52:20 +01:00
|
|
|
output(/IOException: bar/)
|
2013-11-23 18:11:29 -08:00
|
|
|
end
|
2013-03-26 21:23:13 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-23 12:25:48 -08:00
|
|
|
describe "eval_string and binding_stack" do
|
2012-12-23 19:58:18 -08:00
|
|
|
it "shouldn't break if we start a nested REPL" do
|
2012-12-23 12:25:48 -08:00
|
|
|
ReplTester.start do
|
2019-03-23 00:44:56 +02:00
|
|
|
input 'Pry::REPL.new(pry_instance, :target => 10).start'
|
2012-12-23 12:25:48 -08:00
|
|
|
output ''
|
2015-01-22 22:52:20 +01:00
|
|
|
prompt(/10.*> $/)
|
2012-12-23 00:03:29 -08:00
|
|
|
|
2012-12-23 12:25:48 -08:00
|
|
|
input 'self'
|
|
|
|
output '=> 10'
|
2012-12-23 00:03:29 -08:00
|
|
|
|
2012-12-23 12:25:48 -08:00
|
|
|
input nil # Ctrl-D
|
|
|
|
output ''
|
2012-12-23 00:03:29 -08:00
|
|
|
|
2012-12-23 12:25:48 -08:00
|
|
|
input 'self'
|
|
|
|
output '=> main'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-23 19:58:18 -08:00
|
|
|
it "shouldn't break if we start a nested instance" do
|
|
|
|
ReplTester.start do
|
2019-03-25 02:40:05 +02:00
|
|
|
input 'Pry.start(10)'
|
2012-12-23 19:58:18 -08:00
|
|
|
output ''
|
2015-01-22 22:52:20 +01:00
|
|
|
prompt(/10.*> $/)
|
2012-12-23 19:58:18 -08:00
|
|
|
|
|
|
|
input 'self'
|
|
|
|
output '=> 10'
|
|
|
|
|
|
|
|
input nil # Ctrl-D
|
|
|
|
output '=> nil' # return value of Pry session
|
|
|
|
|
|
|
|
input 'self'
|
|
|
|
output '=> main'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-23 12:25:48 -08:00
|
|
|
it "shouldn't break if we pop bindings in Ruby" do
|
|
|
|
ReplTester.start do
|
|
|
|
input 'cd 10'
|
|
|
|
output ''
|
2015-01-22 22:52:20 +01:00
|
|
|
prompt(/10.*> $/)
|
2012-12-23 12:25:48 -08:00
|
|
|
|
2019-03-23 00:44:56 +02:00
|
|
|
input 'pry_instance.binding_stack.pop'
|
2015-01-22 22:52:20 +01:00
|
|
|
output(/^=> #<Binding/)
|
|
|
|
prompt(/main.*> $/)
|
2012-12-23 12:25:48 -08:00
|
|
|
|
2019-03-23 00:44:56 +02:00
|
|
|
input 'pry_instance.binding_stack.pop'
|
2015-01-22 22:52:20 +01:00
|
|
|
output(/^=> #<Binding/)
|
2012-12-23 12:25:48 -08:00
|
|
|
assert_exited
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-23 15:21:58 -08:00
|
|
|
it "should immediately evaluate eval_string after cmd if complete" do
|
|
|
|
set = Pry::CommandSet.new do
|
|
|
|
import Pry::Commands
|
|
|
|
|
|
|
|
command 'hello!' do
|
|
|
|
eval_string.replace('"hello"')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-13 03:09:29 +08:00
|
|
|
ReplTester.start(commands: set) do
|
2012-12-23 15:21:58 -08:00
|
|
|
input 'def x'
|
|
|
|
output ''
|
2015-01-22 22:52:20 +01:00
|
|
|
prompt(/\* $/)
|
2012-12-23 15:21:58 -08:00
|
|
|
|
|
|
|
input 'hello!'
|
|
|
|
output '=> "hello"'
|
2015-01-22 22:52:20 +01:00
|
|
|
prompt(/> $/)
|
2012-12-23 12:25:48 -08:00
|
|
|
end
|
2012-12-23 00:03:29 -08:00
|
|
|
end
|
|
|
|
end
|
2013-03-26 21:23:13 +08:00
|
|
|
|
2015-03-08 08:41:48 +02:00
|
|
|
describe "space prefix" do
|
|
|
|
describe "with 1 space" do
|
|
|
|
it "it prioritizes variables over commands" do
|
|
|
|
expect(pry_eval(' ls = 2+2', ' ls')).to eq(4)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "with more than 1 space" do
|
|
|
|
it "prioritizes commands over variables" do
|
|
|
|
expect(mock_pry(' ls = 2+2')).to match(/SyntaxError.+unexpected '='/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-08-24 02:56:39 +01:00
|
|
|
|
|
|
|
describe "#piping?" do
|
|
|
|
it "returns false when $stdout is a non-IO object" do
|
|
|
|
repl = described_class.new(Pry.new, {})
|
|
|
|
old_stdout = $stdout
|
|
|
|
$stdout = Class.new { def write(*) end }.new
|
|
|
|
expect(repl.send(:piping?)).to eq(false)
|
|
|
|
$stdout = old_stdout
|
|
|
|
end
|
|
|
|
end
|
2018-10-03 22:43:36 +02:00
|
|
|
|
|
|
|
describe "autoindent" do
|
|
|
|
it "should raise no exception when indented with a tab" do
|
|
|
|
ReplTester.start(correct_indent: true, auto_indent: true) do
|
2018-11-04 17:34:24 +08:00
|
|
|
output = @pry.config.output
|
2019-03-02 15:35:35 +02:00
|
|
|
def output.tty?
|
|
|
|
true
|
|
|
|
end
|
2019-03-24 15:36:06 +02:00
|
|
|
input <<TAB
|
2018-10-03 22:43:36 +02:00
|
|
|
loop do
|
|
|
|
break #note the tab here
|
|
|
|
end
|
2019-03-24 15:36:06 +02:00
|
|
|
TAB
|
2018-10-03 22:43:36 +02:00
|
|
|
output("do\n break #note the tab here\nend\n\e[1B\e[0G=> nil")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-12-15 14:09:16 -08:00
|
|
|
end
|