require 'test/unit' require 'rockit/dparser' class ATestSimpleGrammar < Test::Unit::TestCase SimpleTestGrammar = Rockit::DParser::Grammar.new do start :Str, [[:A, :B, :A, :C, ast(:Str, 0, 1, 3)]] term :A, ["a"] term :B, ["b"] term :C, ["c"] end def test_01_creation_of_grammar assert_kind_of(Rockit::DParser::Grammar, SimpleTestGrammar) assert_equal(1, SimpleTestGrammar.rules.length) assert_equal(3, SimpleTestGrammar.terms.values.length) assert_equal(:Str, SimpleTestGrammar.start_symbol) end def test_02_creation_of_parser parser = SimpleTestGrammar.new_parser assert_kind_of(Rockit::DParser::Parser, parser) end def test_03_use_parser parser = SimpleTestGrammar.new_parser ast = parser.parse "ab a\tc" assert_equal("Str", ast.name) assert_kind_of(parser.astclass_of_name(:Str), ast) assert_equal(3, ast.num_children) assert_equal("a", ast[0]) assert_equal("b", ast[1]) assert_equal("c", ast[2]) end end