<commit_before>require File.expand_path('../../../spec_helper', __FILE__)

describe :regexp_match, :shared => true do
  it "returns nil if there is no match" do
    /xyz/.send(@method,"abxyc").should be_nil
  end

  it "returns nil if the object is nil" do
    /\w+/.send(@method, nil).should be_nil
  end
end

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

  it "returns the index of the first character of the matching region" do
    (/(.)(.)(.)/ =~ "abc").should == 0
  end
end

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

  it "returns a MatchData object" do
    /(.)(.)(.)/.match("abc").should be_kind_of(MatchData)
  end

  ruby_version_is "1.9" do
    it "matches the input at a given position" do
      /./.match("abc", 1).begin(0).should == 1
    end

    describe "when passed a block" do
      it "yields the MatchData" do
        /./.match("abc") {|m| ScratchPad.record m }
        ScratchPad.recorded.should be_kind_of(MatchData)
      end

      it "returns the block result" do
        /./.match("abc") { :result }.should == :result
      end

      it "does not yield if there is no match" do
        ScratchPad.record []
        /a/.match("b") {|m| ScratchPad << m }
        ScratchPad.recorded.should == []<commit_msg>Add specs into Regexp. Adjust for MRI 1.9~ behaviors.<commit_after>require File.expand_path('../../../spec_helper', __FILE__)

describe :regexp_match, :shared => true do
  it "returns nil if there is no match" do
    /xyz/.send(@method,"abxyc").should be_nil
  end

  it "returns nil if the object is nil" do
    /\w+/.send(@method, nil).should be_nil
  end
end

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

  it "returns the index of the first character of the matching region" do
    (/(.)(.)(.)/ =~ "abc").should == 0
  end

  ruby_version_is "1.9" do
    it "returns the index too, when argument is a Symbol" do
      (/(.)(.)(.)/ =~ :abc).should == 0
    end
  end
end

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

  it "returns a MatchData object" do
    /(.)(.)(.)/.match("abc").should be_kind_of(MatchData)
  end

  ruby_version_is "1.9" do
    it "returns a MatchData object, when argument is a Symbol" do
      /(.)(.)(.)/.match(:abc).should be_kind_of(MatchData)
    end

    it "matches the input at a given position" do
      /./.match("abc", 1).begin(0).should == 1
    end

    describe "when passed a block" do
      it "yields the MatchData" do
        /./.match("abc") {|m| ScratchPad.record m }
        ScratchPad.recorded.should be_kind_of(MatchData)
      end

      it "returns the block result" do
        /./.match("abc") { :result }.should == :result
      end

      it "does not yield if there is no match" do
        ScratchPad.record []
        /a/.match("b") {|m| ScratchPad << m }
        ScratchPad.recorded.should == []
{'fraction_non_alphanumeric': 0.15116684082201323, 'fraction_numerical': 0.0059212817833507484, 'mean_word_length': 2.6679438058748404, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5184313', 'n_tokens_mistral': 1032, 'n_tokens_neox': 973, 'n_words': 300}