Sha256: f27f4c58fa391f7d222ebe4db0655a1fa54711a3598d7a2ff96a3aeb99c0abf7

Contents?: true

Size: 974 Bytes

Versions: 2

Compression:

Stored size: 974 Bytes

Contents

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

      let(:yaml){
        <<-YAML
          bool_and:
            - [ bool_lit, bool_lit ]
          bool_lit:
            - true
            - false
          var_name:
            !ruby/regexp /^[a-z]+$/
        YAML
      }

      let(:rules){
        Sexpr.load_yaml(yaml)
      }

      subject{ compile_rules(rules) }

      it{ should be_a(Hash) }

      it 'has expected keys' do
        subject.keys.should eq([:bool_and, :bool_lit, :var_name])
      end

      it 'has expected values' do
        subject.values.each do |val|
          val.should be_a(Matcher::Rule)
        end
      end

      it 'has expected defn' do
        subject[:bool_and].defn.should be_a(Matcher::NonTerminal)
        subject[:bool_lit].defn.should be_a(Matcher::Alternative)
        subject[:var_name].defn.should be_a(Matcher::Terminal)
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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