sencha-lang/Sencha-lang/Tests/TestASTInspector.cpp

77 lines
2.5 KiB
C++

/*
* TestASTInspector.cpp
*
* Created on: Dec 18, 2012
* Author: att
*/
#include "TestASTInspector.h"
TestASTInspector::TestASTInspector() {
// TODO Auto-generated constructor stub
}
TestASTInspector::~TestASTInspector() {
// TODO Auto-generated destructor stub
}
std::string TestASTInspector::test_inspecting_basic_expression()
{
std::string test_report = "";
BasicExpression * be = new BasicExpression(new ConstantExpression(SenchaObject(9)),
new ConstantExpression(SenchaObject(122)), "+");
be->accept(&inspector);
std::string assert_report = "Report:\n" + inspector.get_report();
muu_assert("ASTInspector didn\'t write any report", inspector.get_report() != "");
muu_assert("Some of nodes were missed in visit", inspector.how_many_visits() == 3);
muu_assert("Some of nodes were missed in visit", inspector.how_many_occurences_of("BasicExpression") == 1);
muu_assert("Some of nodes were missed in visit", inspector.how_many_occurences_of("ConstantExpression") == 2);
delete be;
inspector.forget_everything();
return test_report;
}
std::string TestASTInspector::test_inspecting_simple_AST()
{
std::string test_report = "";
BasicExpression * left = build_basic_expression("-", SenchaObject(88), SenchaObject(-19));
BasicExpression * right = build_basic_expression("*", SenchaObject(9), SenchaObject(12));
BasicExpression * be = build_simple_AST("+", left, right);
be->accept(&inspector);
std::string assert_report = "Report:\n" + inspector.get_report();
muu_assert("ASTInspector didn\'t write any report", inspector.get_report() != "");
muu_assert("Some of nodes were missed in visit", inspector.how_many_visits() == 7);
muu_assert("Some of nodes were missed in visit", inspector.how_many_occurences_of("BasicExpression") == 3);
muu_assert("Some of nodes were missed in visit", inspector.how_many_occurences_of("ConstantExpression") == 4);
delete be;
inspector.forget_everything();
return test_report;
}
std::string TestASTInspector::all_tests()
{
std::string test_report = "";
mu_run_test(test_inspecting_basic_expression);
mu_run_test(test_inspecting_simple_AST);
return test_report;
}
BasicExpression * TestASTInspector::build_basic_expression(std::string oper, SenchaObject arg1, SenchaObject arg2)
{
BasicExpression * be = new BasicExpression(new ConstantExpression( arg1), new ConstantExpression( arg2), oper);
return be;
}
BasicExpression * TestASTInspector::build_simple_AST(std::string oper, BasicExpression * left, BasicExpression * right)
{
BasicExpression * be = new BasicExpression(left, right, oper);
return be;
}