Sha256: fdff3b16715316cd8e2fd0464eda93ad736d500a2c6e9561fc217f50be014292

Contents?: true

Size: 640 Bytes

Versions: 3

Compression:

Stored size: 640 Bytes

Contents

require 'strscan'

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

  it "set the scan pointer to the previous position" do
    @s.scan(/This/)
    @s.unscan
    @s.matched.should == nil
    @s.pos.should == 0
  end

  it "remember only one previous position" do
    pos1 = @s.pos
    @s.scan(/This/)
    pos2 = @s.pos
    @s.scan(/ is/)
    @s.unscan
    @s.pos.should == pos2
  end

  it "raises a ScanError when the previous match had failed" do
    lambda { @s.unscan }.should raise_error(ScanError)
    lambda { @s.scan(/\d/); @s.unscan }.should raise_error(ScanError)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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