Sha256: fe247cca3d80d4e9ffd457bd9feb18472db4c6c7373264fd0edddd4fbd155c58

Contents?: true

Size: 797 Bytes

Versions: 5

Compression:

Stored size: 797 Bytes

Contents

require 'dentaku/token_scanner'

describe Dentaku::TokenScanner do
  let(:whitespace) { described_class.new(:whitespace, '\s') }
  let(:numeric)    { described_class.new(:numeric,    '(\d+(\.\d+)?|\.\d+)', lambda{|raw| raw =~ /\./ ? raw.to_f : raw.to_i }) }

  it 'should return a token for a matching string' do
    token = whitespace.scan(' ')
    token.category.should eq(:whitespace)
    token.value.should eq(' ')
  end

  it 'should return falsy for a non-matching string' do
    whitespace.scan('A').should_not be
  end

  it 'should perform raw value conversion' do
    token = numeric.scan('5')
    token.category.should eq(:numeric)
    token.value.should eq(5)
  end

  it 'should return a list of all configured scanners' do
    described_class.scanners.length.should eq 10
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dentaku-1.0.0 spec/token_scanner_spec.rb
dentaku-0.2.14 spec/token_scanner_spec.rb
dentaku-0.2.13 spec/token_scanner_spec.rb
dentaku-0.2.12 spec/token_scanner_spec.rb
dentaku-0.2.11 spec/token_scanner_spec.rb