Sha256: 80cb68bc7210bd1471598f308699e8fb9a1df6ce44b95a71d49bc438d787d2ed

Contents?: true

Size: 1.33 KB

Versions: 114

Compression:

Stored size: 1.33 KB

Contents

describe MethodSource::CodeHelpers do
  before do
    @tester = Object.new.extend(MethodSource::CodeHelpers)
  end

  [
    ["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')"],
    ["=begin", "no-one uses this syntax anymore...", "=end"],
    ["puts 1, 2,", "3"],
    ["puts 'hello'\\", "'world'"]
  ].each do |lines|
    it "should not raise an error on broken lines: #{lines.join("\\n")}" do
      1.upto(lines.size - 1) do |i|
        @tester.complete_expression?(lines[0...i].join("\n") + "\n").should == false
      end
      @tester.complete_expression?(lines.join("\n")).should == true
    end
  end

  [
    ["end"],
    ["puts )("],
    ["1 1"],
    ["puts :"]
  ] + (RbConfig::CONFIG['ruby_install_name'] == '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
      lambda{
        @tester.complete_expression?(foo.join("\n"))
      }.should.raise(SyntaxError)
    end
  end
end

Version data entries

114 entries across 107 versions & 34 rubygems

Version Path
logstash-output-scalyr-0.1.9 vendor/bundle/jruby/2.5.0/gems/method_source-0.8.2/test/test_code_helpers.rb
logstash-output-scalyr-0.1.8 vendor/bundle/jruby/2.5.0/gems/method_source-0.8.2/test/test_code_helpers.rb
logstash-output-scalyr-0.1.7 vendor/bundle/jruby/2.5.0/gems/method_source-0.8.2/test/test_code_helpers.rb
logstash-output-scalyr-0.1.6 vendor/bundle/jruby/2.5.0/gems/method_source-0.8.2/test/test_code_helpers.rb
logstash-output-newrelic-1.2.0 vendor/bundle/jruby/2.5.0/gems/method_source-0.8.2/test/test_code_helpers.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.5.0/gems/method_source-0.8.2/test/test_code_helpers.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.3.0/gems/method_source-0.8.2/test/test_code_helpers.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.3.0/gems/method_source-0.8.2/test/test_code_helpers.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.5.0/gems/method_source-0.8.2/test/test_code_helpers.rb
logstash-output-scalyr-0.1.5 vendor/bundle/jruby/2.5.0/gems/method_source-0.8.2/test/test_code_helpers.rb
logstash-output-scalyr-0.1.4 vendor/bundle/jruby/2.5.0/gems/method_source-0.8.2/test/test_code_helpers.rb
logstash-output-scalyr-0.1.3 vendor/bundle/jruby/2.5.0/gems/method_source-0.8.2/test/test_code_helpers.rb
logstash-output-scalyr-0.1.2 vendor/bundle/jruby/2.5.0/gems/method_source-0.8.2/test/test_code_helpers.rb
logstash-filter-device_detection-1.0.7-java vendor/bundle/jruby/1.9/gems/method_source-0.8.2/test/test_code_helpers.rb
mrcooper-logstash-output-azuresearch-0.2.2 vendor/jruby/2.5.0/gems/method_source-0.8.2/test/test_code_helpers.rb
logstash-output-icinga-1.1.0 vendor/jruby/1.9/gems/method_source-0.8.2/test/test_code_helpers.rb
logstash-output-icinga-1.1.0 vendor/jruby/2.3.0/gems/method_source-0.8.2/test/test_code_helpers.rb
tdiary-5.0.6 vendor/bundle/gems/method_source-0.8.2/test/test_code_helpers.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/method_source-0.8.2/test/test_code_helpers.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/method_source-0.8.2/test/test_code_helpers.rb