require 'test/unit' require File.join(File.dirname(__FILE__), "java") # We test the grammar in several logical "chunks" below with one TestCase # for each logical chunk. class ATestJavaType < Test::Unit::TestCase def assert_parse(exp, str, startSymbol) res = Java::Parser.parse_string(str, startSymbol) assert_equal(exp, res) end include Java::Grammar::ASTs def test_01_resulttype_void assert_parse([:ResultType, "void"], "void", :ResultType) assert_parse([:ResultType, Type[[:TypeName, "byte"], nil]], "byte", :ResultType) assert_parse([:ResultType, Type[[:TypeName, "byte"], ["[]"]]], "byte[]", :ResultType) assert_parse([:ResultType, Type[[:TypeName, "short"], ["[]", "[]"]]], "short[][]", :ResultType) end def test_02_symbols # Note! We should make each grammar be its own class so that constants # are defined within that scope! JavaSymbols.each do |name, symbol_str| assert_parse(symbol_str, symbol_str, :Symbol) end end def test_03 end end