Sha256: 6dc14a57df5ba28cfcbc8c1adef5408573ada65565e986afdcb7ad2ea46d1ba9

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

require 'spec_helper'
require 'bioinform/support/advanced_scan'

describe StringScanner do
  context '#advanced_scan' do
    before do
      @scanner = StringScanner.new('abcde  fghIJKLmnop')
    end
    it 'should return nil if text doesn\'t match. Pointer should not move' do
      @scanner.advanced_scan(/\s\s\s/).should be_nil
      @scanner.pos.should == 0
    end
    it 'should return MatchData if string Matches. Pointer should move' do
      @scanner.advanced_scan(/\w\w\w/).should be_kind_of MatchData
      @scanner.pos.should == 3
    end
    it 'should return have the same groups as regexp has' do
      result = @scanner.advanced_scan(/(\w+)(\s+)([a-z]+)([A-Z]+)/)
      result[0].should == 'abcde  fghIJKL'
      result[1].should == 'abcde'
      result[2].should == '  '
      result[3].should == 'fgh'
      result[4].should == 'IJKL'
    end
    it 'should return have the same named groups as regexp has' do
      result = @scanner.advanced_scan(/(\w+)(\s+)(?<word_downcase>[a-z]+)(?<word_upcase>[A-Z]+)/)
      result[0].should == 'abcde  fghIJKL'
      result[:word_downcase].should == 'fgh'
      result[:word_upcase].should == 'IJKL'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bioinform-0.1.7 spec/support/advanced_scan_spec.rb
bioinform-0.1.6 spec/support/advanced_scan_spec.rb
bioinform-0.1.5 spec/support/advanced_scan_spec.rb