Sha256: 41b255676eb5563aa45fb0a86cfea19c2502a43c44c35bc0f771d8c4ae1d37ba

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
require "usher"

describe StringScanner do
  describe "#scan_before" do
    before :each do
      @scanner = StringScanner.new("/one/two..three")
    end

    describe "when there is a match" do
      it "should return subsequent string without matching pattern in the end" do
        @scanner.scan_before(/\.\./).should == "/one/two"
      end

      it "should set pointer right before the matching pattern" do
        @scanner.scan_before(/\.\./)
        @scanner.scan(/\.\./).should == '..'
      end

      describe "when matching pattern is right at the position" do
        it "should return empty string" do
          @scanner.scan_before(/\//).should == ''
        end
      end
    end

    describe "when there is no match" do
      it "should return nil" do
        @scanner.scan_before(/bla-bla-bla/).should == nil
      end

      it "should not move the pointer" do
        @scanner.scan_before(/bla-bla-bla/)
        @scanner.pos.should == 0
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
usher-0.5.13 spec/private/string_scanner_spec.rb
usher-0.5.12 spec/private/string_scanner_spec.rb
usher-0.5.11 spec/private/string_scanner_spec.rb