require 'test/unit' require File.join(File.dirname(__FILE__), "minibasic") class ATestMiniBasic < Test::Unit::TestCase def assert_parse(exp, str) res = MiniBasic::Parser.parse_string(str) assert_equal(exp, res) end def assert_stmt(expStmt, str) assert_parse([expStmt], str) end include MiniBasic::Grammar::ASTs def test_01 assert_stmt(PrintLn["PRINTLN"], "PRINTLN") end def test_02 assert_stmt(Read["READ", :A], "READ A") end def test_03 assert_stmt(Print["PRINT", :BC], "PRINT BC") end def test_04 assert_stmt(Assign[:D, ":=", 1], "D := 1") assert_stmt(Assign[:D, ":=", 1], "D :=1") assert_stmt(Assign[:D, ":=", 1], "D:=1") end def test_05 assert_stmt(For["FOR", :A, ":=", 1, "TO", 3, [Assign[:S, ":=", OpExpr[:S, "+", :A]], Print["PRINT", :S], ], "NEXT"], "FOR A := 1 TO 3 S:= S + A PRINT S NEXT") end def atest_06 end end