Sha256: bf5081e75d2f1da86025f628be40ef7912cee0139a45e8c83f7d6e19b807e9e3

Contents?: true

Size: 820 Bytes

Versions: 6

Compression:

Stored size: 820 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 =~ /\./ ? BigDecimal.new(raw) : raw.to_i }) }

  it 'returns a token for a matching string' do
    token = whitespace.scan(' ').first
    expect(token.category).to eq(:whitespace)
    expect(token.value).to eq(' ')
  end

  it 'returns falsy for a non-matching string' do
    expect(whitespace.scan('A')).not_to be
  end

  it 'performs raw value conversion' do
    token = numeric.scan('5').first
    expect(token.category).to eq(:numeric)
    expect(token.value).to eq(5)
  end

  it 'returns a list of all configured scanners' do
    expect(described_class.scanners.length).to eq 10
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dentaku-1.2.6 spec/token_scanner_spec.rb
dentaku-1.2.5 spec/token_scanner_spec.rb
dentaku-1.2.4 spec/token_scanner_spec.rb
dentaku-1.2.3 spec/token_scanner_spec.rb
dentaku-1.2.2 spec/token_scanner_spec.rb
dentaku-1.2.1 spec/token_scanner_spec.rb