diff options
Diffstat (limited to 'spec/ruby/library/stringscanner/matched_size_spec.rb')
| -rw-r--r-- | spec/ruby/library/stringscanner/matched_size_spec.rb | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/spec/ruby/library/stringscanner/matched_size_spec.rb b/spec/ruby/library/stringscanner/matched_size_spec.rb index 7aac71878a..d9c338a07e 100644 --- a/spec/ruby/library/stringscanner/matched_size_spec.rb +++ b/spec/ruby/library/stringscanner/matched_size_spec.rb @@ -1,7 +1,24 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../shared/matched_size.rb', __FILE__) +require_relative '../../spec_helper' require 'strscan' describe "StringScanner#matched_size" do - it_behaves_like(:strscan_matched_size, :matched_size) + before :each do + @s = StringScanner.new("This is a test") + end + + it "returns the size of the most recent match" do + @s.check(/This/) + @s.matched_size.should == 4 + @s.matched_size.should == 4 + @s.scan(//) + @s.matched_size.should == 0 + end + + it "returns nil if there was no recent match" do + @s.matched_size.should == nil + @s.check(/\d+/) + @s.matched_size.should == nil + @s.terminate + @s.matched_size.should == nil + end end |
