Sha256: d27d3c3b6338526e8c3ebd3d133b4f1da43c7576565a6adbbc26d1809e0a0c42

Contents?: true

Size: 683 Bytes

Versions: 14

Compression:

Stored size: 683 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
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
dentaku-0.2.10 spec/token_scanner_spec.rb
dentaku-0.2.9 spec/token_scanner_spec.rb
dentaku-0.2.8 spec/token_scanner_spec.rb
dentaku-0.2.7 spec/token_scanner_spec.rb
dentaku-0.2.6 spec/token_scanner_spec.rb
dentaku-0.2.5 spec/token_scanner_spec.rb
dentaku-0.2.4 spec/token_scanner_spec.rb
dentaku-0.2.3 spec/token_scanner_spec.rb
dentaku-0.2.2 spec/token_scanner_spec.rb
dentaku-0.2.1 spec/token_scanner_spec.rb
dentaku-0.1.3 spec/token_scanner_spec.rb
dentaku-0.1.2 spec/token_scanner_spec.rb
dentaku-0.1.1 spec/token_scanner_spec.rb
dentaku-0.1.0 spec/token_scanner_spec.rb