Sha256: 8b26b6094e324c8ba58cc7c77cf102564262e968bc2a21d4754697b522eee024

Contents?: true

Size: 1.39 KB

Versions: 7

Compression:

Stored size: 1.39 KB

Contents

require 'spec_helper'
module Sexpr::Matcher
  describe Many, "eat" do

    let(:term){ Terminal.new(/^[a-z]+$/)   }
    let(:rule){ Many.new term, min, max    }

    context "when set for *" do
      let(:min){ 0   }
      let(:max){ nil }

      it 'returns the subarray when zero match' do
        rule.eat([nil, "world", "then"]).should eq([nil, "world", "then"])
      end

      it 'returns the subarray when one match' do
        rule.eat(["world", nil, "then"]).should eq([nil, "then"])
      end

      it 'returns the subarray when multiple matches' do
        rule.eat(["world", "then"]).should eq([])
      end

    end # *

    context "when set for +" do
      let(:min){ 1   }
      let(:max){ nil }

      it 'returns nil zero match' do
        rule.eat([nil, "world", "then"]).should be_nil
      end

      it 'returns the subarray when one match' do
        rule.eat(["world", nil, "then"]).should eq([nil, "then"])
      end

      it 'returns the subarray when multiple matches' do
        rule.eat(["world", "then"]).should eq([])
      end

    end # +

    context "when set for ?" do
      let(:min){ 0 }
      let(:max){ 1 }

      it 'returns the subarray when zero match' do
        rule.eat([nil, "world", "then"]).should eq([nil, "world", "then"])
      end

      it 'returns the subarray when one match' do
        rule.eat(["world", "then"]).should eq(["then"])
      end

    end # ?

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sexpr-1.1.0 spec/unit/matcher/many/test_eat.rb
sexpr-1.0.0 spec/unit/matcher/many/test_eat.rb
sexpr-0.6.0 spec/unit/matcher/many/test_eat.rb
sexpr-0.5.1 spec/matcher/many/test_eat.rb
sexpr-0.5.0 spec/matcher/many/test_eat.rb
sexpr-0.4.0 spec/matcher/many/test_eat.rb
sexpr-0.3.0 spec/matcher/many/test_eat.rb