Sha256: 7df2e7c88b711beffbfd3c70458a6372020c75e0b4be6c19c2c990bc8fa22106

Contents?: true

Size: 532 Bytes

Versions: 3

Compression:

Stored size: 532 Bytes

Contents

require 'strscan'

describe "StringScanner#exist?" do
  before :each do
    @s = StringScanner.new("This is a test")
  end

  it "returns the index of the first occurrence of the given pattern" do
    @s.exist?(/s/).should == 4
    @s.scan(/This is/)
    @s.exist?(/s/).should == 6
  end

  it "returns 0 if the pattern is empty" do
    @s.exist?(//).should == 0
  end

  it "returns nil if the pattern isn't found in the string" do
    @s.exist?(/S/).should == nil
    @s.scan(/This is/)
    @s.exist?(/i/).should == nil
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubysl-strscan-1.0.1 spec/exist_spec.rb
rubysl-strscan-1.0.0 spec/exist_spec.rb
rubysl-strscan-2.0.0 spec/exist_spec.rb