diff options
Diffstat (limited to 'spec/ruby/library/stringscanner/rest_size_spec.rb')
| -rw-r--r-- | spec/ruby/library/stringscanner/rest_size_spec.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/ruby/library/stringscanner/rest_size_spec.rb b/spec/ruby/library/stringscanner/rest_size_spec.rb new file mode 100644 index 0000000000..65d3b50e08 --- /dev/null +++ b/spec/ruby/library/stringscanner/rest_size_spec.rb @@ -0,0 +1,30 @@ +require_relative '../../spec_helper' +require 'strscan' + +describe "StringScanner#rest_size" do + before :each do + @s = StringScanner.new('This is a test') + end + + it "returns the length of the rest of the string" do + @s.rest_size.should == 14 + @s.scan(/This/) + @s.rest_size.should == 10 + @s.terminate + @s.rest_size.should == 0 + end + + it "is equivalent to rest.bytesize" do + @s.scan(/This/) + @s.rest_size.should == @s.rest.bytesize + + s = StringScanner.new('été') + s.rest_size.should == 5 + s.scan(/./) + s.rest_size.should == 3 + s.scan(/./) + s.rest_size.should == 2 + s.scan(/./) + s.rest_size.should == 0 + end +end |
