Sha256: 86682ed3ddcd3392a8810e120cd4e8d30906ad0054db81d04d3f34d101c7e982
Contents?: true
Size: 1.65 KB
Versions: 4
Compression:
Stored size: 1.65 KB
Contents
require "spec_helper" # Some basic tests to make sure that a strategy can deal with trivial # grammars. Since these grammars can only create a single sentence, all # strategies should work. shared_examples_for "basic derivation strategy" do describe "with the production S -> _epsilon_" do before (:each) do @g = Panini::Grammar.new @n = @g.add_nonterminal @n.add_production([]) end it "generates an empty sentence" do d = described_class.new(@g) d.sentence.should be_empty end end describe "with the production S -> 'a'" do before (:each) do @g = Panini::Grammar.new @n = @g.add_nonterminal @n.add_production(['a']) end it "generates the sentence ['a']" do d = described_class.new(@g) d.sentence.should == ['a'] end end describe "with the productions S -> A, A -> 'a'" do before (:each) do @g = Panini::Grammar.new @n_s = @g.add_nonterminal @n_a = @g.add_nonterminal @n_s.add_production([@n_a]) @n_a.add_production(['a']) end it "generates the sentence ['a']" do d = described_class.new(@g) d.sentence.should == ['a'] end end describe "with the productions S -> AB, A -> 'a', B -> 'b'" do before (:each) do @g = Panini::Grammar.new @n_s = @g.add_nonterminal @n_a = @g.add_nonterminal @n_b = @g.add_nonterminal @n_s.add_production([@n_a, @n_b]) @n_a.add_production(['a']) @n_b.add_production(['b']) end it "generates the sentence ['a', 'b']" do d = described_class.new(@g) d.sentence.should == ['a', 'b'] end end end
Version data entries
4 entries across 4 versions & 1 rubygems