mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Pry: don't strip newlines from multi-line exprs
Fix issue #704 (newlines are stripped from inside pasted strings) Also, make sure that other literals (system calls, regexps) also comply this rule. Reviewed-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
parent
4bb7bd2ac9
commit
b5eec6d882
2 changed files with 48 additions and 9 deletions
|
@ -297,7 +297,7 @@ class Pry
|
|||
inject_sticky_locals!
|
||||
begin
|
||||
if !process_command_safely(line.lstrip)
|
||||
@eval_string << "#{line.chomp}\n" unless line.empty?
|
||||
@eval_string << "#{line.chomp}\n" if !line.empty? || !@eval_string.empty?
|
||||
end
|
||||
rescue RescuableException => e
|
||||
self.last_exception = e
|
||||
|
|
|
@ -109,10 +109,6 @@ describe Pry do
|
|||
pry_eval(o, "self").should == o
|
||||
end
|
||||
|
||||
it 'should work with multi-line input' do
|
||||
mock_pry("x = ", "1 + 4").should =~ /5/
|
||||
end
|
||||
|
||||
it 'should define a nested class under Hello and not on top-level or Pry' do
|
||||
mock_pry(Pry.binding_for(Hello), "class Nested", "end")
|
||||
Hello.const_defined?(:Nested).should == true
|
||||
|
@ -126,10 +122,6 @@ describe Pry do
|
|||
mock_pry("x = 5;").should == ""
|
||||
end
|
||||
|
||||
it 'should suppress output if input ends in a ";" (multi-line)' do
|
||||
mock_pry("def self.blah", ":test", "end;").should == ""
|
||||
end
|
||||
|
||||
it 'should be able to evaluate exceptions normally' do
|
||||
was_called = false
|
||||
mock_pry("RuntimeError.new", :exception_handler => proc{ was_called = true })
|
||||
|
@ -147,6 +139,53 @@ describe Pry do
|
|||
# SIGTERM
|
||||
lambda { mock_pry("raise SignalException.new(15)") }.should.raise SignalException
|
||||
end
|
||||
|
||||
describe "multi-line input" do
|
||||
it "works" do
|
||||
mock_pry('x = ', '1 + 4').should =~ /5/
|
||||
end
|
||||
|
||||
it 'should suppress output if input ends in a ";" (multi-line)' do
|
||||
mock_pry('def self.blah', ':test', 'end;').should == ''
|
||||
end
|
||||
|
||||
describe "newline stripping from an empty string" do
|
||||
it "with double quotes" do
|
||||
mock_pry('"', '"').should =~ %r|"\\n"|
|
||||
mock_pry('"', "\n", "\n", "\n", '"').should =~ %r|"\\n\\n\\n\\n"|
|
||||
end
|
||||
|
||||
it "with single quotes" do
|
||||
mock_pry("'", "'").should =~ %r|"\\n"|
|
||||
mock_pry("'", "\n", "\n", "\n", "'").should =~ %r|"\\n\\n\\n\\n"|
|
||||
end
|
||||
|
||||
it "with fancy delimiters" do
|
||||
mock_pry('%(', ')').should =~ %r|"\\n"|
|
||||
mock_pry('%|', "\n", "\n", '|').should =~ %r|"\\n\\n\\n"|
|
||||
mock_pry('%q[', "\n", "\n", ']').should =~ %r|"\\n\\n\\n"|
|
||||
end
|
||||
end
|
||||
|
||||
describe "newline stripping from an empty regexp" do
|
||||
it "with regular regexp delimiters" do
|
||||
mock_pry('/', '/').should =~ %r{/\n/}
|
||||
end
|
||||
|
||||
it "with fancy delimiters" do
|
||||
mock_pry('%r{', "\n", "\n", '}').should =~ %r{/\n\n\n/}
|
||||
mock_pry('%r<', "\n", '>').should =~ %r{/\n\n/}
|
||||
end
|
||||
end
|
||||
|
||||
describe "newline from an empty heredoc" do
|
||||
it "works" do
|
||||
mock_pry('<<HERE', 'HERE').should =~ %r|""|
|
||||
mock_pry("<<'HERE'", "\n", 'HERE').should =~ %r|"\\n"|
|
||||
mock_pry("<<-'HERE'", "\n", "\n", 'HERE').should =~ %r|"\\n\\n"|
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "repl" do
|
||||
|
|
Loading…
Add table
Reference in a new issue