1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00
pry--pry/test/test_syntax_checking.rb
Conrad Irwin ab2f586e3c Fix edge-case in indent on ruby 1.9.3 [Fixes #517]
This is not fixed on rbx — maybe we should consider using the data we've
collected in indent.rb to look for unbalanced open/close tokens too on
rbx as it's error messages often elide the "Expected }" part of the
message.
2012-04-08 18:45:52 -07:00

64 lines
1.9 KiB
Ruby

require 'helper'
describe Pry do
[
["p = '", "'"],
["def", "a", "(); end"],
["p = <<FOO", "lots", "and", "lots of", "foo", "FOO"],
["[", ":lets,", "'list',", "[/nested/", "], things ]"],
["abc =~ /hello", "/"],
["issue = %W/", "343/"],
["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"],
["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|
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
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
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
end