Sha256: fee13bcbdbb7de883951cd4ff320503b97c1a18272b21df9809657b83972d89c

Contents?: true

Size: 1.65 KB

Versions: 39

Compression:

Stored size: 1.65 KB

Contents

require "re2/string"

class String
  include RE2::String
end

RSpec.describe RE2::String do
  describe "#re2_sub" do
    it "delegates to RE2.Replace to perform replacement" do
      expect("My name is Robert Paulson".re2_sub('Robert', 'Crobert')).to eq("My name is Crobert Paulson")
    end

    it "doesn't perform an in-place replacement" do
      string = "My name is Robert Paulson"
      expect(string.re2_sub('Robert', 'Crobert')).to_not equal(string)
    end
  end

  describe "#re2_gsub" do
    it "delegates to RE2.GlobalReplace to perform replacement" do
      expect("My name is Robert Paulson".re2_gsub('a', 'e')).to eq("My neme is Robert Peulson")
    end

    it "doesn't perform an in-place replacement" do
      string = "My name is Robert Paulson"
      expect(string.re2_gsub('a', 'e')).to_not equal(string)
    end
  end

  describe "#re2_match" do
    it "delegates to RE2::Regexp#match to perform matches" do
      md = "My name is Robert Paulson".re2_match('My name is (\S+) (\S+)')
      expect(md).to be_a(RE2::MatchData)
      expect(md[0]).to eq("My name is Robert Paulson")
      expect(md[1]).to eq("Robert")
      expect(md[2]).to eq("Paulson")
    end

    it "supports limiting the number of matches" do
      md = "My name is Robert Paulson".re2_match('My name is (\S+) (\S+)', 0)
      expect(md).to eq(true)
    end
  end

  describe "#re2_escape" do
    it "escapes the string for use in regular expressions" do
      expect("1.5-2.0?".re2_escape).to eq('1\.5\-2\.0\?')
    end
  end

  describe "#re2_quote" do
    it "escapes the string for use in regular expressions" do
      expect("1.5-2.0?".re2_quote).to eq('1\.5\-2\.0\?')
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
re2-2.0.0 spec/re2/string_spec.rb
re2-2.0.0-x86_64-linux spec/re2/string_spec.rb
re2-2.0.0-x86_64-darwin spec/re2/string_spec.rb
re2-2.0.0-x86-mingw32 spec/re2/string_spec.rb
re2-2.0.0-x86-linux spec/re2/string_spec.rb
re2-2.0.0-x64-mingw32 spec/re2/string_spec.rb
re2-2.0.0-x64-mingw-ucrt spec/re2/string_spec.rb
re2-2.0.0-arm64-darwin spec/re2/string_spec.rb
re2-2.0.0-arm-linux spec/re2/string_spec.rb
re2-2.0.0-aarch64-linux spec/re2/string_spec.rb
re2-2.0.0.beta2 spec/re2/string_spec.rb
re2-2.0.0.beta2-x86_64-linux spec/re2/string_spec.rb
re2-2.0.0.beta2-x86_64-darwin spec/re2/string_spec.rb
re2-2.0.0.beta2-x86-mingw32 spec/re2/string_spec.rb
re2-2.0.0.beta2-x86-linux spec/re2/string_spec.rb
re2-2.0.0.beta2-x64-mingw32 spec/re2/string_spec.rb
re2-2.0.0.beta2-x64-mingw-ucrt spec/re2/string_spec.rb
re2-2.0.0.beta2-arm64-darwin spec/re2/string_spec.rb
re2-2.0.0.beta2-arm-linux spec/re2/string_spec.rb
re2-2.0.0.beta2-aarch64-linux spec/re2/string_spec.rb