1 # Copyright 2007-2014 Greg Hurrell. All rights reserved.
2 # Licensed under the terms of the BSD 2-clause license.
6 describe Walrat::ProcParslet do
8 @parslet = lambda do |string, options|
12 raise Walrat::ParseError.new("expected foobar but got '#{string}'")
17 it 'raises an ArgumentError if initialized with nil' do
19 Walrat::ProcParslet.new nil
20 end.to raise_error(ArgumentError, /nil proc/)
23 it 'complains if asked to parse nil' do
26 end.to raise_error(ArgumentError, /nil string/)
29 it 'raises Walrat::ParseError if unable to parse' do
32 end.to raise_error(Walrat::ParseError)
35 it 'returns a parsed value if able to parse' do
36 @parslet.parse('foobar').should == 'foobar'
39 it 'can be compared for equality' do
40 # in practice only parslets created with the exact same Proc instance will
41 # be eql because Proc returns different hashes for each
42 @parslet.should eql(@parslet.clone)
43 @parslet.should eql(@parslet.dup)
44 @parslet.should_not eql(lambda { nil }.to_parseable)