Sha256: 718f27cf1ddddde40e4211b106c1f38efd7bc598e41b4ee58b7067d9323d61d5

Contents?: true

Size: 1.96 KB

Versions: 8

Compression:

Stored size: 1.96 KB

Contents

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

require 'spec_helper'


describe Raabro do

  describe '.rep' do

    it 'returns a tree with result == 0 in case of failure' do

      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(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

      i = Raabro::Input.new('toto')

      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(i.offset).to eq(0)
    end

    it "succeeds (max set)" do

      i = Raabro::Input.new('tototo')

      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(i.offset).to eq(4)
    end

    it "succeeds (max not set)" do

      i = Raabro::Input.new('toto')

      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(i.offset).to eq(4)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
raabro-1.1.1 spec/rep_spec.rb
raabro-1.1.0 spec/rep_spec.rb
raabro-1.0.5 spec/rep_spec.rb
raabro-1.0.4 spec/rep_spec.rb
raabro-1.0.3 spec/rep_spec.rb
raabro-1.0.2 spec/rep_spec.rb
raabro-1.0.1 spec/rep_spec.rb
raabro-1.0.0 spec/rep_spec.rb