2018-03-04 15:09:32 +00:00
|
|
|
require_relative '../../spec_helper'
|
2017-05-07 12:04:49 +00:00
|
|
|
require 'strscan'
|
|
|
|
|
|
|
|
describe "StringScanner#check" do
|
|
|
|
before :each do
|
|
|
|
@s = StringScanner.new("This is a test")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the value that scan would return, without advancing the scan pointer" do
|
|
|
|
@s.check(/This/).should == "This"
|
|
|
|
@s.matched.should == "This"
|
|
|
|
@s.pos.should == 0
|
|
|
|
@s.check(/is/).should == nil
|
|
|
|
@s.matched.should == nil
|
|
|
|
end
|
2021-10-05 19:41:44 +02:00
|
|
|
|
2022-04-25 14:53:54 +02:00
|
|
|
it "treats String as the pattern itself" do
|
|
|
|
@s.check("This").should == "This"
|
|
|
|
@s.matched.should == "This"
|
|
|
|
@s.pos.should == 0
|
|
|
|
@s.check(/is/).should == nil
|
|
|
|
@s.matched.should == nil
|
2021-10-05 19:41:44 +02:00
|
|
|
end
|
|
|
|
|
2017-05-07 12:04:49 +00:00
|
|
|
end
|