1 # Copyright 2007-2014 Greg Hurrell. All rights reserved.
2 # Licensed under the terms of the BSD 2-clause license.
6 # For more detailed specification of the RegexpParslet behaviour see
7 # regexp_parslet_spec.rb.
8 describe 'using shorthand to get RegexpParslets from Regexp instances' do
9 context 'chaining two Regexps with the "&" operator' do
10 it 'yields a two-element sequence' do
11 sequence = /foo/ & /bar/
12 sequence.parse('foobar').map { |each| each.to_s }.should == ['foo', 'bar']
16 context 'chaining three Regexps with the "&" operator' do
17 it 'yields a three-element sequence' do
18 sequence = /foo/ & /bar/ & /\.\.\./
19 sequence.parse('foobar...').map { |each| each.to_s }.should == ['foo', 'bar', '...']
23 context 'alternating two Regexps with the "|" operator' do
24 it 'yields a MatchDataWrapper' do
25 sequence = /foo/ | /bar/
26 sequence.parse('foobar').to_s.should == 'foo'
27 sequence.parse('bar...').to_s.should == 'bar'
29 sequence.parse('no match')
30 end.to raise_error(Walrat::ParseError)