2011-11-26 07:44:08 +00:00
|
|
|
require 'helper'
|
2012-06-11 13:36:16 +00:00
|
|
|
|
2011-11-26 07:44:08 +00:00
|
|
|
describe Pry do
|
2012-06-11 13:36:16 +00:00
|
|
|
before do
|
|
|
|
@str_output = StringIO.new
|
|
|
|
end
|
2011-11-26 07:44:08 +00:00
|
|
|
|
|
|
|
[
|
|
|
|
["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
|
2012-06-11 13:36:16 +00:00
|
|
|
redirect_pry_io(InputTester.new(*foo), @str_output) do
|
2011-11-26 07:44:08 +00:00
|
|
|
Pry.start
|
|
|
|
end
|
|
|
|
|
2012-06-11 13:36:16 +00:00
|
|
|
@str_output.string.should.not =~ /SyntaxError/
|
2011-11-26 07:44:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
[
|
|
|
|
["end"],
|
|
|
|
["puts )("],
|
|
|
|
["1 1"],
|
2012-04-09 01:45:52 +00:00
|
|
|
["puts :"]
|
|
|
|
] + (Pry::Helpers::BaseHelpers.rbx? ? [] : [
|
|
|
|
["def", "method(1"], # in this case the syntax error is "expecting ')'".
|
|
|
|
["o = Object.new.tap{ def o.render;","'MEH'", "}"] # in this case the syntax error is "expecting keyword_end".
|
|
|
|
]).compact.each do |foo|
|
2011-11-26 07:44:08 +00:00
|
|
|
it "should raise an error on invalid syntax like #{foo.inspect}" do
|
2012-06-11 13:36:16 +00:00
|
|
|
redirect_pry_io(InputTester.new(*foo), @str_output) do
|
2011-11-26 07:44:08 +00:00
|
|
|
Pry.start
|
|
|
|
end
|
2012-06-11 13:36:16 +00:00
|
|
|
|
|
|
|
@str_output.string.should =~ /SyntaxError/
|
2011-11-26 07:44:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not intefere with syntax errors explicitly raised" do
|
2012-06-11 13:36:16 +00:00
|
|
|
redirect_pry_io(InputTester.new(%q{raise SyntaxError, "unexpected $end"}), @str_output) do
|
2011-11-26 07:44:08 +00:00
|
|
|
Pry.start
|
|
|
|
end
|
2012-06-11 13:36:16 +00:00
|
|
|
|
|
|
|
@str_output.string.should =~ /SyntaxError/
|
2011-11-26 07:44:08 +00:00
|
|
|
end
|
2012-01-06 17:33:37 +00:00
|
|
|
|
|
|
|
it "should allow trailing , to continue the line" do
|
|
|
|
pry = Pry.new
|
2012-04-10 13:39:29 +00:00
|
|
|
Pry::Code.complete_expression?("puts 1, 2,").should == false
|
2012-01-06 17:33:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should complete an expression that contains a line ending with a ," do
|
|
|
|
pry = Pry.new
|
2012-04-10 13:39:29 +00:00
|
|
|
Pry::Code.complete_expression?("puts 1, 2,\n3").should == true
|
2012-01-06 17:33:37 +00:00
|
|
|
end
|
2012-01-13 07:21:21 +00:00
|
|
|
|
|
|
|
it "should not clobber _ex_ on a SyntaxError in the repl" do
|
|
|
|
mock_pry("raise RuntimeError, 'foo';", "puts foo)", "_ex_.is_a?(RuntimeError)").should =~ /^RuntimeError.*\nSyntaxError.*\n=> true/m
|
|
|
|
end
|
2011-11-26 07:44:08 +00:00
|
|
|
end
|