Source

par / spec / lib / par_spec.rb

require 'spec_helper'

describe Par do
  include Par

  let(:s) { source 'foobar' }

  describe "sequences" do
    it "parse" do
      (s.string('foo') >> s.string('bar')).should_not == bottom
    end
    it "or not" do
      (s.string('bar') >> s.string('bar')).should == bottom
    end
  end
  describe 'maybe' do
    it "allows optional parsing" do
      (s.string('baz').maybe >> s.string('foobar')).should == 'foobar'
    end
    it "allows maybe on results" do
      s.string('foo').maybe.should == 'foo'
    end
  end
end