diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index 58bee49f..c68a771d 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -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 diff --git a/spec/pry_spec.rb b/spec/pry_spec.rb index b315ee9d..c21c370e 100644 --- a/spec/pry_spec.rb +++ b/spec/pry_spec.rb @@ -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('<