Sha256: 9c8960f3c4e76ad889634b37d208d7281bc616754630bcdcc9deedfe4427155a

Contents?: true

Size: 1.35 KB

Versions: 52

Compression:

Stored size: 1.35 KB

Contents

require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/match', __FILE__)

describe "Regexp#=~" do
  it_behaves_like(:regexp_match, :=~)
end

describe "Regexp#match" do
  it_behaves_like(:regexp_match, :match)

  it "raises TypeError when the given argument cannot be coarce to String" do
    f = 1
    lambda { /foo/.match(f)[0] }.should raise_error(TypeError)
  end

  ruby_version_is ""..."1.9" do
    it "coerces Exceptions into strings" do
      f = Exception.new("foo")
      /foo/.match(f)[0].should == "foo"
    end
  end

  ruby_version_is "1.9" do
    it "raises TypeError when the given argument is an Exception" do
      f = Exception.new("foo")
      lambda { /foo/.match(f)[0] }.should raise_error(TypeError)
    end
  end
end

describe "Regexp#~" do
  it "matches against the contents of $_" do
    $_ = "input data"
    (~ /at/).should == 7
  end
end

describe "Regexp#=~ on a successful match" do
  it "returns the index of the first character of the matching region" do
    (/(.)(.)(.)/ =~ "abc").should == 0
  end
end

describe "Regexp#match on a successful match" do
  it "returns a MatchData object" do
    /(.)(.)(.)/.match("abc").should be_kind_of(MatchData)
  end

  it "resets $~ if passed nil" do
    # set $~
    /./.match("a")
    $~.should be_kind_of(MatchData)

    /1/.match(nil)
    $~.should be_nil
  end
end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
rhodes-7.6.0 spec/framework_spec/app/spec/core/regexp/match_spec.rb
rhodes-7.5.1 spec/framework_spec/app/spec/core/regexp/match_spec.rb
rhodes-7.4.1 spec/framework_spec/app/spec/core/regexp/match_spec.rb
rhodes-7.1.17 spec/framework_spec/app/spec/core/regexp/match_spec.rb
rhodes-6.2.0 spec/framework_spec/app/spec/core/regexp/match_spec.rb
rhodes-6.0.11 spec/framework_spec/app/spec/core/regexp/match_spec.rb
rhodes-5.5.18 spec/framework_spec/app/spec/core/regexp/match_spec.rb
rhodes-5.5.17 spec/framework_spec/app/spec/core/regexp/match_spec.rb
rhodes-5.5.15 spec/framework_spec/app/spec/core/regexp/match_spec.rb
rhodes-5.5.0.22 spec/framework_spec/app/spec/core/regexp/match_spec.rb
rhodes-5.5.2 spec/framework_spec/app/spec/core/regexp/match_spec.rb
rhodes-5.5.0.7 spec/framework_spec/app/spec/core/regexp/match_spec.rb
rhodes-5.5.0.3 spec/framework_spec/app/spec/core/regexp/match_spec.rb
rhodes-5.5.0 spec/framework_spec/app/spec/core/regexp/match_spec.rb
tauplatform-1.0.3 spec/framework_spec/app/spec/core/regexp/match_spec.rb
tauplatform-1.0.2 spec/framework_spec/app/spec/core/regexp/match_spec.rb
tauplatform-1.0.1 spec/framework_spec/app/spec/core/regexp/match_spec.rb
rhodes-3.5.1.12 spec/framework_spec/app/spec/core/regexp/match_spec.rb
rhodes-3.3.5 spec/framework_spec/app/spec/core/regexp/match_spec.rb
rhodes-3.4.2 spec/framework_spec/app/spec/core/regexp/match_spec.rb