Sha256: 55715e9567739a1ebd90a2e719e811a83e7e54acd4d646d07d5392c41fd9ca62

Contents?: true

Size: 1.73 KB

Versions: 6

Compression:

Stored size: 1.73 KB

Contents

require 'dentaku/token_matcher'

describe Dentaku::TokenMatcher do
  it 'with single category should match token category' do
    matcher = described_class.new(:numeric)
    token   = Dentaku::Token.new(:numeric, 5)

    matcher.should == token
  end

  it 'with multiple categories should match any included token category' do
    matcher    = described_class.new([:comparator, :operator])
    numeric    = Dentaku::Token.new(:numeric, 5)
    comparator = Dentaku::Token.new(:comparator, :lt)
    operator   = Dentaku::Token.new(:operator, :add)

    matcher.should == comparator
    matcher.should == operator
    matcher.should_not == numeric
  end

  it 'with single category and value should match token category and value' do
    matcher     = described_class.new(:operator, :add)
    addition    = Dentaku::Token.new(:operator, :add)
    subtraction = Dentaku::Token.new(:operator, :subtract)

    matcher.should == addition
    matcher.should_not == subtraction
  end

  it 'with multiple values should match any included token value' do
    matcher = described_class.new(:operator, [:add, :subtract])
    add = Dentaku::Token.new(:operator, :add)
    sub = Dentaku::Token.new(:operator, :subtract)
    mul = Dentaku::Token.new(:operator, :multiply)
    div = Dentaku::Token.new(:operator, :divide)

    matcher.should == add
    matcher.should == sub
    matcher.should_not == mul
    matcher.should_not == div
  end

  it 'should be invertible' do
    matcher = described_class.new(:operator, [:add, :subtract]).invert
    add = Dentaku::Token.new(:operator, :add)
    mul = Dentaku::Token.new(:operator, :multiply)
    cmp = Dentaku::Token.new(:comparator, :lt)

    matcher.should_not == add
    matcher.should == mul
    matcher.should == cmp
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dentaku-0.2.2 spec/token_matcher_spec.rb
dentaku-0.2.1 spec/token_matcher_spec.rb
dentaku-0.1.3 spec/token_matcher_spec.rb
dentaku-0.1.2 spec/token_matcher_spec.rb
dentaku-0.1.1 spec/token_matcher_spec.rb
dentaku-0.1.0 spec/token_matcher_spec.rb