Sha256: 6e62d3d847f56e19509643b89894e877ddaee0cc0b0ae9cd8b1c1bd544864ab0

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'
module Sexpr
  module Grammar
    describe Matching, "compile_rule" do
      include Matching

      subject{ compile_rule(:hello, defn) }

      shared_examples_for 'a terminal rule' do
        it{ should be_a(Matcher::Rule) }

        it 'should have the expected defn' do
          subject.defn.should be(defn)
        end

        it 'should have the correct name' do
          subject.name.should eq(:hello)
        end
      end

      shared_examples_for 'a non-terminal rule' do
        it{ should be_a(Matcher::Rule) }

        it 'should have the expected non-terminal' do
          subject.defn.should be_a(Matcher::NonTerminal)
          subject.defn.name.should eq(:hello)
          subject.defn.defn.should be(defn)
        end

        it 'should have the correct name' do
          subject.name.should eq(:hello)
        end
      end

      context 'on Alternative' do
        let(:defn){ Matcher::Alternative.new([]) }

        it_should_behave_like "a terminal rule"
      end

      context 'on Terminal' do
        let(:defn){ Matcher::Terminal.new(true) }

        it_should_behave_like "a terminal rule"
      end

      context 'on Sequence' do
        let(:defn){ Matcher::Sequence.new([]) }

        it_should_behave_like "a non-terminal rule"
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sexpr-1.1.0 spec/unit/grammar/matching/test_compile_rule.rb
sexpr-1.0.0 spec/unit/grammar/matching/test_compile_rule.rb
sexpr-0.6.0 spec/unit/grammar/matching/test_compile_rule.rb