Sha256: 60a20a70c5323a2feca60ec63e1afedf26e0c3950d53a8b8d9c02b803142a453

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

#
# specifying raabro
#
# Sun Sep 20 09:36:16 JST 2015
#

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)

      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)
    end

    it "fails (min not reached)" do

      @input.string = 'toto'

      t = Raabro.rep(:x, @input, :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)
    end

    it "succeeds (max set)" do

      @input.string = 'tototo'

      t = Raabro.rep(:x, @input, :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)
    end

    it "succeeds (max not set)" do

      @input.string = 'toto'

      t = Raabro.rep(:x, @input, :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)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
raabro-0.9.0 spec/rep_spec.rb