Sha256: f2798765e6184dca77d3c585756bee08584a4dbcd3dbc82b81c94a8fd0922a36

Contents?: true

Size: 1.89 KB

Versions: 40

Compression:

Stored size: 1.89 KB

Contents

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::Code.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::Code.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

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
pry-0.9.9.6 test/test_syntax_checking.rb
pry-0.9.9.6-i386-mswin32 test/test_syntax_checking.rb
pry-0.9.9.6-i386-mingw32 test/test_syntax_checking.rb
pry-0.9.9.6-java test/test_syntax_checking.rb
pry-0.9.9.6pre2 test/test_syntax_checking.rb
pry-0.9.9.6pre2-i386-mswin32 test/test_syntax_checking.rb
pry-0.9.9.6pre2-i386-mingw32 test/test_syntax_checking.rb
pry-0.9.9.6pre2-java test/test_syntax_checking.rb
pry-0.9.9.6pre1 test/test_syntax_checking.rb
pry-0.9.9.6pre1-i386-mswin32 test/test_syntax_checking.rb
pry-0.9.9.6pre1-i386-mingw32 test/test_syntax_checking.rb
pry-0.9.9.6pre1-java test/test_syntax_checking.rb
pry-0.9.9.5-java test/test_syntax_checking.rb
pry-0.9.9.5 test/test_syntax_checking.rb
pry-0.9.9.5-i386-mingw32 test/test_syntax_checking.rb
pry-0.9.9.5-i386-mswin32 test/test_syntax_checking.rb
pry-0.9.9.4 test/test_syntax_checking.rb
pry-0.9.9.4-i386-mswin32 test/test_syntax_checking.rb
pry-0.9.9.4-i386-mingw32 test/test_syntax_checking.rb
pry-0.9.9.4-java test/test_syntax_checking.rb