2011-11-26 07:44:08 +00:00
|
|
|
require 'helper'
|
|
|
|
describe Pry do
|
|
|
|
|
|
|
|
[
|
|
|
|
["p = '", "'"],
|
|
|
|
["def", "a", "(); end"],
|
|
|
|
["p = <<FOO", "lots", "and", "lots of", "foo", "FOO"],
|
|
|
|
["[", ":lets,", "'list',", "[/nested/", "], things ]"],
|
|
|
|
["abc =~ /hello", "/"],
|
2011-11-26 08:37:47 +00:00
|
|
|
["issue = %W/", "343/"],
|
2011-11-26 07:44:08 +00:00
|
|
|
["pouts(<<HI, 'foo", "bar", "HI", "baz')"],
|
|
|
|
].each do |foo|
|
|
|
|
it "should not raise an error on broken lines: #{foo.join("\\n")}" do
|
|
|
|
output = StringIO.new
|
|
|
|
redirect_pry_io(InputTester.new(*foo), output) do
|
|
|
|
Pry.start
|
|
|
|
end
|
|
|
|
|
|
|
|
output.string.should.not =~ /SyntaxError/
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
[
|
|
|
|
["end"],
|
|
|
|
["puts )("],
|
|
|
|
["1 1"],
|
2011-11-26 07:52:07 +00:00
|
|
|
["puts :"],
|
2011-11-26 07:44:08 +00:00
|
|
|
# in this case the syntax error is "expecting ')'".
|
2011-12-27 22:38:25 +00:00
|
|
|
(Pry::Helpers::BaseHelpers.rbx? ? nil : ["def", "method(1"])
|
2011-11-26 07:44:08 +00:00
|
|
|
].compact.each do |foo|
|
|
|
|
it "should raise an error on invalid syntax like #{foo.inspect}" do
|
|
|
|
output = StringIO.new
|
|
|
|
redirect_pry_io(InputTester.new(*foo), output) do
|
|
|
|
Pry.start
|
|
|
|
end
|
|
|
|
output.string.should =~ /SyntaxError/
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not intefere with syntax errors explicitly raised" do
|
|
|
|
output = StringIO.new
|
|
|
|
redirect_pry_io(InputTester.new(%q{raise SyntaxError, "unexpected $end"}), output) do
|
|
|
|
Pry.start
|
|
|
|
end
|
|
|
|
output.string.should =~ /SyntaxError/
|
|
|
|
end
|
2012-01-06 17:33:37 +00:00
|
|
|
|
|
|
|
it "should allow trailing , to continue the line" do
|
|
|
|
pry = Pry.new
|
|
|
|
|
|
|
|
pry.complete_expression?("puts 1, 2,").should == false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should complete an expression that contains a line ending with a ," do
|
|
|
|
pry = Pry.new
|
|
|
|
pry.complete_expression?("puts 1, 2,\n3").should == true
|
|
|
|
end
|
2011-11-26 07:44:08 +00:00
|
|
|
end
|