spec/rep_spec.rb in raabro-0.9.0 vs spec/rep_spec.rb in raabro-1.0.0

- old
+ new

@@ -8,75 +8,87 @@ require 'spec_helper' describe Raabro do - before :each do - - @input = Raabro::Input.new('toto') - end - describe '.rep' do it 'returns a tree with result == 0 in case of failure' do - t = Raabro.rep(:x, @input, :to, 3, 4) + i = Raabro::Input.new('toto') + t = Raabro.rep(:x, i, :to, 3, 4) + expect(t.to_a(:leaves => true)).to eq( [ :x, 0, 0, 0, nil, :rep, [ [ nil, 1, 0, 2, nil, :str, 'to' ], [ nil, 1, 2, 2, nil, :str, 'to' ], [ nil, 0, 4, 0, nil, :str, [] ] ] ] ) - expect(@input.offset).to eq(0) + expect(i.offset).to eq(0) end + it 'prunes' do + + i = Raabro::Input.new('toto', :prune => true) + + t = Raabro.rep(:x, i, :to, 3, 4) + + expect(t.to_a(:leaves => true)).to eq( + [ :x, 0, 0, 0, nil, :rep, [ + [ nil, 1, 0, 2, nil, :str, 'to' ], + [ nil, 1, 2, 2, nil, :str, 'to' ] + ] ] + ) + expect(i.offset).to eq(0) + end + it "fails (min not reached)" do - @input.string = 'toto' + i = Raabro::Input.new('toto') - t = Raabro.rep(:x, @input, :to, 3) + t = Raabro.rep(:x, i, :to, 3) expect(t.to_a(:leaves => true)).to eq( [ :x, 0, 0, 0, nil, :rep, [ [ nil, 1, 0, 2, nil, :str, 'to' ], [ nil, 1, 2, 2, nil, :str, 'to' ], [ nil, 0, 4, 0, nil, :str, [] ] ] ] ) - expect(@input.offset).to eq(0) + expect(i.offset).to eq(0) end it "succeeds (max set)" do - @input.string = 'tototo' + i = Raabro::Input.new('tototo') - t = Raabro.rep(:x, @input, :to, 1, 2) + t = Raabro.rep(:x, i, :to, 1, 2) expect(t.to_a(:leaves => true)).to eq( [ :x, 1, 0, 4, nil, :rep, [ [ nil, 1, 0, 2, nil, :str, 'to' ], [ nil, 1, 2, 2, nil, :str, 'to' ] ] ] ) - expect(@input.offset).to eq(4) + expect(i.offset).to eq(4) end it "succeeds (max not set)" do - @input.string = 'toto' + i = Raabro::Input.new('toto') - t = Raabro.rep(:x, @input, :to, 1) + t = Raabro.rep(:x, i, :to, 1) expect(t.to_a(:leaves => true)).to eq( [ :x, 1, 0, 4, nil, :rep, [ [ nil, 1, 0, 2, nil, :str, 'to' ], [ nil, 1, 2, 2, nil, :str, 'to' ], [ nil, 0, 4, 0, nil, :str, [] ] ] ] ) - expect(@input.offset).to eq(4) + expect(i.offset).to eq(4) end end end