1. Kaspar Schiess
  2. par

Source

par / spec / lib / par / result_spec.rb

require 'spec_helper'

describe Par::Result do
  include Par

  context 'given 2 results' do
    let(:a) { result 'foo' }
    let(:b) { result 'bar' }
    
    it "should allow concatenation" do
      (a >> b).to_s.should == 'foobar'
    end
    it "should allow alternation" do
      (a | b).should == a
    end
    it "allow calling maybe" do
      a.maybe.should == a
    end
  end
  context '.bot' do
    let(:any) { result 'any' }

    it "cannot be concatenated left" do
      (bot >> any).should == bot
    end
    it "cannot be concatenated right" do
      (any >> bot).should == bot 
    end
    it "can be alternated left" do
      (bot | any).should == any
    end
    it "can be alternated right" do
      (any | bot).should == any
    end
  end
  context '.top' do
    let(:any) { result('any') }
    it 'allows concatenation left' do
      (top >> any).should == any
    end
    it 'allows concatenation right' do
      (any >> top).should == any
    end
    it 'allows alternation' do
      (any | top).should == any
      (top | any).should == top
    end
    it 'can be maybeed' do
      top.maybe.should == top
    end
  end
end