require 'test/unit' require 'parse/ebnf_grammar' include Parse::Grammar class UT_Parse_ebnf_grammar < Test::Unit::TestCase def test_01_Maybe_expansion g = Grammar.new do r :Start, [ [maybe(:A), "1"] ] r :A, ["a"] end g.expand! assert_equal(3, g.nonterminals.length) end def test_02_Plus_expansion g = Grammar.new do r :Start, [ [plus(:A), "1"] ] r :A, ["a"] end g.expand! assert_equal(4, g.nonterminals.length) end def test_03_Mult_expansion g = Grammar.new do r :Start, [ [mult(:A), "1"] ] r :A, ["a"] end g.expand! assert_equal(3, g.nonterminals.length) end def test_04_Group_expansion g = Grammar.new do r :Start, [ [group("1", "2"), "3"] ] end g.expand! puts g.inspect assert_equal(2, g.nonterminals.length) end end